def cache_exitnodes_to_disk(self): """ Wite a copy of self.exit_candidates to the file self.exitnode_cache. :returns: None """ exit_nodes = Network() for peer in self.exit_candidates.values(): exit_nodes.add_verified_peer(peer) self.logger.debug('Writing exit nodes to cache: %s', self.exitnode_cache) with open(self.exitnode_cache, 'wb') as cache: cache.write(exit_nodes.snapshot())
def cache_exitnodes_to_disk(self): """ Wite a copy of self.exit_candidates to the file self.exitnode_cache. :returns: None """ exit_nodes = Network() for peer in self.exit_candidates.values(): exit_nodes.add_verified_peer(peer) self.logger.debug('Writing exit nodes to cache: %s', self.exitnode_cache) with open(self.exitnode_cache, 'w') as cache: cache.write(exit_nodes.snapshot())
def restore_exitnodes_from_disk(self): """ Send introduction requests to peers stored in the file self.exitnode_cache. :returns: None """ if os.path.isfile(self.exitnode_cache): self.logger.debug('Loading exit nodes from cache: %s', self.exitnode_cache) exit_nodes = Network() with open(self.exitnode_cache, 'rb') as cache: exit_nodes.load_snapshot(cache.read()) for exit_node in exit_nodes.get_walkable_addresses(): self.endpoint.send(exit_node, self.create_introduction_request(exit_node)) else: self.logger.error('Could not retrieve backup exitnode cache, file does not exist!')
def restore_exitnodes_from_disk(self): """ Send introduction requests to peers stored in the file self.exitnode_cache. :returns: None """ if os.path.isfile(self.exitnode_cache): self.logger.debug('Loading exit nodes from cache: %s', self.exitnode_cache) exit_nodes = Network() with open(self.exitnode_cache, 'r') as cache: exit_nodes.load_snapshot(cache.read()) for exit_node in exit_nodes.get_walkable_addresses(): self.endpoint.send(exit_node, self.create_introduction_request(exit_node)) else: self.logger.error('Could not retrieve backup exitnode cache, file does not exist!')
def load_tunnel_community_in_session(self, session, exitnode=False): """ Load the tunnel community in a given session. We are using our own tunnel community here instead of the one used in Tribler. """ keypair = ECCrypto().generate_key(u"curve25519") tunnel_peer = Peer(keypair) session.config.set_tunnel_community_exitnode_enabled(exitnode) overlay = self.test_class(tunnel_peer, session.lm.ipv8.endpoint, session.lm.ipv8.network, tribler_session=session, dht_provider=MockDHTProvider( session.lm.ipv8.endpoint.get_address())) overlay._use_main_thread = False session.lm.ipv8.overlays.append(overlay) session.lm.ipv8.strategies.append((RandomWalk(overlay), 20)) # We disable the discovery communities in this session since we don't want to walk to the live network for overlay in session.lm.ipv8.overlays: if isinstance(overlay, DiscoveryCommunity): overlay.unload() # Also reset the IPv8 network session.lm.ipv8.network = Network() return overlay
def sanitize_network(self, session): # We disable the discovery communities in this session since we don't want to walk to the live network for overlay in session.lm.ipv8.overlays: if isinstance(overlay, DiscoveryCommunity): overlay.unload() session.lm.ipv8.overlays = [] session.lm.ipv8.strategies = [] # Also reset the IPv8 network session.lm.ipv8.network = Network()
def __init__(self, crypto_curve, overlay_class, *args, **kwargs): self.endpoint = AutoMockEndpoint() self.endpoint.open() self.network = Network() self.my_peer = Peer(ECCrypto().generate_key(crypto_curve), self.endpoint.wan_address) self.overlay = overlay_class(self.my_peer, self.endpoint, self.network, *args, **kwargs) self.discovery = MockWalk(self.overlay) self.overlay.my_estimated_wan = self.endpoint.wan_address self.overlay.my_estimated_lan = self.endpoint.lan_address
def __init__(self): self.exit_candidates = {} self.network = Network()