0
0
Fork 0
mirror of https://github.com/schollz/croc.git synced 2025-10-11 13:21:00 +02:00

improve comm

This commit is contained in:
Zack Scholl 2018-09-23 19:24:57 -07:00
parent ba20bb63ca
commit 711f8dfeec
3 changed files with 11 additions and 10 deletions

View file

@ -44,12 +44,12 @@ func (c Comm) Read() (buf []byte, numBytes int, bs []byte, err error) {
if err != nil {
return
}
tmp := make([]byte, 1)
for {
bs = bytes.Trim(bytes.Trim(bs, "\x00"), "\x05")
bs = bytes.Trim(bs, "\x00")
if len(bs) == 5 {
break
}
tmp := make([]byte, 1)
c.connection.Read(tmp)
bs = append(bs, tmp...)
}
@ -57,18 +57,19 @@ func (c Comm) Read() (buf []byte, numBytes int, bs []byte, err error) {
if err != nil {
return nil, 0, nil, err
}
buf = []byte{}
tmp := make([]byte, numBytes)
buf = make([]byte, numBytes)
tmp = make([]byte, numBytes)
bufStart := 0
for {
_, err = c.connection.Read(tmp)
if err != nil {
return nil, numBytes, bs, err
}
tmp = bytes.TrimRight(tmp, "\x00")
tmp = bytes.TrimRight(tmp, "\x05")
buf = append(buf, tmp...)
if len(buf) < numBytes {
tmp = make([]byte, numBytes-len(buf))
copy(buf[bufStart:bufStart+len(tmp)], tmp[:])
bufStart += len(tmp)
if bufStart < numBytes {
tmp = tmp[:numBytes-bufStart]
} else {
break
}

View file

@ -62,7 +62,7 @@ func receive(serverAddress, serverTCP string, isLocal bool, c *websocket.Conn, c
pw := []byte(codephrase)
// initialize recipient Q ("1" indicates recipient)
Q, err := pake.Init(pw, 1, curve, 100*time.Millisecond)
Q, err := pake.Init(pw, 1, curve, 1*time.Millisecond)
if err != nil {
return
}

View file

@ -73,7 +73,7 @@ func send(serverAddress, serverTCP string, isLocal bool, c *websocket.Conn, fnam
// both parties should have a weak key
pw := []byte(codephrase)
// initialize sender P ("0" indicates sender)
P, err := pake.Init(pw, 0, curve, 100*time.Millisecond)
P, err := pake.Init(pw, 0, curve, 1*time.Millisecond)
if err != nil {
return
}