mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
p2p: fix maxDialedConns for maxpeers < dialRatio
Always allocate at least one dial slot unless dialing is disabled using NoDial or MaxPeers == 0. Most importantly, this fixes MaxPeers == 1 to dedicate the sole slot to dialing instead of listening.
This commit is contained in:
parent
463842c950
commit
af30b4d982
1 changed files with 10 additions and 6 deletions
|
|
@ -620,15 +620,19 @@ func (srv *Server) maxInboundConns() int {
|
|||
return srv.MaxPeers - srv.maxDialedConns()
|
||||
}
|
||||
|
||||
func (srv *Server) maxDialedConns() int {
|
||||
if srv.NoDial {
|
||||
func (srv *Server) maxDialedConns() (limit int) {
|
||||
if srv.NoDial || srv.MaxPeers == 0 {
|
||||
return 0
|
||||
}
|
||||
r := srv.DialRatio
|
||||
if r == 0 {
|
||||
r = defaultDialRatio
|
||||
if srv.DialRatio == 0 {
|
||||
limit = srv.MaxPeers / defaultDialRatio
|
||||
} else {
|
||||
limit = srv.MaxPeers / srv.DialRatio
|
||||
}
|
||||
return srv.MaxPeers / r
|
||||
if limit == 0 {
|
||||
limit = 1
|
||||
}
|
||||
return limit
|
||||
}
|
||||
|
||||
func (srv *Server) setupListening() error {
|
||||
|
|
|
|||
Loading…
Reference in a new issue