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