diff options
author | Philipp Tölke <toelke@in.tum.de> | 2011-08-31 10:14:17 +0000 |
---|---|---|
committer | Philipp Tölke <toelke@in.tum.de> | 2011-08-31 10:14:17 +0000 |
commit | 48d92a6a7ff018ec85fe4374f5cbe78133c64560 (patch) | |
tree | 7fba95c25d09cde9d53fbfb3bb85a9ba97e58563 /src/mesh/mesh_api.c | |
parent | 455bf840c258768849614c53103f58da984dfe7c (diff) | |
download | gnunet-48d92a6a7ff018ec85fe4374f5cbe78133c64560.tar.gz gnunet-48d92a6a7ff018ec85fe4374f5cbe78133c64560.zip |
send a hello-packet for the mesh regularily
Diffstat (limited to 'src/mesh/mesh_api.c')
-rw-r--r-- | src/mesh/mesh_api.c | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c index 2fdd7504e..5ea4789b8 100644 --- a/src/mesh/mesh_api.c +++ b/src/mesh/mesh_api.c | |||
@@ -112,6 +112,13 @@ struct peer_list_element | |||
112 | 112 | ||
113 | struct GNUNET_TRANSPORT_ATS_Information atsi; | 113 | struct GNUNET_TRANSPORT_ATS_Information atsi; |
114 | struct peer_list_element *next, *prev; | 114 | struct peer_list_element *next, *prev; |
115 | |||
116 | /* The handle that sends the hellos to this peer */ | ||
117 | struct GNUNET_CORE_TransmitHandle *hello; | ||
118 | |||
119 | GNUNET_SCHEDULER_TaskIdentifier sched; | ||
120 | |||
121 | struct GNUNET_MESH_Handle *handle; | ||
115 | }; | 122 | }; |
116 | 123 | ||
117 | struct peer_list | 124 | struct peer_list |
@@ -191,7 +198,9 @@ send_hello_message (void *cls, size_t size, void *buf) | |||
191 | 198 | ||
192 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending hello\n"); | 199 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending hello\n"); |
193 | 200 | ||
194 | struct GNUNET_MESH_Handle *handle = cls; | 201 | struct peer_list_element *element = cls; |
202 | struct GNUNET_MESH_Handle *handle = element->handle; | ||
203 | element->hello = NULL; | ||
195 | struct GNUNET_MessageHeader *hdr = buf; | 204 | struct GNUNET_MessageHeader *hdr = buf; |
196 | 205 | ||
197 | size_t sent = | 206 | size_t sent = |
@@ -207,6 +216,24 @@ send_hello_message (void *cls, size_t size, void *buf) | |||
207 | return sent; | 216 | return sent; |
208 | } | 217 | } |
209 | 218 | ||
219 | void schedule_hello_message(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tctx) | ||
220 | { | ||
221 | struct peer_list_element *element = cls; | ||
222 | element->sched = GNUNET_SCHEDULER_NO_TASK; | ||
223 | |||
224 | if ((tctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
225 | return; | ||
226 | |||
227 | if (element->hello == NULL) | ||
228 | element->hello = GNUNET_CORE_notify_transmit_ready (element->handle->core, GNUNET_NO, 42, | ||
229 | GNUNET_TIME_UNIT_SECONDS, &element->peer, | ||
230 | sizeof (struct GNUNET_MessageHeader) + | ||
231 | element->handle->hello_message_size, | ||
232 | &send_hello_message, element); | ||
233 | |||
234 | element->sched = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, schedule_hello_message, cls); | ||
235 | } | ||
236 | |||
210 | 237 | ||
211 | /** | 238 | /** |
212 | * Core calls this if we are connected to a new peer. | 239 | * Core calls this if we are connected to a new peer. |
@@ -223,17 +250,14 @@ core_connect (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 250 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
224 | "Core tells us we are connected to peer %s\n", GNUNET_i2s (peer)); | 251 | "Core tells us we are connected to peer %s\n", GNUNET_i2s (peer)); |
225 | 252 | ||
226 | /* Send a hello to this peer */ | ||
227 | GNUNET_CORE_notify_transmit_ready (handle->core, GNUNET_NO, 42, | ||
228 | GNUNET_TIME_UNIT_SECONDS, peer, | ||
229 | sizeof (struct GNUNET_MessageHeader) + | ||
230 | handle->hello_message_size, | ||
231 | &send_hello_message, cls); | ||
232 | |||
233 | /* put the new peer into the list of connected peers */ | 253 | /* put the new peer into the list of connected peers */ |
234 | struct peer_list_element *element = | 254 | struct peer_list_element *element = |
235 | GNUNET_malloc (sizeof (struct peer_list_element)); | 255 | GNUNET_malloc (sizeof (struct peer_list_element)); |
236 | memcpy (&element->peer, peer, sizeof (struct GNUNET_PeerIdentity)); | 256 | memcpy (&element->peer, peer, sizeof (struct GNUNET_PeerIdentity)); |
257 | element->handle = handle; | ||
258 | |||
259 | /* Send a hello to this peer */ | ||
260 | element->sched = GNUNET_SCHEDULER_add_now(schedule_hello_message, element); | ||
237 | 261 | ||
238 | if (NULL != atsi) | 262 | if (NULL != atsi) |
239 | memcpy (&element->atsi, atsi, | 263 | memcpy (&element->atsi, atsi, |
@@ -303,6 +327,8 @@ core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
303 | tail); | 327 | tail); |
304 | GNUNET_free (tail); | 328 | GNUNET_free (tail); |
305 | } | 329 | } |
330 | GNUNET_CORE_notify_transmit_ready_cancel(element->hello); | ||
331 | GNUNET_SCHEDULER_cancel(element->sched); | ||
306 | GNUNET_free (element); | 332 | GNUNET_free (element); |
307 | } | 333 | } |
308 | 334 | ||
@@ -859,6 +885,8 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | |||
859 | tail); | 885 | tail); |
860 | GNUNET_free (tail); | 886 | GNUNET_free (tail); |
861 | } | 887 | } |
888 | GNUNET_CORE_notify_transmit_ready_cancel(element->hello); | ||
889 | GNUNET_SCHEDULER_cancel(element->sched); | ||
862 | GNUNET_free (element); | 890 | GNUNET_free (element); |
863 | element = next; | 891 | element = next; |
864 | } | 892 | } |
@@ -884,4 +912,4 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle) | |||
884 | GNUNET_free (handle); | 912 | GNUNET_free (handle); |
885 | } | 913 | } |
886 | 914 | ||
887 | /* end of mesh_api.c */ \ No newline at end of file | 915 | /* end of mesh_api.c */ |