@@ -272,14 +272,9 @@ void P2P::ListenerThread(int update_interval)
272272 fromIPString += std::to_string (ntohs (remoteAddr.sin_port ));
273273
274274 // See if peer is somewhere in the peerlist
275- if (InPeerList (fromIPString)){
276- // Reset life of this peer to 0
277- p2pConnections[fromIPString]->life = 0 ;
278- }
279- else {
280- // Add peer to collection of connections
281- AddToPeerList (fromIPString);
282- }
275+ AddToPeerList (fromIPString);
276+ // Reset life of this peer to 0
277+ p2pConnections[fromIPString]->life = 0 ;
283278
284279 // If not currently connected, accept this connection.
285280 if ((otherAddrStr == " " || otherAddrStr == " 0.0.0.0:0" ) && otherAddrStr != clientIPPort){
@@ -386,11 +381,10 @@ void P2P::ListenerThread(int update_interval)
386381
387382 CONNECTED_TO_PEER = true ;
388383
389- // Add item to peer list, and save to file
390- if (!InPeerList (otherAddrStr)){
391- // Add peer to collection of connections
392- AddToPeerList (otherAddrStr);
393- }
384+ // Add peer to collection of connections
385+ AddToPeerList (otherAddrStr);
386+
387+ p2pConnections[otherAddrStr]->testedOnline = true ;
394388 }
395389 // If the peer is ending the connection
396390 else if (totalMessage == " peer~disconnect" ) {
@@ -519,9 +513,7 @@ void P2P::ListenerThread(int update_interval)
519513 messagePrefix += " announce~" ;
520514 json announcedInfo = json::parse (totalMessage.substr (messagePrefix.size ()));
521515 // Add peer to collection of connections if not there yet
522- if (p2pConnections.find (otherAddrStr) == p2pConnections.end ()){
523- AddToPeerList (otherAddrStr);
524- }
516+ AddToPeerList (otherAddrStr);
525517
526518 p2pConnections[otherAddrStr]->height = announcedInfo[" height" ];
527519 p2pConnections[otherAddrStr]->peerList = announcedInfo[" peerList" ];
@@ -634,17 +626,12 @@ void P2P::InitPeerList() {
634626 // Create a new Peer entry in p2pConnections for each address
635627 while (std::getline (peerFile, line)) {
636628 if (line[0 ] != ' #' && line != " " ){
637- if (!InPeerList (line)){
638- // Add peer to collection of connections
639- AddToPeerList (line);
640- }
629+ AddToPeerList (line);
641630 }
642631 }
643632 // If DCCARK is not in peerlist, add it.
644633 std::string arkIP = DCCARK_ADDR;
645- if (!InPeerList (arkIP)){
646- AddToPeerList (arkIP);
647- }
634+ AddToPeerList (arkIP);
648635
649636 peerFile.close ();
650637 SavePeerList ();
0 commit comments