aboutsummaryrefslogtreecommitdiff
path: root/src/hostlist/gnunet-daemon-hostlist.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2010-04-08 13:06:54 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2010-04-08 13:06:54 +0000
commit967a3bbae2c2a7c6fe5c975f1ba6cdbbd17d183f (patch)
treebf7a9af6761b62d3e8abfc95469d470547fb93cc /src/hostlist/gnunet-daemon-hostlist.c
parente8757f03baa17eddef096da91122a282a39e9cb7 (diff)
downloadgnunet-967a3bbae2c2a7c6fe5c975f1ba6cdbbd17d183f.tar.gz
gnunet-967a3bbae2c2a7c6fe5c975f1ba6cdbbd17d183f.zip
hostlist client gets notified when hostlist advertisments arrive
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist.c')
-rw-r--r--src/hostlist/gnunet-daemon-hostlist.c60
1 files changed, 42 insertions, 18 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c
index 9f3453890..2197a50b1 100644
--- a/src/hostlist/gnunet-daemon-hostlist.c
+++ b/src/hostlist/gnunet-daemon-hostlist.c
@@ -75,6 +75,12 @@ static struct GNUNET_STATISTICS_Handle *stats;
75struct GNUNET_CORE_Handle *core; 75struct GNUNET_CORE_Handle *core;
76 76
77/** 77/**
78 * Handle to the hostlist client's advertisement handler
79 */
80GNUNET_CORE_MessageCallback client_adv_handler = NULL;
81
82
83/**
78 * gnunet-daemon-hostlist command line options. 84 * gnunet-daemon-hostlist command line options.
79 */ 85 */
80static struct GNUNET_GETOPT_CommandLineOption options[] = { 86static struct GNUNET_GETOPT_CommandLineOption options[] = {
@@ -112,20 +118,41 @@ core_init (void *cls,
112/** 118/**
113 * Core handler for p2p hostlist advertisements 119 * Core handler for p2p hostlist advertisements
114 */ 120 */
115static int handle_hostlist_advertisement (void *cls, 121static int advertisement_handler (void *cls,
116 const struct GNUNET_PeerIdentity * peer, 122 const struct GNUNET_PeerIdentity * peer,
117 const struct GNUNET_MessageHeader * message, 123 const struct GNUNET_MessageHeader * message,
118 struct GNUNET_TIME_Relative latency, 124 struct GNUNET_TIME_Relative latency,
119 uint32_t distance) 125 uint32_t distance)
120{ 126{
121#if DEBUG_HOSTLIST_LEARNING 127 if (advertising && (NULL != client_adv_handler))
122 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 128 {
123 _("Recieved hostlist advertisement\n")); 129 (*client_adv_handler) (cls, peer, message, latency, distance);
124#endif 130 return GNUNET_YES;
131 }
132 return GNUNET_NO;
133}
125 134
126 return GNUNET_OK; 135/**
136 * Method called whenever a given peer connects.
137 *
138 * @param cls closure
139 * @param peer peer identity this notification is about
140 * @param latency reported latency of the connection with 'other'
141 * @param distance reported distance (DV) to 'other'
142 */
143static void
144connect_handler (void *cls,
145 const struct
146 GNUNET_PeerIdentity * peer,
147 struct GNUNET_TIME_Relative latency,
148 uint32_t distance)
149{
150 /* call hostlist client connection handler*/
151
152 /* do my own stuff */
127} 153}
128 154
155
129/** 156/**
130 * Last task run during shutdown. Disconnects us from 157 * Last task run during shutdown. Disconnects us from
131 * the other services. 158 * the other services.
@@ -161,7 +188,7 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
161 * service. 188 * service.
162 */ 189 */
163static struct GNUNET_CORE_MessageHandler handlers[] = { 190static struct GNUNET_CORE_MessageHandler handlers[] = {
164 { &handle_hostlist_advertisement, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0}, 191 { &advertisement_handler, GNUNET_MESSAGE_TYPE_HOSTLIST_ADVERTISEMENT, 0},
165 { NULL, 0, 0 } 192 { NULL, 0, 0 }
166}; 193};
167 194
@@ -184,14 +211,6 @@ run (void *cls,
184 GNUNET_CORE_ConnectEventHandler ch = NULL; 211 GNUNET_CORE_ConnectEventHandler ch = NULL;
185 GNUNET_CORE_DisconnectEventHandler dh = NULL; 212 GNUNET_CORE_DisconnectEventHandler dh = NULL;
186 213
187
188
189 struct GNUNET_CORE_MessageHandler null_handler[] = {
190 { NULL, 0, 0 }
191 };
192
193 struct GNUNET_CORE_MessageHandler *used_handler = null_handler;
194
195 if ( (! bootstrapping) && 214 if ( (! bootstrapping) &&
196 (! learning) && 215 (! learning) &&
197 (! provide_hostlist) ) 216 (! provide_hostlist) )
@@ -204,7 +223,7 @@ run (void *cls,
204 if (bootstrapping) 223 if (bootstrapping)
205 { 224 {
206 GNUNET_HOSTLIST_client_start (cfg, sched, stats, 225 GNUNET_HOSTLIST_client_start (cfg, sched, stats,
207 &ch, &dh); 226 &ch, &dh, &client_adv_handler);
208 } 227 }
209 if (provide_hostlist) 228 if (provide_hostlist)
210 { 229 {
@@ -212,9 +231,14 @@ run (void *cls,
212 } 231 }
213 if (learning) 232 if (learning)
214 { 233 {
215 used_handler = handlers; 234
216 } 235 }
217 236
237
238 struct GNUNET_TIME_Relative a;
239 advertisement_handler(NULL,NULL,NULL,a,6);
240
241
218 core = GNUNET_CORE_connect (sched, cfg, 242 core = GNUNET_CORE_connect (sched, cfg,
219 GNUNET_TIME_UNIT_FOREVER_REL, 243 GNUNET_TIME_UNIT_FOREVER_REL,
220 NULL, 244 NULL,
@@ -222,7 +246,7 @@ run (void *cls,
222 NULL, ch, dh, 246 NULL, ch, dh,
223 NULL, GNUNET_NO, 247 NULL, GNUNET_NO,
224 NULL, GNUNET_NO, 248 NULL, GNUNET_NO,
225 used_handler); 249 handlers);
226 250
227 GNUNET_SCHEDULER_add_delayed (sched, 251 GNUNET_SCHEDULER_add_delayed (sched,
228 GNUNET_TIME_UNIT_FOREVER_REL, 252 GNUNET_TIME_UNIT_FOREVER_REL,