mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-02-22 22:36:34 +01:00
node: Fix bug where we we could have more connections than allowed by bitcoin-s.node.maxConnectedPeers
(#5885)
* node: Fix bug where we we could have more connections than allowed by bitcoin-s.node.maxConnectedPeers * node: Add log to indiciate if we are initializing disconnect
This commit is contained in:
parent
6a51b7c103
commit
52040da386
1 changed files with 11 additions and 4 deletions
|
@ -575,7 +575,7 @@ case class PeerManager(
|
|||
case m: MisbehavingPeer =>
|
||||
// disconnect the misbehaving peer
|
||||
for {
|
||||
_ <- disconnectPeer(m.badPeer)
|
||||
_ <- handleInitializeDisconnect(m.badPeer, m)
|
||||
} yield {
|
||||
runningState
|
||||
}
|
||||
|
@ -1111,9 +1111,10 @@ case class PeerManager(
|
|||
val notCfPeers = runningState.peerDataMap
|
||||
.filter(p => !p._2.serviceIdentifier.nodeCompactFilters)
|
||||
.keys
|
||||
val availableFilterSlot = hasCf && notCfPeers.nonEmpty
|
||||
val hasConnectionSlot =
|
||||
runningState.connectedPeerCount < nodeAppConfig.maxConnectedPeers
|
||||
val availableFilterSlot = hasCf && notCfPeers.nonEmpty
|
||||
|
||||
val newStateF: Future[NodeRunningState] = {
|
||||
if (hasConnectionSlot || availableFilterSlot) {
|
||||
val addPeerF: Future[NodeRunningState] = runningState match {
|
||||
|
@ -1155,13 +1156,18 @@ case class PeerManager(
|
|||
|
||||
addPeerF.flatMap { addPeer =>
|
||||
if (availableFilterSlot && notCfPeers.nonEmpty) {
|
||||
disconnectPeer(notCfPeers.head).map(_ => addPeer)
|
||||
handleInitializeDisconnect(peer = notCfPeers.head, state = addPeer)
|
||||
} else {
|
||||
Future.successful(addPeer)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Future.successful(runningState)
|
||||
// we don't have a connection slot or a filter slot
|
||||
// for this peer so disconnect it
|
||||
peerDataOpt
|
||||
.map(_.disconnect())
|
||||
.map(f => f.map(_ => runningState))
|
||||
.getOrElse(Future.successful(runningState))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1187,6 +1193,7 @@ case class PeerManager(
|
|||
)
|
||||
Future.successful(running)
|
||||
} else {
|
||||
logger.info(s"Initializing disconnect for peer=$peer state=$state")
|
||||
val client: PeerData =
|
||||
running.getPeerData(peer) match {
|
||||
case Some(p) => p
|
||||
|
|
Loading…
Add table
Reference in a new issue