def setUp(self): self.test_storage_dir = tempfile.mkdtemp() # Sample node. self.wallet = btctxstore.BtcTxStore(testnet=False, dryrun=True) self.wif = self.wallet.get_key(self.wallet.create_wallet()) self.node_id = address_to_node_id(self.wallet.get_address(self.wif)) self.store_config = { os.path.join(self.test_storage_dir, "storage"): {"limit": 0} } # dht_node = pyp2p.dht_msg.DHT(node_id=node_id) self.dht_node = storjnode.network.Node( self.wif, bootstrap_nodes=DEFAULT_BOOTSTRAP_NODES, disable_data_transfer=True ) # Transfer client. self.client = FileTransfer( pyp2p.net.Net( node_type="simultaneous", nat_type="preserving", net_type="direct", passive_port=0, dht_node=self.dht_node, debug=1 ), BandwidthLimit(), wif=self.wif, store_config=self.store_config ) # Accept all transfers. def accept_handler(contract_id, src_unl, data_id, file_size): return 1 # Add accept handler. self.client.handlers["accept"].add(accept_handler) # Accept UNL requests. enable_unl_requests(self.dht_node)
def setUpClass(cls): # start profiler if PROFILE: cls.profile = cProfile.Profile() cls.profile.enable() # create swarm print("TEST: creating swarm") cls.btctxstore = btctxstore.BtcTxStore(testnet=False) cls.swarm = [] for i in range(SWARM_SIZE): # isolate swarm bootstrap_nodes = [(LAN_IP, PORT + x) for x in range(i)][-20:] # create node node = storjnode.network.Node( cls.btctxstore.create_wallet(), port=(PORT + i), ksize=KSIZE, bootstrap_nodes=bootstrap_nodes, refresh_neighbours_interval=0.0, store_config={STORAGE_DIR: None}, nat_type="preserving", node_type="passive", disable_data_transfer=False ) storjnode.network.messages.info.enable(node, {}) storjnode.network.messages.peers.enable(node) enable_unl_requests(node) node.bandwidth_test.enable() cls.swarm.append(node) msg = "TEST: created node {0} @ 127.0.0.1:{1}" print(msg.format(node.get_address(), node.port)) # Peer used for get unl requests. unl_peer_bootstrap_nodes = [ (LAN_IP, PORT + x) for x in range(SWARM_SIZE) ][-20:] cls.test_get_unl_peer = storjnode.network.Node( cls.btctxstore.create_wallet(), bootstrap_nodes=unl_peer_bootstrap_nodes, refresh_neighbours_interval=0.0, store_config={STORAGE_DIR: None}, nat_type="preserving", node_type="passive", disable_data_transfer=False ) enable_unl_requests(cls.test_get_unl_peer) # stabalize network overlay print("TEST: stabalize network overlay") time.sleep(WALK_TIMEOUT) for node in cls.swarm: node.refresh_neighbours() cls.test_get_unl_peer.refresh_neighbours() time.sleep(WALK_TIMEOUT) for node in cls.swarm: node.refresh_neighbours() cls.test_get_unl_peer.refresh_neighbours() time.sleep(WALK_TIMEOUT) print("TEST: created swarm")