aboutsummaryrefslogtreecommitdiff
path: root/src/dv/dv_api.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dv/dv_api.c')
-rw-r--r--src/dv/dv_api.c24
1 files changed, 21 insertions, 3 deletions
diff --git a/src/dv/dv_api.c b/src/dv/dv_api.c
index dab7c7ad3..ecc13941b 100644
--- a/src/dv/dv_api.c
+++ b/src/dv/dv_api.c
@@ -114,6 +114,11 @@ struct GNUNET_DV_ServiceHandle
114 GNUNET_DV_ConnectCallback connect_cb; 114 GNUNET_DV_ConnectCallback connect_cb;
115 115
116 /** 116 /**
117 * Function to call on distance change events.
118 */
119 GNUNET_DV_DistanceChangedCallback distance_cb;
120
121 /**
117 * Function to call on disconnect events. 122 * Function to call on disconnect events.
118 */ 123 */
119 GNUNET_DV_DisconnectCallback disconnect_cb; 124 GNUNET_DV_DisconnectCallback disconnect_cb;
@@ -288,6 +293,7 @@ handle_message_receipt (void *cls,
288{ 293{
289 struct GNUNET_DV_ServiceHandle *sh = cls; 294 struct GNUNET_DV_ServiceHandle *sh = cls;
290 const struct GNUNET_DV_ConnectMessage *cm; 295 const struct GNUNET_DV_ConnectMessage *cm;
296 const struct GNUNET_DV_DistanceUpdateMessage *dum;
291 const struct GNUNET_DV_DisconnectMessage *dm; 297 const struct GNUNET_DV_DisconnectMessage *dm;
292 const struct GNUNET_DV_ReceivedMessage *rm; 298 const struct GNUNET_DV_ReceivedMessage *rm;
293 const struct GNUNET_MessageHeader *payload; 299 const struct GNUNET_MessageHeader *payload;
@@ -314,6 +320,18 @@ handle_message_receipt (void *cls,
314 &cm->peer, 320 &cm->peer,
315 ntohl (cm->distance)); 321 ntohl (cm->distance));
316 break; 322 break;
323 case GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED:
324 if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DistanceUpdateMessage))
325 {
326 GNUNET_break (0);
327 reconnect (sh);
328 return;
329 }
330 dum = (const struct GNUNET_DV_DistanceUpdateMessage *) msg;
331 sh->distance_cb (sh->cls,
332 &dum->peer,
333 ntohl (dum->distance));
334 break;
317 case GNUNET_MESSAGE_TYPE_DV_DISCONNECT: 335 case GNUNET_MESSAGE_TYPE_DV_DISCONNECT:
318 if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DisconnectMessage)) 336 if (ntohs (msg->size) != sizeof (struct GNUNET_DV_DisconnectMessage))
319 { 337 {
@@ -361,9 +379,6 @@ handle_message_receipt (void *cls,
361 &process_ack, 379 &process_ack,
362 &ctx); 380 &ctx);
363 break; 381 break;
364 case GNUNET_MESSAGE_TYPE_DV_DISTANCE_CHANGED:
365 GNUNET_break (0);
366 break;
367 default: 382 default:
368 reconnect (sh); 383 reconnect (sh);
369 break; 384 break;
@@ -478,6 +493,7 @@ reconnect (struct GNUNET_DV_ServiceHandle *sh)
478 * @param cfg configuration 493 * @param cfg configuration
479 * @param cls closure for callbacks 494 * @param cls closure for callbacks
480 * @param connect_cb function to call on connects 495 * @param connect_cb function to call on connects
496 * @param distance_cb function to call if distances change
481 * @param disconnect_cb function to call on disconnects 497 * @param disconnect_cb function to call on disconnects
482 * @param message_cb function to call if we receive messages 498 * @param message_cb function to call if we receive messages
483 * @return handle to access the service 499 * @return handle to access the service
@@ -486,6 +502,7 @@ struct GNUNET_DV_ServiceHandle *
486GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 502GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
487 void *cls, 503 void *cls,
488 GNUNET_DV_ConnectCallback connect_cb, 504 GNUNET_DV_ConnectCallback connect_cb,
505 GNUNET_DV_DistanceChangedCallback distance_cb,
489 GNUNET_DV_DisconnectCallback disconnect_cb, 506 GNUNET_DV_DisconnectCallback disconnect_cb,
490 GNUNET_DV_MessageReceivedCallback message_cb) 507 GNUNET_DV_MessageReceivedCallback message_cb)
491{ 508{
@@ -495,6 +512,7 @@ GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
495 sh->cfg = cfg; 512 sh->cfg = cfg;
496 sh->cls = cls; 513 sh->cls = cls;
497 sh->connect_cb = connect_cb; 514 sh->connect_cb = connect_cb;
515 sh->distance_cb = distance_cb;
498 sh->disconnect_cb = disconnect_cb; 516 sh->disconnect_cb = disconnect_cb;
499 sh->message_cb = message_cb; 517 sh->message_cb = message_cb;
500 sh->send_callbacks = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES); 518 sh->send_callbacks = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES);