diff options
author | Felföldi Zsolt <zsfelfoldi@gmail.com> | 2019-03-20 16:35:05 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-03-20 16:35:05 +0800 |
commit | c53c5e616f04ae8b041bfb64309cbc7f3e70303a (patch) | |
tree | b71b353e670031efbd6b952296a985b5e02e7d9a | |
parent | e7d1867964734cfa4c1067944f213ba5aaceffe1 (diff) | |
download | go-tangerine-c53c5e616f04ae8b041bfb64309cbc7f3e70303a.tar go-tangerine-c53c5e616f04ae8b041bfb64309cbc7f3e70303a.tar.gz go-tangerine-c53c5e616f04ae8b041bfb64309cbc7f3e70303a.tar.bz2 go-tangerine-c53c5e616f04ae8b041bfb64309cbc7f3e70303a.tar.lz go-tangerine-c53c5e616f04ae8b041bfb64309cbc7f3e70303a.tar.xz go-tangerine-c53c5e616f04ae8b041bfb64309cbc7f3e70303a.tar.zst go-tangerine-c53c5e616f04ae8b041bfb64309cbc7f3e70303a.zip |
les: fix peer id and reply error handling (#19289)
* les: fixed peer id format
* les: fixed peer reply error handling
-rw-r--r-- | les/handler.go | 10 | ||||
-rw-r--r-- | les/peer.go | 5 |
2 files changed, 11 insertions, 4 deletions
diff --git a/les/handler.go b/les/handler.go index 50c32fb95..7c290b717 100644 --- a/les/handler.go +++ b/les/handler.go @@ -329,6 +329,11 @@ func (pm *ProtocolManager) handle(p *peer) error { // handleMsg is invoked whenever an inbound message is received from a remote // peer. The remote connection is torn down upon returning any error. func (pm *ProtocolManager) handleMsg(p *peer) error { + select { + case err := <-p.errCh: + return err + default: + } // Read the next message from the remote peer, and ensure it's fully consumed msg, err := p.rw.ReadMsg() if err != nil { @@ -389,7 +394,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error { if reply != nil { p.queueSend(func() { if err := reply.send(bv); err != nil { - p.errCh <- err + select { + case p.errCh <- err: + default: + } } }) } diff --git a/les/peer.go b/les/peer.go index 8b506de62..0c15add9c 100644 --- a/les/peer.go +++ b/les/peer.go @@ -98,15 +98,14 @@ type peer struct { } func newPeer(version int, network uint64, isTrusted bool, p *p2p.Peer, rw p2p.MsgReadWriter) *peer { - id := p.ID() - return &peer{ Peer: p, rw: rw, version: version, network: network, - id: fmt.Sprintf("%x", id), + id: fmt.Sprintf("%x", p.ID().Bytes()), isTrusted: isTrusted, + errCh: make(chan error, 1), } } |