Browse Source

les: fix peer id and reply error handling (#19289)

* les: fixed peer id format

* les: fixed peer reply error handling
Felföldi Zsolt 6 years ago
parent
commit
c53c5e616f
2 changed files with 11 additions and 4 deletions
  1. 9 1
      les/handler.go
  2. 2 3
      les/peer.go

+ 9 - 1
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
 // handleMsg is invoked whenever an inbound message is received from a remote
 // peer. The remote connection is torn down upon returning any error.
 // peer. The remote connection is torn down upon returning any error.
 func (pm *ProtocolManager) handleMsg(p *peer) 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
 	// Read the next message from the remote peer, and ensure it's fully consumed
 	msg, err := p.rw.ReadMsg()
 	msg, err := p.rw.ReadMsg()
 	if err != nil {
 	if err != nil {
@@ -389,7 +394,10 @@ func (pm *ProtocolManager) handleMsg(p *peer) error {
 		if reply != nil {
 		if reply != nil {
 			p.queueSend(func() {
 			p.queueSend(func() {
 				if err := reply.send(bv); err != nil {
 				if err := reply.send(bv); err != nil {
-					p.errCh <- err
+					select {
+					case p.errCh <- err:
+					default:
+					}
 				}
 				}
 			})
 			})
 		}
 		}

+ 2 - 3
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 {
 func newPeer(version int, network uint64, isTrusted bool, p *p2p.Peer, rw p2p.MsgReadWriter) *peer {
-	id := p.ID()
-
 	return &peer{
 	return &peer{
 		Peer:      p,
 		Peer:      p,
 		rw:        rw,
 		rw:        rw,
 		version:   version,
 		version:   version,
 		network:   network,
 		network:   network,
-		id:        fmt.Sprintf("%x", id),
+		id:        fmt.Sprintf("%x", p.ID().Bytes()),
 		isTrusted: isTrusted,
 		isTrusted: isTrusted,
+		errCh:     make(chan error, 1),
 	}
 	}
 }
 }