1
0
mirror of https://github.com/schollz/croc.git synced 2024-11-27 12:34:19 +03:00

ok windows seems to work now

This commit is contained in:
Zack Scholl 2018-09-24 08:29:54 -07:00
parent 5397634217
commit 26f0fc3319
3 changed files with 10 additions and 12 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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)