-
Notifications
You must be signed in to change notification settings - Fork 2
/
dht.h
76 lines (56 loc) · 1.86 KB
/
dht.h
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#ifndef _NODE_DHT_H_
#define _NODE_DHT_H_
#pragma once
#include <node.h>
#include <libcage/cage.hpp>
#include <node_events.h>
namespace node_dht {
class DHT : public node::ObjectWrap
{
public:
static v8::Persistent<v8::FunctionTemplate> constructor_template;
// callback classes {{{
class dht_callback {
public:
DHT* dht;
v8::Persistent<v8::Function> cb;
};
class dgram_func : public dht_callback {
public:
void operator() (void* buf, size_t len, uint8_t* addr);
};
class join_func : public dht_callback {
public:
void operator() (bool success, std::vector<libcage::cageaddr> &nodes);
};
class get_func : public dht_callback {
public:
void operator() (bool success, libcage::dht::value_set_ptr data);
};
// }}}
libcage::cage* cage;
dgram_func dgram_fn;
join_func join_fn;
get_func get_fn;
DHT();
~DHT();
v8::Local<v8::String> getNodeId();
void setNodeIdProperty();
static void Initialize(v8::Handle<v8::Object> target);
protected:
static v8::Handle<v8::Value> SendDgram(const v8::Arguments& args);
static v8::Handle<v8::Value> SetDgramCallback(const v8::Arguments& args);
static v8::Handle<v8::Value> PrintState(const v8::Arguments& args);
static v8::Handle<v8::Value> FillGetBuffers(const v8::Arguments& args);
static v8::Handle<v8::Value> Put(const v8::Arguments& args);
static v8::Handle<v8::Value> Get(const v8::Arguments& args);
static v8::Handle<v8::Value> Open(const v8::Arguments& args);
static v8::Handle<v8::Value> SetGlobal(const v8::Arguments& args);
static v8::Handle<v8::Value> GetNatState(const v8::Arguments& args);
static v8::Handle<v8::Value> Join(const v8::Arguments& args);
static v8::Handle<v8::Value> New(const v8::Arguments& args);
static v8::Handle<v8::Value> GetPeerAddress(const v8::Arguments& args);
private:
};
} /* namespace node_dht */
#endif /* _NODE_DHT_H_ */