-
Notifications
You must be signed in to change notification settings - Fork 56
/
dht.i
97 lines (85 loc) · 2.65 KB
/
dht.i
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
%{
#include <libtorrent/kademlia/item.hpp>
#include <libtorrent/ed25519.hpp>
#include <boost/bind.hpp>
#include <stdio.h>
%}
%{
namespace libtorrent {
class dht_put_operation {
public:
entry *data;
boost::array<char, 32> public_key;
boost::array<char, 64> private_key;
std::string salt;
dht_put_operation(unsigned char* public_key, unsigned char* private_key) {
for (int i = 0; i < 32; i++) {
this->public_key[i] = public_key[i];
}
for (int i = 0; i < 64; i++) {
this->private_key[i] = private_key[i];
}
}
};
class dht_get_operation {
public:
entry *data;
boost::array<char, 32> public_key;
std::string salt;
dht_get_operation(unsigned char* public_key) {
for (int i = 0; i < 32; i++) {
this->public_key[i] = public_key[i];
}
}
};
void dht_put_item_cb(entry& e, boost::array<char, 64>& sig, boost::uint64_t& seq,
std::string const& salt, char const* public_key, char const* private_key,
entry& data)
{
e = data;
std::vector<char> buf;
bencode(std::back_inserter(buf), e);
seq++;
libtorrent::dht::sign_mutable_item(
std::pair<char const*, int>(buf.data(), buf.size()),
std::pair<char const*, int>(salt.data(), salt.size()),
seq,
public_key,
private_key,
sig.data());
}
}
%}
namespace libtorrent {
class dht_put_operation {
public:
entry *data;
boost::array<char, 32> public_key;
boost::array<char, 64> private_key;
std::string salt;
dht_put_operation(unsigned char* INOUT, unsigned char* INOUT);
};
class dht_get_operation {
public:
entry *data;
boost::array<char, 32> public_key;
std::string salt;
dht_get_operation(unsigned char* INOUT);
};
}
%extend libtorrent::session {
libtorrent::sha1_hash dht_put_item(entry& item) {
return $self->dht_put_item(item);
}
void dht_get_item(libtorrent::dht_get_operation& op) {
$self->dht_get_item(op.public_key, op.salt);
}
void dht_put_mutable_item(libtorrent::dht_put_operation& op) {
$self->dht_put_item(
op.public_key,
boost::bind(
&libtorrent::dht_put_item_cb, _1, _2, _3, _4,
op.public_key.data(), op.private_key.data(), *op.data),
op.salt);
}
}