aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-09-16 13:54:53 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-09-16 13:54:53 +0000
commitb9a26a3891508c9891ca2ceb142caef2e3b08f31 (patch)
tree1aeeaa77e9d4d0390a7184ad965851943426825c /src/transport/plugin_transport_udp.c
parente5cdb00d7e936e202f7ef57519dd3b4c8b168154 (diff)
downloadgnunet-b9a26a3891508c9891ca2ceb142caef2e3b08f31.tar.gz
gnunet-b9a26a3891508c9891ca2ceb142caef2e3b08f31.zip
fix: do not return inbound sessions when transport asks for outbound session
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r--src/transport/plugin_transport_udp.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index a344ec0cf..25760255b 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -192,6 +192,7 @@ struct SessionCompareContext
192{ 192{
193 struct Session *res; 193 struct Session *res;
194 const struct GNUNET_HELLO_Address *addr; 194 const struct GNUNET_HELLO_Address *addr;
195 int inbound;
195}; 196};
196 197
197 198
@@ -1479,6 +1480,8 @@ session_cmp_it (void *cls,
1479 udp_address_to_string (NULL, (void *) address->address, 1480 udp_address_to_string (NULL, (void *) address->address,
1480 address->address_length), 1481 address->address_length),
1481 GNUNET_a2s (s->sock_addr, s->addrlen)); 1482 GNUNET_a2s (s->sock_addr, s->addrlen));
1483 if (s->inbound != cctx->inbound)
1484 return GNUNET_YES;
1482 if ((address->address_length == sizeof (struct IPv4UdpAddress)) && 1485 if ((address->address_length == sizeof (struct IPv4UdpAddress)) &&
1483 (s_addrlen == sizeof (struct sockaddr_in))) 1486 (s_addrlen == sizeof (struct sockaddr_in)))
1484 { 1487 {
@@ -1533,11 +1536,13 @@ udp_get_network (void *cls,
1533 * 1536 *
1534 * @param cls the plugin 1537 * @param cls the plugin
1535 * @param address the address 1538 * @param address the address
1539 * @param inbound look for inbound session
1536 * @return the session or NULL of max connections exceeded 1540 * @return the session or NULL of max connections exceeded
1537 */ 1541 */
1538static struct Session * 1542static struct Session *
1539udp_plugin_lookup_session (void *cls, 1543udp_plugin_lookup_session (void *cls,
1540 const struct GNUNET_HELLO_Address *address) 1544 const struct GNUNET_HELLO_Address *address,
1545 int inbound)
1541{ 1546{
1542 struct Plugin * plugin = cls; 1547 struct Plugin * plugin = cls;
1543 struct IPv6UdpAddress * udp_a6; 1548 struct IPv6UdpAddress * udp_a6;
@@ -1581,6 +1586,7 @@ udp_plugin_lookup_session (void *cls,
1581 struct SessionCompareContext cctx; 1586 struct SessionCompareContext cctx;
1582 cctx.addr = address; 1587 cctx.addr = address;
1583 cctx.res = NULL; 1588 cctx.res = NULL;
1589 cctx.inbound = inbound;
1584 LOG (GNUNET_ERROR_TYPE_DEBUG, 1590 LOG (GNUNET_ERROR_TYPE_DEBUG,
1585 "Looking for existing session for peer `%s' `%s' \n", 1591 "Looking for existing session for peer `%s' `%s' \n",
1586 GNUNET_i2s (&address->peer), 1592 GNUNET_i2s (&address->peer),
@@ -1597,7 +1603,8 @@ udp_plugin_lookup_session (void *cls,
1597 1603
1598static struct Session * 1604static struct Session *
1599udp_plugin_create_session (void *cls, 1605udp_plugin_create_session (void *cls,
1600 const struct GNUNET_HELLO_Address *address) 1606 const struct GNUNET_HELLO_Address *address,
1607 int inbound)
1601{ 1608{
1602 struct Session *s; 1609 struct Session *s;
1603 1610
@@ -1608,8 +1615,10 @@ udp_plugin_create_session (void *cls,
1608 NULL, NULL); 1615 NULL, NULL);
1609 if (NULL == s) 1616 if (NULL == s)
1610 return NULL; /* protocol not supported or address invalid */ 1617 return NULL; /* protocol not supported or address invalid */
1618 s->inbound = inbound;
1611 LOG (GNUNET_ERROR_TYPE_DEBUG, 1619 LOG (GNUNET_ERROR_TYPE_DEBUG,
1612 "Creating new session %p for peer `%s' address `%s'\n", 1620 "Creating new %s session %p for peer `%s' address `%s'\n",
1621 (GNUNET_YES == s->inbound) ? "inbound" : "outbound",
1613 s, 1622 s,
1614 GNUNET_i2s(&address->peer), 1623 GNUNET_i2s(&address->peer),
1615 udp_address_to_string(NULL,address->address,address->address_length)); 1624 udp_address_to_string(NULL,address->address,address->address_length));
@@ -1650,9 +1659,9 @@ udp_plugin_get_session (void *cls,
1650 return NULL; 1659 return NULL;
1651 1660
1652 /* otherwise create new */ 1661 /* otherwise create new */
1653 if (NULL != (s = udp_plugin_lookup_session (cls, address))) 1662 if (NULL != (s = udp_plugin_lookup_session (cls, address, GNUNET_NO)))
1654 return s; 1663 return s;
1655 return udp_plugin_create_session (cls, address); 1664 return udp_plugin_create_session (cls, address, GNUNET_NO);
1656} 1665}
1657 1666
1658 1667
@@ -2037,14 +2046,13 @@ process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg,
2037 GNUNET_a2s (sender_addr, sender_addr_len)); 2046 GNUNET_a2s (sender_addr, sender_addr_len));
2038 2047
2039 struct GNUNET_HELLO_Address * address = GNUNET_HELLO_address_allocate(&msg->sender, "udp", arg, args); 2048 struct GNUNET_HELLO_Address * address = GNUNET_HELLO_address_allocate(&msg->sender, "udp", arg, args);
2040 if (NULL == (s = udp_plugin_lookup_session (plugin, address))) 2049 if (NULL == (s = udp_plugin_lookup_session (plugin, address, GNUNET_YES)))
2041 { 2050 {
2042 s = udp_plugin_create_session(plugin, address); 2051 s = udp_plugin_create_session (plugin, address, GNUNET_YES);
2043 s->inbound = GNUNET_YES; 2052 plugin->env->session_start (NULL, &address->peer, PLUGIN_NAME,
2044 plugin->env->session_start (NULL, &address->peer, PLUGIN_NAME, 2053 (GNUNET_YES == s->inbound) ? NULL : address->address,
2045 (GNUNET_YES == s->inbound) ? NULL : address->address, 2054 (GNUNET_YES == s->inbound) ? 0 : address->address_length,
2046 (GNUNET_YES == s->inbound) ? 0 : address->address_length, 2055 s, NULL, 0);
2047 s, NULL, 0);
2048 } 2056 }
2049 GNUNET_free (address); 2057 GNUNET_free (address);
2050 2058