def __init__(self, boot_nodes): # the endpoint of this server # this is a fake ip address used in packets. self.endpoint = EndPoint(u'127.0.0.1', 30303, 30303) # boot nodes self.boot_nodes = boot_nodes # hold all of pending self.pending_hold = [] # last pong received time of the special node id self.last_pong_received = {} # last ping received time of the special node id self.last_ping_received = {} # have the private key priv_key_file = open('priv_key', 'r') priv_key_serialized = priv_key_file.read() priv_key_file.close() self.priv_key = PrivateKey() self.priv_key.deserialize(priv_key_serialized) # routing table self.table = RoutingTable( Node(self.endpoint, pubkey_format(self.priv_key.pubkey)[1:]), self) # initialize UDP socket self.sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) self.sock.bind(('0.0.0.0', self.endpoint.udpPort)) # set socket non-blocking mode self.sock.setblocking(0)
def __init__(self, node, bootstrap=None, context=None): self.data = {} self.bootstrap = bootstrap self.node = node self.routing_table = RoutingTable(node, bootstrap) self.context = context if context != None else zmq.Context() self._thread_uid = None self._shutdown_flag = threading.Event()