aboutsummaryrefslogtreecommitdiff
path: root/src/mesh
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2013-12-05 14:15:25 +0000
committerBart Polot <bart@net.in.tum.de>2013-12-05 14:15:25 +0000
commit44d957c38051c6e778595b74f4a831da8ad1a179 (patch)
tree235e33b27ba570e6e857f306ff4ed27791d21d14 /src/mesh
parentb83fc2e7baf2713881c1ff59971e6dbd4609e771 (diff)
downloadgnunet-44d957c38051c6e778595b74f4a831da8ad1a179.tar.gz
gnunet-44d957c38051c6e778595b74f4a831da8ad1a179.zip
- change mesh channel creation/notification API
Diffstat (limited to 'src/mesh')
-rw-r--r--src/mesh/mesh_api.c65
-rw-r--r--src/mesh/test_mesh_local.c5
-rw-r--r--src/mesh/test_mesh_single.c6
-rw-r--r--src/mesh/test_mesh_small.c12
4 files changed, 30 insertions, 58 deletions
diff --git a/src/mesh/mesh_api.c b/src/mesh/mesh_api.c
index 0d1d70026..46dfe546f 100644
--- a/src/mesh/mesh_api.c
+++ b/src/mesh/mesh_api.c
@@ -277,19 +277,9 @@ struct GNUNET_MESH_Channel
277 unsigned int packet_size; 277 unsigned int packet_size;
278 278
279 /** 279 /**
280 * Is the channel allowed to buffer? 280 * Channel options: reliability, etc.
281 */ 281 */
282 int nobuffer; 282 enum MeshOption options;
283
284 /**
285 * Is the channel realiable?
286 */
287 int reliable;
288
289 /**
290 * If reliable, is the channel out of order?
291 */
292 int ooorder;
293 283
294 /** 284 /**
295 * Are we allowed to send to the service? 285 * Are we allowed to send to the service?
@@ -439,7 +429,6 @@ create_channel (struct GNUNET_MESH_Handle *h, MESH_ChannelNumber chid)
439 ch->chid = chid; 429 ch->chid = chid;
440 } 430 }
441 ch->allow_send = GNUNET_NO; 431 ch->allow_send = GNUNET_NO;
442 ch->nobuffer = GNUNET_NO;
443 return ch; 432 return ch;
444} 433}
445 434
@@ -782,24 +771,10 @@ process_channel_created (struct GNUNET_MESH_Handle *h,
782 ch->mesh = h; 771 ch->mesh = h;
783 ch->chid = chid; 772 ch->chid = chid;
784 ch->port = port; 773 ch->port = port;
785 if (0 != (msg->opt & GNUNET_MESH_OPTION_NOBUFFER)) 774 ch->options = ntohl (msg->opt);
786 ch->nobuffer = GNUNET_YES;
787 else
788 ch->nobuffer = GNUNET_NO;
789
790 if (0 != (msg->opt & GNUNET_MESH_OPTION_RELIABLE))
791 ch->reliable = GNUNET_YES;
792 else
793 ch->reliable = GNUNET_NO;
794
795 if (GNUNET_YES == ch->reliable &&
796 0 != (msg->opt & GNUNET_MESH_OPTION_OOORDER))
797 ch->ooorder = GNUNET_YES;
798 else
799 ch->ooorder = GNUNET_NO;
800 775
801 LOG (GNUNET_ERROR_TYPE_DEBUG, " created channel %p\n", ch); 776 LOG (GNUNET_ERROR_TYPE_DEBUG, " created channel %p\n", ch);
802 ctx = h->new_channel (h->cls, ch, &msg->peer, ch->port); 777 ctx = h->new_channel (h->cls, ch, &msg->peer, ch->port, ch->options);
803 if (NULL != ctx) 778 if (NULL != ctx)
804 ch->ctx = ctx; 779 ch->ctx = ctx;
805 LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n"); 780 LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n");
@@ -1398,18 +1373,16 @@ GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
1398 * @param channel_ctx client's channel context to associate with the channel 1373 * @param channel_ctx client's channel context to associate with the channel
1399 * @param peer peer identity the channel should go to 1374 * @param peer peer identity the channel should go to
1400 * @param port Port number. 1375 * @param port Port number.
1401 * @param nobuffer Flag for disabling buffering on relay nodes. 1376 * @param options MeshOption flag field, with all desired option bits set to 1.
1402 * @param reliable Flag for end-to-end reliability.
1403 * 1377 *
1404 * @return handle to the channel 1378 * @return handle to the channel
1405 */ 1379 */
1406struct GNUNET_MESH_Channel * 1380struct GNUNET_MESH_Channel *
1407GNUNET_MESH_channel_create (struct GNUNET_MESH_Handle *h, 1381GNUNET_MESH_channel_create (struct GNUNET_MESH_Handle *h,
1408 void *channel_ctx, 1382 void *channel_ctx,
1409 const struct GNUNET_PeerIdentity *peer, 1383 const struct GNUNET_PeerIdentity *peer,
1410 uint32_t port, 1384 uint32_t port,
1411 int nobuffer, 1385 enum MeshOption options)
1412 int reliable)
1413{ 1386{
1414 struct GNUNET_MESH_Channel *ch; 1387 struct GNUNET_MESH_Channel *ch;
1415 struct GNUNET_MESH_ChannelMessage msg; 1388 struct GNUNET_MESH_ChannelMessage msg;
@@ -1427,12 +1400,7 @@ GNUNET_MESH_channel_create (struct GNUNET_MESH_Handle *h,
1427 msg.channel_id = htonl (ch->chid); 1400 msg.channel_id = htonl (ch->chid);
1428 msg.port = htonl (port); 1401 msg.port = htonl (port);
1429 msg.peer = *peer; 1402 msg.peer = *peer;
1430 msg.opt = 0; 1403 msg.opt = htonl (options);
1431 if (GNUNET_YES == reliable)
1432 msg.opt |= GNUNET_MESH_OPTION_RELIABLE;
1433 if (GNUNET_YES == nobuffer)
1434 msg.opt |= GNUNET_MESH_OPTION_NOBUFFER;
1435 msg.opt = htonl (msg.opt);
1436 ch->allow_send = 0; 1404 ch->allow_send = 0;
1437 send_packet (h, &msg.header, ch); 1405 send_packet (h, &msg.header, ch);
1438 return ch; 1406 return ch;
@@ -1489,20 +1457,21 @@ GNUNET_MESH_channel_destroy (struct GNUNET_MESH_Channel *channel)
1489 */ 1457 */
1490const union GNUNET_MESH_ChannelInfo * 1458const union GNUNET_MESH_ChannelInfo *
1491GNUNET_MESH_channel_get_info (struct GNUNET_MESH_Channel *channel, 1459GNUNET_MESH_channel_get_info (struct GNUNET_MESH_Channel *channel,
1492 enum MeshOption option, ...) 1460 enum MeshOption option, ...)
1493{ 1461{
1462 static int bool_flag;
1494 const union GNUNET_MESH_ChannelInfo *ret; 1463 const union GNUNET_MESH_ChannelInfo *ret;
1495 1464
1496 switch (option) 1465 switch (option)
1497 { 1466 {
1498 case GNUNET_MESH_OPTION_NOBUFFER: 1467 case GNUNET_MESH_OPTION_NOBUFFER:
1499 ret = (const union GNUNET_MESH_ChannelInfo *) &channel->nobuffer;
1500 break;
1501 case GNUNET_MESH_OPTION_RELIABLE: 1468 case GNUNET_MESH_OPTION_RELIABLE:
1502 ret = (const union GNUNET_MESH_ChannelInfo *) &channel->reliable;
1503 break;
1504 case GNUNET_MESH_OPTION_OOORDER: 1469 case GNUNET_MESH_OPTION_OOORDER:
1505 ret = (const union GNUNET_MESH_ChannelInfo *) &channel->ooorder; 1470 if (0 != (option & channel->options))
1471 bool_flag = GNUNET_YES;
1472 else
1473 bool_flag = GNUNET_NO;
1474 ret = (const union GNUNET_MESH_ChannelInfo *) &bool_flag;
1506 break; 1475 break;
1507 case GNUNET_MESH_OPTION_PEER: 1476 case GNUNET_MESH_OPTION_PEER:
1508 ret = (const union GNUNET_MESH_ChannelInfo *) GNUNET_PEER_resolve2 (channel->peer); 1477 ret = (const union GNUNET_MESH_ChannelInfo *) GNUNET_PEER_resolve2 (channel->peer);
diff --git a/src/mesh/test_mesh_local.c b/src/mesh/test_mesh_local.c
index bdd603351..35a16b0d9 100644
--- a/src/mesh/test_mesh_local.c
+++ b/src/mesh/test_mesh_local.c
@@ -141,13 +141,14 @@ data_callback (void *cls, struct GNUNET_MESH_Channel *channel,
141 * @param channel new handle to the channel 141 * @param channel new handle to the channel
142 * @param initiator peer that started the channel 142 * @param initiator peer that started the channel
143 * @param port port number 143 * @param port port number
144 * @param options channel options
144 * @return initial channel context for the channel 145 * @return initial channel context for the channel
145 * (can be NULL -- that's not an error) 146 * (can be NULL -- that's not an error)
146 */ 147 */
147static void * 148static void *
148inbound_channel (void *cls, struct GNUNET_MESH_Channel *channel, 149inbound_channel (void *cls, struct GNUNET_MESH_Channel *channel,
149 const struct GNUNET_PeerIdentity *initiator, 150 const struct GNUNET_PeerIdentity *initiator,
150 uint32_t port) 151 uint32_t port, enum MeshOption options)
151{ 152{
152 long id = (long) cls; 153 long id = (long) cls;
153 154
@@ -256,7 +257,7 @@ do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
256 GNUNET_TESTING_peer_get_identity (me, &id); 257 GNUNET_TESTING_peer_get_identity (me, &id);
257 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n"); 258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
258 ch = GNUNET_MESH_channel_create (mesh_peer_1, NULL, &id, 1, 259 ch = GNUNET_MESH_channel_create (mesh_peer_1, NULL, &id, 1,
259 GNUNET_YES, GNUNET_NO); 260 GNUNET_MESH_OPTION_DEFAULT);
260 mth = GNUNET_MESH_notify_transmit_ready (ch, GNUNET_NO, 261 mth = GNUNET_MESH_notify_transmit_ready (ch, GNUNET_NO,
261 GNUNET_TIME_UNIT_FOREVER_REL, 262 GNUNET_TIME_UNIT_FOREVER_REL,
262 sizeof (struct GNUNET_MessageHeader), 263 sizeof (struct GNUNET_MessageHeader),
diff --git a/src/mesh/test_mesh_single.c b/src/mesh/test_mesh_single.c
index 15e8a1dbd..689139b82 100644
--- a/src/mesh/test_mesh_single.c
+++ b/src/mesh/test_mesh_single.c
@@ -162,13 +162,14 @@ data_callback (void *cls, struct GNUNET_MESH_Channel *channel,
162 * @param channel new handle to the channel 162 * @param channel new handle to the channel
163 * @param initiator peer that started the channel 163 * @param initiator peer that started the channel
164 * @param port port number 164 * @param port port number
165 * @param options channel option flags
165 * @return initial channel context for the channel 166 * @return initial channel context for the channel
166 * (can be NULL -- that's not an error) 167 * (can be NULL -- that's not an error)
167 */ 168 */
168static void * 169static void *
169inbound_channel (void *cls, struct GNUNET_MESH_Channel *channel, 170inbound_channel (void *cls, struct GNUNET_MESH_Channel *channel,
170 const struct GNUNET_PeerIdentity *initiator, 171 const struct GNUNET_PeerIdentity *initiator,
171 uint32_t port) 172 uint32_t port, enum MeshOption options)
172{ 173{
173 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 174 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
174 "received incoming channel on port %u\n", 175 "received incoming channel on port %u\n",
@@ -256,7 +257,8 @@ do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
256 257
257 GNUNET_TESTING_peer_get_identity (me, &id); 258 GNUNET_TESTING_peer_get_identity (me, &id);
258 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n"); 259 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CONNECT BY PORT\n");
259 ch1 = GNUNET_MESH_channel_create (mesh, NULL, &id, 1, GNUNET_YES, GNUNET_NO); 260 ch1 = GNUNET_MESH_channel_create (mesh, NULL, &id, 1,
261 GNUNET_MESH_OPTION_DEFAULT);
260 GNUNET_MESH_notify_transmit_ready (ch1, GNUNET_NO, 262 GNUNET_MESH_notify_transmit_ready (ch1, GNUNET_NO,
261 GNUNET_TIME_UNIT_FOREVER_REL, 263 GNUNET_TIME_UNIT_FOREVER_REL,
262 size, &do_send, NULL); 264 size, &do_send, NULL);
diff --git a/src/mesh/test_mesh_small.c b/src/mesh/test_mesh_small.c
index 49e394f03..e63e343cf 100644
--- a/src/mesh/test_mesh_small.c
+++ b/src/mesh/test_mesh_small.c
@@ -536,13 +536,14 @@ static struct GNUNET_MESH_MessageHandler handlers[] = {
536 * @param channel New handle to the channel. 536 * @param channel New handle to the channel.
537 * @param initiator Peer that started the channel. 537 * @param initiator Peer that started the channel.
538 * @param port Port this channel is connected to. 538 * @param port Port this channel is connected to.
539 * @param options channel option flags
539 * @return Initial channel context for the channel 540 * @return Initial channel context for the channel
540 * (can be NULL -- that's not an error). 541 * (can be NULL -- that's not an error).
541 */ 542 */
542static void * 543static void *
543incoming_channel (void *cls, struct GNUNET_MESH_Channel *channel, 544incoming_channel (void *cls, struct GNUNET_MESH_Channel *channel,
544 const struct GNUNET_PeerIdentity *initiator, 545 const struct GNUNET_PeerIdentity *initiator,
545 uint32_t port) 546 uint32_t port, enum MeshOption options)
546{ 547{
547 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 548 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
548 "Incoming channel from %s to peer %d\n", 549 "Incoming channel from %s to peer %d\n",
@@ -629,7 +630,7 @@ channel_cleaner (void *cls, const struct GNUNET_MESH_Channel *channel,
629static void 630static void
630do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 631do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
631{ 632{
632 int rel; 633 enum MeshOption flags;
633 634
634 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n"); 635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "test_task\n");
635 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add peer 2\n"); 636 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "add peer 2\n");
@@ -641,14 +642,13 @@ do_test (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
641 GNUNET_SCHEDULER_cancel (disconnect_task); 642 GNUNET_SCHEDULER_cancel (disconnect_task);
642 } 643 }
643 644
645 flags = GNUNET_MESH_OPTION_DEFAULT;
644 if (SPEED_REL == test) 646 if (SPEED_REL == test)
645 { 647 {
646 test = SPEED; 648 test = SPEED;
647 rel = GNUNET_YES; 649 flags |= GNUNET_MESH_OPTION_RELIABLE;
648 } 650 }
649 else 651 ch = GNUNET_MESH_channel_create (h1, NULL, p_id[1], 1, flags);
650 rel = GNUNET_NO;
651 ch = GNUNET_MESH_channel_create (h1, NULL, p_id[1], 1, GNUNET_NO, rel);
652 652
653 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME, 653 disconnect_task = GNUNET_SCHEDULER_add_delayed (SHORT_TIME,
654 &disconnect_mesh_peers, 654 &disconnect_mesh_peers,