function __construct() { parent::__construct('Kademlia Bucket Test'); $settings = new Kademlia\Settings(); $settings->own_node_id = Kademlia\Node::randomNodeId(); $this->settings = $settings; }
static function constructNode($overwrite_data = array(), $overwrite_host = NULL) { $valid_host = "8.8.8.8"; $valid_data = ["id" => $first_node = Kademlia\Node::randomNodeId()]; $host = $overwrite_host !== NULL ? $overwrite_host : $valid_host; $data = array_merge($valid_data, $overwrite_data); return new Kademlia\Node($data, $host); }
public function testSetsOwnNodeIdWhenNodeNotFound() { $settings = new Kademlia\Settings(); $settings->id = NULL; $bootstrap = new Kademlia\Bootstrap($settings, $this->node_list); $callback = new TestCallback(); $bootstrap->enqueue()->allDone([$callback, 'callMe']); var_dump($bootstrap->find_node_task); $bootstrap->find_node_task->emit('success', Kademlia\Node::randomNodeId()); }
public function testCallsFindValueForNodes() { $mock_protocol =& new MockProtocol(); $mock_task =& new MockTask(); $mock_settings =& new MockSettings(); $mock_settings->own_node_id = Kademlia\Node::randomNodeId(); $mock_settings->returns('instantiateProtocolById', $mock_protocol); $mock_protocol->setReturnValue('sendFindRequest', $mock_task); $mock_nodes = []; $M = $mock_settings->alpha + 10; for ($i = 0; $i < $M; $i++) { $mock_nodes[$i] =& new MockNode(); $mock_nodes[$i]->returns('favoriteProtocolId', 0); $mock_node_id = str_repeat('00', N / 8); $mock_node_id[N / 8 - 1 - $i] = '1'; $mock_nodes[$i]->returns('idBin', Kademlia\Node::hexId2bin($mock_node_id)); } $needle_id = str_repeat('00', N / 8); $needle_id = Kademlia\Node::hexId2bin($needle_id); $task = new Kademlia\FindValue($mock_settings, $needle_id, new Kademlia\NodeList($mock_nodes)); $task->enqueue(); $mock_protocol->expectOnce('sendFindRequest', [Kademlia\Find::VALUE, array_slice($mock_nodes, 0, $mock_settings->alpha)]); }