Add missing include
[oweals/gnunet.git] / src / transport / plugin_transport_udp_broadcasting.c
index 102e262aeee92ddbce2473371b9bf89c93941c66..1f26706d4d3d05ac545c7bb02e3ee657049a8800 100644 (file)
@@ -89,7 +89,6 @@ struct Mstv6Context
 };
 
 
-
 int
 broadcast_ipv6_mst_cb (void *cls, void *client,
                        const struct GNUNET_MessageHeader *message)
@@ -98,9 +97,10 @@ broadcast_ipv6_mst_cb (void *cls, void *client,
   struct Plugin *plugin = cls;
   struct Mstv6Context *mc = client;
   const struct GNUNET_MessageHeader *hello;
-  struct UDP_Beacon_Message *msg;
+  const struct UDP_Beacon_Message *msg;
+  struct GNUNET_ATS_Information atsi;
 
-  msg = (struct UDP_Beacon_Message *) message;
+  msg = (const struct UDP_Beacon_Message *) message;
 
   if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON !=
       ntohs (msg->header.type))
@@ -109,28 +109,25 @@ broadcast_ipv6_mst_cb (void *cls, void *client,
        "Received beacon with %u bytes from peer `%s' via address `%s'\n",
        ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
        udp_address_to_string (NULL, &mc->addr, sizeof (mc->addr)));
-  struct GNUNET_ATS_Information atsi[2];
 
   /* setup ATS */
-  atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
-  atsi[0].value = htonl (1);
-  atsi[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
-  atsi[1].value = mc->ats_address_network_type;
+  atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE);
+  atsi.value = mc->ats_address_network_type;
   GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED);
 
   hello = (struct GNUNET_MessageHeader *) &msg[1];
   plugin->env->receive (plugin->env->cls,
-                                                                                       &msg->sender,
-                                                                                       hello,
+                       &msg->sender,
+                       hello,
                         NULL,
                         (const char *) &mc->addr,
                         sizeof (mc->addr));
   plugin->env->update_address_metrics (plugin->env->cls,
-               &msg->sender,
-               (const char *) &mc->addr,
-               sizeof (mc->addr),
-      NULL,
-      (struct GNUNET_ATS_Information *) &atsi, 2);
+                                      &msg->sender,
+                                      (const char *) &mc->addr,
+                                      sizeof (mc->addr),
+                                      NULL,
+                                      &atsi, 1);
 
   GNUNET_STATISTICS_update (plugin->env->stats,
                             _
@@ -140,6 +137,7 @@ broadcast_ipv6_mst_cb (void *cls, void *client,
   return GNUNET_OK;
 }
 
+
 int
 broadcast_ipv4_mst_cb (void *cls, void *client,
                        const struct GNUNET_MessageHeader *message)
@@ -147,9 +145,10 @@ broadcast_ipv4_mst_cb (void *cls, void *client,
   struct Plugin *plugin = cls;
   struct Mstv4Context *mc = client;
   const struct GNUNET_MessageHeader *hello;
-  struct UDP_Beacon_Message *msg;
+  const struct UDP_Beacon_Message *msg;
+  struct GNUNET_ATS_Information atsi;
 
-  msg = (struct UDP_Beacon_Message *) message;
+  msg = (const struct UDP_Beacon_Message *) message;
 
   if (GNUNET_MESSAGE_TYPE_TRANSPORT_BROADCAST_BEACON !=
       ntohs (msg->header.type))
@@ -159,29 +158,26 @@ broadcast_ipv4_mst_cb (void *cls, void *client,
        ntohs (msg->header.size), GNUNET_i2s (&msg->sender),
        udp_address_to_string (NULL, &mc->addr, sizeof (mc->addr)));
 
-  struct GNUNET_ATS_Information atsi[2];
 
   /* setup ATS */
-  atsi[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
-  atsi[0].value = htonl (1);
-  atsi[1].type = htonl (GNUNET_ATS_NETWORK_TYPE);
-  atsi[1].value = mc->ats_address_network_type;
+  atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE);
+  atsi.value = mc->ats_address_network_type;
   GNUNET_break (ntohl(mc->ats_address_network_type) != GNUNET_ATS_NET_UNSPECIFIED);
 
   hello = (struct GNUNET_MessageHeader *) &msg[1];
   plugin->env->receive (plugin->env->cls,
-                                                                                       &msg->sender,
-                                                                                       hello,
+                       &msg->sender,
+                       hello,
                         NULL,
                         (const char *) &mc->addr,
                         sizeof (mc->addr));
 
   plugin->env->update_address_metrics (plugin->env->cls,
-               &msg->sender,
-               (const char *) &mc->addr,
-               sizeof (mc->addr),
-      NULL,
-      (struct GNUNET_ATS_Information *) &atsi, 2);
+                                      &msg->sender,
+                                      (const char *) &mc->addr,
+                                      sizeof (mc->addr),
+                                      NULL,
+                                      &atsi, 1);
 
   GNUNET_STATISTICS_update (plugin->env->stats,
                             _
@@ -276,7 +272,7 @@ udp_ipv4_broadcast_send (void *cls,
   plugin->send_ipv4_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
 
   msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *) &buf);
-  sent = 0;
+
   baddr = plugin->ipv4_broadcast_head;
   /* just IPv4 */
   while ((msg_size > 0) && (baddr != NULL) && (baddr->addrlen == sizeof (struct sockaddr_in)))
@@ -328,7 +324,6 @@ udp_ipv6_broadcast_send (void *cls,
   plugin->send_ipv6_broadcast_task = GNUNET_SCHEDULER_NO_TASK;
 
   msg_size = prepare_beacon(plugin, (struct UDP_Beacon_Message *) &buf);
-  sent = 0;
   sent = GNUNET_NETWORK_socket_sendto (plugin->sockv6, &buf, msg_size,
                                     (const struct sockaddr *)
                                     &plugin->ipv6_multicast_address,
@@ -398,9 +393,20 @@ iface_proc (void *cls, const char *name, int isDefault,
 void
 setup_broadcast (struct Plugin *plugin, struct sockaddr_in6 *serverAddrv6, struct sockaddr_in *serverAddrv4)
 {
+  const struct GNUNET_MessageHeader *hello;
+  hello = plugin->env->get_our_hello ();
+
+  if (GNUNET_YES == GNUNET_HELLO_is_friend_only((const struct GNUNET_HELLO_Message *) hello))
+  {
+    LOG (GNUNET_ERROR_TYPE_WARNING,
+         _("Disabling HELLO broadcasting due to friend-to-friend only configuration!\n"));
+    return;
+  }
+
+
   /* create IPv4 broadcast socket */
   plugin->broadcast_ipv4 = GNUNET_NO;
-  if (plugin->sockv4 != NULL)
+  if ((GNUNET_YES == plugin->enable_ipv4) && (plugin->sockv4 != NULL))
   {
     int yes = 1;
 
@@ -428,7 +434,7 @@ setup_broadcast (struct Plugin *plugin, struct sockaddr_in6 *serverAddrv6, struc
   }
 
   plugin->broadcast_ipv6 = GNUNET_NO;
-  if (plugin->sockv6 != NULL)
+  if ((GNUNET_YES == plugin->enable_ipv6) && (plugin->sockv6 != NULL))
   {
     memset (&plugin->ipv6_multicast_address, 0, sizeof (struct sockaddr_in6));
     GNUNET_assert (1 ==