diff options
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 77 |
1 files changed, 64 insertions, 13 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 081b930ca..949023fd1 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -262,6 +262,15 @@ struct ReceiveContext | |||
262 | 262 | ||
263 | }; | 263 | }; |
264 | 264 | ||
265 | struct BroadcastAddress | ||
266 | { | ||
267 | struct BroadcastAddress *next; | ||
268 | struct BroadcastAddress *prev; | ||
269 | |||
270 | void * addr; | ||
271 | socklen_t addrlen; | ||
272 | }; | ||
273 | |||
265 | 274 | ||
266 | /** | 275 | /** |
267 | * Encapsulation of all of the state of the plugin. | 276 | * Encapsulation of all of the state of the plugin. |
@@ -351,6 +360,9 @@ struct Plugin | |||
351 | */ | 360 | */ |
352 | struct GNUNET_NETWORK_Handle *sockv4_broadcast; | 361 | struct GNUNET_NETWORK_Handle *sockv4_broadcast; |
353 | 362 | ||
363 | struct BroadcastAddress *head; | ||
364 | struct BroadcastAddress *tail; | ||
365 | |||
354 | /** | 366 | /** |
355 | * ID of select broadcast task | 367 | * ID of select broadcast task |
356 | */ | 368 | */ |
@@ -1506,14 +1518,10 @@ udp_broadcast_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1506 | // /ssize_t ret; | 1518 | // /ssize_t ret; |
1507 | const struct GNUNET_MessageHeader *hello; | 1519 | const struct GNUNET_MessageHeader *hello; |
1508 | struct UDP_Beacon_Message *msg; | 1520 | struct UDP_Beacon_Message *msg; |
1521 | struct BroadcastAddress * baddr; | ||
1509 | 1522 | ||
1510 | plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK; | 1523 | plugin->send_broadcast_task = GNUNET_SCHEDULER_NO_TASK; |
1511 | 1524 | ||
1512 | struct sockaddr_in baddr; | ||
1513 | |||
1514 | baddr.sin_family = AF_INET; | ||
1515 | baddr.sin_port = htons (plugin->broadcast_port); | ||
1516 | baddr.sin_addr.s_addr = htonl (-1); /* send message to 255.255.255.255 */ | ||
1517 | 1525 | ||
1518 | hello = plugin->env->get_our_hello (); | 1526 | hello = plugin->env->get_our_hello (); |
1519 | hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); | 1527 | hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); |
@@ -1528,14 +1536,21 @@ udp_broadcast_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1528 | msg->header.size = ntohs (msg_size); | 1536 | msg->header.size = ntohs (msg_size); |
1529 | msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON); | 1537 | msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON); |
1530 | memcpy (&msg[1], hello, hello_size); | 1538 | memcpy (&msg[1], hello, hello_size); |
1539 | sent = 0; | ||
1531 | 1540 | ||
1532 | sent = | 1541 | baddr = plugin->head; |
1533 | GNUNET_NETWORK_socket_sendto (plugin->sockv4_broadcast, msg, msg_size, | 1542 | while (baddr != NULL) |
1534 | (const struct sockaddr *) &baddr, | 1543 | { |
1535 | sizeof (struct sockaddr_in)); | 1544 | sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4_broadcast, msg, msg_size, |
1536 | 1545 | baddr->addr, | |
1537 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Sent HELLO beacon broadcast with %i bytes\n", | 1546 | baddr->addrlen); |
1538 | sent); | 1547 | if (sent == GNUNET_SYSERR) |
1548 | GNUNET_log_strerror(GNUNET_ERROR_TYPE_ERROR, "sendto"); | ||
1549 | else | ||
1550 | LOG (GNUNET_ERROR_TYPE_ERROR, "Sent HELLO beacon broadcast with %i bytes to address %s\n", | ||
1551 | sent, GNUNET_a2s(baddr->addr, baddr->addrlen)); | ||
1552 | baddr = baddr->next; | ||
1553 | } | ||
1539 | 1554 | ||
1540 | plugin->send_broadcast_task = | 1555 | plugin->send_broadcast_task = |
1541 | GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval, | 1556 | GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval, |
@@ -1869,6 +1884,32 @@ udp_nat_port_map_callback (void *cls, int add_remove, | |||
1869 | } | 1884 | } |
1870 | 1885 | ||
1871 | 1886 | ||
1887 | static int | ||
1888 | iface_proc (void *cls, const char *name, | ||
1889 | int isDefault, | ||
1890 | const struct sockaddr * addr, | ||
1891 | const struct sockaddr * broadcast_addr, | ||
1892 | const struct sockaddr * netmask, | ||
1893 | socklen_t addrlen) | ||
1894 | { | ||
1895 | struct Plugin *plugin = cls; | ||
1896 | |||
1897 | if (broadcast_addr != NULL) | ||
1898 | { | ||
1899 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Adding broadcast address %s for interface %s %p\n ", | ||
1900 | GNUNET_a2s(broadcast_addr,addrlen), name, broadcast_addr); | ||
1901 | |||
1902 | struct BroadcastAddress * ba = GNUNET_malloc(sizeof (struct BroadcastAddress)); | ||
1903 | ba->addr = GNUNET_malloc(addrlen); | ||
1904 | memcpy(ba->addr, broadcast_addr, addrlen); | ||
1905 | ba->addrlen = addrlen; | ||
1906 | |||
1907 | GNUNET_CONTAINER_DLL_insert(plugin->head, plugin->tail, ba); | ||
1908 | } | ||
1909 | return GNUNET_OK; | ||
1910 | } | ||
1911 | |||
1912 | |||
1872 | /** | 1913 | /** |
1873 | * The exported method. Makes the core api available via a global and | 1914 | * The exported method. Makes the core api available via a global and |
1874 | * returns the udp transport API. | 1915 | * returns the udp transport API. |
@@ -2183,8 +2224,10 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2183 | plugin->broadcast_rs, NULL, | 2224 | plugin->broadcast_rs, NULL, |
2184 | &udp_plugin_broadcast_select, plugin); | 2225 | &udp_plugin_broadcast_select, plugin); |
2185 | 2226 | ||
2227 | GNUNET_OS_network_interfaces_list(iface_proc, plugin); | ||
2186 | plugin->send_broadcast_task = | 2228 | plugin->send_broadcast_task = |
2187 | GNUNET_SCHEDULER_add_now (&udp_broadcast_send, plugin); | 2229 | GNUNET_SCHEDULER_add_now (&udp_broadcast_send, plugin); |
2230 | |||
2188 | } | 2231 | } |
2189 | else | 2232 | else |
2190 | plugin->broadcast = GNUNET_NO; | 2233 | plugin->broadcast = GNUNET_NO; |
@@ -2265,6 +2308,14 @@ libgnunet_plugin_transport_udp_done (void *cls) | |||
2265 | plugin->sockv4_broadcast = NULL; | 2308 | plugin->sockv4_broadcast = NULL; |
2266 | } | 2309 | } |
2267 | GNUNET_NETWORK_fdset_destroy (plugin->broadcast_rs); | 2310 | GNUNET_NETWORK_fdset_destroy (plugin->broadcast_rs); |
2311 | |||
2312 | while (plugin->head != NULL) | ||
2313 | { | ||
2314 | struct BroadcastAddress * p= plugin->head; | ||
2315 | GNUNET_CONTAINER_DLL_remove(plugin->head, plugin->tail, p); | ||
2316 | GNUNET_free (p->addr); | ||
2317 | GNUNET_free (p); | ||
2318 | } | ||
2268 | } | 2319 | } |
2269 | 2320 | ||
2270 | GNUNET_SERVER_mst_destroy (plugin->mst); | 2321 | GNUNET_SERVER_mst_destroy (plugin->mst); |