Commit de9f6f64 authored by Kirill Smelkov's avatar Kirill Smelkov

go/{zeo,neo}: handshake: Report "unexpected EOF" if peer sends only partial data

NEO was already doing this, but let's use xio.NoEOF everywhere for
uniformity.
parent 1986a126
// Copyright (C) 2016-2018 Nexedi SA and Contributors. // Copyright (C) 2016-2020 Nexedi SA and Contributors.
// Kirill Smelkov <kirr@nexedi.com> // Kirill Smelkov <kirr@nexedi.com>
// //
// This program is free software: you can Use, Study, Modify and Redistribute // This program is free software: you can Use, Study, Modify and Redistribute
...@@ -29,6 +29,7 @@ import ( ...@@ -29,6 +29,7 @@ import (
"sync" "sync"
"lab.nexedi.com/kirr/go123/xnet" "lab.nexedi.com/kirr/go123/xnet"
"lab.nexedi.com/kirr/neo/go/internal/xio"
"lab.nexedi.com/kirr/neo/go/neo/proto" "lab.nexedi.com/kirr/neo/go/neo/proto"
) )
...@@ -84,9 +85,7 @@ func handshake(ctx context.Context, conn net.Conn, version uint32) (err error) { ...@@ -84,9 +85,7 @@ func handshake(ctx context.Context, conn net.Conn, version uint32) (err error) {
go func() { go func() {
var b [4]byte var b [4]byte
_, err := io.ReadFull(conn, b[:]) _, err := io.ReadFull(conn, b[:])
if err == io.EOF { err = xio.NoEOF(err) // can be returned with n = 0
err = io.ErrUnexpectedEOF // can be returned with n = 0
}
if err == nil { if err == nil {
peerVersion := binary.BigEndian.Uint32(b[:]) // XXX -> ntoh32 ? peerVersion := binary.BigEndian.Uint32(b[:]) // XXX -> ntoh32 ?
if peerVersion != version { if peerVersion != version {
......
...@@ -479,7 +479,7 @@ func handshake(ctx context.Context, conn net.Conn) (_ *zLink, err error) { ...@@ -479,7 +479,7 @@ func handshake(ctx context.Context, conn net.Conn) (_ *zLink, err error) {
// first letter is preferred encoding: 'M' (msgpack), or 'Z' (pickles). // first letter is preferred encoding: 'M' (msgpack), or 'Z' (pickles).
pkb, err := zl.recvPkt() pkb, err := zl.recvPkt()
if err != nil { if err != nil {
return fmt.Errorf("rx: %s", err) return fmt.Errorf("rx: %s", xio.NoEOF(err))
} }
proto := string(pkb.Payload()) proto := string(pkb.Payload())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment