aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/server.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2015-05-04 22:35:49 +0800
committerPéter Szilágyi <peterke@gmail.com>2015-05-07 20:30:56 +0800
commit4d5a719f256d7dfbaab2cc9c632cd7996067508f (patch)
treed4841e10035f4fd557ef09f2f4c2f478dc3bf762 /p2p/server.go
parentaf932177755f5f839ab29b16dc490d3e1bb3708d (diff)
downloaddexon-4d5a719f256d7dfbaab2cc9c632cd7996067508f.tar
dexon-4d5a719f256d7dfbaab2cc9c632cd7996067508f.tar.gz
dexon-4d5a719f256d7dfbaab2cc9c632cd7996067508f.tar.bz2
dexon-4d5a719f256d7dfbaab2cc9c632cd7996067508f.tar.lz
dexon-4d5a719f256d7dfbaab2cc9c632cd7996067508f.tar.xz
dexon-4d5a719f256d7dfbaab2cc9c632cd7996067508f.tar.zst
dexon-4d5a719f256d7dfbaab2cc9c632cd7996067508f.zip
cmd, eth, p2p: introduce pending peer cli arg, add tests
Diffstat (limited to 'p2p/server.go')
-rw-r--r--p2p/server.go25
1 files changed, 18 insertions, 7 deletions
diff --git a/p2p/server.go b/p2p/server.go
index 164aaba37..77f66f167 100644
--- a/p2p/server.go
+++ b/p2p/server.go
@@ -22,9 +22,7 @@ const (
refreshPeersInterval = 30 * time.Second
staticPeerCheckInterval = 15 * time.Second
- // This is the maximum number of inbound connection
- // that are allowed to linger between 'accepted' and
- // 'added as peer'.
+ // Maximum number of concurrently handshaking inbound connections.
maxAcceptConns = 10
// Maximum number of concurrently dialing outbound connections.
@@ -55,6 +53,11 @@ type Server struct {
// connected. It must be greater than zero.
MaxPeers int
+ // MaxPendingPeers is the maximum number of peers that can be pending in the
+ // handshake phase, counted separately for inbound and outbound connections.
+ // Zero defaults to preset values.
+ MaxPendingPeers int
+
// Name sets the node name of this server.
// Use common.MakeName to create a name that follows existing conventions.
Name string
@@ -334,8 +337,12 @@ func (srv *Server) listenLoop() {
// This channel acts as a semaphore limiting
// active inbound connections that are lingering pre-handshake.
// If all slots are taken, no further connections are accepted.
- slots := make(chan struct{}, maxAcceptConns)
- for i := 0; i < maxAcceptConns; i++ {
+ tokens := maxAcceptConns
+ if srv.MaxPendingPeers > 0 {
+ tokens = srv.MaxPendingPeers
+ }
+ slots := make(chan struct{}, tokens)
+ for i := 0; i < tokens; i++ {
slots <- struct{}{}
}
@@ -405,8 +412,12 @@ func (srv *Server) dialLoop() {
defer refresh.Stop()
// Limit the number of concurrent dials
- slots := make(chan struct{}, maxDialingConns)
- for i := 0; i < maxDialingConns; i++ {
+ tokens := maxAcceptConns
+ if srv.MaxPendingPeers > 0 {
+ tokens = srv.MaxPendingPeers
+ }
+ slots := make(chan struct{}, tokens)
+ for i := 0; i < tokens; i++ {
slots <- struct{}{}
}
dial := func(dest *discover.Node) {