diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-21 14:11:49 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-11-21 14:11:49 +0000 |
commit | bb82e293b4988b807546b7827b36388ca53ce41f (patch) | |
tree | 2a2b86f336db6f661ae502418921c38ea7b0d681 /src/transport | |
parent | fee335752fd00c1d283718fb790db8ae39ed1b5f (diff) | |
download | gnunet-bb82e293b4988b807546b7827b36388ca53ce41f.tar.gz gnunet-bb82e293b4988b807546b7827b36388ca53ce41f.zip |
now using default socket and sending on default port
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 444 |
1 files changed, 96 insertions, 348 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index a97017555..d15bbe349 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -361,35 +361,6 @@ struct Plugin | |||
361 | int broadcast_ipv4; | 361 | int broadcast_ipv4; |
362 | 362 | ||
363 | /** | 363 | /** |
364 | * Tokenizer for inbound messages. | ||
365 | */ | ||
366 | struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv4_mst; | ||
367 | |||
368 | /** | ||
369 | * The read socket for IPv4 | ||
370 | */ | ||
371 | struct GNUNET_NETWORK_Handle *sockv4_broadcast; | ||
372 | |||
373 | struct BroadcastAddress *tail; | ||
374 | struct BroadcastAddress *head; | ||
375 | |||
376 | /** | ||
377 | * ID of select broadcast task | ||
378 | */ | ||
379 | GNUNET_SCHEDULER_TaskIdentifier select_ipv4_broadcast_task; | ||
380 | |||
381 | /** | ||
382 | * ID of select broadcast task | ||
383 | */ | ||
384 | GNUNET_SCHEDULER_TaskIdentifier send_ipv4_broadcast_task; | ||
385 | |||
386 | /** | ||
387 | * FD Read set | ||
388 | */ | ||
389 | struct GNUNET_NETWORK_FDSet *broadcast_ipv4_rs; | ||
390 | |||
391 | |||
392 | /** | ||
393 | * Broadcast with IPv6 | 364 | * Broadcast with IPv6 |
394 | */ | 365 | */ |
395 | int broadcast_ipv6; | 366 | int broadcast_ipv6; |
@@ -399,33 +370,28 @@ struct Plugin | |||
399 | * Tokenizer for inbound messages. | 370 | * Tokenizer for inbound messages. |
400 | */ | 371 | */ |
401 | struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv6_mst; | 372 | struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv6_mst; |
402 | 373 | struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv4_mst; | |
403 | /** | ||
404 | * The read socket for IPv6 | ||
405 | */ | ||
406 | struct GNUNET_NETWORK_Handle *sockv6_broadcast; | ||
407 | |||
408 | 374 | ||
409 | /** | 375 | /** |
410 | * ID of select broadcast task | 376 | * ID of select broadcast task |
411 | */ | 377 | */ |
412 | GNUNET_SCHEDULER_TaskIdentifier select_ipv6_broadcast_task; | 378 | GNUNET_SCHEDULER_TaskIdentifier send_ipv4_broadcast_task; |
413 | 379 | ||
414 | /** | 380 | /** |
415 | * ID of select broadcast task | 381 | * ID of select broadcast task |
416 | */ | 382 | */ |
417 | GNUNET_SCHEDULER_TaskIdentifier send_ipv6_broadcast_task; | 383 | GNUNET_SCHEDULER_TaskIdentifier send_ipv6_broadcast_task; |
418 | 384 | ||
419 | |||
420 | /** | 385 | /** |
421 | * FD Read set | 386 | * IPv6 multicast address |
422 | */ | 387 | */ |
423 | struct GNUNET_NETWORK_FDSet *broadcast_ipv6_rs; | 388 | struct sockaddr_in6 ipv6_multicast_address; |
424 | 389 | ||
425 | /** | 390 | /** |
426 | * IPv6 multicast address | 391 | * DLL of IPv4 broadcast addresses |
427 | */ | 392 | */ |
428 | struct sockaddr_in6 ipv6_multicast_address; | 393 | struct BroadcastAddress *ipv4_broadcast_tail; |
394 | struct BroadcastAddress *ipv4_broadcast_head; | ||
429 | 395 | ||
430 | 396 | ||
431 | /** | 397 | /** |
@@ -1270,6 +1236,20 @@ find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, | |||
1270 | return GNUNET_YES; | 1236 | return GNUNET_YES; |
1271 | } | 1237 | } |
1272 | 1238 | ||
1239 | struct Mstv4Context | ||
1240 | { | ||
1241 | struct Plugin *plugin; | ||
1242 | |||
1243 | struct IPv4UdpAddress addr; | ||
1244 | }; | ||
1245 | |||
1246 | struct Mstv6Context | ||
1247 | { | ||
1248 | struct Plugin *plugin; | ||
1249 | |||
1250 | struct IPv6UdpAddress addr; | ||
1251 | }; | ||
1252 | |||
1273 | 1253 | ||
1274 | /** | 1254 | /** |
1275 | * Read and process a message from the given socket. | 1255 | * Read and process a message from the given socket. |
@@ -1317,6 +1297,43 @@ udp_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | |||
1317 | } | 1297 | } |
1318 | switch (ntohs (msg->type)) | 1298 | switch (ntohs (msg->type)) |
1319 | { | 1299 | { |
1300 | case GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON: | ||
1301 | { | ||
1302 | if (fromlen == sizeof (struct sockaddr_in)) | ||
1303 | { | ||
1304 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received IPv4 HELLO beacon broadcast with %i bytes from address %s\n", | ||
1305 | ret, GNUNET_a2s((const struct sockaddr *) &addr, fromlen)); | ||
1306 | |||
1307 | struct Mstv4Context *mc; | ||
1308 | mc = GNUNET_malloc (sizeof (struct Mstv4Context)); | ||
1309 | struct sockaddr_in *av4 = (struct sockaddr_in *) &addr; | ||
1310 | |||
1311 | mc->addr.ipv4_addr = av4->sin_addr.s_addr; | ||
1312 | mc->addr.u4_port = av4->sin_port; | ||
1313 | if (GNUNET_OK != | ||
1314 | GNUNET_SERVER_mst_receive (plugin->broadcast_ipv4_mst, mc, buf, ret, GNUNET_NO, | ||
1315 | GNUNET_NO)) | ||
1316 | GNUNET_free (mc); | ||
1317 | } | ||
1318 | else if (fromlen == sizeof (struct sockaddr_in6)) | ||
1319 | { | ||
1320 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received IPv6 HELLO beacon broadcast with %i bytes from address %s\n", | ||
1321 | ret, GNUNET_a2s((const struct sockaddr *) &addr, fromlen)); | ||
1322 | |||
1323 | struct Mstv6Context *mc; | ||
1324 | mc = GNUNET_malloc (sizeof (struct Mstv6Context)); | ||
1325 | struct sockaddr_in6 *av6 = (struct sockaddr_in6 *) &addr; | ||
1326 | |||
1327 | mc->addr.ipv6_addr = av6->sin6_addr; | ||
1328 | mc->addr.u6_port = av6->sin6_port; | ||
1329 | |||
1330 | if (GNUNET_OK != | ||
1331 | GNUNET_SERVER_mst_receive (plugin->broadcast_ipv6_mst, mc, buf, ret, GNUNET_NO, | ||
1332 | GNUNET_NO)) | ||
1333 | GNUNET_free (mc); | ||
1334 | } | ||
1335 | return; | ||
1336 | } | ||
1320 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: | 1337 | case GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE: |
1321 | if (ntohs (msg->size) < sizeof (struct UDPMessage)) | 1338 | if (ntohs (msg->size) < sizeof (struct UDPMessage)) |
1322 | { | 1339 | { |
@@ -1468,20 +1485,6 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1468 | } | 1485 | } |
1469 | 1486 | ||
1470 | 1487 | ||
1471 | struct Mstv4Context | ||
1472 | { | ||
1473 | struct Plugin *plugin; | ||
1474 | |||
1475 | struct IPv4UdpAddress addr; | ||
1476 | }; | ||
1477 | |||
1478 | struct Mstv6Context | ||
1479 | { | ||
1480 | struct Plugin *plugin; | ||
1481 | |||
1482 | struct IPv6UdpAddress addr; | ||
1483 | }; | ||
1484 | |||
1485 | void | 1488 | void |
1486 | broadcast_ipv4_mst_cb (void *cls, void *client, | 1489 | broadcast_ipv4_mst_cb (void *cls, void *client, |
1487 | const struct GNUNET_MessageHeader *message) | 1490 | const struct GNUNET_MessageHeader *message) |
@@ -1555,68 +1558,6 @@ broadcast_ipv6_mst_cb (void *cls, void *client, | |||
1555 | } | 1558 | } |
1556 | 1559 | ||
1557 | 1560 | ||
1558 | |||
1559 | |||
1560 | /** | ||
1561 | * Read and process a message from the given socket. | ||
1562 | * | ||
1563 | * @param plugin the overall plugin | ||
1564 | * @param rsock socket to read from | ||
1565 | */ | ||
1566 | static void | ||
1567 | udp_broadcast_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock) | ||
1568 | { | ||
1569 | socklen_t fromlen; | ||
1570 | char addr[32]; | ||
1571 | char buf[65536]; | ||
1572 | ssize_t ret; | ||
1573 | |||
1574 | |||
1575 | |||
1576 | fromlen = sizeof (addr); | ||
1577 | memset (&addr, 0, sizeof (addr)); | ||
1578 | ret = | ||
1579 | GNUNET_NETWORK_socket_recvfrom (rsock, buf, sizeof (buf), | ||
1580 | (struct sockaddr *) &addr, &fromlen); | ||
1581 | if (ret < sizeof (struct GNUNET_MessageHeader)) | ||
1582 | { | ||
1583 | /* malformed beacon, just throw it away */ | ||
1584 | return; | ||
1585 | } | ||
1586 | |||
1587 | if (fromlen == sizeof (struct sockaddr_in)) | ||
1588 | { | ||
1589 | struct Mstv4Context *mc; | ||
1590 | mc = GNUNET_malloc (sizeof (struct Mstv4Context)); | ||
1591 | struct sockaddr_in *av4 = (struct sockaddr_in *) &addr; | ||
1592 | |||
1593 | mc->addr.ipv4_addr = av4->sin_addr.s_addr; | ||
1594 | mc->addr.u4_port = av4->sin_port; | ||
1595 | if (GNUNET_OK != | ||
1596 | GNUNET_SERVER_mst_receive (plugin->broadcast_ipv4_mst, mc, buf, ret, GNUNET_NO, | ||
1597 | GNUNET_NO)) | ||
1598 | GNUNET_free (mc); | ||
1599 | } | ||
1600 | else if (fromlen == sizeof (struct sockaddr_in6)) | ||
1601 | { | ||
1602 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received IPv6 HELLO beacon broadcast with %i bytes from address %s\n", | ||
1603 | ret, GNUNET_a2s((const struct sockaddr *) &addr, fromlen)); | ||
1604 | |||
1605 | struct Mstv6Context *mc; | ||
1606 | mc = GNUNET_malloc (sizeof (struct Mstv6Context)); | ||
1607 | struct sockaddr_in6 *av6 = (struct sockaddr_in6 *) &addr; | ||
1608 | |||
1609 | mc->addr.ipv6_addr = av6->sin6_addr; | ||
1610 | mc->addr.u6_port = av6->sin6_port; | ||
1611 | |||
1612 | if (GNUNET_OK != | ||
1613 | GNUNET_SERVER_mst_receive (plugin->broadcast_ipv6_mst, mc, buf, ret, GNUNET_NO, | ||
1614 | GNUNET_NO)) | ||
1615 | GNUNET_free (mc); | ||
1616 | } | ||
1617 | } | ||
1618 | |||
1619 | |||
1620 | static void | 1561 | static void |
1621 | udp_ipv4_broadcast_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1562 | udp_ipv4_broadcast_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
1622 | { | 1563 | { |
@@ -1632,7 +1573,6 @@ udp_ipv4_broadcast_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t | |||
1632 | 1573 | ||
1633 | plugin->send_ipv4_broadcast_task = GNUNET_SCHEDULER_NO_TASK; | 1574 | plugin->send_ipv4_broadcast_task = GNUNET_SCHEDULER_NO_TASK; |
1634 | 1575 | ||
1635 | |||
1636 | hello = plugin->env->get_our_hello (); | 1576 | hello = plugin->env->get_our_hello (); |
1637 | hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); | 1577 | hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); |
1638 | msg_size = hello_size + sizeof (struct UDP_Beacon_Message); | 1578 | msg_size = hello_size + sizeof (struct UDP_Beacon_Message); |
@@ -1648,14 +1588,14 @@ udp_ipv4_broadcast_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t | |||
1648 | memcpy (&msg[1], hello, hello_size); | 1588 | memcpy (&msg[1], hello, hello_size); |
1649 | sent = 0; | 1589 | sent = 0; |
1650 | 1590 | ||
1651 | baddr = plugin->head; | 1591 | baddr = plugin->ipv4_broadcast_head; |
1652 | /* just IPv4 */ | 1592 | /* just IPv4 */ |
1653 | while ((baddr != NULL) && (baddr->addrlen == sizeof (struct sockaddr_in))) | 1593 | while ((baddr != NULL) && (baddr->addrlen == sizeof (struct sockaddr_in))) |
1654 | { | 1594 | { |
1655 | struct sockaddr_in * addr = (struct sockaddr_in * ) baddr->addr; | 1595 | struct sockaddr_in * addr = (struct sockaddr_in * ) baddr->addr; |
1656 | addr->sin_port = htons (plugin->broadcast_port); | 1596 | addr->sin_port = htons (plugin->port); |
1657 | 1597 | ||
1658 | sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4_broadcast, msg, msg_size, | 1598 | sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4, msg, msg_size, |
1659 | (const struct sockaddr *) addr, | 1599 | (const struct sockaddr *) addr, |
1660 | baddr->addrlen); | 1600 | baddr->addrlen); |
1661 | if (sent == GNUNET_SYSERR) | 1601 | if (sent == GNUNET_SYSERR) |
@@ -1700,7 +1640,7 @@ udp_ipv6_broadcast_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t | |||
1700 | memcpy (&msg[1], hello, hello_size); | 1640 | memcpy (&msg[1], hello, hello_size); |
1701 | sent = 0; | 1641 | sent = 0; |
1702 | 1642 | ||
1703 | sent = GNUNET_NETWORK_socket_sendto (plugin->sockv6_broadcast, msg, msg_size, | 1643 | sent = GNUNET_NETWORK_socket_sendto (plugin->sockv6, msg, msg_size, |
1704 | (const struct sockaddr *) &plugin->ipv6_multicast_address, | 1644 | (const struct sockaddr *) &plugin->ipv6_multicast_address, |
1705 | sizeof(struct sockaddr_in6)); | 1645 | sizeof(struct sockaddr_in6)); |
1706 | if (sent == GNUNET_SYSERR) | 1646 | if (sent == GNUNET_SYSERR) |
@@ -1717,69 +1657,6 @@ udp_ipv6_broadcast_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *t | |||
1717 | } | 1657 | } |
1718 | 1658 | ||
1719 | /** | 1659 | /** |
1720 | * We have been notified that our writeset has something to read. We don't | ||
1721 | * know which socket needs to be read, so we have to check each one | ||
1722 | * Then reschedule this function to be called again once more is available. | ||
1723 | * | ||
1724 | * @param cls the plugin handle | ||
1725 | * @param tc the scheduling context (for rescheduling this function again) | ||
1726 | */ | ||
1727 | static void | ||
1728 | udp_plugin_ipv4_broadcast_select (void *cls, | ||
1729 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1730 | { | ||
1731 | struct Plugin *plugin = cls; | ||
1732 | |||
1733 | plugin->select_ipv4_broadcast_task = GNUNET_SCHEDULER_NO_TASK; | ||
1734 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
1735 | return; | ||
1736 | |||
1737 | if ((NULL != plugin->sockv4_broadcast) && | ||
1738 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4_broadcast))) | ||
1739 | udp_broadcast_read (plugin, plugin->sockv4_broadcast); | ||
1740 | |||
1741 | plugin->select_ipv4_broadcast_task = | ||
1742 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
1743 | GNUNET_SCHEDULER_NO_TASK, | ||
1744 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1745 | plugin->broadcast_ipv4_rs, NULL, | ||
1746 | &udp_plugin_ipv4_broadcast_select, plugin); | ||
1747 | } | ||
1748 | |||
1749 | /** | ||
1750 | * We have been notified that our writeset has something to read. We don't | ||
1751 | * know which socket needs to be read, so we have to check each one | ||
1752 | * Then reschedule this function to be called again once more is available. | ||
1753 | * | ||
1754 | * @param cls the plugin handle | ||
1755 | * @param tc the scheduling context (for rescheduling this function again) | ||
1756 | */ | ||
1757 | static void | ||
1758 | udp_plugin_ipv6_broadcast_select (void *cls, | ||
1759 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1760 | { | ||
1761 | struct Plugin *plugin = cls; | ||
1762 | |||
1763 | plugin->select_ipv6_broadcast_task = GNUNET_SCHEDULER_NO_TASK; | ||
1764 | if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) | ||
1765 | return; | ||
1766 | |||
1767 | if ((NULL != plugin->sockv6_broadcast) && | ||
1768 | (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6_broadcast))) | ||
1769 | { | ||
1770 | udp_broadcast_read (plugin, plugin->sockv6_broadcast); | ||
1771 | } | ||
1772 | |||
1773 | plugin->select_ipv6_broadcast_task = | ||
1774 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
1775 | GNUNET_SCHEDULER_NO_TASK, | ||
1776 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
1777 | plugin->broadcast_ipv6_rs, NULL, | ||
1778 | &udp_plugin_ipv6_broadcast_select, plugin); | ||
1779 | } | ||
1780 | |||
1781 | |||
1782 | /** | ||
1783 | * Check if the given port is plausible (must be either our listen | 1660 | * Check if the given port is plausible (must be either our listen |
1784 | * port or our advertised port). If it is neither, we return | 1661 | * port or our advertised port). If it is neither, we return |
1785 | * GNUNET_SYSERR. | 1662 | * GNUNET_SYSERR. |
@@ -2098,7 +1975,7 @@ iface_proc (void *cls, const char *name, | |||
2098 | ba->addr = GNUNET_malloc(addrlen); | 1975 | ba->addr = GNUNET_malloc(addrlen); |
2099 | memcpy(ba->addr, broadcast_addr, addrlen); | 1976 | memcpy(ba->addr, broadcast_addr, addrlen); |
2100 | ba->addrlen = addrlen; | 1977 | ba->addrlen = addrlen; |
2101 | GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, ba); | 1978 | GNUNET_CONTAINER_DLL_insert(plugin->ipv4_broadcast_head, plugin->ipv4_broadcast_tail, ba); |
2102 | } | 1979 | } |
2103 | } | 1980 | } |
2104 | return GNUNET_OK; | 1981 | return GNUNET_OK; |
@@ -2118,7 +1995,6 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2118 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; | 1995 | struct GNUNET_TRANSPORT_PluginEnvironment *env = cls; |
2119 | unsigned long long port; | 1996 | unsigned long long port; |
2120 | unsigned long long aport; | 1997 | unsigned long long aport; |
2121 | unsigned long long bport; | ||
2122 | struct GNUNET_TRANSPORT_PluginFunctions *api; | 1998 | struct GNUNET_TRANSPORT_PluginFunctions *api; |
2123 | struct Plugin *plugin; | 1999 | struct Plugin *plugin; |
2124 | int sockets_created; | 2000 | int sockets_created; |
@@ -2151,11 +2027,6 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2151 | 2027 | ||
2152 | if (GNUNET_OK != | 2028 | if (GNUNET_OK != |
2153 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", | 2029 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", |
2154 | "BROADCAST_PORT", &bport)) | ||
2155 | bport = 20086; | ||
2156 | |||
2157 | if (GNUNET_OK != | ||
2158 | GNUNET_CONFIGURATION_get_value_number (env->cfg, "transport-udp", | ||
2159 | "MAX_BPS", &udp_max_bps)) | 2030 | "MAX_BPS", &udp_max_bps)) |
2160 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ | 2031 | udp_max_bps = 1024 * 1024 * 50; /* 50 MB/s == infinity for practical purposes */ |
2161 | if (GNUNET_OK != | 2032 | if (GNUNET_OK != |
@@ -2179,8 +2050,6 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2179 | plugin->last_expected_delay = GNUNET_TIME_UNIT_SECONDS; | 2050 | plugin->last_expected_delay = GNUNET_TIME_UNIT_SECONDS; |
2180 | plugin->port = port; | 2051 | plugin->port = port; |
2181 | plugin->aport = aport; | 2052 | plugin->aport = aport; |
2182 | plugin->broadcast_port = bport; | ||
2183 | plugin->broadcast_ipv4 = broadcast; | ||
2184 | plugin->env = env; | 2053 | plugin->env = env; |
2185 | plugin->broadcast_interval = interval; | 2054 | plugin->broadcast_interval = interval; |
2186 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 2055 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); |
@@ -2351,153 +2220,54 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2351 | if (broadcast) | 2220 | if (broadcast) |
2352 | { | 2221 | { |
2353 | /* create IPv4 broadcast socket */ | 2222 | /* create IPv4 broadcast socket */ |
2354 | plugin->sockv4_broadcast = | 2223 | plugin->broadcast_ipv4 = GNUNET_NO; |
2355 | GNUNET_NETWORK_socket_create (PF_INET, SOCK_DGRAM, 0); | 2224 | if (plugin->sockv4 != NULL) |
2356 | if (NULL == plugin->sockv4_broadcast) | ||
2357 | { | ||
2358 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); | ||
2359 | } | ||
2360 | else | ||
2361 | { | ||
2362 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
2363 | serverAddrv4.sin_len = sizeof (serverAddrv4); | ||
2364 | #endif | ||
2365 | serverAddrv4.sin_family = AF_INET; | ||
2366 | serverAddrv4.sin_addr.s_addr = INADDR_ANY; | ||
2367 | serverAddrv4.sin_port = htons (plugin->broadcast_port); | ||
2368 | addrlen = sizeof (serverAddrv4); | ||
2369 | serverAddr = (struct sockaddr *) &serverAddrv4; | ||
2370 | #if DEBUG_UDP | ||
2371 | #endif | ||
2372 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding Broadcast to IPv4 port %d\n", | ||
2373 | ntohs (serverAddrv4.sin_port)); | ||
2374 | |||
2375 | if (GNUNET_NETWORK_socket_bind | ||
2376 | (plugin->sockv4_broadcast, serverAddr, addrlen) != GNUNET_OK) | ||
2377 | { | ||
2378 | LOG (GNUNET_ERROR_TYPE_WARNING, | ||
2379 | _("Failed to create IPv4 broadcast socket on port %d\n"), | ||
2380 | ntohs (serverAddrv4.sin_port)); | ||
2381 | GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast); | ||
2382 | plugin->sockv4_broadcast = NULL; | ||
2383 | } | ||
2384 | if (plugin->sockv4_broadcast != NULL) | ||
2385 | { | 2225 | { |
2386 | int yes = 1; | 2226 | int yes = 1; |
2387 | 2227 | ||
2388 | if (GNUNET_NETWORK_socket_setsockopt | 2228 | if (GNUNET_NETWORK_socket_setsockopt |
2389 | (plugin->sockv4_broadcast, SOL_SOCKET, SO_BROADCAST, &yes, | 2229 | (plugin->sockv4, SOL_SOCKET, SO_BROADCAST, &yes, sizeof (int)) != GNUNET_OK) |
2390 | sizeof (int)) != GNUNET_OK) | ||
2391 | { | 2230 | { |
2392 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2231 | LOG (GNUNET_ERROR_TYPE_WARNING, |
2393 | _ | 2232 | _ |
2394 | ("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"), | 2233 | ("Failed to set IPv4 broadcast option for broadcast socket on port %d\n"), |
2395 | ntohs (serverAddrv4.sin_port)); | 2234 | ntohs (serverAddrv4.sin_port)); |
2396 | GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast); | ||
2397 | plugin->sockv4_broadcast = NULL; | ||
2398 | } | 2235 | } |
2399 | else | 2236 | else |
2400 | { | 2237 | { |
2401 | plugin->broadcast_ipv4_rs = GNUNET_NETWORK_fdset_create (); | 2238 | GNUNET_OS_network_interfaces_list(iface_proc, plugin); |
2402 | GNUNET_NETWORK_fdset_set (plugin->broadcast_ipv4_rs, | 2239 | plugin->send_ipv4_broadcast_task = |
2403 | plugin->sockv4_broadcast); | 2240 | GNUNET_SCHEDULER_add_now (&udp_ipv4_broadcast_send, plugin); |
2241 | |||
2242 | plugin->broadcast_ipv4_mst = | ||
2243 | GNUNET_SERVER_mst_create (broadcast_ipv4_mst_cb, plugin); | ||
2244 | |||
2245 | LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv4 Broadcasting running\n"); | ||
2246 | plugin->broadcast_ipv4 = GNUNET_YES; | ||
2404 | } | 2247 | } |
2405 | } | 2248 | } |
2406 | if (plugin->sockv4_broadcast != NULL) | ||
2407 | { | ||
2408 | plugin->broadcast_ipv4 = GNUNET_YES; | ||
2409 | plugin->broadcast_ipv4_mst = | ||
2410 | GNUNET_SERVER_mst_create (broadcast_ipv4_mst_cb, plugin); | ||
2411 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
2412 | _("# IPv4 broadcast HELLO beacons received via udp"), 1, | ||
2413 | GNUNET_NO); | ||
2414 | plugin->select_ipv4_broadcast_task = | ||
2415 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
2416 | GNUNET_SCHEDULER_NO_TASK, | ||
2417 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
2418 | plugin->broadcast_ipv4_rs, NULL, | ||
2419 | &udp_plugin_ipv4_broadcast_select, plugin); | ||
2420 | |||
2421 | GNUNET_OS_network_interfaces_list(iface_proc, plugin); | ||
2422 | plugin->send_ipv4_broadcast_task = | ||
2423 | GNUNET_SCHEDULER_add_now (&udp_ipv4_broadcast_send, plugin); | ||
2424 | |||
2425 | LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv4 Broadcasting on port %d running\n", | ||
2426 | ntohs (serverAddrv4.sin_port)); | ||
2427 | } | ||
2428 | else | ||
2429 | plugin->broadcast_ipv4 = GNUNET_NO; | ||
2430 | 2249 | ||
2431 | /* create IPv6 broadcast socket */ | 2250 | plugin->broadcast_ipv6 = GNUNET_NO; |
2432 | plugin->sockv6_broadcast = | 2251 | if (plugin->sockv6 != NULL) |
2433 | GNUNET_NETWORK_socket_create (PF_INET6, SOCK_DGRAM, 0); | ||
2434 | if (NULL == plugin->sockv6_broadcast) | ||
2435 | { | ||
2436 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "socket"); | ||
2437 | } | ||
2438 | else | ||
2439 | { | ||
2440 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
2441 | serverAddrv6.sin6_len = sizeof (serverAddrv6); | ||
2442 | #endif | ||
2443 | serverAddrv6.sin6_family = AF_INET6; | ||
2444 | serverAddrv6.sin6_addr = in6addr_any; | ||
2445 | serverAddrv6.sin6_port = htons (plugin->broadcast_port); | ||
2446 | addrlen = sizeof (serverAddrv6); | ||
2447 | serverAddr = (struct sockaddr *) &serverAddrv6; | ||
2448 | #if DEBUG_UDP | ||
2449 | #endif | ||
2450 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Binding Broadcast to IPv6 port %d\n", | ||
2451 | ntohs (serverAddrv6.sin6_port)); | ||
2452 | |||
2453 | if (GNUNET_NETWORK_socket_bind | ||
2454 | (plugin->sockv6_broadcast, serverAddr, addrlen) != GNUNET_OK) | ||
2455 | { | 2252 | { |
2456 | LOG (GNUNET_ERROR_TYPE_WARNING, | 2253 | memset (&plugin->ipv6_multicast_address, 0, sizeof (struct sockaddr_in6)); |
2457 | _("Failed to create IPv6 broadcast socket on port %d\n"), | 2254 | GNUNET_assert (1 == inet_pton(AF_INET6, "ff02::1", &plugin->ipv6_multicast_address.sin6_addr)); |
2458 | ntohs (serverAddrv6.sin6_port)); | ||
2459 | GNUNET_NETWORK_socket_close (plugin->sockv6_broadcast); | ||
2460 | plugin->sockv6_broadcast = NULL; | ||
2461 | } | ||
2462 | plugin->broadcast_ipv6_rs = GNUNET_NETWORK_fdset_create (); | ||
2463 | GNUNET_NETWORK_fdset_set (plugin->broadcast_ipv6_rs, | ||
2464 | plugin->sockv6_broadcast); | ||
2465 | } | ||
2466 | } | ||
2467 | 2255 | ||
2468 | if (plugin->sockv6_broadcast != NULL) | 2256 | plugin->ipv6_multicast_address.sin6_family = AF_INET6; |
2469 | { | 2257 | plugin->ipv6_multicast_address.sin6_port = htons(plugin->port); |
2470 | plugin->broadcast_ipv6 = GNUNET_YES; | ||
2471 | plugin->broadcast_ipv6_mst = | ||
2472 | GNUNET_SERVER_mst_create (broadcast_ipv6_mst_cb, plugin); | ||
2473 | |||
2474 | GNUNET_STATISTICS_update (plugin->env->stats, | ||
2475 | _("# IPv6 multicast HELLO beacons received via udp"), 1, | ||
2476 | GNUNET_NO); | ||
2477 | plugin->select_ipv6_broadcast_task = | ||
2478 | GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, | ||
2479 | GNUNET_SCHEDULER_NO_TASK, | ||
2480 | GNUNET_TIME_UNIT_FOREVER_REL, | ||
2481 | plugin->broadcast_ipv6_rs, NULL, | ||
2482 | &udp_plugin_ipv6_broadcast_select, plugin); | ||
2483 | |||
2484 | memset (&plugin->ipv6_multicast_address, 0, sizeof (struct sockaddr_in6)); | ||
2485 | GNUNET_assert (1 == inet_pton(AF_INET6, "ff02::1", &plugin->ipv6_multicast_address.sin6_addr)); | ||
2486 | |||
2487 | plugin->ipv6_multicast_address.sin6_family = AF_INET6; | ||
2488 | plugin->ipv6_multicast_address.sin6_port = htons(plugin->broadcast_port); | ||
2489 | |||
2490 | LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 Broadcasting on port %d running\n", | ||
2491 | ntohs (serverAddrv6.sin6_port)); | ||
2492 | 2258 | ||
2493 | plugin->send_ipv6_broadcast_task = | 2259 | plugin->broadcast_ipv6_mst = |
2494 | GNUNET_SCHEDULER_add_now (&udp_ipv6_broadcast_send, plugin); | 2260 | GNUNET_SERVER_mst_create (broadcast_ipv6_mst_cb, plugin); |
2495 | } | 2261 | |
2496 | else | 2262 | LOG (GNUNET_ERROR_TYPE_DEBUG, "IPv6 Broadcasting running\n"); |
2497 | plugin->broadcast_ipv6 = GNUNET_NO; | ||
2498 | } | ||
2499 | 2263 | ||
2500 | 2264 | ||
2265 | plugin->send_ipv6_broadcast_task = | ||
2266 | GNUNET_SCHEDULER_add_now (&udp_ipv6_broadcast_send, plugin); | ||
2267 | plugin->broadcast_ipv6 = GNUNET_YES; | ||
2268 | } | ||
2269 | } | ||
2270 | |||
2501 | if (sockets_created == 0) | 2271 | if (sockets_created == 0) |
2502 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); | 2272 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Failed to open UDP sockets\n")); |
2503 | plugin->nat = | 2273 | plugin->nat = |
@@ -2555,30 +2325,19 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
2555 | 2325 | ||
2556 | if (plugin->broadcast_ipv4) | 2326 | if (plugin->broadcast_ipv4) |
2557 | { | 2327 | { |
2558 | if (plugin->select_ipv4_broadcast_task != GNUNET_SCHEDULER_NO_TASK) | ||
2559 | { | ||
2560 | GNUNET_SCHEDULER_cancel (plugin->select_ipv4_broadcast_task); | ||
2561 | plugin->select_ipv4_broadcast_task = GNUNET_SCHEDULER_NO_TASK; | ||
2562 | } | ||
2563 | if (plugin->send_ipv4_broadcast_task != GNUNET_SCHEDULER_NO_TASK) | 2328 | if (plugin->send_ipv4_broadcast_task != GNUNET_SCHEDULER_NO_TASK) |
2564 | { | 2329 | { |
2565 | GNUNET_SCHEDULER_cancel (plugin->send_ipv4_broadcast_task); | 2330 | GNUNET_SCHEDULER_cancel (plugin->send_ipv4_broadcast_task); |
2566 | plugin->send_ipv4_broadcast_task = GNUNET_SCHEDULER_NO_TASK; | 2331 | plugin->send_ipv4_broadcast_task = GNUNET_SCHEDULER_NO_TASK; |
2567 | } | 2332 | } |
2333 | |||
2568 | if (plugin->broadcast_ipv4_mst != NULL) | 2334 | if (plugin->broadcast_ipv4_mst != NULL) |
2569 | GNUNET_SERVER_mst_destroy (plugin->broadcast_ipv4_mst); | 2335 | GNUNET_SERVER_mst_destroy (plugin->broadcast_ipv4_mst); |
2570 | if (plugin->sockv4_broadcast != NULL) | ||
2571 | { | ||
2572 | GNUNET_break (GNUNET_OK == | ||
2573 | GNUNET_NETWORK_socket_close (plugin->sockv4_broadcast)); | ||
2574 | plugin->sockv4_broadcast = NULL; | ||
2575 | } | ||
2576 | GNUNET_NETWORK_fdset_destroy (plugin->broadcast_ipv4_rs); | ||
2577 | 2336 | ||
2578 | while (plugin->head != NULL) | 2337 | while (plugin->ipv4_broadcast_head != NULL) |
2579 | { | 2338 | { |
2580 | struct BroadcastAddress * p= plugin->head; | 2339 | struct BroadcastAddress * p= plugin->ipv4_broadcast_head; |
2581 | GNUNET_CONTAINER_DLL_remove(plugin->head, plugin->tail, p); | 2340 | GNUNET_CONTAINER_DLL_remove(plugin->ipv4_broadcast_head, plugin->ipv4_broadcast_tail, p); |
2582 | GNUNET_free (p->addr); | 2341 | GNUNET_free (p->addr); |
2583 | GNUNET_free (p); | 2342 | GNUNET_free (p); |
2584 | } | 2343 | } |
@@ -2586,25 +2345,14 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
2586 | 2345 | ||
2587 | if (plugin->broadcast_ipv6) | 2346 | if (plugin->broadcast_ipv6) |
2588 | { | 2347 | { |
2589 | if (plugin->select_ipv6_broadcast_task != GNUNET_SCHEDULER_NO_TASK) | ||
2590 | { | ||
2591 | GNUNET_SCHEDULER_cancel (plugin->select_ipv6_broadcast_task); | ||
2592 | plugin->select_ipv6_broadcast_task = GNUNET_SCHEDULER_NO_TASK; | ||
2593 | } | ||
2594 | if (plugin->send_ipv6_broadcast_task != GNUNET_SCHEDULER_NO_TASK) | 2348 | if (plugin->send_ipv6_broadcast_task != GNUNET_SCHEDULER_NO_TASK) |
2595 | { | 2349 | { |
2596 | GNUNET_SCHEDULER_cancel (plugin->send_ipv6_broadcast_task); | 2350 | GNUNET_SCHEDULER_cancel (plugin->send_ipv6_broadcast_task); |
2597 | plugin->send_ipv6_broadcast_task = GNUNET_SCHEDULER_NO_TASK; | 2351 | plugin->send_ipv6_broadcast_task = GNUNET_SCHEDULER_NO_TASK; |
2598 | } | 2352 | } |
2353 | |||
2599 | if (plugin->broadcast_ipv6_mst != NULL) | 2354 | if (plugin->broadcast_ipv6_mst != NULL) |
2600 | GNUNET_SERVER_mst_destroy (plugin->broadcast_ipv6_mst); | 2355 | GNUNET_SERVER_mst_destroy (plugin->broadcast_ipv6_mst); |
2601 | if (plugin->sockv6_broadcast != NULL) | ||
2602 | { | ||
2603 | GNUNET_break (GNUNET_OK == | ||
2604 | GNUNET_NETWORK_socket_close (plugin->sockv6_broadcast)); | ||
2605 | plugin->sockv6_broadcast = NULL; | ||
2606 | } | ||
2607 | GNUNET_NETWORK_fdset_destroy (plugin->broadcast_ipv6_rs); | ||
2608 | } | 2356 | } |
2609 | 2357 | ||
2610 | GNUNET_SERVER_mst_destroy (plugin->mst); | 2358 | GNUNET_SERVER_mst_destroy (plugin->mst); |