def test_account(self): proxy_id = get_proxy_id() self.assertIsNotNone(proxy_id) test_data = 'test string' sign_data = sign_proxy_data(test_data) data = derive_proxy_data(sign_data) self.assertEqual(data, test_data)
def bootstrap_done(_): if self.ip: addr = '%s,%d' % (self.ip, self.service_port) asyncio.ensure_future( peer.set(self.peer_id, sign_proxy_data( addr))).add_done_callback(set_key_done) else: asyncio.ensure_future(peer.protocol.stun( boot_nodes[0])).add_done_callback(stun_done)
def stun_done(future): addr = future.result() self.ip = addr[1][0] addr = '%s,%d' % (self.ip, self.service_port) asyncio.ensure_future( peer.set( self.peer_id, sign_proxy_data(addr))).add_done_callback(set_key_done)
def stun_done(future): addr = future.result() ip = addr[1][0] # proxy addr format: (ip, ctrl_port, file_port, stream_ws_port, stream_restful_port) addr = '%s,%d,%d,%d,%d' % (ip, config.proxy.server_port, config.proxy.server_file_port, config.proxy.server_stream_ws_port, config.proxy.server_stream_restful_port) asyncio.ensure_future(self.set( proxy_id, sign_proxy_data(addr))).add_done_callback(set_key_done)
def fake_bootstrap(): tid = generate_tid() msg = { 'type': 'bootstrap', 'tid': tid, 'sign_tid': sign_proxy_data(tid), 'peer_ip': None, 'peer_id': peer_id, 'peer_info': service_port, 'peer_conf': None } return msg
def bootstrap_done(_): ip = config.proxy.server_ip if ip: # proxy addr format: (ip, ctrl_port, file_port, stream_ws_port, stream_restful_port) addr = '%s,%d,%d,%d,%d' % ( ip, config.proxy.server_port, config.proxy.server_file_port, config.proxy.server_stream_ws_port, config.proxy.server_stream_restful_port) asyncio.ensure_future(self.set( proxy_id, sign_proxy_data(addr))).add_done_callback(set_key_done) else: asyncio.ensure_future(self.protocol.stun( boot_nodes[0])).add_done_callback(stun_done)
def bootstrap(self, addr): if self.transport is None: return reactor.callLater(1, self.bootstrap) self.peer_conf['cpu'] = get_cpu_info() self.peer_conf['mem'] = get_mem_info() self.peer_conf['nic'] = get_nic_info(addr[0]) tid = generate_tid() msg = { 'type': 'bootstrap', 'tid': tid, 'sign_tid': sign_proxy_data(tid), 'peer_ip': self.peer_ip, 'peer_id': self.peer_id, 'peer_info': self.peer_info, 'peer_conf': self.peer_conf } return self.send_msg(msg, addr)