network: fix logic and logging for sendVersion() errors

It doesn't make sense trying to read from a broken connection and the
disconnect is to be logger from the server on unregistration.
This commit is contained in:
Roman Khimov 2020-01-13 16:56:59 +03:00
parent b5f234ddef
commit 2192b6602a

View file

@ -82,9 +82,8 @@ func (t *TCPTransport) handleConn(conn net.Conn) {
t.server.register <- p
// When a new peer is connected we send out our version immediately.
if err := t.server.sendVersion(p); err != nil {
t.log.Error("error on sendVersion", zap.Stringer("addr", p.RemoteAddr()), zap.Error(err))
}
err = t.server.sendVersion(p)
if err == nil {
r := io.NewBinReaderFromIO(p.conn)
for {
msg := &Message{}
@ -100,6 +99,7 @@ func (t *TCPTransport) handleConn(conn net.Conn) {
break
}
}
}
t.server.unregister <- peerDrop{p, err}
p.Disconnect(err)
}