forked from manuels/kademlia.php
/
instance.php
47 lines (33 loc) · 1.02 KB
/
instance.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace Kademlia;
class Instance implements \JsonSerializable {
function __construct($json, $supported_protocols) {
$s = new Settings();
if($json !== "")
$s->fromJson($json);
$this->settings = $s;
}
public function bootstrap($bootstrap_nodes = NULL) {
$nodes = $this->settings->kbuckets->toNodeList();
if($bootstrap_nodes !== NULL)
$nodes->addNodeList($bootstrap_nodes);
$task = new Bootstrap($this->settings, $nodes);
return $task->enqueue();
}
public function processRequest($protocol_id, $request) {
$prot = $this->settings->instantiateProtocolById($protocol_id);
return $prot->processRequest($request);
}
public function findValue($needle_id) {
$task = new FindValue($this->settings, $needle_id);
return $task->enqueue();
}
public function store($key_id, $value, $expire) {
$task = new Store($this->settings, $key_id, $value, $expire);
return $task->enqueue();
}
public function jsonSerialize() {
return $this->settings;
}
}
?>