aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-04-27 12:53:35 +0000
committerChristian Grothoff <christian@grothoff.org>2015-04-27 12:53:35 +0000
commit3fbcb46c218e5197377ed8ed12533cef68deef94 (patch)
tree23b47cc7855b4b9254097869cd2559389be51fd0 /src/dht
parent9a9e7ffe6e13d60009e749e0811dcc7b997a764c (diff)
downloadgnunet-3fbcb46c218e5197377ed8ed12533cef68deef94.tar.gz
gnunet-3fbcb46c218e5197377ed8ed12533cef68deef94.zip
eliminating dead HELLO logic, not needed for x-vine/whanau
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/Makefile.am2
-rw-r--r--src/dht/gnunet-service-wdht.c93
-rw-r--r--src/dht/gnunet-service-wdht_clients.c54
-rw-r--r--src/dht/gnunet-service-wdht_hello.c137
-rw-r--r--src/dht/gnunet-service-wdht_hello.h55
-rw-r--r--src/dht/gnunet-service-wdht_neighbours.h43
-rw-r--r--src/dht/gnunet-service-xdht.c78
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.h8
8 files changed, 30 insertions, 440 deletions
diff --git a/src/dht/Makefile.am b/src/dht/Makefile.am
index 039cdb038..2c820385f 100644
--- a/src/dht/Makefile.am
+++ b/src/dht/Makefile.am
@@ -82,7 +82,6 @@ gnunet_service_dht_xvine_SOURCES = \
82 gnunet-service-xdht.c gnunet-service-xdht.h \ 82 gnunet-service-xdht.c gnunet-service-xdht.h \
83 gnunet-service-xdht_clients.c gnunet-service-xdht_clients.h \ 83 gnunet-service-xdht_clients.c gnunet-service-xdht_clients.h \
84 gnunet-service-xdht_datacache.c gnunet-service-xdht_datacache.h \ 84 gnunet-service-xdht_datacache.c gnunet-service-xdht_datacache.h \
85 gnunet-service-xdht_hello.c gnunet-service-xdht_hello.h \
86 gnunet-service-xdht_nse.c gnunet-service-xdht_nse.h \ 85 gnunet-service-xdht_nse.c gnunet-service-xdht_nse.h \
87 gnunet-service-xdht_neighbours.c gnunet-service-xdht_neighbours.h \ 86 gnunet-service-xdht_neighbours.c gnunet-service-xdht_neighbours.h \
88 gnunet-service-xdht_routing.c gnunet-service-xdht_routing.h 87 gnunet-service-xdht_routing.c gnunet-service-xdht_routing.h
@@ -103,7 +102,6 @@ gnunet_service_dht_whanau_SOURCES = \
103 gnunet-service-wdht.c gnunet-service-wdht.h \ 102 gnunet-service-wdht.c gnunet-service-wdht.h \
104 gnunet-service-wdht_clients.c gnunet-service-wdht_clients.h \ 103 gnunet-service-wdht_clients.c gnunet-service-wdht_clients.h \
105 gnunet-service-wdht_datacache.c gnunet-service-wdht_datacache.h \ 104 gnunet-service-wdht_datacache.c gnunet-service-wdht_datacache.h \
106 gnunet-service-wdht_hello.c gnunet-service-wdht_hello.h \
107 gnunet-service-wdht_nse.c gnunet-service-wdht_nse.h \ 105 gnunet-service-wdht_nse.c gnunet-service-wdht_nse.h \
108 gnunet-service-wdht_neighbours.c gnunet-service-wdht_neighbours.h \ 106 gnunet-service-wdht_neighbours.c gnunet-service-wdht_neighbours.h \
109 gnunet-service-wdht_routing.c gnunet-service-wdht_routing.h 107 gnunet-service-wdht_routing.c gnunet-service-wdht_routing.h
diff --git a/src/dht/gnunet-service-wdht.c b/src/dht/gnunet-service-wdht.c
index 13e60acf4..015381a55 100644
--- a/src/dht/gnunet-service-wdht.c
+++ b/src/dht/gnunet-service-wdht.c
@@ -57,55 +57,6 @@ struct GNUNET_BLOCK_Context *GDS_block_context;
57 */ 57 */
58const struct GNUNET_CONFIGURATION_Handle *GDS_cfg; 58const struct GNUNET_CONFIGURATION_Handle *GDS_cfg;
59 59
60/**
61 * Our HELLO
62 */
63struct GNUNET_MessageHeader *GDS_my_hello;
64
65/**
66 * Handle to the transport service, for getting our hello
67 */
68struct GNUNET_TRANSPORT_Handle *GDS_transport_handle;
69
70/**
71 * Handle to get our current HELLO.
72 */
73static struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
74
75/**
76 * Hello address expiration
77 */
78struct GNUNET_TIME_Relative hello_expiration;
79
80/**
81 * Should we store our topology predecessor and successor IDs into statistics?
82 */
83extern unsigned int track_topology;
84
85#if ENABLE_MALICIOUS
86/**
87 * Should this peer act malicious?
88 */
89unsigned int malicious;
90#endif
91
92
93/**
94 * Receive the HELLO from transport service, free current and replace
95 * if necessary.
96 *
97 * @param cls NULL
98 * @param message HELLO message of peer
99 */
100static void
101process_hello (void *cls, const struct GNUNET_MessageHeader *message)
102{
103 GNUNET_assert (message != NULL);
104 GNUNET_free_non_null (GDS_my_hello);
105 GDS_my_hello = GNUNET_malloc (ntohs (message->size));
106 memcpy (GDS_my_hello, message, ntohs (message->size));
107}
108
109 60
110/** 61/**
111 * Task run during shutdown. 62 * Task run during shutdown.
@@ -116,21 +67,9 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
116static void 67static void
117shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 68shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118{ 69{
119 if (NULL != ghh)
120 {
121 GNUNET_TRANSPORT_get_hello_cancel (ghh);
122 ghh = NULL;
123 }
124 if (GDS_transport_handle != NULL)
125 {
126 GNUNET_TRANSPORT_disconnect (GDS_transport_handle);
127 GDS_transport_handle = NULL;
128 }
129
130 GDS_NEIGHBOURS_done (); 70 GDS_NEIGHBOURS_done ();
131 GDS_DATACACHE_done (); 71 GDS_DATACACHE_done ();
132 GDS_ROUTING_done (); 72 GDS_ROUTING_done ();
133 GDS_HELLO_done ();
134 GDS_NSE_done (); 73 GDS_NSE_done ();
135 if (GDS_block_context != NULL) 74 if (GDS_block_context != NULL)
136 { 75 {
@@ -142,8 +81,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
142 GNUNET_STATISTICS_destroy (GDS_stats, GNUNET_YES); 81 GNUNET_STATISTICS_destroy (GDS_stats, GNUNET_YES);
143 GDS_stats = NULL; 82 GDS_stats = NULL;
144 } 83 }
145 GNUNET_free_non_null (GDS_my_hello);
146 GDS_my_hello = NULL;
147} 84}
148 85
149 86
@@ -159,41 +96,22 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
159 const struct GNUNET_CONFIGURATION_Handle *c) 96 const struct GNUNET_CONFIGURATION_Handle *c)
160{ 97{
161 unsigned long long _track_topology; 98 unsigned long long _track_topology;
99
162 GDS_cfg = c; 100 GDS_cfg = c;
163 if (GNUNET_OK !=
164 GNUNET_CONFIGURATION_get_value_time (c, "transport", "HELLO_EXPIRATION", &hello_expiration))
165 {
166 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
167 }
168 GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg); 101 GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg);
169 GDS_stats = GNUNET_STATISTICS_create ("dht", GDS_cfg); 102 GDS_stats = GNUNET_STATISTICS_create ("dht", GDS_cfg);
170 GDS_ROUTING_init (); 103 GDS_ROUTING_init ();
171 GDS_NSE_init (); 104 GDS_NSE_init ();
172 GDS_DATACACHE_init (); 105 GDS_DATACACHE_init ();
173 GDS_HELLO_init ();
174 GDS_CLIENTS_init (server); 106 GDS_CLIENTS_init (server);
175 if (GNUNET_OK ==
176 GNUNET_CONFIGURATION_get_value_number (c, "xdht", "track_toplogy",
177 &_track_topology))
178 {
179 track_topology = (unsigned int) _track_topology;
180 }
181 if (GNUNET_OK != GDS_NEIGHBOURS_init ()) 107 if (GNUNET_OK != GDS_NEIGHBOURS_init ())
182 { 108 {
183 shutdown_task (NULL, NULL); 109 shutdown_task (NULL, NULL);
184 return; 110 return;
185 } 111 }
186 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 112 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
113 &shutdown_task,
187 NULL); 114 NULL);
188 GDS_transport_handle =
189 GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL);
190 if (GDS_transport_handle == NULL)
191 {
192 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
193 _("Failed to connect to transport service!\n"));
194 return;
195 }
196 ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle, &process_hello, NULL);
197} 115}
198 116
199 117
@@ -211,10 +129,11 @@ main (int argc, char *const *argv)
211 129
212 ret = 130 ret =
213 (GNUNET_OK == 131 (GNUNET_OK ==
214 GNUNET_SERVICE_run (argc, argv, "dht", GNUNET_SERVICE_OPTION_NONE, &run, 132 GNUNET_SERVICE_run (argc, argv, "wdht",
133 GNUNET_SERVICE_OPTION_NONE, &run,
215 NULL)) ? 0 : 1; 134 NULL)) ? 0 : 1;
216 GDS_CLIENTS_done (); 135 GDS_CLIENTS_done ();
217 return ret; 136 return ret;
218} 137}
219 138
220/* end of gnunet-service-dht.c */ 139/* end of gnunet-service-wdht.c */
diff --git a/src/dht/gnunet-service-wdht_clients.c b/src/dht/gnunet-service-wdht_clients.c
index 2e4d4ef0a..896920e98 100644
--- a/src/dht/gnunet-service-wdht_clients.c
+++ b/src/dht/gnunet-service-wdht_clients.c
@@ -19,7 +19,7 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file dht/gnunet-service-dht_clients.c 22 * @file dht/gnunet-service-wdht_clients.c
23 * @brief GNUnet DHT service's client management code 23 * @brief GNUnet DHT service's client management code
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 * @author Nathan Evans 25 * @author Nathan Evans
@@ -473,8 +473,8 @@ remove_client_records (void *cls, const struct GNUNET_HashCode * key, void *valu
473 * @param cls the 'struct ForwardReplyContext' 473 * @param cls the 'struct ForwardReplyContext'
474 * @param key current key 474 * @param key current key
475 * @param value value in the hash map, a ClientQueryRecord 475 * @param value value in the hash map, a ClientQueryRecord
476 * @return GNUNET_YES (we should continue to iterate), 476 * @return #GNUNET_YES (we should continue to iterate),
477 * if the result is mal-formed, GNUNET_NO 477 * if the result is mal-formed, #GNUNET_NO
478 */ 478 */
479static int 479static int
480forward_reply (void *cls, const struct GNUNET_HashCode * key, void *value) 480forward_reply (void *cls, const struct GNUNET_HashCode * key, void *value)
@@ -777,7 +777,7 @@ GDS_CLIENTS_process_put (uint32_t options,
777 unsigned int path_length, 777 unsigned int path_length,
778 const struct GNUNET_PeerIdentity *path, 778 const struct GNUNET_PeerIdentity *path,
779 struct GNUNET_TIME_Absolute exp, 779 struct GNUNET_TIME_Absolute exp,
780 const struct GNUNET_HashCode * key, 780 const struct GNUNET_HashCode *key,
781 const void *data, 781 const void *data,
782 size_t size) 782 size_t size)
783{ 783{
@@ -1161,7 +1161,7 @@ struct RemoveByUniqueIdContext
1161 * @param cls unique ID and client to search for in source routes 1161 * @param cls unique ID and client to search for in source routes
1162 * @param key current key code 1162 * @param key current key code
1163 * @param value value in the hash map, a ClientQueryRecord 1163 * @param value value in the hash map, a ClientQueryRecord
1164 * @return GNUNET_YES (we should continue to iterate) 1164 * @return #GNUNET_YES (we should continue to iterate)
1165 */ 1165 */
1166static int 1166static int
1167remove_by_unique_id (void *cls, const struct GNUNET_HashCode * key, void *value) 1167remove_by_unique_id (void *cls, const struct GNUNET_HashCode * key, void *value)
@@ -1289,47 +1289,10 @@ handle_dht_local_monitor_stop (void *cls, struct GNUNET_SERVER_Client *client,
1289 } 1289 }
1290 r = r->next; 1290 r = r->next;
1291 } 1291 }
1292
1293 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1292 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1294} 1293}
1295 1294
1296 1295
1297#if ENABLE_MALICIOUS
1298/**
1299 * Handler for act malicious message.
1300 *
1301 * @param cls closure for the service
1302 * @param client the client we received this message from
1303 * @param message the actual message received
1304 *
1305 */
1306static void
1307handle_dht_act_malicious (void *cls, struct GNUNET_SERVER_Client *client,
1308 const struct GNUNET_MessageHeader *message)
1309{
1310 const struct GNUNET_DHT_ActMaliciousMessage *msg;
1311 struct PendingMessage *pm;
1312 struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *conf;
1313 unsigned int malicious_action;
1314
1315 msg = (const struct GNUNET_DHT_ActMaliciousMessage *)message;
1316 malicious_action = msg->action;
1317
1318 if(GNUNET_OK == GDS_NEIGHBOURS_act_malicious (malicious_action))
1319 {
1320 pm = GNUNET_malloc (sizeof (struct PendingMessage) +
1321 sizeof (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage));
1322 conf = (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *) &pm[1];
1323 conf->header.size = htons (sizeof (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage));
1324 conf->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_ACT_MALICIOUS_OK);
1325 pm->msg = &conf->header;
1326 add_pending_message (find_active_client (client), pm);
1327 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1328 }
1329}
1330#endif
1331
1332
1333/** 1296/**
1334 * Functions with this signature are called whenever a client 1297 * Functions with this signature are called whenever a client
1335 * is disconnected on the network level. 1298 * is disconnected on the network level.
@@ -1405,11 +1368,6 @@ GDS_CLIENTS_init (struct GNUNET_SERVER_Handle *server)
1405 sizeof (struct GNUNET_DHT_MonitorStartStopMessage)}, 1368 sizeof (struct GNUNET_DHT_MonitorStartStopMessage)},
1406 {&handle_dht_local_get_result_seen, NULL, 1369 {&handle_dht_local_get_result_seen, NULL,
1407 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, 0}, 1370 GNUNET_MESSAGE_TYPE_DHT_CLIENT_GET_RESULTS_KNOWN, 0},
1408 #if ENABLE_MALICIOUS
1409 {&handle_dht_act_malicious, NULL,
1410 GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS,
1411 sizeof (struct GNUNET_DHT_ActMaliciousMessage)},
1412 #endif
1413 {NULL, NULL, 0, 0} 1371 {NULL, NULL, 0, 0}
1414 }; 1372 };
1415 forward_map = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO); 1373 forward_map = GNUNET_CONTAINER_multihashmap_create (1024, GNUNET_NO);
@@ -1446,4 +1404,4 @@ GDS_CLIENTS_done ()
1446 } 1404 }
1447} 1405}
1448 1406
1449/* end of gnunet-service-dht_clients.c */ 1407/* end of gnunet-service-wdht_clients.c */
diff --git a/src/dht/gnunet-service-wdht_hello.c b/src/dht/gnunet-service-wdht_hello.c
deleted file mode 100644
index c5e6c7999..000000000
--- a/src/dht/gnunet-service-wdht_hello.c
+++ /dev/null
@@ -1,137 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file dht/gnunet-service-xdht_hello.c
23 * @brief GNUnet DHT integration with peerinfo
24 * @author Christian Grothoff
25 *
26 * TODO:
27 * - consider adding mechanism to remove expired HELLOs
28 */
29#include "platform.h"
30#include "gnunet-service-wdht.h"
31#include "gnunet-service-wdht_hello.h"
32#include "gnunet_peerinfo_service.h"
33
34
35/**
36 * Handle for peerinfo notifications.
37 */
38static struct GNUNET_PEERINFO_NotifyContext *pnc;
39
40/**
41 * Hash map of peers to HELLOs.
42 */
43static struct GNUNET_CONTAINER_MultiPeerMap *peer_to_hello;
44
45
46/**
47 * Obtain a peer's HELLO if available
48 *
49 * @param peer peer to look for a HELLO from
50 * @return HELLO for the given peer
51 */
52const struct GNUNET_HELLO_Message *
53GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer)
54{
55 if (NULL == peer_to_hello)
56 return NULL;
57 return GNUNET_CONTAINER_multipeermap_get (peer_to_hello, peer);
58}
59
60
61/**
62 * Function called for each HELLO known to PEERINFO.
63 *
64 * @param cls closure
65 * @param peer id of the peer, NULL for last call
66 * @param hello hello message for the peer (can be NULL)
67 * @param err_msg error message (not used)
68 */
69static void
70process_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
71 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
72{
73 struct GNUNET_TIME_Absolute ex;
74 struct GNUNET_HELLO_Message *hm;
75
76 if (hello == NULL)
77 return;
78 ex = GNUNET_HELLO_get_last_expiration (hello);
79 if (0 == GNUNET_TIME_absolute_get_remaining (ex).rel_value_us)
80 return;
81 GNUNET_STATISTICS_update (GDS_stats,
82 gettext_noop ("# HELLOs obtained from peerinfo"), 1,
83 GNUNET_NO);
84 hm = GNUNET_CONTAINER_multipeermap_get (peer_to_hello, peer);
85 GNUNET_free_non_null (hm);
86 hm = GNUNET_malloc (GNUNET_HELLO_size (hello));
87 memcpy (hm, hello, GNUNET_HELLO_size (hello));
88 GNUNET_assert (GNUNET_SYSERR !=
89 GNUNET_CONTAINER_multipeermap_put (peer_to_hello,
90 peer, hm,
91 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE));
92}
93
94
95/**
96 * Initialize HELLO subsystem.
97 */
98void
99GDS_HELLO_init ()
100{
101 pnc = GNUNET_PEERINFO_notify (GDS_cfg, GNUNET_NO, &process_hello, NULL);
102 peer_to_hello = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_NO);
103}
104
105
106/**
107 * Free memory occopied by the HELLO.
108 */
109static int
110free_hello (void *cls,
111 const struct GNUNET_PeerIdentity *key,
112 void *hello)
113{
114 GNUNET_free (hello);
115 return GNUNET_OK;
116}
117
118
119/**
120 * Shutdown HELLO subsystem.
121 */
122void
123GDS_HELLO_done ()
124{
125 if (NULL != pnc)
126 {
127 GNUNET_PEERINFO_notify_cancel (pnc);
128 pnc = NULL;
129 }
130 if (NULL != peer_to_hello)
131 {
132 GNUNET_CONTAINER_multipeermap_iterate (peer_to_hello, &free_hello, NULL);
133 GNUNET_CONTAINER_multipeermap_destroy (peer_to_hello);
134 }
135}
136
137/* end of gnunet-service-dht_hello.c */
diff --git a/src/dht/gnunet-service-wdht_hello.h b/src/dht/gnunet-service-wdht_hello.h
deleted file mode 100644
index e7376e7b0..000000000
--- a/src/dht/gnunet-service-wdht_hello.h
+++ /dev/null
@@ -1,55 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19*/
20
21/**
22 * @file dht/gnunet-service-xdht_hello.h
23 * @brief GNUnet DHT integration with peerinfo
24 * @author Christian Grothoff
25 */
26#ifndef GNUNET_SERVICE_XDHT_HELLO_H
27#define GNUNET_SERVICE_XDHT_HELLO_H
28
29#include "gnunet_util_lib.h"
30#include "gnunet_hello_lib.h"
31
32/**
33 * Obtain a peer's HELLO if available
34 *
35 * @param peer peer to look for a HELLO from
36 * @return HELLO for the given peer
37 */
38const struct GNUNET_HELLO_Message *
39GDS_HELLO_get (const struct GNUNET_PeerIdentity *peer);
40
41
42/**
43 * Initialize HELLO subsystem.
44 */
45void
46GDS_HELLO_init (void);
47
48
49/**
50 * Shutdown HELLO subsystem.
51 */
52void
53GDS_HELLO_done (void);
54
55#endif
diff --git a/src/dht/gnunet-service-wdht_neighbours.h b/src/dht/gnunet-service-wdht_neighbours.h
index edb241a6c..87acc3908 100644
--- a/src/dht/gnunet-service-wdht_neighbours.h
+++ b/src/dht/gnunet-service-wdht_neighbours.h
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 Copyright (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors) 3 Copyright (C) 2009, 2010, 2011, 2015 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -19,28 +19,19 @@
19*/ 19*/
20 20
21/** 21/**
22 * @file dht/gnunet-service-xdht_neighbours.h 22 * @file dht/gnunet-service-wdht_neighbours.h
23 * @brief GNUnet DHT routing code 23 * @brief GNUnet DHT routing code
24 * @author Supriti Singh 24 * @author Supriti Singh
25 */ 25 */
26 26
27#ifndef GNUNET_SERVICE_XDHT_NEIGHBOURS_H 27#ifndef GNUNET_SERVICE_WDHT_NEIGHBOURS_H
28#define GNUNET_SERVICE_XDHT_NEIGHBOURS_H 28#define GNUNET_SERVICE_WDHT_NEIGHBOURS_H
29 29
30#include "gnunet_util_lib.h" 30#include "gnunet_util_lib.h"
31#include "gnunet_block_lib.h" 31#include "gnunet_block_lib.h"
32#include "gnunet_dht_service.h" 32#include "gnunet_dht_service.h"
33 33
34 34
35#if ENABLE_MALICIOUS
36/**
37 * Set the ENABLE_MALICIOUS value to malicious.
38 * @param malicious
39 */
40int
41GDS_NEIGHBOURS_act_malicious (unsigned int malicious);
42#endif
43
44/** 35/**
45 * Handle the put request from the client. 36 * Handle the put request from the client.
46 * @param key Key for the content 37 * @param key Key for the content
@@ -69,10 +60,11 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key,
69 * @param desired_replication_level Desired replication count 60 * @param desired_replication_level Desired replication count
70 */ 61 */
71void 62void
72GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key, 63GDS_NEIGHBOURS_handle_get (const struct GNUNET_HashCode *key,
73 enum GNUNET_BLOCK_Type block_type, 64 enum GNUNET_BLOCK_Type block_type,
74 enum GNUNET_DHT_RouteOption options, 65 enum GNUNET_DHT_RouteOption options,
75 uint32_t desired_replication_level); 66 uint32_t desired_replication_level);
67
76 68
77/** 69/**
78 * Send the get result to requesting client. 70 * Send the get result to requesting client.
@@ -100,25 +92,8 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key,
100 struct GNUNET_TIME_Absolute expiration, 92 struct GNUNET_TIME_Absolute expiration,
101 const void *data, size_t data_size); 93 const void *data, size_t data_size);
102 94
103/**
104 * Construct a trail teardown message and forward it to target friend.
105 * @param trail_id Unique identifier of the trail.
106 * @param trail_direction Direction of trail.
107 * @param target_friend Friend to get this message.
108 */
109void
110GDS_NEIGHBOURS_send_trail_teardown (const struct GNUNET_HashCode *trail_id,
111 unsigned int trail_direction,
112 const struct GNUNET_PeerIdentity *peer);
113 95
114/** 96/**
115 * Return friend corresponding to peer.
116 * @param peer
117 * @return Friend
118 */
119struct FriendInfo *
120GDS_NEIGHBOURS_get_friend (struct GNUNET_PeerIdentity peer);
121/**
122 * Initialize neighbours subsystem. 97 * Initialize neighbours subsystem.
123 * 98 *
124 * @return #GNUNET_OK on success, 99 * @return #GNUNET_OK on success,
diff --git a/src/dht/gnunet-service-xdht.c b/src/dht/gnunet-service-xdht.c
index f5ad28001..b946dc048 100644
--- a/src/dht/gnunet-service-xdht.c
+++ b/src/dht/gnunet-service-xdht.c
@@ -58,26 +58,6 @@ struct GNUNET_BLOCK_Context *GDS_block_context;
58const struct GNUNET_CONFIGURATION_Handle *GDS_cfg; 58const struct GNUNET_CONFIGURATION_Handle *GDS_cfg;
59 59
60/** 60/**
61 * Our HELLO
62 */
63struct GNUNET_MessageHeader *GDS_my_hello;
64
65/**
66 * Handle to the transport service, for getting our hello
67 */
68struct GNUNET_TRANSPORT_Handle *GDS_transport_handle;
69
70/**
71 * Handle to get our current HELLO.
72 */
73static struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
74
75/**
76 * Hello address expiration
77 */
78struct GNUNET_TIME_Relative hello_expiration;
79
80/**
81 * Should we store our topology predecessor and successor IDs into statistics? 61 * Should we store our topology predecessor and successor IDs into statistics?
82 */ 62 */
83extern unsigned int track_topology; 63extern unsigned int track_topology;
@@ -91,23 +71,6 @@ unsigned int malicious;
91 71
92 72
93/** 73/**
94 * Receive the HELLO from transport service, free current and replace
95 * if necessary.
96 *
97 * @param cls NULL
98 * @param message HELLO message of peer
99 */
100static void
101process_hello (void *cls, const struct GNUNET_MessageHeader *message)
102{
103 GNUNET_assert (message != NULL);
104 GNUNET_free_non_null (GDS_my_hello);
105 GDS_my_hello = GNUNET_malloc (ntohs (message->size));
106 memcpy (GDS_my_hello, message, ntohs (message->size));
107}
108
109
110/**
111 * Task run during shutdown. 74 * Task run during shutdown.
112 * 75 *
113 * @param cls unused 76 * @param cls unused
@@ -116,21 +79,9 @@ process_hello (void *cls, const struct GNUNET_MessageHeader *message)
116static void 79static void
117shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 80shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
118{ 81{
119 if (NULL != ghh)
120 {
121 GNUNET_TRANSPORT_get_hello_cancel (ghh);
122 ghh = NULL;
123 }
124 if (GDS_transport_handle != NULL)
125 {
126 GNUNET_TRANSPORT_disconnect (GDS_transport_handle);
127 GDS_transport_handle = NULL;
128 }
129
130 GDS_NEIGHBOURS_done (); 82 GDS_NEIGHBOURS_done ();
131 GDS_DATACACHE_done (); 83 GDS_DATACACHE_done ();
132 GDS_ROUTING_done (); 84 GDS_ROUTING_done ();
133 GDS_HELLO_done ();
134 GDS_NSE_done (); 85 GDS_NSE_done ();
135 if (GDS_block_context != NULL) 86 if (GDS_block_context != NULL)
136 { 87 {
@@ -142,8 +93,6 @@ shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
142 GNUNET_STATISTICS_destroy (GDS_stats, GNUNET_YES); 93 GNUNET_STATISTICS_destroy (GDS_stats, GNUNET_YES);
143 GDS_stats = NULL; 94 GDS_stats = NULL;
144 } 95 }
145 GNUNET_free_non_null (GDS_my_hello);
146 GDS_my_hello = NULL;
147} 96}
148 97
149 98
@@ -159,18 +108,13 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
159 const struct GNUNET_CONFIGURATION_Handle *c) 108 const struct GNUNET_CONFIGURATION_Handle *c)
160{ 109{
161 unsigned long long _track_topology; 110 unsigned long long _track_topology;
111
162 GDS_cfg = c; 112 GDS_cfg = c;
163 if (GNUNET_OK !=
164 GNUNET_CONFIGURATION_get_value_time (c, "transport", "HELLO_EXPIRATION", &hello_expiration))
165 {
166 hello_expiration = GNUNET_CONSTANTS_HELLO_ADDRESS_EXPIRATION;
167 }
168 GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg); 113 GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg);
169 GDS_stats = GNUNET_STATISTICS_create ("dht", GDS_cfg); 114 GDS_stats = GNUNET_STATISTICS_create ("dht", GDS_cfg);
170 GDS_ROUTING_init (); 115 GDS_ROUTING_init ();
171 GDS_NSE_init (); 116 GDS_NSE_init ();
172 GDS_DATACACHE_init (); 117 GDS_DATACACHE_init ();
173 GDS_HELLO_init ();
174 GDS_CLIENTS_init (server); 118 GDS_CLIENTS_init (server);
175 if (GNUNET_OK == 119 if (GNUNET_OK ==
176 GNUNET_CONFIGURATION_get_value_number (c, "xdht", "track_toplogy", 120 GNUNET_CONFIGURATION_get_value_number (c, "xdht", "track_toplogy",
@@ -183,17 +127,9 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
183 shutdown_task (NULL, NULL); 127 shutdown_task (NULL, NULL);
184 return; 128 return;
185 } 129 }
186 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task, 130 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
131 &shutdown_task,
187 NULL); 132 NULL);
188 GDS_transport_handle =
189 GNUNET_TRANSPORT_connect (GDS_cfg, NULL, NULL, NULL, NULL, NULL);
190 if (GDS_transport_handle == NULL)
191 {
192 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
193 _("Failed to connect to transport service!\n"));
194 return;
195 }
196 ghh = GNUNET_TRANSPORT_get_hello (GDS_transport_handle, &process_hello, NULL);
197} 133}
198 134
199 135
@@ -211,10 +147,12 @@ main (int argc, char *const *argv)
211 147
212 ret = 148 ret =
213 (GNUNET_OK == 149 (GNUNET_OK ==
214 GNUNET_SERVICE_run (argc, argv, "dht", GNUNET_SERVICE_OPTION_NONE, &run, 150 GNUNET_SERVICE_run (argc, argv,
151 "xdht",
152 GNUNET_SERVICE_OPTION_NONE, &run,
215 NULL)) ? 0 : 1; 153 NULL)) ? 0 : 1;
216 GDS_CLIENTS_done (); 154 GDS_CLIENTS_done ();
217 return ret; 155 return ret;
218} 156}
219 157
220/* end of gnunet-service-dht.c */ 158/* end of gnunet-service-xdht.c */
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h
index edb241a6c..a46210139 100644
--- a/src/dht/gnunet-service-xdht_neighbours.h
+++ b/src/dht/gnunet-service-xdht_neighbours.h
@@ -111,13 +111,7 @@ GDS_NEIGHBOURS_send_trail_teardown (const struct GNUNET_HashCode *trail_id,
111 unsigned int trail_direction, 111 unsigned int trail_direction,
112 const struct GNUNET_PeerIdentity *peer); 112 const struct GNUNET_PeerIdentity *peer);
113 113
114/** 114
115 * Return friend corresponding to peer.
116 * @param peer
117 * @return Friend
118 */
119struct FriendInfo *
120GDS_NEIGHBOURS_get_friend (struct GNUNET_PeerIdentity peer);
121/** 115/**
122 * Initialize neighbours subsystem. 116 * Initialize neighbours subsystem.
123 * 117 *