Пример #1
0
 public function testRawStoring()
 {
     $settings = new \Kademlia\Settings();
     $protocol = new \Kademlia\Http\Protocol($settings);
     $expire = 10;
     $sender_node = KademliaTestFactory::constructNode();
     $key_id_A = \Kademlia\Node::randomNodeId();
     $value = 'foobar';
     $protocol->createStoreResponse($sender_node, $key_id_A, $value, $expire);
     $key_id_B = \Kademlia\Node::randomNodeId();
     $protocol->createStoreResponse($sender_node, $key_id_B, $value, $expire);
     $sender_node = KademliaTestFactory::constructNode();
     $value = 'barfoo';
     $protocol->createStoreResponse($sender_node, $key_id_B, $value, $expire);
     $this->assertEqual(count($settings->value_storage), 2);
     $response = $protocol->createFindValueResponse($key_id_B, $sender_node);
     $this->assertEqual($response['values'], ['foobar', 'barfoo']);
     $response = $protocol->createFindValueResponse($key_id_A, $sender_node);
     $this->assertEqual($response['values'], ['foobar']);
 }
Пример #2
0
 public function perform()
 {
     $data = ['type' => 'STORE', 'key_id' => \Kademlia\Node::binId2hex($this->key_id), 'value' => base64_encode($this->value), 'expire' => $this->expire];
     $results = parent::perform($data);
     $stored = false;
     foreach ($results as $r) {
         if ($r['data'] === "{}") {
             $stored = true;
             break;
         }
     }
     if ($stored) {
         $this->emit('success');
     } else {
         $this->emit('failed');
     }
 }