(self)
| 902 | return found[0:need_num] |
| 903 | |
| 904 | def getConnectedPeers(self): |
| 905 | back = [] |
| 906 | if not self.connection_server: |
| 907 | return [] |
| 908 | |
| 909 | tor_manager = self.connection_server.tor_manager |
| 910 | for connection in self.connection_server.connections: |
| 911 | if not connection.connected and time.time() - connection.start_time > 20: # Still not connected after 20s |
| 912 | continue |
| 913 | peer = self.peers.get("%s:%s" % (connection.ip, connection.port)) |
| 914 | if peer: |
| 915 | if connection.ip.endswith(".onion") and connection.target_onion and tor_manager.start_onions: |
| 916 | # Check if the connection is made with the onion address created for the site |
| 917 | valid_target_onions = (tor_manager.getOnion(self.address), tor_manager.getOnion("global")) |
| 918 | if connection.target_onion not in valid_target_onions: |
| 919 | continue |
| 920 | if not peer.connection: |
| 921 | peer.connect(connection) |
| 922 | back.append(peer) |
| 923 | return back |
| 924 | |
| 925 | # Cleanup probably dead peers and close connection if too much |
| 926 | def cleanupPeers(self, peers_protected=[]): |
no test coverage detected