aboutsummaryrefslogtreecommitdiff
path: root/src/transport/plugin_transport_udp_broadcasting.c
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2012-03-23 17:30:32 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2012-03-23 17:30:32 +0000
commit73a01de336de530bc74b823561d52ef18b2dbea4 (patch)
tree26d39bf93afd8d29b42644c112f753b61784ebd1 /src/transport/plugin_transport_udp_broadcasting.c
parent37a1fa789344ef161122a0533095e771c1b88f39 (diff)
downloadgnunet-73a01de336de530bc74b823561d52ef18b2dbea4.tar.gz
gnunet-73a01de336de530bc74b823561d52ef18b2dbea4.zip
- dedup
Diffstat (limited to 'src/transport/plugin_transport_udp_broadcasting.c')
-rw-r--r--src/transport/plugin_transport_udp_broadcasting.c73
1 files changed, 27 insertions, 46 deletions
diff --git a/src/transport/plugin_transport_udp_broadcasting.c b/src/transport/plugin_transport_udp_broadcasting.c
index e33af26be..db12026e3 100644
--- a/src/transport/plugin_transport_udp_broadcasting.c
+++ b/src/transport/plugin_transport_udp_broadcasting.c
@@ -224,37 +224,43 @@ udp_broadcast_receive (struct Plugin *plugin, const char * buf, ssize_t size, st
224 } 224 }
225} 225}
226 226
227static void 227static unsigned int
228udp_ipv4_broadcast_send (void *cls, 228prepare_beacon (struct Plugin *plugin, struct UDP_Beacon_Message *msg)
229 const struct GNUNET_SCHEDULER_TaskContext *tc)
230{ 229{
231 struct Plugin *plugin = cls;
232 int sent;
233 uint16_t msg_size;
234 uint16_t hello_size; 230 uint16_t hello_size;
235 char buf[65536]; 231 uint16_t msg_size;
236 232
237 const struct GNUNET_MessageHeader *hello; 233 const struct GNUNET_MessageHeader *hello;
238 struct UDP_Beacon_Message *msg;
239 struct BroadcastAddress *baddr;
240
241 plugin->send_ipv4_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
242
243 hello = plugin->env->get_our_hello (); 234 hello = plugin->env->get_our_hello ();
244 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello); 235 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
245 msg_size = hello_size + sizeof (struct UDP_Beacon_Message); 236 msg_size = hello_size + sizeof (struct UDP_Beacon_Message);
246 237
247 if (hello_size < (sizeof (struct GNUNET_MessageHeader)) || 238 if (hello_size < (sizeof (struct GNUNET_MessageHeader)) ||
248 (msg_size > (UDP_MTU))) 239 (msg_size > (UDP_MTU)))
249 return; 240 return 0;
250 241
251 msg = (struct UDP_Beacon_Message *) buf;
252 msg->sender = *(plugin->env->my_identity); 242 msg->sender = *(plugin->env->my_identity);
253 msg->header.size = ntohs (msg_size); 243 msg->header.size = htons (msg_size);
254 msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON); 244 msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON);
255 memcpy (&msg[1], hello, hello_size); 245 memcpy (&msg[1], hello, hello_size);
256 sent = 0; 246 return msg_size;
247}
248
249static void
250udp_ipv4_broadcast_send (void *cls,
251 const struct GNUNET_SCHEDULER_TaskContext *tc)
252{
253 struct Plugin *plugin = cls;
254 int sent;
255 uint16_t msg_size;
256 char buf[65536];
257 struct UDP_Beacon_Message msg;
258 struct BroadcastAddress *baddr;
259
260 plugin->send_ipv4_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
257 261
262 msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *) &buf);
263 sent = 0;
258 baddr = plugin->ipv4_broadcast_head; 264 baddr = plugin->ipv4_broadcast_head;
259 /* just IPv4 */ 265 /* just IPv4 */
260 while ((baddr != NULL) && (baddr->addrlen == sizeof (struct sockaddr_in))) 266 while ((baddr != NULL) && (baddr->addrlen == sizeof (struct sockaddr_in)))
@@ -263,19 +269,16 @@ udp_ipv4_broadcast_send (void *cls,
263 269
264 addr->sin_port = htons (plugin->port); 270 addr->sin_port = htons (plugin->port);
265 271
266 sent = 272 sent = GNUNET_NETWORK_socket_sendto (plugin->sockv4, &buf, msg_size,
267 GNUNET_NETWORK_socket_sendto (plugin->sockv4, msg, msg_size,
268 (const struct sockaddr *) addr, 273 (const struct sockaddr *) addr,
269 baddr->addrlen); 274 baddr->addrlen);
270 if (sent == GNUNET_SYSERR) 275 if (sent == GNUNET_SYSERR)
271 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); 276 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
272 else 277 else
273 { 278 {
274#if DEBUG_UDP_BROADCASTING
275 LOG (GNUNET_ERROR_TYPE_DEBUG, 279 LOG (GNUNET_ERROR_TYPE_DEBUG,
276 "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent, 280 "Sent HELLO beacon broadcast with %i bytes to address %s\n", sent,
277 GNUNET_a2s (baddr->addr, baddr->addrlen)); 281 GNUNET_a2s (baddr->addr, baddr->addrlen));
278#endif
279 } 282 }
280 baddr = baddr->next; 283 baddr = baddr->next;
281 } 284 }
@@ -292,31 +295,13 @@ udp_ipv6_broadcast_send (void *cls,
292 struct Plugin *plugin = cls; 295 struct Plugin *plugin = cls;
293 int sent; 296 int sent;
294 uint16_t msg_size; 297 uint16_t msg_size;
295 uint16_t hello_size;
296 char buf[65536]; 298 char buf[65536];
297 299
298 const struct GNUNET_MessageHeader *hello;
299 struct UDP_Beacon_Message *msg;
300
301 plugin->send_ipv6_broadcast_task = GNUNET_SCHEDULER_NO_TASK; 300 plugin->send_ipv6_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
302 301
303 hello = plugin->env->get_our_hello (); 302 msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *) &buf);
304 hello_size = GNUNET_HELLO_size ((struct GNUNET_HELLO_Message *) hello);
305 msg_size = hello_size + sizeof (struct UDP_Beacon_Message);
306
307 if (hello_size < (sizeof (struct GNUNET_MessageHeader)) ||
308 (msg_size > (UDP_MTU)))
309 return;
310
311 msg = (struct UDP_Beacon_Message *) buf;
312 msg->sender = *(plugin->env->my_identity);
313 msg->header.size = ntohs (msg_size);
314 msg->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON);
315 memcpy (&msg[1], hello, hello_size);
316 sent = 0; 303 sent = 0;
317 304 sent = GNUNET_NETWORK_socket_sendto (plugin->sockv6, &buf, msg_size,
318 sent =
319 GNUNET_NETWORK_socket_sendto (plugin->sockv6, msg, msg_size,
320 (const struct sockaddr *) 305 (const struct sockaddr *)
321 &plugin->ipv6_multicast_address, 306 &plugin->ipv6_multicast_address,
322 sizeof (struct sockaddr_in6)); 307 sizeof (struct sockaddr_in6));
@@ -324,16 +309,12 @@ udp_ipv6_broadcast_send (void *cls,
324 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto"); 309 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "sendto");
325 else 310 else
326 { 311 {
327#if DEBUG_UDP_BROADCASTING
328 LOG (GNUNET_ERROR_TYPE_DEBUG, 312 LOG (GNUNET_ERROR_TYPE_DEBUG,
329 "Sending IPv6 HELLO beacon broadcast with %i bytes to address %s\n", 313 "Sending IPv6 HELLO beacon broadcast with %i bytes to address %s\n",
330 sent, 314 sent,
331 GNUNET_a2s ((const struct sockaddr *) &plugin->ipv6_multicast_address, 315 GNUNET_a2s ((const struct sockaddr *) &plugin->ipv6_multicast_address,
332 sizeof (struct sockaddr_in6))); 316 sizeof (struct sockaddr_in6)));
333#endif
334 } 317 }
335
336
337 plugin->send_ipv6_broadcast_task = 318 plugin->send_ipv6_broadcast_task =
338 GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval, 319 GNUNET_SCHEDULER_add_delayed (plugin->broadcast_interval,
339 &udp_ipv6_broadcast_send, plugin); 320 &udp_ipv6_broadcast_send, plugin);