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