diff --git a/p2p/net/pnet/psk_conn.go b/p2p/net/pnet/psk_conn.go index a6e4247185..b9fc750b3c 100644 --- a/p2p/net/pnet/psk_conn.go +++ b/p2p/net/pnet/psk_conn.go @@ -43,13 +43,10 @@ func (c *pskConn) Read(out []byte) (int, error) { in = in[:maxn] // truncate to required length n, err := c.Conn.Read(in) // read to in - if err != nil { - return 0, err + if n > 0 { + c.readS20.XORKeyStream(out[:n], in[:n]) // decrypt to out buffer } - - c.readS20.XORKeyStream(out[:n], in[:n]) // decrypt to out buffer - - return n, nil + return n, err } func (c *pskConn) Write(in []byte) (int, error) {