From 26f0fc331940d3f76529ca50d93dc14e41fa6b12 Mon Sep 17 00:00:00 2001 From: Zack Scholl Date: Mon, 24 Sep 2018 08:29:54 -0700 Subject: [PATCH] ok windows seems to work now --- main.go | 4 ++++ src/comm/comm.go | 16 +++++----------- src/recipient/recipient.go | 2 +- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index 72fcccd..d73009d 100644 --- a/main.go +++ b/main.go @@ -69,6 +69,7 @@ func main() { cli.BoolFlag{Name: "debug", Usage: "increase verbosity (a lot)"}, cli.BoolFlag{Name: "yes", Usage: "automatically agree to all prompts"}, cli.BoolFlag{Name: "stdout", Usage: "redirect file to stdout"}, + cli.BoolFlag{Name: "force-tcp", Usage: "force TCP"}, cli.StringFlag{Name: "port", Value: "8153", Usage: "port that the websocket listens on"}, cli.StringFlag{Name: "tcp-port", Value: "8154", Usage: "port that the tcp server listens on"}, cli.StringFlag{Name: "curve", Value: "siec", Usage: "specify elliptic curve to use (p224, p256, p384, p521, siec)"}, @@ -96,6 +97,9 @@ func main() { cr.RelayWebsocketPort = c.String("port") cr.RelayTCPPort = c.String("tcp-port") cr.CurveType = c.String("curve") + if c.GlobalBool("force-tcp") { + cr.ForceSend = 2 + } return nil } diff --git a/src/comm/comm.go b/src/comm/comm.go index 7b3554d..a58cd6d 100644 --- a/src/comm/comm.go +++ b/src/comm/comm.go @@ -70,26 +70,20 @@ func (c Comm) Read() (buf []byte, numBytes int, bs []byte, err error) { if err != nil { return nil, 0, nil, err } - buf = make([]byte, numBytes) + buf = []byte{} tmp = make([]byte, numBytes) - bufStart := 0 for { n, err := c.connection.Read(tmp) if err != nil { return nil, 0, nil, err } - tmpCopy := make([]byte, n) + tmpCopy = make([]byte, n) // Copy the buffer so it doesn't get changed while read by the recipient. copy(tmpCopy, tmp[:n]) - - tmpCopy = bytes.TrimSpace(tmpCopy) - tmpCopy = bytes.Replace(tmpCopy, []byte(" "), []byte{}, -1) - tmpCopy = bytes.Trim(tmpCopy, "\x00") - copy(buf[bufStart:bufStart+len(tmpCopy)], tmpCopy[:]) - bufStart = len(buf) - if bufStart < numBytes { + buf = append(buf, bytes.TrimRight(tmpCopy, "\x00")...) + if len(buf) < numBytes { // shrink the amount we need to read - tmp = tmp[:numBytes-bufStart] + tmp = tmp[:numBytes-len(buf)] } else { break } diff --git a/src/recipient/recipient.go b/src/recipient/recipient.go index aacfcdb..d2b7e92 100644 --- a/src/recipient/recipient.go +++ b/src/recipient/recipient.go @@ -221,7 +221,7 @@ func receive(forceSend int, serverAddress, serverTCP string, isLocal bool, c *we var enc crypt.Encryption err = json.Unmarshal(message, &enc) if err != nil { - log.Errorf("%s: %s (%d/%d) %+v", err.Error(), message, len(message), numBytes, bs) + log.Errorf("%s: [%s] [%+v] (%d/%d) %+v", err.Error(), message, message, len(message), numBytes, bs) return err } decrypted, err := enc.Decrypt(sessionKey, !fstats.IsEncrypted)