diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-07 15:40:12 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-07 15:40:12 +0000 |
commit | 03fc37c78093f21bbe4f34201ab109d81340f216 (patch) | |
tree | e77c85aae7a0cc0b5cb636175d530541f1826b33 /src/hostlist/gnunet-daemon-hostlist.c | |
parent | 777ca32789a5fbcbaae6d795bd9ed12375101de7 (diff) | |
download | gnunet-03fc37c78093f21bbe4f34201ab109d81340f216.tar.gz gnunet-03fc37c78093f21bbe4f34201ab109d81340f216.zip |
Initial changes to implement hostlist learning
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist.c')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 65 |
1 files changed, 53 insertions, 12 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 133308edf..d02efdc62 100644 --- a/src/hostlist/gnunet-daemon-hostlist.c +++ b/src/hostlist/gnunet-daemon-hostlist.c | |||
@@ -42,6 +42,8 @@ | |||
42 | #include "gnunet_time_lib.h" | 42 | #include "gnunet_time_lib.h" |
43 | #include "gnunet_util_lib.h" | 43 | #include "gnunet_util_lib.h" |
44 | 44 | ||
45 | #define DEBUG_HOSTLIST_LEARNING GNUNET_YES | ||
46 | #define VERBOSE GNUNET_YES | ||
45 | 47 | ||
46 | /** | 48 | /** |
47 | * Set if we are allowed to advertise our hostlist to others. | 49 | * Set if we are allowed to advertise our hostlist to others. |
@@ -110,6 +112,22 @@ core_init (void *cls, | |||
110 | } | 112 | } |
111 | } | 113 | } |
112 | 114 | ||
115 | /** | ||
116 | * Core handler for p2p hostlist advertisements | ||
117 | */ | ||
118 | static int handle_hostlist_advertisement (void *cls, | ||
119 | const struct GNUNET_PeerIdentity * peer, | ||
120 | const struct GNUNET_MessageHeader * message, | ||
121 | struct GNUNET_TIME_Relative latency, | ||
122 | uint32_t distance) | ||
123 | { | ||
124 | #if DEBUG_HOSTLIST_LEARNING | ||
125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
126 | _("Recieved hostlist advertisement\n")); | ||
127 | #endif | ||
128 | |||
129 | return GNUNET_OK; | ||
130 | } | ||
113 | 131 | ||
114 | /** | 132 | /** |
115 | * Last task run during shutdown. Disconnects us from | 133 | * Last task run during shutdown. Disconnects us from |
@@ -119,7 +137,7 @@ static void | |||
119 | cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 137 | cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
120 | { | 138 | { |
121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 139 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
122 | "Hostlist daemon is shutting down.\n"); | 140 | "Hostlist daemon is shutting down\n"); |
123 | if (bootstrapping) | 141 | if (bootstrapping) |
124 | { | 142 | { |
125 | GNUNET_HOSTLIST_client_stop (); | 143 | GNUNET_HOSTLIST_client_stop (); |
@@ -141,6 +159,14 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
141 | } | 159 | } |
142 | } | 160 | } |
143 | 161 | ||
162 | /** | ||
163 | * List of handlers for the messages understood by this | ||
164 | * service. | ||
165 | */ | ||
166 | static struct GNUNET_CORE_MessageHandler handlers[] = { | ||
167 | { &handle_hostlist_advertisement, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, | ||
168 | { NULL, 0, 0 } | ||
169 | }; | ||
144 | 170 | ||
145 | /** | 171 | /** |
146 | * Main function that will be run. | 172 | * Main function that will be run. |
@@ -160,10 +186,14 @@ run (void *cls, | |||
160 | { | 186 | { |
161 | GNUNET_CORE_ConnectEventHandler ch = NULL; | 187 | GNUNET_CORE_ConnectEventHandler ch = NULL; |
162 | GNUNET_CORE_DisconnectEventHandler dh = NULL; | 188 | GNUNET_CORE_DisconnectEventHandler dh = NULL; |
163 | struct GNUNET_CORE_MessageHandler handlers[] = | 189 | |
164 | { | 190 | |
191 | |||
192 | struct GNUNET_CORE_MessageHandler null_handler[] = { | ||
165 | { NULL, 0, 0 } | 193 | { NULL, 0, 0 } |
166 | }; | 194 | }; |
195 | |||
196 | struct GNUNET_CORE_MessageHandler *used_handler = null_handler; | ||
167 | 197 | ||
168 | if ( (! bootstrapping) && | 198 | if ( (! bootstrapping) && |
169 | (! learning) && | 199 | (! learning) && |
@@ -185,16 +215,18 @@ run (void *cls, | |||
185 | } | 215 | } |
186 | if (learning) | 216 | if (learning) |
187 | { | 217 | { |
188 | /* FIXME (register handler with core for hostlist ads) */ | 218 | used_handler = handlers; |
189 | } | 219 | } |
220 | |||
190 | core = GNUNET_CORE_connect (sched, cfg, | 221 | core = GNUNET_CORE_connect (sched, cfg, |
191 | GNUNET_TIME_UNIT_FOREVER_REL, | 222 | GNUNET_TIME_UNIT_FOREVER_REL, |
192 | NULL, | 223 | NULL, |
193 | &core_init, | 224 | &core_init, |
194 | NULL, ch, dh, | 225 | NULL, ch, dh, |
195 | NULL, GNUNET_NO, | 226 | NULL, GNUNET_NO, |
196 | NULL, GNUNET_NO, | 227 | NULL, GNUNET_NO, |
197 | handlers); | 228 | used_handler); |
229 | |||
198 | GNUNET_SCHEDULER_add_delayed (sched, | 230 | GNUNET_SCHEDULER_add_delayed (sched, |
199 | GNUNET_TIME_UNIT_FOREVER_REL, | 231 | GNUNET_TIME_UNIT_FOREVER_REL, |
200 | &cleaning_task, NULL); | 232 | &cleaning_task, NULL); |
@@ -220,6 +252,14 @@ int | |||
220 | main (int argc, char *const *argv) | 252 | main (int argc, char *const *argv) |
221 | { | 253 | { |
222 | int ret; | 254 | int ret; |
255 | GNUNET_log_setup ("hostlist","DEBUG",NULL); | ||
256 | |||
257 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
258 | "ERROR\n"); | ||
259 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
260 | "DEBUG\n"); | ||
261 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | ||
262 | "INFO\n"); | ||
223 | 263 | ||
224 | ret = (GNUNET_OK == | 264 | ret = (GNUNET_OK == |
225 | GNUNET_PROGRAM_run (argc, | 265 | GNUNET_PROGRAM_run (argc, |
@@ -228,6 +268,7 @@ main (int argc, char *const *argv) | |||
228 | _("GNUnet hostlist server and client"), | 268 | _("GNUnet hostlist server and client"), |
229 | options, | 269 | options, |
230 | &run, NULL)) ? 0 : 1; | 270 | &run, NULL)) ? 0 : 1; |
271 | |||
231 | return ret; | 272 | return ret; |
232 | } | 273 | } |
233 | 274 | ||