[REFACTOR] PKT protocol

- Use `Fprintf` to convert to hex and do padding. Simplifies the code.
- Use `Read()` and `io.ReadFull` instead of `ReadByte()`. Should improve
performance and allows for cleaner code.
- s/pktLineTypeUnknow/pktLineTypeUnknown.
- Disallow empty Pkt line per the specification.
- Disallow too large Pkt line per the specification.
- Add unit tests.
This commit is contained in:
Gusted 2024-03-29 00:20:21 +01:00
parent a11116602e
commit 2c8bcc163e
No known key found for this signature in database
GPG key ID: FD821B732837125F
3 changed files with 93 additions and 52 deletions

View file

@ -14,6 +14,7 @@ import (
"regexp"
"strconv"
"strings"
"testing"
"time"
"unicode"
@ -106,7 +107,10 @@ func fail(ctx context.Context, userMessage, logMsgFmt string, args ...any) error
logMsg = userMessage + ". " + logMsg
}
}
_ = private.SSHLog(ctx, true, logMsg)
// Don't send an log if this is done in a test and no InternalToken is set.
if !testing.Testing() || setting.InternalToken != "" {
_ = private.SSHLog(ctx, true, logMsg)
}
}
return cli.Exit("", 1)
}