aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/server.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-05-08 22:09:38 +0800
committerFelix Lange <fjl@twurst.com>2015-05-08 22:09:55 +0800
commitd4f0a67323dec12e5b84ba4907970267a2e27601 (patch)
tree1136276c2c0a3a1067edc1ec4d05858bc1bbc4fb /p2p/server.go
parente45d9bb29d3c04d57fd40533b43ea7929b6a4513 (diff)
downloadgo-tangerine-d4f0a67323dec12e5b84ba4907970267a2e27601.tar.gz
go-tangerine-d4f0a67323dec12e5b84ba4907970267a2e27601.tar.zst
go-tangerine-d4f0a67323dec12e5b84ba4907970267a2e27601.zip
p2p: drop connections with no matching protocols
Diffstat (limited to 'p2p/server.go')
-rw-r--r--p2p/server.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/p2p/server.go b/p2p/server.go
index 171798a1d..3c6fb5893 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -518,7 +518,7 @@ func (srv *Server) startPeer(fd net.Conn, dest *discover.Node) {
conn: fd, rtimeout: frameReadTimeout, wtimeout: frameWriteTimeout,
}
p := newPeer(fd, conn, srv.Protocols)
- if ok, reason := srv.addPeer(conn.ID, p); !ok {
+ if ok, reason := srv.addPeer(conn, p); !ok {
glog.V(logger.Detail).Infof("Not adding %v (%v)\n", p, reason)
p.politeDisconnect(reason)
srv.peerWG.Done()
@@ -564,13 +564,18 @@ func (srv *Server) runPeer(p *Peer) {
})
}
-func (srv *Server) addPeer(id discover.NodeID, p *Peer) (bool, DiscReason) {
+func (srv *Server) addPeer(conn *conn, p *Peer) (bool, DiscReason) {
+ // drop connections with no matching protocols.
+ if len(srv.Protocols) > 0 && countMatchingProtocols(srv.Protocols, conn.protoHandshake.Caps) == 0 {
+ return false, DiscUselessPeer
+ }
+ // add the peer if it passes the other checks.
srv.lock.Lock()
defer srv.lock.Unlock()
- if ok, reason := srv.checkPeer(id); !ok {
+ if ok, reason := srv.checkPeer(conn.ID); !ok {
return false, reason
}
- srv.peers[id] = p
+ srv.peers[conn.ID] = p
return true, 0
}