aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_tcp.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2010-04-13 14:12:00 +0000
committerChristian Grothoff <christian@grothoff.org>2010-04-13 14:12:00 +0000
commitd0f14ce4076688b90da1a88db984043eceda0566 (patch)
tree36a180c6ae4260f4d4f6e6b84353ebe3d01ca48e /src/transport/plugin_transport_tcp.c
parent6ba13deb812b0b55ae5c34de044ad4bf6cb7835d (diff)
downloadgnunet-d0f14ce4076688b90da1a88db984043eceda0566.tar.gz
gnunet-d0f14ce4076688b90da1a88db984043eceda0566.zip
transport API changes in preparation for the storm
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r--src/transport/plugin_transport_tcp.c82
1 files changed, 44 insertions, 38 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c
index 43cdceb43..2a3d52193 100644
--- a/src/transport/plugin_transport_tcp.c
+++ b/src/transport/plugin_transport_tcp.c
@@ -640,6 +640,7 @@ select_better_session (struct Session *s1,
640 * require plugins to discard the message after the timeout, 640 * require plugins to discard the message after the timeout,
641 * just advisory for the desired delay; most plugins will ignore 641 * just advisory for the desired delay; most plugins will ignore
642 * this as well) 642 * this as well)
643 * @param session which session must be used (or NULL for "any")
643 * @param addr the address to use (can be NULL if the plugin 644 * @param addr the address to use (can be NULL if the plugin
644 * is "on its own" (i.e. re-use existing TCP connection)) 645 * is "on its own" (i.e. re-use existing TCP connection))
645 * @param addrlen length of the address in bytes 646 * @param addrlen length of the address in bytes
@@ -664,13 +665,13 @@ tcp_plugin_send (void *cls,
664 size_t msgbuf_size, 665 size_t msgbuf_size,
665 uint32_t priority, 666 uint32_t priority,
666 struct GNUNET_TIME_Relative timeout, 667 struct GNUNET_TIME_Relative timeout,
668 struct Session *session,
667 const void *addr, 669 const void *addr,
668 size_t addrlen, 670 size_t addrlen,
669 int force_address, 671 int force_address,
670 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 672 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
671{ 673{
672 struct Plugin *plugin = cls; 674 struct Plugin *plugin = cls;
673 struct Session *session;
674 struct Session *cand_session; 675 struct Session *cand_session;
675 struct Session *next; 676 struct Session *next;
676 struct PendingMessage *pm; 677 struct PendingMessage *pm;
@@ -684,44 +685,47 @@ tcp_plugin_send (void *cls,
684 /* FIXME: we could do this a cheaper with a hash table 685 /* FIXME: we could do this a cheaper with a hash table
685 where we could restrict the iteration to entries that match 686 where we could restrict the iteration to entries that match
686 the target peer... */ 687 the target peer... */
687 cand_session = NULL; 688 if (session == NULL)
688 next = plugin->sessions;
689 while (NULL != (session = next))
690 { 689 {
691 next = session->next; 690 cand_session = NULL;
692 GNUNET_assert (session->client != NULL); 691 next = plugin->sessions;
693 if (0 != memcmp (target, 692 while (NULL != (session = next))
694 &session->target,
695 sizeof (struct GNUNET_PeerIdentity)))
696 continue;
697 if ( ( (GNUNET_SYSERR == force_address) &&
698 (session->expecting_welcome == GNUNET_NO) ) ||
699 (GNUNET_NO == force_address) )
700 { 693 {
694 next = session->next;
695 GNUNET_assert (session->client != NULL);
696 if (0 != memcmp (target,
697 &session->target,
698 sizeof (struct GNUNET_PeerIdentity)))
699 continue;
700 if ( ( (GNUNET_SYSERR == force_address) &&
701 (session->expecting_welcome == GNUNET_NO) ) ||
702 (GNUNET_NO == force_address) )
703 {
704 cand_session = select_better_session (cand_session,
705 session);
706 continue;
707 }
708 if (GNUNET_SYSERR == force_address)
709 continue;
710 GNUNET_break (GNUNET_YES == force_address);
711 if (addr == NULL)
712 {
713 GNUNET_break (0);
714 break;
715 }
716 if (session->inbound == GNUNET_YES)
717 continue;
718 if (addrlen != session->connect_alen)
719 continue;
720 if (0 != memcmp (session->connect_addr,
721 addr,
722 addrlen))
723 continue;
701 cand_session = select_better_session (cand_session, 724 cand_session = select_better_session (cand_session,
702 session); 725 session);
703 continue;
704 } 726 }
705 if (GNUNET_SYSERR == force_address) 727 session = cand_session;
706 continue;
707 GNUNET_break (GNUNET_YES == force_address);
708 if (addr == NULL)
709 {
710 GNUNET_break (0);
711 break;
712 }
713 if (session->inbound == GNUNET_YES)
714 continue;
715 if (addrlen != session->connect_alen)
716 continue;
717 if (0 != memcmp (session->connect_addr,
718 addr,
719 addrlen))
720 continue;
721 cand_session = select_better_session (cand_session,
722 session);
723 } 728 }
724 session = cand_session;
725 if ( (session == NULL) && 729 if ( (session == NULL) &&
726 (addr == NULL) ) 730 (addr == NULL) )
727 { 731 {
@@ -1134,7 +1138,9 @@ delayed_done (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1134 session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK; 1138 session->receive_delay_task = GNUNET_SCHEDULER_NO_TASK;
1135 delay = session->plugin->env->receive (session->plugin->env->cls, 1139 delay = session->plugin->env->receive (session->plugin->env->cls,
1136 &session->target, 1140 &session->target,
1137 NULL, 0, NULL, 0); 1141 NULL, 0,
1142 session,
1143 NULL, 0);
1138 if (delay.value == 0) 1144 if (delay.value == 0)
1139 GNUNET_SERVER_receive_done (session->client, GNUNET_OK); 1145 GNUNET_SERVER_receive_done (session->client, GNUNET_OK);
1140 else 1146 else
@@ -1187,9 +1193,9 @@ handle_tcp_data (void *cls,
1187 ntohs (message->size), 1193 ntohs (message->size),
1188 GNUNET_NO); 1194 GNUNET_NO);
1189 delay = plugin->env->receive (plugin->env->cls, &session->target, message, 1, 1195 delay = plugin->env->receive (plugin->env->cls, &session->target, message, 1,
1190 session->connect_addr, 1196 session,
1191 session->connect_alen); 1197 (GNUNET_YES == session->inbound) ? NULL : session->connect_addr,
1192 1198 (GNUNET_YES == session->inbound) ? 0 : session->connect_alen);
1193 if (delay.value == 0) 1199 if (delay.value == 0)
1194 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1200 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1195 else 1201 else