@ -113,17 +113,16 @@ func (t *rlpxTransport) close(err error) {
// Tell the remote end why we're disconnecting if possible.
// Tell the remote end why we're disconnecting if possible.
// We only bother doing this if the underlying connection supports
// We only bother doing this if the underlying connection supports
// setting a timeout tough.
// setting a timeout tough.
if t . conn != nil {
if reason , ok := err . ( DiscReason ) ; ok && reason != DiscNetworkError {
if r , ok := err . ( DiscReason ) ; ok && r != DiscNetworkError {
// We do not use the WriteMsg func since we want a custom deadline
deadline := time . Now ( ) . Add ( discWriteTimeout )
deadline := time . Now ( ) . Add ( discWriteTimeout )
if err := t . conn . SetWriteDeadline ( deadline ) ; err == nil {
if err := t . conn . SetWriteDeadline ( deadline ) ; err == nil {
// Connection supports write deadline.
// Connection supports write deadline.
t . wbuf . Reset ( )
t . wbuf . Reset ( )
rlp . Encode ( & t . wbuf , [ ] DiscRe aso n{ r } )
rlp . Encode ( & t . wbuf , [ ] any { reason } )
t . conn . Write ( discMsg , t . wbuf . Bytes ( ) )
t . conn . Write ( discMsg , t . wbuf . Bytes ( ) )
}
}
}
}
}
t . conn . Close ( )
t . conn . Close ( )
}
}
@ -163,11 +162,8 @@ func readProtocolHandshake(rw MsgReader) (*protoHandshake, error) {
if msg . Code == discMsg {
if msg . Code == discMsg {
// Disconnect before protocol handshake is valid according to the
// Disconnect before protocol handshake is valid according to the
// spec and we send it ourself if the post-handshake checks fail.
// spec and we send it ourself if the post-handshake checks fail.
// We can't return the reason directly, though, because it is echoed
r := decodeDisconnectMessage ( msg . Payload )
// back otherwise. Wrap it in a string instead.
return nil , r
var reason [ 1 ] DiscReason
rlp . Decode ( msg . Payload , & reason )
return nil , reason [ 0 ]
}
}
if msg . Code != handshakeMsg {
if msg . Code != handshakeMsg {
return nil , fmt . Errorf ( "expected handshake, got %x" , msg . Code )
return nil , fmt . Errorf ( "expected handshake, got %x" , msg . Code )