mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-03 06:35:08 -04:00
* Improved udpbitdht tests.
* Added Simple example - so others can understand how to interface with bitdht. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3724 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
33282bfc77
commit
cbdd08cd34
7 changed files with 1401 additions and 515 deletions
16
libbitdht/src/example/Makefile
Normal file
16
libbitdht/src/example/Makefile
Normal file
|
@ -0,0 +1,16 @@
|
|||
|
||||
CXXFLAGS = -Wall -g -I..
|
||||
#CXXFLAGS += -arch i386 # OSX
|
||||
|
||||
LIBS = -L../lib -lbitdht
|
||||
|
||||
|
||||
|
||||
EXEC : bdexample
|
||||
|
||||
EGOBJ = bdhandler.o bdexample.o
|
||||
|
||||
bdexample: $(EGOBJ)
|
||||
$(CXX) $(CXXFLAGS) -o bdexample $(EGOBJ) $(LIBS)
|
||||
|
||||
|
500
libbitdht/src/example/bdboot.txt
Normal file
500
libbitdht/src/example/bdboot.txt
Normal file
|
@ -0,0 +1,500 @@
|
|||
64.121.80.63 45642
|
||||
84.82.225.139 52002
|
||||
200.104.218.244 24447
|
||||
116.81.147.106 10014
|
||||
76.238.231.136 37770
|
||||
68.148.109.134 32815
|
||||
78.43.60.243 18973
|
||||
62.33.209.243 20600
|
||||
84.40.115.5 49669
|
||||
93.11.108.82 45078
|
||||
90.157.139.222 28487
|
||||
79.83.184.114 40139
|
||||
109.104.187.16 30000
|
||||
87.101.162.223 21364
|
||||
99.251.104.111 60382
|
||||
130.63.133.216 47451
|
||||
64.216.32.37 6881
|
||||
75.137.149.242 19860
|
||||
208.102.25.182 50675
|
||||
75.72.144.15 54485
|
||||
68.148.20.202 22025
|
||||
69.148.177.153 26961
|
||||
121.222.5.240 51932
|
||||
88.161.156.9 48251
|
||||
88.200.104.216 27784
|
||||
109.160.52.2 36630
|
||||
74.12.101.58 61864
|
||||
174.71.75.121 48749
|
||||
186.66.255.5 37580
|
||||
24.116.239.194 59147
|
||||
95.65.178.164 23715
|
||||
220.70.175.83 43726
|
||||
182.169.110.245 64684
|
||||
119.247.164.154 22132
|
||||
77.202.227.150 15621
|
||||
79.129.217.171 17248
|
||||
98.117.197.195 53478
|
||||
71.72.3.201 40665
|
||||
72.88.206.217 57170
|
||||
95.29.8.61 59559
|
||||
142.163.161.23 60957
|
||||
70.27.27.105 23047
|
||||
90.42.104.194 10595
|
||||
114.36.7.29 26051
|
||||
78.26.164.132 59437
|
||||
70.126.197.41 14207
|
||||
187.14.3.249 8753
|
||||
62.166.34.78 62133
|
||||
82.45.213.218 24740
|
||||
213.123.71.145 56050
|
||||
93.12.188.2 22070
|
||||
203.184.0.161 10295
|
||||
69.156.209.139 19165
|
||||
83.81.119.121 34439
|
||||
109.208.211.98 36278
|
||||
84.3.208.199 50001
|
||||
85.87.98.187 53911
|
||||
93.127.107.157 35691
|
||||
188.195.145.172 21827
|
||||
184.56.151.190 11951
|
||||
98.168.190.247 61279
|
||||
83.237.221.242 16613
|
||||
75.30.79.175 57107
|
||||
90.24.61.26 57262
|
||||
125.27.132.48 10018
|
||||
94.98.122.161 62266
|
||||
81.25.50.209 44962
|
||||
94.24.137.191 35691
|
||||
74.119.191.181 62498
|
||||
46.33.237.37 21135
|
||||
183.83.30.78 15822
|
||||
109.75.207.23 14085
|
||||
92.147.163.123 36706
|
||||
110.3.132.18 10149
|
||||
90.38.163.86 61080
|
||||
77.50.87.114 11399
|
||||
76.106.47.230 6881
|
||||
24.47.46.185 59822
|
||||
118.150.145.87 16553
|
||||
98.121.178.252 31353
|
||||
95.62.64.40 12174
|
||||
85.91.17.78 8644
|
||||
98.148.37.251 55774
|
||||
122.117.82.108 16293
|
||||
200.26.143.117 14013
|
||||
187.37.80.22 25095
|
||||
95.19.224.225 25446
|
||||
79.132.4.131 36094
|
||||
109.86.136.248 44281
|
||||
85.54.187.59 28890
|
||||
99.225.92.6 38080
|
||||
178.40.89.75 10018
|
||||
189.237.151.135 17643
|
||||
189.114.233.119 12308
|
||||
93.13.211.51 59788
|
||||
80.56.69.253 25685
|
||||
83.131.224.235 62622
|
||||
201.229.9.69 28159
|
||||
201.223.65.4 43804
|
||||
77.167.196.115 64788
|
||||
71.72.158.196 37961
|
||||
86.132.129.242 23071
|
||||
93.103.167.242 35298
|
||||
212.37.169.128 31631
|
||||
74.105.104.186 23922
|
||||
173.176.243.27 31393
|
||||
86.13.110.77 47020
|
||||
76.181.24.116 35553
|
||||
94.158.107.234 32516
|
||||
99.242.143.80 19034
|
||||
201.209.54.201 26726
|
||||
109.87.52.11 20186
|
||||
98.121.161.117 54068
|
||||
75.69.6.91 6881
|
||||
98.223.44.215 35998
|
||||
123.193.220.215 54157
|
||||
95.130.12.23 61546
|
||||
84.215.125.229 51413
|
||||
77.203.179.13 23145
|
||||
217.172.179.78 18692
|
||||
85.170.52.161 12310
|
||||
98.244.158.38 40311
|
||||
71.201.200.183 41435
|
||||
99.111.202.61 10341
|
||||
84.252.27.201 17253
|
||||
210.6.173.193 6887
|
||||
74.67.142.125 17874
|
||||
94.23.212.70 57174
|
||||
77.99.18.29 63852
|
||||
91.100.81.198 49999
|
||||
82.74.117.94 25000
|
||||
78.83.127.162 53345
|
||||
95.84.255.201 17122
|
||||
85.228.78.9 47500
|
||||
217.77.60.189 58847
|
||||
67.174.74.95 35000
|
||||
95.105.198.233 80
|
||||
85.238.105.154 40000
|
||||
70.114.173.8 26375
|
||||
71.100.182.81 21724
|
||||
24.9.187.250 29985
|
||||
72.204.16.239 50200
|
||||
78.94.104.125 63580
|
||||
67.83.132.220 51515
|
||||
96.52.145.135 12607
|
||||
85.187.24.45 14111
|
||||
91.148.128.36 24464
|
||||
24.186.53.139 61726
|
||||
109.110.3.135 57756
|
||||
78.159.108.124 63982
|
||||
82.244.72.113 10620
|
||||
24.16.216.224 45546
|
||||
24.60.118.120 60005
|
||||
89.135.149.47 52055
|
||||
88.191.117.198 46881
|
||||
79.108.19.172 52750
|
||||
84.24.37.138 15678
|
||||
213.93.83.121 51413
|
||||
87.50.207.134 60361
|
||||
77.120.182.144 30585
|
||||
80.109.42.12 29168
|
||||
188.230.38.94 32525
|
||||
109.86.246.11 11400
|
||||
93.72.108.237 39272
|
||||
109.160.201.32 27495
|
||||
90.214.93.249 25238
|
||||
2.106.159.182 28860
|
||||
24.49.43.222 26917
|
||||
67.215.242.139 6881
|
||||
83.83.52.92 10000
|
||||
89.161.85.250 27553
|
||||
76.20.230.30 58335
|
||||
60.62.38.145 22101
|
||||
62.148.159.55 52603
|
||||
69.123.52.81 64701
|
||||
67.215.242.138 6881
|
||||
99.225.194.114 45586
|
||||
79.124.27.117 26472
|
||||
86.10.209.139 12001
|
||||
95.181.30.110 37075
|
||||
65.5.225.206 6881
|
||||
66.110.140.217 6881
|
||||
99.112.96.188 35979
|
||||
87.120.113.236 18301
|
||||
67.162.118.20 9820
|
||||
173.51.87.191 37950
|
||||
58.69.218.34 38072
|
||||
87.120.78.253 25118
|
||||
69.137.192.214 6881
|
||||
81.57.50.221 11095
|
||||
89.212.93.62 32590
|
||||
93.152.176.62 6881
|
||||
96.250.206.111 20965
|
||||
93.72.132.238 47860
|
||||
96.20.161.32 44893
|
||||
24.235.41.231 11181
|
||||
88.80.49.238 35857
|
||||
89.215.103.145 16242
|
||||
142.162.65.171 30537
|
||||
178.162.184.203 6821
|
||||
93.182.0.249 32217
|
||||
217.208.59.201 46227
|
||||
79.132.182.136 30129
|
||||
77.70.96.3 11949
|
||||
174.59.144.37 5895
|
||||
24.206.168.152 22102
|
||||
24.64.233.94 17962
|
||||
109.168.162.23 32195
|
||||
71.53.119.62 23108
|
||||
60.241.156.191 24064
|
||||
18.242.7.242 65435
|
||||
216.113.97.150 29801
|
||||
89.133.173.35 37855
|
||||
78.82.124.105 20047
|
||||
78.128.57.15 22034
|
||||
99.54.50.211 64189
|
||||
174.118.36.27 60010
|
||||
189.120.102.167 63495
|
||||
187.1.109.123 20546
|
||||
123.193.205.49 22248
|
||||
87.48.15.175 52767
|
||||
195.145.124.15 33639
|
||||
189.34.175.133 1142
|
||||
188.16.249.8 10428
|
||||
78.96.153.123 10943
|
||||
209.188.19.242 61204
|
||||
94.208.99.166 13733
|
||||
77.70.32.188 9459
|
||||
69.134.71.56 10713
|
||||
74.213.69.68 17477
|
||||
175.137.140.31 18987
|
||||
219.79.191.108 35982
|
||||
86.129.7.137 21672
|
||||
78.225.25.249 10323
|
||||
216.195.251.137 41238
|
||||
201.6.19.10 64067
|
||||
76.101.164.51 20673
|
||||
196.221.130.175 18290
|
||||
80.192.63.126 59768
|
||||
80.177.109.9 34474
|
||||
77.243.211.17 40330
|
||||
99.179.5.68 55337
|
||||
206.63.116.47 47092
|
||||
2.83.53.144 14926
|
||||
188.25.174.202 26218
|
||||
86.28.149.67 39274
|
||||
92.133.136.242 41243
|
||||
95.28.8.196 39167
|
||||
213.231.136.129 13219
|
||||
98.237.145.195 46637
|
||||
58.165.71.127 25006
|
||||
111.252.45.153 25943
|
||||
89.29.15.90 56736
|
||||
86.171.44.134 57592
|
||||
94.59.26.121 36725
|
||||
81.191.88.223 54799
|
||||
75.81.195.23 22056
|
||||
81.109.38.132 31233
|
||||
109.121.220.16 10301
|
||||
212.92.246.213 22544
|
||||
95.158.10.130 13941
|
||||
112.118.166.151 45684
|
||||
202.154.59.140 43442
|
||||
93.181.215.55 46157
|
||||
76.217.106.151 62033
|
||||
61.227.125.97 13874
|
||||
78.58.201.174 28778
|
||||
81.231.229.41 19130
|
||||
186.10.23.230 37769
|
||||
83.254.77.75 17232
|
||||
84.110.59.219 62065
|
||||
81.98.22.127 47800
|
||||
85.17.5.132 51413
|
||||
83.55.120.23 42521
|
||||
195.18.28.147 35691
|
||||
61.202.78.247 22221
|
||||
93.80.153.76 48878
|
||||
95.29.196.251 61629
|
||||
94.75.148.194 24796
|
||||
109.194.167.19 47193
|
||||
207.216.26.166 36202
|
||||
76.186.158.107 56213
|
||||
79.118.112.122 26181
|
||||
93.115.48.2 16132
|
||||
84.32.80.26 6881
|
||||
72.198.44.72 31231
|
||||
70.162.57.125 48027
|
||||
216.162.201.192 17384
|
||||
77.49.95.176 45619
|
||||
77.47.185.248 15245
|
||||
80.185.186.95 10318
|
||||
82.200.130.249 58389
|
||||
67.162.140.62 29974
|
||||
118.168.172.177 27161
|
||||
114.51.38.178 23793
|
||||
125.175.146.71 17014
|
||||
80.66.213.182 64219
|
||||
77.50.234.5 25866
|
||||
78.90.218.100 49844
|
||||
46.118.135.250 58667
|
||||
92.80.58.143 14569
|
||||
99.253.186.136 43003
|
||||
71.60.40.75 41590
|
||||
151.11.145.100 18163
|
||||
123.237.49.221 17321
|
||||
201.130.198.7 56378
|
||||
64.219.119.229 53546
|
||||
121.118.219.211 6880
|
||||
114.32.171.238 6881
|
||||
110.33.112.22 7336
|
||||
85.58.8.57 59138
|
||||
77.70.70.8 19445
|
||||
178.140.72.96 33178
|
||||
78.166.69.33 40531
|
||||
211.24.149.162 39719
|
||||
62.16.162.73 50001
|
||||
95.84.244.177 33076
|
||||
46.118.71.243 57944
|
||||
91.139.194.92 24902
|
||||
77.248.205.101 58849
|
||||
83.152.236.85 46613
|
||||
41.236.189.5 11493
|
||||
94.26.63.5 29973
|
||||
189.100.145.169 45441
|
||||
84.202.146.45 32122
|
||||
183.179.108.42 15833
|
||||
78.247.112.51 48465
|
||||
95.102.42.122 6881
|
||||
89.185.199.69 49879
|
||||
74.129.254.238 21830
|
||||
99.181.161.222 27636
|
||||
96.235.14.144 40928
|
||||
189.71.180.71 18172
|
||||
96.54.129.2 26085
|
||||
222.141.53.49 16006
|
||||
121.184.217.130 21563
|
||||
84.3.111.252 51111
|
||||
79.103.174.69 40190
|
||||
89.139.35.26 45625
|
||||
62.215.144.191 33078
|
||||
75.27.19.0 42707
|
||||
83.192.127.87 10785
|
||||
99.174.215.236 51128
|
||||
78.36.180.6 33016
|
||||
92.101.222.111 42441
|
||||
85.91.17.59 14091
|
||||
24.14.120.77 11682
|
||||
188.26.55.161 13650
|
||||
77.37.133.138 63572
|
||||
117.199.5.229 28835
|
||||
66.231.126.16 53509
|
||||
151.68.147.67 38146
|
||||
86.28.168.196 52549
|
||||
95.208.206.96 24833
|
||||
99.36.177.82 57416
|
||||
82.19.43.141 50274
|
||||
88.243.226.34 31952
|
||||
89.117.4.177 9026
|
||||
92.62.81.2 11369
|
||||
124.103.179.186 15356
|
||||
62.182.72.252 56899
|
||||
195.174.137.55 10152
|
||||
220.77.252.33 64170
|
||||
84.28.164.197 38804
|
||||
92.247.230.190 56889
|
||||
77.255.188.154 50182
|
||||
188.52.90.206 62502
|
||||
58.99.68.183 16001
|
||||
81.166.131.74 49856
|
||||
84.72.160.67 21783
|
||||
61.58.164.40 61726
|
||||
121.3.76.229 24859
|
||||
119.188.12.17 16003
|
||||
109.194.148.235 35691
|
||||
89.152.22.150 54895
|
||||
79.169.181.30 15368
|
||||
71.229.7.56 63792
|
||||
85.152.185.205 37976
|
||||
72.179.54.146 62040
|
||||
188.168.19.251 33178
|
||||
62.42.136.67 14957
|
||||
95.104.224.245 55165
|
||||
68.148.68.46 61984
|
||||
122.3.9.39 62546
|
||||
121.222.50.109 33067
|
||||
212.7.27.71 59005
|
||||
41.233.123.170 57369
|
||||
85.69.170.120 44386
|
||||
83.209.26.106 57404
|
||||
79.114.213.111 41823
|
||||
72.139.120.43 64593
|
||||
220.235.102.85 40329
|
||||
189.114.35.172 9884
|
||||
213.89.205.22 51413
|
||||
206.45.53.201 6881
|
||||
95.93.140.179 58457
|
||||
86.212.236.62 41939
|
||||
64.120.217.48 6821
|
||||
24.192.141.196 43444
|
||||
98.111.205.18 38107
|
||||
72.70.248.25 50824
|
||||
93.80.95.102 6882
|
||||
78.161.215.48 1024
|
||||
92.46.27.57 32582
|
||||
109.185.14.134 10020
|
||||
76.10.184.99 48754
|
||||
59.129.24.10 12345
|
||||
79.167.72.16 24971
|
||||
76.69.58.83 33258
|
||||
212.75.11.116 18431
|
||||
91.111.73.116 60521
|
||||
188.177.32.124 25573
|
||||
70.119.124.175 32302
|
||||
93.141.74.98 25058
|
||||
24.113.236.144 28024
|
||||
76.22.33.148 47355
|
||||
84.38.176.176 59787
|
||||
90.3.48.40 52585
|
||||
89.72.89.197 19610
|
||||
204.191.41.127 23927
|
||||
221.217.45.24 47709
|
||||
74.137.200.28 6112
|
||||
84.1.255.253 39168
|
||||
90.230.207.166 64697
|
||||
109.195.179.25 49034
|
||||
213.7.173.150 27444
|
||||
113.190.35.133 26298
|
||||
219.71.14.70 20000
|
||||
188.26.238.55 12082
|
||||
188.126.90.189 42521
|
||||
92.152.222.207 60086
|
||||
94.41.126.183 35691
|
||||
92.124.18.175 7691
|
||||
121.84.53.235 36421
|
||||
114.181.232.144 14859
|
||||
87.126.166.37 23145
|
||||
79.136.38.51 61193
|
||||
79.136.29.76 64123
|
||||
91.203.188.89 31780
|
||||
173.70.56.200 34107
|
||||
69.112.65.152 26394
|
||||
122.168.6.130 36327
|
||||
124.24.226.162 8640
|
||||
178.164.171.162 38624
|
||||
92.241.245.68 47765
|
||||
99.99.66.212 23188
|
||||
211.38.161.183 41794
|
||||
95.153.168.28 8033
|
||||
114.77.55.185 14890
|
||||
114.41.140.117 11675
|
||||
66.41.250.122 26560
|
||||
66.131.96.98 9090
|
||||
95.42.148.127 21982
|
||||
217.172.183.163 6881
|
||||
78.56.249.219 11699
|
||||
82.209.126.232 49180
|
||||
74.129.176.196 18957
|
||||
119.246.185.40 25295
|
||||
87.207.245.56 14132
|
||||
86.205.109.156 9739
|
||||
92.239.247.56 39166
|
||||
24.9.173.223 61423
|
||||
80.54.16.78 14221
|
||||
173.58.23.148 56221
|
||||
174.93.222.175 58944
|
||||
83.188.251.214 37857
|
||||
96.242.15.74 31666
|
||||
71.56.126.209 50316
|
||||
178.46.224.6 61397
|
||||
203.121.129.35 48913
|
||||
78.107.255.16 6884
|
||||
178.30.150.171 49763
|
||||
97.118.36.234 28186
|
||||
58.179.125.192 62734
|
||||
92.28.78.203 14274
|
||||
80.219.210.106 56365
|
||||
89.38.197.172 27077
|
||||
201.226.156.70 16668
|
||||
183.191.171.160 4041
|
||||
95.233.192.118 52630
|
||||
94.253.81.217 52858
|
||||
189.98.226.168 54960
|
||||
93.103.210.87 35228
|
||||
109.86.255.184 6881
|
||||
200.120.232.126 42476
|
||||
80.56.123.123 15541
|
||||
81.234.102.107 18764
|
||||
89.253.109.172 31844
|
||||
122.166.49.234 16842
|
||||
188.27.102.215 33333
|
||||
212.233.236.87 1041
|
||||
79.165.176.206 39053
|
||||
109.171.12.85 51441
|
||||
178.94.111.98 59615
|
||||
94.112.39.248 7289
|
||||
125.134.85.142 21707
|
||||
46.33.245.141 45822
|
||||
217.23.176.216 58252
|
||||
154.5.172.67 23127
|
||||
126.12.49.142 23120
|
42
libbitdht/src/example/bdexample.cc
Normal file
42
libbitdht/src/example/bdexample.cc
Normal file
|
@ -0,0 +1,42 @@
|
|||
|
||||
|
||||
#include "bitdht/bdiface.h"
|
||||
#include "bitdht/bdstddht.h"
|
||||
#include "bdhandler.h"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
|
||||
/* startup dht : with a random id! */
|
||||
bdNodeId ownId;
|
||||
bdStdRandomNodeId(&ownId);
|
||||
|
||||
uint16_t port = 6775;
|
||||
std::string appId = "exId";
|
||||
std::string bootstrapfile = "bdboot.txt";
|
||||
|
||||
BitDhtHandler dht(&ownId, port, appId, bootstrapfile);
|
||||
|
||||
/* run your program */
|
||||
while(1)
|
||||
{
|
||||
bdNodeId searchId;
|
||||
bdStdRandomNodeId(&searchId);
|
||||
|
||||
dht.FindNode(&searchId);
|
||||
|
||||
sleep(180);
|
||||
|
||||
dht.DropNode(&searchId);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
251
libbitdht/src/example/bdhandler.cc
Normal file
251
libbitdht/src/example/bdhandler.cc
Normal file
|
@ -0,0 +1,251 @@
|
|||
/*
|
||||
* libretroshare/src/dht: bdhandler.h
|
||||
*
|
||||
* BitDht example interface
|
||||
*
|
||||
* Copyright 2009-2010 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "retroshare@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include <udp/udpstack.h>
|
||||
#include <udp/udpbitdht.h>
|
||||
#include <bitdht/bdstddht.h>
|
||||
|
||||
#include "bdhandler.h"
|
||||
|
||||
/* This is a conversion callback class
|
||||
*/
|
||||
|
||||
class BdCallback: public BitDhtCallback
|
||||
{
|
||||
public:
|
||||
|
||||
BdCallback(BitDhtHandler *parent)
|
||||
:mParent(parent) { return; }
|
||||
|
||||
virtual int dhtNodeCallback(const bdId *id, uint32_t peerflags)
|
||||
{
|
||||
return mParent->NodeCallback(id, peerflags);
|
||||
}
|
||||
|
||||
virtual int dhtPeerCallback(const bdNodeId *id, uint32_t status)
|
||||
{
|
||||
return mParent->PeerCallback(id, status);
|
||||
}
|
||||
|
||||
virtual int dhtValueCallback(const bdNodeId *id, std::string key, uint32_t status)
|
||||
{
|
||||
return mParent->ValueCallback(id, key, status);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
BitDhtHandler *mParent;
|
||||
};
|
||||
|
||||
|
||||
BitDhtHandler::BitDhtHandler(bdNodeId *ownId, uint16_t port, std::string appId, std::string bootstrapfile)
|
||||
{
|
||||
std::cerr << "BitDhtHandler::BitDhtHandler()" << std::endl;
|
||||
std::cerr << "Using Id: ";
|
||||
bdStdPrintNodeId(std::cerr, ownId);
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "Using Bootstrap File: " << bootstrapfile;
|
||||
std::cerr << std::endl;
|
||||
std::cerr << "Converting OwnId to bdNodeId....";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* standard dht behaviour */
|
||||
bdDhtFunctions *stdfns = new bdStdDht();
|
||||
|
||||
std::cerr << "BitDhtHandler() startup ... creating UdpBitDht";
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* create dht */
|
||||
struct sockaddr_in local;
|
||||
memset(&local, 0, sizeof(local));
|
||||
local.sin_family = AF_INET;
|
||||
local.sin_addr.s_addr = 0;
|
||||
local.sin_port = htons(port);
|
||||
|
||||
mStack = new UdpStack(local);
|
||||
|
||||
mUdpBitDht = new UdpBitDht(mStack, ownId, appId, bootstrapfile, stdfns);
|
||||
mStack->addReceiver(mUdpBitDht);
|
||||
|
||||
/* setup callback to here */
|
||||
BdCallback *bdcb = new BdCallback(this);
|
||||
mUdpBitDht->addCallback(bdcb);
|
||||
|
||||
std::cerr << "BitDhtHandler() starting threads and dht";
|
||||
std::cerr << std::endl;
|
||||
|
||||
mUdpBitDht->start(); /* starts up the bitdht thread */
|
||||
|
||||
/* switch on the dht too */
|
||||
mUdpBitDht->startDht();
|
||||
}
|
||||
|
||||
/* pqiNetAssist - external interface functions */
|
||||
void BitDhtHandler::enable(bool on)
|
||||
{
|
||||
std::cerr << "p3BitDht::enable(" << on << ")";
|
||||
std::cerr << std::endl;
|
||||
if (on)
|
||||
{
|
||||
mUdpBitDht->startDht();
|
||||
}
|
||||
else
|
||||
{
|
||||
mUdpBitDht->stopDht();
|
||||
}
|
||||
}
|
||||
|
||||
void BitDhtHandler::shutdown() /* blocking call */
|
||||
{
|
||||
mUdpBitDht->stopDht();
|
||||
}
|
||||
|
||||
|
||||
void BitDhtHandler::restart()
|
||||
{
|
||||
mUdpBitDht->stopDht();
|
||||
mUdpBitDht->startDht();
|
||||
}
|
||||
|
||||
bool BitDhtHandler::getEnabled()
|
||||
{
|
||||
return (mUdpBitDht->stateDht() != 0);
|
||||
}
|
||||
|
||||
bool BitDhtHandler::getActive()
|
||||
{
|
||||
return (mUdpBitDht->stateDht() >= BITDHT_MGR_STATE_ACTIVE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/* pqiNetAssistConnect - external interface functions */
|
||||
/* add / remove peers */
|
||||
bool BitDhtHandler::FindNode(bdNodeId *peerId)
|
||||
{
|
||||
std::cerr << "BitDhtHandler::FindNode(";
|
||||
bdStdPrintNodeId(std::cerr, peerId);
|
||||
std::cerr << ")" << std::endl;
|
||||
|
||||
/* add in peer */
|
||||
mUdpBitDht->addFindNode(peerId, BITDHT_QFLAGS_DO_IDLE);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
bool BitDhtHandler::DropNode(bdNodeId *peerId)
|
||||
{
|
||||
std::cerr << "BitDhtHandler::DropNode(";
|
||||
bdStdPrintNodeId(std::cerr, peerId);
|
||||
std::cerr << ")" << std::endl;
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* remove in peer */
|
||||
mUdpBitDht->removeFindNode(peerId);
|
||||
|
||||
return true ;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/********************** Callback Functions **************************/
|
||||
|
||||
int BitDhtHandler::NodeCallback(const bdId *id, uint32_t peerflags)
|
||||
{
|
||||
#ifdef DEBUG_BITDHT
|
||||
std::cerr << "BitDhtHandler::NodeCallback()";
|
||||
bdStdPrintNodeId(std::cerr, &(id->id));
|
||||
std::cerr << " flags: " << peerflags;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int BitDhtHandler::PeerCallback(const bdNodeId *id, uint32_t status)
|
||||
{
|
||||
std::cerr << "BitDhtHandler::PeerCallback() NodeId: ";
|
||||
bdStdPrintNodeId(std::cerr, id);
|
||||
std::cerr << std::endl;
|
||||
|
||||
bool connect = false;
|
||||
switch(status)
|
||||
{
|
||||
case BITDHT_MGR_QUERY_FAILURE:
|
||||
/* do nothing */
|
||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY FAILURE ... do nothin ";
|
||||
std::cerr << std::endl;
|
||||
|
||||
break;
|
||||
|
||||
case BITDHT_MGR_QUERY_PEER_OFFLINE:
|
||||
/* do nothing */
|
||||
|
||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER OFFLINE ... do nothin ";
|
||||
std::cerr << std::endl;
|
||||
|
||||
break;
|
||||
|
||||
case BITDHT_MGR_QUERY_PEER_UNREACHABLE:
|
||||
/* do nothing */
|
||||
|
||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER UNREACHABLE ... flag? / do nothin ";
|
||||
std::cerr << std::endl;
|
||||
|
||||
|
||||
break;
|
||||
|
||||
case BITDHT_MGR_QUERY_PEER_ONLINE:
|
||||
/* do something */
|
||||
|
||||
std::cerr << "BitDhtHandler::PeerCallback() QUERY PEER ONLINE ... try udp connection";
|
||||
std::cerr << std::endl;
|
||||
|
||||
connect = true;
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int BitDhtHandler::ValueCallback(const bdNodeId *id, std::string key, uint32_t status)
|
||||
{
|
||||
std::cerr << "BitDhtHandler::ValueCallback() NOOP for NOW";
|
||||
std::cerr << std::endl;
|
||||
|
||||
std::cerr << "BitDhtHandler::ValueCallback()";
|
||||
bdStdPrintNodeId(std::cerr, id);
|
||||
std::cerr << " key: " << key;
|
||||
std::cerr << " status: " << status;
|
||||
std::cerr << std::endl;
|
||||
|
||||
/* ignore for now */
|
||||
return 0;
|
||||
}
|
||||
|
71
libbitdht/src/example/bdhandler.h
Normal file
71
libbitdht/src/example/bdhandler.h
Normal file
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* libbitdht/src/example/bdhandler.h
|
||||
*
|
||||
* BitDht interface example
|
||||
*
|
||||
* Copyright 2009-2010 by Robert Fernie.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Library General Public
|
||||
* License Version 2 as published by the Free Software Foundation.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
||||
* USA.
|
||||
*
|
||||
* Please report all bugs and problems to "bitdht@lunamutt.com".
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#ifndef BITDHT_HANDLER_H
|
||||
#define BITDHT_HANDLER_H
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
|
||||
#include "udp/udpstack.h"
|
||||
#include "udp/udpbitdht.h"
|
||||
#include "bitdht/bdiface.h"
|
||||
|
||||
/*** This class can be overloaded to use the XXXXCallback() Functions *****/
|
||||
class BitDhtIntCallback;
|
||||
|
||||
class BitDhtHandler
|
||||
{
|
||||
|
||||
public:
|
||||
|
||||
BitDhtHandler(bdNodeId *ownId, uint16_t port, std::string appId, std::string bootstrapfile);
|
||||
|
||||
void enable(bool on);
|
||||
void shutdown(); /* blocking call */
|
||||
void restart();
|
||||
|
||||
bool getEnabled();
|
||||
bool getActive();
|
||||
|
||||
bool FindNode(bdNodeId *peerId);
|
||||
bool DropNode(bdNodeId *peerId);
|
||||
|
||||
virtual int NodeCallback(const bdId *id, uint32_t peerflags);
|
||||
virtual int PeerCallback(const bdNodeId *id, uint32_t status);
|
||||
virtual int ValueCallback(const bdNodeId *id, std::string key, uint32_t status);
|
||||
|
||||
private:
|
||||
|
||||
/* real DHT classes */
|
||||
UdpStack *mStack;
|
||||
UdpBitDht *mUdpBitDht;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif /* BITDHT_HANDLER_H */
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue