diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-08 14:29:44 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2010-04-08 14:29:44 +0000 |
commit | ab44ab06bbd602e11035e9109c9f7d5b9a244cb0 (patch) | |
tree | 4a3b7bc9a0f0ee151419e94bb1f3be537af0b5c9 /src/hostlist/gnunet-daemon-hostlist.c | |
parent | 089091bf7560dbe74876b0be4b3daed53b572d46 (diff) | |
download | gnunet-ab44ab06bbd602e11035e9109c9f7d5b9a244cb0.tar.gz gnunet-ab44ab06bbd602e11035e9109c9f7d5b9a244cb0.zip |
Modifications so hostlist client and server will notified when new peers connect
Diffstat (limited to 'src/hostlist/gnunet-daemon-hostlist.c')
-rw-r--r-- | src/hostlist/gnunet-daemon-hostlist.c | 68 |
1 files changed, 53 insertions, 15 deletions
diff --git a/src/hostlist/gnunet-daemon-hostlist.c b/src/hostlist/gnunet-daemon-hostlist.c index 2197a50b1..cf4be4798 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 GNUNET_YES | ||
46 | |||
45 | /** | 47 | /** |
46 | * Set if we are allowed to advertise our hostlist to others. | 48 | * Set if we are allowed to advertise our hostlist to others. |
47 | */ | 49 | */ |
@@ -79,6 +81,25 @@ struct GNUNET_CORE_Handle *core; | |||
79 | */ | 81 | */ |
80 | GNUNET_CORE_MessageCallback client_adv_handler = NULL; | 82 | GNUNET_CORE_MessageCallback client_adv_handler = NULL; |
81 | 83 | ||
84 | /** | ||
85 | * Handle to hostlist client's connect handler | ||
86 | */ | ||
87 | GNUNET_CORE_ConnectEventHandler client_ch = NULL; | ||
88 | |||
89 | /** | ||
90 | * Handle to hostlist client's disconnect handler | ||
91 | */ | ||
92 | GNUNET_CORE_DisconnectEventHandler client_dh = NULL; | ||
93 | |||
94 | /** | ||
95 | * Handle to hostlist server's connect handler | ||
96 | */ | ||
97 | GNUNET_CORE_ConnectEventHandler server_ch = NULL; | ||
98 | |||
99 | /** | ||
100 | * Handle to hostlist server's disconnect handler | ||
101 | */ | ||
102 | GNUNET_CORE_DisconnectEventHandler server_dh = NULL; | ||
82 | 103 | ||
83 | /** | 104 | /** |
84 | * gnunet-daemon-hostlist command line options. | 105 | * gnunet-daemon-hostlist command line options. |
@@ -133,7 +154,7 @@ static int advertisement_handler (void *cls, | |||
133 | } | 154 | } |
134 | 155 | ||
135 | /** | 156 | /** |
136 | * Method called whenever a given peer connects. | 157 | * Method called whenever a given peer connects. Wrapper to call both client's and server's functions |
137 | * | 158 | * |
138 | * @param cls closure | 159 | * @param cls closure |
139 | * @param peer peer identity this notification is about | 160 | * @param peer peer identity this notification is about |
@@ -147,11 +168,36 @@ connect_handler (void *cls, | |||
147 | struct GNUNET_TIME_Relative latency, | 168 | struct GNUNET_TIME_Relative latency, |
148 | uint32_t distance) | 169 | uint32_t distance) |
149 | { | 170 | { |
150 | /* call hostlist client connection handler*/ | 171 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
151 | 172 | "A new peer connected, notifying client and server\n"); | |
152 | /* do my own stuff */ | 173 | if ( NULL != client_ch) |
174 | (*client_ch) (cls, peer, latency, distance); | ||
175 | if ( NULL != server_ch) | ||
176 | (*server_ch) (cls, peer, latency, distance); | ||
153 | } | 177 | } |
154 | 178 | ||
179 | /** | ||
180 | * Method called whenever a given peer disconnects. Wrapper to call both client's and server's functions | ||
181 | * | ||
182 | * @param cls closure | ||
183 | * @param peer peer identity this notification is about | ||
184 | * @param latency reported latency of the connection with 'other' | ||
185 | * @param distance reported distance (DV) to 'other' | ||
186 | */ | ||
187 | static void | ||
188 | disconnect_handler (void *cls, | ||
189 | const struct | ||
190 | GNUNET_PeerIdentity * peer) | ||
191 | { | ||
192 | |||
193 | /* call hostlist client disconnect handler*/ | ||
194 | if ( NULL != client_dh) | ||
195 | (*client_dh) (cls, peer); | ||
196 | |||
197 | /* call hostlist server disconnect handler*/ | ||
198 | if ( NULL != server_dh) | ||
199 | (*server_dh) (cls, peer); | ||
200 | } | ||
155 | 201 | ||
156 | /** | 202 | /** |
157 | * Last task run during shutdown. Disconnects us from | 203 | * Last task run during shutdown. Disconnects us from |
@@ -208,9 +254,6 @@ run (void *cls, | |||
208 | const char *cfgfile, | 254 | const char *cfgfile, |
209 | const struct GNUNET_CONFIGURATION_Handle * cfg) | 255 | const struct GNUNET_CONFIGURATION_Handle * cfg) |
210 | { | 256 | { |
211 | GNUNET_CORE_ConnectEventHandler ch = NULL; | ||
212 | GNUNET_CORE_DisconnectEventHandler dh = NULL; | ||
213 | |||
214 | if ( (! bootstrapping) && | 257 | if ( (! bootstrapping) && |
215 | (! learning) && | 258 | (! learning) && |
216 | (! provide_hostlist) ) | 259 | (! provide_hostlist) ) |
@@ -223,27 +266,22 @@ run (void *cls, | |||
223 | if (bootstrapping) | 266 | if (bootstrapping) |
224 | { | 267 | { |
225 | GNUNET_HOSTLIST_client_start (cfg, sched, stats, | 268 | GNUNET_HOSTLIST_client_start (cfg, sched, stats, |
226 | &ch, &dh, &client_adv_handler); | 269 | &client_ch, &client_dh, &client_adv_handler); |
227 | } | 270 | } |
228 | if (provide_hostlist) | 271 | if (provide_hostlist) |
229 | { | 272 | { |
230 | GNUNET_HOSTLIST_server_start (cfg, sched, stats); | 273 | GNUNET_HOSTLIST_server_start (cfg, sched, stats, &server_ch, &server_dh); |
231 | } | 274 | } |
232 | if (learning) | 275 | if (learning) |
233 | { | 276 | { |
234 | 277 | ||
235 | } | 278 | } |
236 | 279 | ||
237 | |||
238 | struct GNUNET_TIME_Relative a; | ||
239 | advertisement_handler(NULL,NULL,NULL,a,6); | ||
240 | |||
241 | |||
242 | core = GNUNET_CORE_connect (sched, cfg, | 280 | core = GNUNET_CORE_connect (sched, cfg, |
243 | GNUNET_TIME_UNIT_FOREVER_REL, | 281 | GNUNET_TIME_UNIT_FOREVER_REL, |
244 | NULL, | 282 | NULL, |
245 | &core_init, | 283 | &core_init, |
246 | NULL, ch, dh, | 284 | NULL, &connect_handler, &disconnect_handler, |
247 | NULL, GNUNET_NO, | 285 | NULL, GNUNET_NO, |
248 | NULL, GNUNET_NO, | 286 | NULL, GNUNET_NO, |
249 | handlers); | 287 | handlers); |