diff options
author | obscuren <geffobscura@gmail.com> | 2014-09-16 22:19:48 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-09-16 22:19:48 +0800 |
commit | fb528c47c0c51a7a204a18227349e6500aba49ab (patch) | |
tree | 73a3f432d8f44f6e76ef4b8cd91b39165a76c35e /ethwire/messaging.go | |
parent | 74de0f1f2ab342466556baddbab166a284f86891 (diff) | |
download | go-tangerine-fb528c47c0c51a7a204a18227349e6500aba49ab.tar go-tangerine-fb528c47c0c51a7a204a18227349e6500aba49ab.tar.gz go-tangerine-fb528c47c0c51a7a204a18227349e6500aba49ab.tar.bz2 go-tangerine-fb528c47c0c51a7a204a18227349e6500aba49ab.tar.lz go-tangerine-fb528c47c0c51a7a204a18227349e6500aba49ab.tar.xz go-tangerine-fb528c47c0c51a7a204a18227349e6500aba49ab.tar.zst go-tangerine-fb528c47c0c51a7a204a18227349e6500aba49ab.zip |
Moved code
Diffstat (limited to 'ethwire/messaging.go')
-rw-r--r-- | ethwire/messaging.go | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/ethwire/messaging.go b/ethwire/messaging.go index 99f6be8db..4f4393a9d 100644 --- a/ethwire/messaging.go +++ b/ethwire/messaging.go @@ -109,29 +109,24 @@ func ReadMessages(conn net.Conn) (msgs []*Msg, err error) { } } - if n == 0 { + if n == 0 && len(buff) == 0 { continue } + buff = append(buff, b[:n]...) if msgLength == 0 { // Check if the received 4 first bytes are the magic token - if bytes.Compare(MagicToken, b[:4]) != 0 { - return nil, fmt.Errorf("MagicToken mismatch. Received %v", b[:4]) + if bytes.Compare(MagicToken, buff[:4]) != 0 { + return nil, fmt.Errorf("MagicToken mismatch. Received %v", buff[:4]) } - // Remove the token - b = b[4:] // Read the length of the message - msgLength = int(ethutil.BytesToNumber(b[:4])) - - // Remove the length - b = b[4:] + msgLength = int(ethutil.BytesToNumber(buff[4:8])) - n -= 8 + // Remove the token and length + buff = buff[8:] } - buff = append(buff, b[:n]...) - if len(buff) >= msgLength { messages = append(messages, buff[:msgLength]) buff = buff[msgLength:] |