@@ -518,7 +518,7 @@ func (srv *Server) startPeer(fd net.Conn, dest *discover.Node) {
518
518
conn : fd , rtimeout : frameReadTimeout , wtimeout : frameWriteTimeout ,
519
519
}
520
520
p := newPeer (fd , conn , srv .Protocols )
521
- if ok , reason := srv .addPeer (conn . ID , p ); ! ok {
521
+ if ok , reason := srv .addPeer (conn , p ); ! ok {
522
522
glog .V (logger .Detail ).Infof ("Not adding %v (%v)\n " , p , reason )
523
523
p .politeDisconnect (reason )
524
524
srv .peerWG .Done ()
@@ -564,13 +564,18 @@ func (srv *Server) runPeer(p *Peer) {
564
564
})
565
565
}
566
566
567
- func (srv * Server ) addPeer (id discover.NodeID , p * Peer ) (bool , DiscReason ) {
567
+ func (srv * Server ) addPeer (conn * conn , p * Peer ) (bool , DiscReason ) {
568
+ // drop connections with no matching protocols.
569
+ if len (srv .Protocols ) > 0 && countMatchingProtocols (srv .Protocols , conn .protoHandshake .Caps ) == 0 {
570
+ return false , DiscUselessPeer
571
+ }
572
+ // add the peer if it passes the other checks.
568
573
srv .lock .Lock ()
569
574
defer srv .lock .Unlock ()
570
- if ok , reason := srv .checkPeer (id ); ! ok {
575
+ if ok , reason := srv .checkPeer (conn . ID ); ! ok {
571
576
return false , reason
572
577
}
573
- srv .peers [id ] = p
578
+ srv .peers [conn . ID ] = p
574
579
return true , 0
575
580
}
576
581
0 commit comments