def bootstrap(self, seed_nodes=[]): """ 根据初始节点引导初始化 :param seed_nodes:<Node list> 种子节点列表 :return: """ for seed_node in seed_nodes: #判断是否已经存在在邻居中 flag = self.tablsp.judnei(seed_node) #不同的格式怎么处理todo print self.tablsp.basetable[1] if flag == 0: #不在邻居中 #将该节点放入邻居中 self.tablsp.neighbourip.append(seed_node.ip) self.tablsp.neighbourport.append(seed_node.port) #设置距离 d = random.choice((1, 2, 3, 4, 40, 40, 40, 40)) print "insert distance in bootrs" print d self.tablsp.neighbourdistance.append(d) # 握手,加入lsptab中 self.sendversion( seed_node, Version( 1, int(time.time()), self.node_id, seed_node.node_id, db.get_block_height( self.blockchain.get_wallet_address()), d)) #建立邻居完毕后整理lsp self.tablsp.generatelsp() print "neighbour" print self.tablsp.lsp
def bootstrap(self, seed_nodes=[]): """ 根据初始节点引导初始化 :param seed_nodes:<Node list> 种子节点列表 :return: """ for seed_node in seed_nodes: # 握手 self.sendversion( seed_node, Version( 1, int(time.time()), self.node_id, seed_node.node_id, db.get_block_height(self.blockchain.get_wallet_address()))) for seed_node in seed_nodes: self.iterative_find_nodes(self.client.node_id, seed_node) if len(seed_nodes) == 0: for seed_node in self.buckets.get_all_nodes(): self.iterative_find_nodes(self.client.node_id, seed_node)