Skip to content

Commit

Permalink
Merge pull request Superalgos#5137 from BastianMuc/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Awhiteweb authored May 15, 2024
2 parents b3950fc + d0d99ad commit cba287d
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions Projects/Network/SA/Modules/P2PNetworkNodesConnectedTo.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,9 @@ exports.newNetworkModulesP2PNetworkNodesConnectedTo = function newNetworkModules
// logPeers()
if (thisObject.peers.length >= maxOutgoingPeers) {
checkConnectedPeers()
if(thisObject.peers.length >= maxOutgoingPeers) {
const itemsToPrune = thisObject.peers.splice(0, maxOutgoingPeers)
for(let i = 0; i < itemsToPrune.length; i++) {
itemsToPrune[i].webSocketsClient.finalize()
}
}
intervalIdConnectToPeers = setTimeout(connectToPeers, RECONNECT_DELAY)
return
}
let processedPeers = []
for (let i = 0; i < p2pNetwork.p2pNodesToConnect.length; i++) {
if (thisObject.peers.length >= maxOutgoingPeers) {
SA.logger.info('breaking from loop due to max peers being met')
Expand All @@ -83,7 +76,7 @@ exports.newNetworkModulesP2PNetworkNodesConnectedTo = function newNetworkModules
}

peer.webSocketsClient = SA.projects.network.modules.webSocketsNetworkClient.newNetworkModulesWebSocketsNetworkClient()
const task = peer.webSocketsClient.initialize(
await peer.webSocketsClient.initialize(
callerRole,
p2pNetworkClientIdentity,
peer.p2pNetworkNode,
Expand All @@ -92,10 +85,9 @@ exports.newNetworkModulesP2PNetworkNodesConnectedTo = function newNetworkModules
)
.then(addPeer)
.catch(onError)
processedPeers.push(task)
// automatically add to the peer group then remove if connection is unsuccessful
thisObject.peers.push(peer)

function addPeer() {
thisObject.peers.push(peer)
SA.logger.info('added peer ' + peerInfo(peer))
// logPeers()
// console.log('this is our connected network peers', thisObject.peers)
Expand Down Expand Up @@ -128,8 +120,6 @@ exports.newNetworkModulesP2PNetworkNodesConnectedTo = function newNetworkModules
}
}

await Promise.all(processedPeers)

function isPeerConnected(peer) {
return findPeerIndex(peer) > -1
}
Expand Down

0 comments on commit cba287d

Please sign in to comment.