aboutsummaryrefslogtreecommitdiff
path: root/src/dv
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-03-15 19:46:04 +0000
committerChristian Grothoff <christian@grothoff.org>2013-03-15 19:46:04 +0000
commit538a69e10fb7ef1441fadb14320ce3228fe777bf (patch)
treec605606446f3f78c0e6b87ff360690eddac723ca /src/dv
parent836b412e8acb0a796fed94a46826b3fb9a679fc6 (diff)
downloadgnunet-538a69e10fb7ef1441fadb14320ce3228fe777bf.tar.gz
gnunet-538a69e10fb7ef1441fadb14320ce3228fe777bf.zip
-box DV messages when needed
Diffstat (limited to 'src/dv')
-rw-r--r--src/dv/plugin_transport_dv.c62
1 files changed, 61 insertions, 1 deletions
diff --git a/src/dv/plugin_transport_dv.c b/src/dv/plugin_transport_dv.c
index 1c03d4a5f..19c577f13 100644
--- a/src/dv/plugin_transport_dv.c
+++ b/src/dv/plugin_transport_dv.c
@@ -156,6 +156,11 @@ struct Plugin
156 */ 156 */
157 struct GNUNET_DV_ServiceHandle *dvh; 157 struct GNUNET_DV_ServiceHandle *dvh;
158 158
159 /**
160 * Tokenizer for boxed messages.
161 */
162 struct GNUNET_SERVER_MessageStreamTokenizer *mst;
163
159}; 164};
160 165
161 166
@@ -172,6 +177,35 @@ notify_distance_change (struct Session *session)
172 177
173 178
174/** 179/**
180 * Function called by MST on each message from the box.
181 *
182 * @param cls closure with the 'struct Plugin'
183 * @param client identification of the client (with the 'struct Session')
184 * @param message the actual message
185 * @return GNUNET_OK on success
186 */
187static int
188unbox_cb (void *cls,
189 void *client,
190 const struct GNUNET_MessageHeader *message)
191{
192 struct Plugin *plugin = cls;
193 struct Session *session = client;
194 struct GNUNET_ATS_Information ats;
195
196 ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
197 ats.value = htonl (session->distance);
198 session->active = GNUNET_YES;
199 plugin->env->receive (plugin->env->cls,
200 &session->sender,
201 message,
202 &ats, 1,
203 session, "", 0);
204 return GNUNET_OK;
205}
206
207
208/**
175 * Handler for messages received from the DV service. 209 * Handler for messages received from the DV service.
176 * 210 *
177 * @param cls closure with the plugin 211 * @param cls closure with the plugin
@@ -196,6 +230,17 @@ handle_dv_message_received (void *cls,
196 GNUNET_break (0); 230 GNUNET_break (0);
197 return; 231 return;
198 } 232 }
233 if (GNUNET_MESSAGE_TYPE_DV_BOX == ntohs (msg->type))
234 {
235 /* need to unbox using MST */
236 GNUNET_SERVER_mst_receive (plugin->mst,
237 session,
238 (const char *) &msg[1],
239 ntohs (msg->size) - sizeof (struct GNUNET_MessageHeader),
240 GNUNET_YES,
241 GNUNET_NO);
242 return;
243 }
199 ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE); 244 ats.type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
200 ats.value = htonl (distance); 245 ats.value = htonl (distance);
201 session->active = GNUNET_YES; 246 session->active = GNUNET_YES;
@@ -382,9 +427,19 @@ dv_plugin_send (void *cls,
382{ 427{
383 struct PendingRequest *pr; 428 struct PendingRequest *pr;
384 const struct GNUNET_MessageHeader *msg; 429 const struct GNUNET_MessageHeader *msg;
430 struct GNUNET_MessageHeader *box;
385 431
432 box = NULL;
386 msg = (const struct GNUNET_MessageHeader *) msgbuf; 433 msg = (const struct GNUNET_MessageHeader *) msgbuf;
387 GNUNET_assert (ntohs (msg->size) == msgbuf_size); // API will change... 434 if (ntohs (msg->size) != msgbuf_size)
435 {
436 /* need to box */
437 box = GNUNET_malloc (sizeof (struct GNUNET_MessageHeader) + msgbuf_size);
438 box->type = htons (GNUNET_MESSAGE_TYPE_DV_BOX);
439 box->size = htons (sizeof (struct GNUNET_MessageHeader) + msgbuf_size);
440 memcpy (&box[1], msgbuf, msgbuf_size);
441 msg = box;
442 }
388 pr = GNUNET_malloc (sizeof (struct PendingRequest)); 443 pr = GNUNET_malloc (sizeof (struct PendingRequest));
389 pr->transmit_cont = cont; 444 pr->transmit_cont = cont;
390 pr->transmit_cont_cls = cont_cls; 445 pr->transmit_cont_cls = cont_cls;
@@ -397,6 +452,7 @@ dv_plugin_send (void *cls,
397 msg, 452 msg,
398 &send_finished, 453 &send_finished,
399 pr); 454 pr);
455 GNUNET_free_non_null (box);
400 return 0; /* DV */ 456 return 0; /* DV */
401} 457}
402 458
@@ -580,6 +636,8 @@ libgnunet_plugin_transport_dv_init (void *cls)
580 plugin = GNUNET_malloc (sizeof (struct Plugin)); 636 plugin = GNUNET_malloc (sizeof (struct Plugin));
581 plugin->env = env; 637 plugin->env = env;
582 plugin->sessions = GNUNET_CONTAINER_multihashmap_create (1024 * 8, GNUNET_YES); 638 plugin->sessions = GNUNET_CONTAINER_multihashmap_create (1024 * 8, GNUNET_YES);
639 plugin->mst = GNUNET_SERVER_mst_create (&unbox_cb,
640 plugin);
583 plugin->dvh = GNUNET_DV_service_connect (env->cfg, 641 plugin->dvh = GNUNET_DV_service_connect (env->cfg,
584 plugin, 642 plugin,
585 &handle_dv_connect, 643 &handle_dv_connect,
@@ -589,6 +647,7 @@ libgnunet_plugin_transport_dv_init (void *cls)
589 if (NULL == plugin->dvh) 647 if (NULL == plugin->dvh)
590 { 648 {
591 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); 649 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
650 GNUNET_SERVER_mst_destroy (plugin->mst);
592 GNUNET_free (plugin); 651 GNUNET_free (plugin);
593 return NULL; 652 return NULL;
594 } 653 }
@@ -639,6 +698,7 @@ libgnunet_plugin_transport_dv_done (void *cls)
639 &free_session_iterator, 698 &free_session_iterator,
640 NULL); 699 NULL);
641 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions); 700 GNUNET_CONTAINER_multihashmap_destroy (plugin->sessions);
701 GNUNET_SERVER_mst_destroy (plugin->mst);
642 GNUNET_free (plugin); 702 GNUNET_free (plugin);
643 GNUNET_free (api); 703 GNUNET_free (api);
644 return NULL; 704 return NULL;