aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/transport/gnunet-service-transport.c92
-rw-r--r--src/transport/plugin_transport.h39
-rw-r--r--src/transport/plugin_transport_tcp.c82
-rw-r--r--src/transport/plugin_transport_template.c2
-rw-r--r--src/transport/plugin_transport_udp.c6
-rw-r--r--src/transport/plugin_transport_udp_nat.c24
6 files changed, 187 insertions, 58 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c
index d05e88824..fce1ba7d3 100644
--- a/src/transport/gnunet-service-transport.c
+++ b/src/transport/gnunet-service-transport.c
@@ -175,6 +175,12 @@ struct ForeignAddressList
175 const void *addr; 175 const void *addr;
176 176
177 /** 177 /**
178 * Session (or NULL if no valid session currently exists or if the
179 * plugin does not use sessions).
180 */
181 struct Session *session;
182
183 /**
178 * What was the last latency observed for this address, plugin and peer? 184 * What was the last latency observed for this address, plugin and peer?
179 */ 185 */
180 struct GNUNET_TIME_Relative latency; 186 struct GNUNET_TIME_Relative latency;
@@ -1347,6 +1353,7 @@ try_transmission_to_peer (struct NeighbourList *neighbour)
1347 mq->message_buf_size, 1353 mq->message_buf_size,
1348 mq->priority, 1354 mq->priority,
1349 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT, 1355 GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
1356 mq->specific_address->session,
1350 mq->specific_address->addr, 1357 mq->specific_address->addr,
1351 mq->specific_address->addrlen, 1358 mq->specific_address->addrlen,
1352 force_address, 1359 force_address,
@@ -1624,6 +1631,61 @@ expire_address_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1624 1631
1625 1632
1626/** 1633/**
1634 * Function that will be called whenever the plugin internally
1635 * cleans up a session pointer and hence the service needs to
1636 * discard all of those sessions as well. Plugins that do not
1637 * use sessions can simply omit calling this function and always
1638 * use NULL wherever a session pointer is needed.
1639 *
1640 * @param cls closure
1641 * @param peer which peer was the session for
1642 * @param session which session is being destoyed
1643 */
1644static void
1645plugin_env_session_end (void *cls,
1646 const struct GNUNET_PeerIdentity *peer,
1647 struct Session *session)
1648{
1649 struct TransportPlugin *p = cls;
1650 struct NeighbourList *nl;
1651 struct ReadyList *rl;
1652 struct ForeignAddressList *pos;
1653 struct ForeignAddressList *prev;
1654
1655 nl = find_neighbour (peer);
1656 if (nl == NULL)
1657 return;
1658 rl = nl->plugins;
1659 while (rl != NULL)
1660 {
1661 if (rl->plugin == p)
1662 break;
1663 rl = rl->next;
1664 }
1665 if (rl == NULL)
1666 return;
1667 prev = NULL;
1668 pos = rl->addresses;
1669 while ( (pos != NULL) &&
1670 (pos->session != session) )
1671 {
1672 prev = pos;
1673 pos = pos->next;
1674 }
1675 if (pos == NULL)
1676 return;
1677 pos->session = NULL;
1678 if (pos->addrlen != 0)
1679 return;
1680 if (prev == NULL)
1681 rl->addresses = pos->next;
1682 else
1683 prev->next = pos->next;
1684 GNUNET_free (pos);
1685}
1686
1687
1688/**
1627 * Function that must be called by each plugin to notify the 1689 * Function that must be called by each plugin to notify the
1628 * transport service about the addresses under which the transport 1690 * transport service about the addresses under which the transport
1629 * provided by the plugin can be reached. 1691 * provided by the plugin can be reached.
@@ -1743,6 +1805,8 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
1743 * 1805 *
1744 * @param neighbour which peer we care about 1806 * @param neighbour which peer we care about
1745 * @param tname name of the transport plugin 1807 * @param tname name of the transport plugin
1808 * @param session session to look for, NULL for 'any'; otherwise
1809 * can be used for the service to "learn" this session ID
1746 * @param addr binary address 1810 * @param addr binary address
1747 * @param addrlen length of addr 1811 * @param addrlen length of addr
1748 * @return NULL if no such entry exists 1812 * @return NULL if no such entry exists
@@ -1750,6 +1814,7 @@ notify_clients_disconnect (const struct GNUNET_PeerIdentity *peer)
1750static struct ForeignAddressList * 1814static struct ForeignAddressList *
1751find_peer_address(struct NeighbourList *neighbour, 1815find_peer_address(struct NeighbourList *neighbour,
1752 const char *tname, 1816 const char *tname,
1817 struct Session *session,
1753 const char *addr, 1818 const char *addr,
1754 size_t addrlen) 1819 size_t addrlen)
1755{ 1820{
@@ -1771,6 +1836,8 @@ find_peer_address(struct NeighbourList *neighbour,
1771 ( (address_head->addrlen != addrlen) || 1836 ( (address_head->addrlen != addrlen) ||
1772 (memcmp(address_head->addr, addr, addrlen) != 0) ) ) 1837 (memcmp(address_head->addr, addr, addrlen) != 0) ) )
1773 address_head = address_head->next; 1838 address_head = address_head->next;
1839 if (session != NULL)
1840 address_head->session = session; /* learn it! */
1774 return address_head; 1841 return address_head;
1775} 1842}
1776 1843
@@ -1781,6 +1848,7 @@ find_peer_address(struct NeighbourList *neighbour,
1781 * 1848 *
1782 * @param neighbour which peer we care about 1849 * @param neighbour which peer we care about
1783 * @param tname name of the transport plugin 1850 * @param tname name of the transport plugin
1851 * @param session session of the plugin, or NULL for none
1784 * @param addr binary address 1852 * @param addr binary address
1785 * @param addrlen length of addr 1853 * @param addrlen length of addr
1786 * @return NULL if we do not have a transport plugin for 'tname' 1854 * @return NULL if we do not have a transport plugin for 'tname'
@@ -1788,13 +1856,14 @@ find_peer_address(struct NeighbourList *neighbour,
1788static struct ForeignAddressList * 1856static struct ForeignAddressList *
1789add_peer_address (struct NeighbourList *neighbour, 1857add_peer_address (struct NeighbourList *neighbour,
1790 const char *tname, 1858 const char *tname,
1859 struct Session *session,
1791 const char *addr, 1860 const char *addr,
1792 size_t addrlen) 1861 size_t addrlen)
1793{ 1862{
1794 struct ReadyList *head; 1863 struct ReadyList *head;
1795 struct ForeignAddressList *ret; 1864 struct ForeignAddressList *ret;
1796 1865
1797 ret = find_peer_address (neighbour, tname, addr, addrlen); 1866 ret = find_peer_address (neighbour, tname, session, addr, addrlen);
1798 if (ret != NULL) 1867 if (ret != NULL)
1799 return ret; 1868 return ret;
1800 head = neighbour->plugins; 1869 head = neighbour->plugins;
@@ -1807,6 +1876,7 @@ add_peer_address (struct NeighbourList *neighbour,
1807 if (head == NULL) 1876 if (head == NULL)
1808 return NULL; 1877 return NULL;
1809 ret = GNUNET_malloc(sizeof(struct ForeignAddressList) + addrlen); 1878 ret = GNUNET_malloc(sizeof(struct ForeignAddressList) + addrlen);
1879 ret->session = session;
1810 ret->addr = (const char*) &ret[1]; 1880 ret->addr = (const char*) &ret[1];
1811 memcpy (&ret[1], addr, addrlen); 1881 memcpy (&ret[1], addr, addrlen);
1812 ret->addrlen = addrlen; 1882 ret->addrlen = addrlen;
@@ -2014,7 +2084,7 @@ add_to_foreign_address_list (void *cls,
2014 1, 2084 1,
2015 GNUNET_NO); 2085 GNUNET_NO);
2016 try = GNUNET_NO; 2086 try = GNUNET_NO;
2017 fal = find_peer_address (n, tname, addr, addrlen); 2087 fal = find_peer_address (n, tname, NULL, addr, addrlen);
2018 if (fal == NULL) 2088 if (fal == NULL)
2019 { 2089 {
2020#if DEBUG_TRANSPORT 2090#if DEBUG_TRANSPORT
@@ -2025,7 +2095,7 @@ add_to_foreign_address_list (void *cls,
2025 GNUNET_i2s (&n->id), 2095 GNUNET_i2s (&n->id),
2026 expiration.value); 2096 expiration.value);
2027#endif 2097#endif
2028 fal = add_peer_address (n, tname, addr, addrlen); 2098 fal = add_peer_address (n, tname, NULL, addr, addrlen);
2029 if (fal == NULL) 2099 if (fal == NULL)
2030 { 2100 {
2031 GNUNET_STATISTICS_update (stats, 2101 GNUNET_STATISTICS_update (stats,
@@ -2392,6 +2462,7 @@ check_pending_validation (void *cls,
2392 n->public_key_valid = GNUNET_YES; 2462 n->public_key_valid = GNUNET_YES;
2393 fal = add_peer_address (n, 2463 fal = add_peer_address (n,
2394 ve->transport_name, 2464 ve->transport_name,
2465 NULL,
2395 ve->addr, 2466 ve->addr,
2396 ve->addrlen); 2467 ve->addrlen);
2397 GNUNET_assert (fal != NULL); 2468 GNUNET_assert (fal != NULL);
@@ -2604,7 +2675,7 @@ run_validation (void *cls,
2604 neighbour = setup_new_neighbour(&id); 2675 neighbour = setup_new_neighbour(&id);
2605 neighbour->publicKey = va->publicKey; 2676 neighbour->publicKey = va->publicKey;
2606 neighbour->public_key_valid = GNUNET_YES; 2677 neighbour->public_key_valid = GNUNET_YES;
2607 peer_address = add_peer_address(neighbour, tname, addr, addrlen); 2678 peer_address = add_peer_address(neighbour, tname, NULL, addr, addrlen);
2608 GNUNET_assert(peer_address != NULL); 2679 GNUNET_assert(peer_address != NULL);
2609 hello_size = GNUNET_HELLO_size(our_hello); 2680 hello_size = GNUNET_HELLO_size(our_hello);
2610 tsize = sizeof(struct TransportPingMessage) + hello_size; 2681 tsize = sizeof(struct TransportPingMessage) + hello_size;
@@ -3018,8 +3089,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
3018 GNUNET_CRYPTO_rsa_sign (my_private_key, 3089 GNUNET_CRYPTO_rsa_sign (my_private_key,
3019 &pong->purpose, &pong->signature)); 3090 &pong->purpose, &pong->signature));
3020 n = find_neighbour(peer); 3091 n = find_neighbour(peer);
3021 if (n == NULL) 3092 GNUNET_assert (n != NULL);
3022 n = setup_new_neighbour(peer);
3023 /* first try reliable response transmission */ 3093 /* first try reliable response transmission */
3024 rl = n->plugins; 3094 rl = n->plugins;
3025 while (rl != NULL) 3095 while (rl != NULL)
@@ -3033,6 +3103,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
3033 ntohs (pong->header.size), 3103 ntohs (pong->header.size),
3034 TRANSPORT_PONG_PRIORITY, 3104 TRANSPORT_PONG_PRIORITY,
3035 HELLO_VERIFICATION_TIMEOUT, 3105 HELLO_VERIFICATION_TIMEOUT,
3106 fal->session,
3036 fal->addr, 3107 fal->addr,
3037 fal->addrlen, 3108 fal->addrlen,
3038 GNUNET_SYSERR, 3109 GNUNET_SYSERR,
@@ -3088,6 +3159,7 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
3088 * @param message the message, NULL if we only care about 3159 * @param message the message, NULL if we only care about
3089 * learning about the delay until we should receive again 3160 * learning about the delay until we should receive again
3090 * @param distance in overlay hops; use 1 unless DV (or 0 if message == NULL) 3161 * @param distance in overlay hops; use 1 unless DV (or 0 if message == NULL)
3162 * @param session identifier used for this session (can be NULL)
3091 * @param sender_address binary address of the sender (if observed) 3163 * @param sender_address binary address of the sender (if observed)
3092 * @param sender_address_len number of bytes in sender_address 3164 * @param sender_address_len number of bytes in sender_address
3093 * @return how long the plugin should wait until receiving more data 3165 * @return how long the plugin should wait until receiving more data
@@ -3096,11 +3168,13 @@ handle_ping(void *cls, const struct GNUNET_MessageHeader *message,
3096static struct GNUNET_TIME_Relative 3168static struct GNUNET_TIME_Relative
3097plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer, 3169plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
3098 const struct GNUNET_MessageHeader *message, 3170 const struct GNUNET_MessageHeader *message,
3099 unsigned int distance, const char *sender_address, 3171 unsigned int distance,
3172 struct Session *session,
3173 const char *sender_address,
3100 size_t sender_address_len) 3174 size_t sender_address_len)
3101{ 3175{
3102 struct ReadyList *service_context;
3103 struct TransportPlugin *plugin = cls; 3176 struct TransportPlugin *plugin = cls;
3177 struct ReadyList *service_context;
3104 struct TransportClient *cpos; 3178 struct TransportClient *cpos;
3105 struct InboundMessage *im; 3179 struct InboundMessage *im;
3106 struct ForeignAddressList *peer_address; 3180 struct ForeignAddressList *peer_address;
@@ -3119,6 +3193,7 @@ plugin_env_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
3119 { 3193 {
3120 peer_address = add_peer_address(n, 3194 peer_address = add_peer_address(n,
3121 plugin->short_name, 3195 plugin->short_name,
3196 session,
3122 sender_address, 3197 sender_address,
3123 sender_address_len); 3198 sender_address_len);
3124 if (peer_address != NULL) 3199 if (peer_address != NULL)
@@ -3577,6 +3652,7 @@ create_environment (struct TransportPlugin *plug)
3577 plug->env.cls = plug; 3652 plug->env.cls = plug;
3578 plug->env.receive = &plugin_env_receive; 3653 plug->env.receive = &plugin_env_receive;
3579 plug->env.notify_address = &plugin_env_notify_address; 3654 plug->env.notify_address = &plugin_env_notify_address;
3655 plug->env.session_end = &plugin_env_session_end;
3580 plug->env.max_connections = max_connect_per_transport; 3656 plug->env.max_connections = max_connect_per_transport;
3581 plug->env.stats = stats; 3657 plug->env.stats = stats;
3582} 3658}
diff --git a/src/transport/plugin_transport.h b/src/transport/plugin_transport.h
index 0291f9bb4..2b7017036 100644
--- a/src/transport/plugin_transport.h
+++ b/src/transport/plugin_transport.h
@@ -36,6 +36,33 @@
36#include "gnunet_statistics_service.h" 36#include "gnunet_statistics_service.h"
37#include "gnunet_transport_service.h" 37#include "gnunet_transport_service.h"
38 38
39/**
40 * Opaque pointer that plugins can use to distinguish specific
41 * connections to a given peer. Typically used by stateful plugins to
42 * allow the service to refer to specific streams instead of a more
43 * general notion of "some connection" to the given peer. This is
44 * useful since sometimes (i.e. for inbound TCP connections) a
45 * connection may not have an address that can be used for meaningful
46 * distinction between sessions to the same peer.
47 */
48struct Session;
49
50
51/**
52 * Function that will be called whenever the plugin internally
53 * cleans up a session pointer and hence the service needs to
54 * discard all of those sessions as well. Plugins that do not
55 * use sessions can simply omit calling this function and always
56 * use NULL wherever a session pointer is needed.
57 *
58 * @param cls closure
59 * @param peer which peer was the session for
60 * @param session which session is being destoyed
61 */
62typedef void (*GNUNET_TRANSPORT_SessionEnd) (void *cls,
63 const struct GNUNET_PeerIdentity *peer,
64 struct Session *session);
65
39 66
40/** 67/**
41 * Function called by the transport for each received message. 68 * Function called by the transport for each received message.
@@ -47,6 +74,7 @@
47 * @param message the message, NULL if we only care about 74 * @param message the message, NULL if we only care about
48 * learning about the delay until we should receive again -- FIXME! 75 * learning about the delay until we should receive again -- FIXME!
49 * @param distance in overlay hops; use 1 unless DV (or 0 if message == NULL) 76 * @param distance in overlay hops; use 1 unless DV (or 0 if message == NULL)
77 * @param session identifier used for this session (can be NULL)
50 * @param sender_address binary address of the sender (if observed) 78 * @param sender_address binary address of the sender (if observed)
51 * @param sender_address_len number of bytes in sender_address 79 * @param sender_address_len number of bytes in sender_address
52 * @return how long the plugin should wait until receiving more data 80 * @return how long the plugin should wait until receiving more data
@@ -60,6 +88,7 @@ typedef struct GNUNET_TIME_Relative (*GNUNET_TRANSPORT_PluginReceiveCallback) (v
60 GNUNET_MessageHeader * 88 GNUNET_MessageHeader *
61 message, 89 message,
62 uint32_t distance, 90 uint32_t distance,
91 struct Session *session,
63 const char *sender_address, 92 const char *sender_address,
64 size_t sender_address_len); 93 size_t sender_address_len);
65 94
@@ -157,6 +186,12 @@ struct GNUNET_TRANSPORT_PluginEnvironment
157 GNUNET_TRANSPORT_TrafficReport traffic_report; 186 GNUNET_TRANSPORT_TrafficReport traffic_report;
158 187
159 /** 188 /**
189 * Function that must be called by the plugin when a non-NULL
190 * session handle stops being valid (is destroyed).
191 */
192 GNUNET_TRANSPORT_SessionEnd session_end;
193
194 /**
160 * What is the maximum number of connections that this transport 195 * What is the maximum number of connections that this transport
161 * should allow? Transports that do not have sessions (such as 196 * should allow? Transports that do not have sessions (such as
162 * UDP) can ignore this value. 197 * UDP) can ignore this value.
@@ -201,6 +236,7 @@ typedef void
201 * require plugins to discard the message after the timeout, 236 * require plugins to discard the message after the timeout,
202 * just advisory for the desired delay; most plugins will ignore 237 * just advisory for the desired delay; most plugins will ignore
203 * this as well) 238 * this as well)
239 * @param session which session must be used (or NULL for "any")
204 * @param addr the address to use (can be NULL if the plugin 240 * @param addr the address to use (can be NULL if the plugin
205 * is "on its own" (i.e. re-use existing TCP connection)) 241 * is "on its own" (i.e. re-use existing TCP connection))
206 * @param addrlen length of the address in bytes 242 * @param addrlen length of the address in bytes
@@ -226,6 +262,7 @@ typedef ssize_t
226 size_t msgbuf_size, 262 size_t msgbuf_size,
227 uint32_t priority, 263 uint32_t priority,
228 struct GNUNET_TIME_Relative timeout, 264 struct GNUNET_TIME_Relative timeout,
265 struct Session *session,
229 const void *addr, 266 const void *addr,
230 size_t addrlen, 267 size_t addrlen,
231 int force_address, 268 int force_address,
@@ -323,7 +360,7 @@ struct GNUNET_TRANSPORT_PluginFunctions
323 360
324 /** 361 /**
325 * Function that the transport service will use to transmit data to 362 * Function that the transport service will use to transmit data to
326 * another peer. May be null for plugins that only support 363 * another peer. May be NULL for plugins that only support
327 * receiving data. After this call, the plugin call the specified 364 * receiving data. After this call, the plugin call the specified
328 * continuation with success or error before notifying us about the 365 * continuation with success or error before notifying us about the
329 * target having disconnected. 366 * target having disconnected.
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
diff --git a/src/transport/plugin_transport_template.c b/src/transport/plugin_transport_template.c
index 6ad555a51..f09503b9b 100644
--- a/src/transport/plugin_transport_template.c
+++ b/src/transport/plugin_transport_template.c
@@ -139,6 +139,7 @@ struct Plugin
139 * @param msgbuf the message to transmit 139 * @param msgbuf the message to transmit
140 * @param msgbuf_size number of bytes in 'msgbuf' 140 * @param msgbuf_size number of bytes in 'msgbuf'
141 * @param timeout when should we time out 141 * @param timeout when should we time out
142 * @param session which session must be used (or NULL for "any")
142 * @param addr the address to use (can be NULL if the plugin 143 * @param addr the address to use (can be NULL if the plugin
143 * is "on its own" (i.e. re-use existing TCP connection)) 144 * is "on its own" (i.e. re-use existing TCP connection))
144 * @param addrlen length of the address in bytes 145 * @param addrlen length of the address in bytes
@@ -162,6 +163,7 @@ template_plugin_send (void *cls,
162 size_t msgbuf_size, 163 size_t msgbuf_size,
163 unsigned int priority, 164 unsigned int priority,
164 struct GNUNET_TIME_Relative timeout, 165 struct GNUNET_TIME_Relative timeout,
166 struct Session *session,
165 const void *addr, 167 const void *addr,
166 size_t addrlen, 168 size_t addrlen,
167 int force_address, 169 int force_address,
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index bdec32490..3e59f89dc 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -184,6 +184,7 @@ udp_transport_server_stop (void *cls)
184 * @param msgbuf_size the size of the msgbuf to send 184 * @param msgbuf_size the size of the msgbuf to send
185 * @param priority how important is the message (ignored by UDP) 185 * @param priority how important is the message (ignored by UDP)
186 * @param timeout when should we time out (give up) if we can not transmit? 186 * @param timeout when should we time out (give up) if we can not transmit?
187 * @param session which session must be used (always NULL for UDP)
187 * @param addr the addr to send the message to, needs to be a sockaddr for us 188 * @param addr the addr to send the message to, needs to be a sockaddr for us
188 * @param addrlen the len of addr 189 * @param addrlen the len of addr
189 * @param force_address GNUNET_YES if the plugin MUST use the given address, 190 * @param force_address GNUNET_YES if the plugin MUST use the given address,
@@ -206,6 +207,7 @@ udp_plugin_send (void *cls,
206 size_t msgbuf_size, 207 size_t msgbuf_size,
207 unsigned int priority, 208 unsigned int priority,
208 struct GNUNET_TIME_Relative timeout, 209 struct GNUNET_TIME_Relative timeout,
210 struct Session *session,
209 const void *addr, 211 const void *addr,
210 size_t addrlen, 212 size_t addrlen,
211 int force_address, 213 int force_address,
@@ -216,6 +218,7 @@ udp_plugin_send (void *cls,
216 int ssize; 218 int ssize;
217 ssize_t sent; 219 ssize_t sent;
218 220
221 GNUNET_assert (NULL == session);
219 GNUNET_assert(udp_sock != NULL); 222 GNUNET_assert(udp_sock != NULL);
220 if ( (addr == NULL) || (addrlen == 0) ) 223 if ( (addr == NULL) || (addrlen == 0) )
221 { 224 {
@@ -417,7 +420,8 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
417 count, ntohs(currhdr->type), ntohs(currhdr->size), offset); 420 count, ntohs(currhdr->type), ntohs(currhdr->size), offset);
418#endif 421#endif
419 plugin->env->receive (plugin->env->cls, 422 plugin->env->receive (plugin->env->cls,
420 sender, currhdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen); 423 sender, currhdr, UDP_DIRECT_DISTANCE,
424 NULL, (const char *)&addr, fromlen);
421 offset += ntohs(currhdr->size); 425 offset += ntohs(currhdr->size);
422#if DEBUG_UDP 426#if DEBUG_UDP
423 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ 427 GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
diff --git a/src/transport/plugin_transport_udp_nat.c b/src/transport/plugin_transport_udp_nat.c
index 3733130e2..531f2ae10 100644
--- a/src/transport/plugin_transport_udp_nat.c
+++ b/src/transport/plugin_transport_udp_nat.c
@@ -627,6 +627,7 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen)
627 * @param msgbuf_size the size of the msgbuf to send 627 * @param msgbuf_size the size of the msgbuf to send
628 * @param priority how important is the message (ignored by UDP) 628 * @param priority how important is the message (ignored by UDP)
629 * @param timeout when should we time out (give up) if we can not transmit? 629 * @param timeout when should we time out (give up) if we can not transmit?
630 * @param session identifier used for this session (can be NULL)
630 * @param addr the addr to send the message to, needs to be a sockaddr for us 631 * @param addr the addr to send the message to, needs to be a sockaddr for us
631 * @param addrlen the len of addr 632 * @param addrlen the len of addr
632 * @param force_address not used, we had better have an address to send to 633 * @param force_address not used, we had better have an address to send to
@@ -642,15 +643,16 @@ run_gnunet_nat_client (struct Plugin *plugin, const char *addr, size_t addrlen)
642 */ 643 */
643static ssize_t 644static ssize_t
644udp_nat_plugin_send (void *cls, 645udp_nat_plugin_send (void *cls,
645 const struct GNUNET_PeerIdentity *target, 646 const struct GNUNET_PeerIdentity *target,
646 const char *msgbuf, 647 const char *msgbuf,
647 size_t msgbuf_size, 648 size_t msgbuf_size,
648 unsigned int priority, 649 unsigned int priority,
649 struct GNUNET_TIME_Relative timeout, 650 struct GNUNET_TIME_Relative timeout,
650 const void *addr, 651 struct Session *session,
651 size_t addrlen, 652 const void *addr,
652 int force_address, 653 size_t addrlen,
653 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls) 654 int force_address,
655 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
654{ 656{
655 struct Plugin *plugin = cls; 657 struct Plugin *plugin = cls;
656 ssize_t sent; 658 ssize_t sent;
@@ -659,6 +661,7 @@ udp_nat_plugin_send (void *cls,
659 struct sockaddr_in *sockaddr = (struct sockaddr_in *)addr; 661 struct sockaddr_in *sockaddr = (struct sockaddr_in *)addr;
660 int other_peer_natd; 662 int other_peer_natd;
661 663
664 GNUNET_assert (NULL == session);
662 other_peer_natd = GNUNET_NO; 665 other_peer_natd = GNUNET_NO;
663 if ((sockaddr->sin_family == AF_INET) && (ntohs(sockaddr->sin_port) == 0)) 666 if ((sockaddr->sin_family == AF_INET) && (ntohs(sockaddr->sin_port) == 0))
664 { 667 {
@@ -1177,7 +1180,8 @@ udp_nat_demultiplexer(struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
1177 /* If we receive these just ignore! */ 1180 /* If we receive these just ignore! */
1178 break; 1181 break;
1179 default: 1182 default:
1180 plugin->env->receive (plugin->env->cls, sender, currhdr, UDP_DIRECT_DISTANCE, (char *)sender_addr, fromlen); 1183 plugin->env->receive (plugin->env->cls, sender, currhdr, UDP_DIRECT_DISTANCE,
1184 NULL, (char *)sender_addr, fromlen);
1181 } 1185 }
1182 1186
1183} 1187}