tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / transport / gnunet-communicator-unix.c
index 0df3fd45dea69dbcc02ccfa784aaaa1fc5d2a776..642703f29426184025f8aa6657c19794c9ab001d 100644 (file)
@@ -14,6 +14,8 @@
 
      You should have received a copy of the GNU Affero General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 
 /**
@@ -27,6 +29,8 @@
 #include "platform.h"
 #include "gnunet_util_lib.h"
 #include "gnunet_protocols.h"
+#include "gnunet_constants.h"
+#include "gnunet_nt_lib.h"
 #include "gnunet_statistics_service.h"
 #include "gnunet_transport_communication_service.h"
 
@@ -230,7 +234,7 @@ queue_destroy (struct Queue *queue)
                                                       &queue->target,
                                                       queue));
   GNUNET_STATISTICS_set (stats,
-                        "# UNIX queues active",
+                        "# queues active",
                         GNUNET_CONTAINER_multipeermap_size (queue_map),
                         GNUNET_NO);
   if (NULL != queue->timeout_task)
@@ -630,21 +634,21 @@ mq_error (void *cls,
  */
 static struct Queue *
 setup_queue (const struct GNUNET_PeerIdentity *target,
-            enum GNUNET_TRANSPORT_ConnectionStatus cs,
-            const struct sockaddr_un *un,
-            socklen_t un_len)
+             enum GNUNET_TRANSPORT_ConnectionStatus cs,
+             const struct sockaddr_un *un,
+             socklen_t un_len)
 {
   struct Queue *queue;
 
   queue = GNUNET_new (struct Queue);
   queue->target = *target;
   queue->address = GNUNET_memdup (un,
-                                 un_len);
+                                  un_len);
   queue->address_len = un_len;
   (void) GNUNET_CONTAINER_multipeermap_put (queue_map,
-                                           &queue->target,
-                                           queue,
-                                           GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
+                                            &queue->target,
+                                            queue,
+                                            GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
   GNUNET_STATISTICS_set (stats,
                         "# queues active",
                         GNUNET_CONTAINER_multipeermap_size (queue_map),
@@ -652,38 +656,37 @@ setup_queue (const struct GNUNET_PeerIdentity *target,
   queue->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
   queue->timeout_task
     = GNUNET_SCHEDULER_add_delayed (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
-                                   &queue_timeout,
-                                   queue);
+                                    &queue_timeout,
+                                    queue);
   queue->mq
     = GNUNET_MQ_queue_for_callbacks (&mq_send,
-                                    &mq_destroy,
-                                    &mq_cancel,
-                                    queue,
-                                    NULL,
-                                    &mq_error,
-                                    queue);
+                                     &mq_destroy,
+                                     &mq_cancel,
+                                     queue,
+                                     NULL,
+                                     &mq_error,
+                                     queue);
   {
     char *foreign_addr;
 
     if ('\0' == un->sun_path[0])
       GNUNET_asprintf (&foreign_addr,
-                      "%s-@%s",
-                      COMMUNICATOR_ADDRESS_PREFIX,
-                      &un->sun_path[1]);
+                       "%s-@%s",
+                       COMMUNICATOR_ADDRESS_PREFIX,
+                       &un->sun_path[1]);
     else
       GNUNET_asprintf (&foreign_addr,
-                      "%s-%s",
-                      COMMUNICATOR_ADDRESS_PREFIX,
-                      un->sun_path);
+                       "%s-%s",
+                       COMMUNICATOR_ADDRESS_PREFIX,
+                       un->sun_path);
     queue->qh
       = GNUNET_TRANSPORT_communicator_mq_add (ch,
-                                             &queue->target,
-                                             foreign_addr,
-                                             UNIX_MTU,
-                                             GNUNET_NT_LOOPBACK,
-                                              0 /* distance */,
-                                             cs,
-                                             queue->mq);
+                                              &queue->target,
+                                              foreign_addr,
+                                              UNIX_MTU,
+                                              GNUNET_NT_LOOPBACK,
+                                              cs,
+                                              queue->mq);
     GNUNET_free (foreign_addr);
   }
   return queue;
@@ -715,16 +718,16 @@ receive_complete_cb (void *cls,
   delivering_messages--;
   if (GNUNET_OK != success)
     GNUNET_STATISTICS_update (stats,
-                             "# transport transmission failures",
-                             1,
-                             GNUNET_NO);
+                              "# transport transmission failures",
+                              1,
+                              GNUNET_NO);
   GNUNET_assert (NULL != unix_sock);
   if ( (NULL == read_task) &&
        (delivering_messages < max_queue_length) )
     read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
-                                              unix_sock,
-                                              &select_read_cb,
-                                              NULL);
+                                               unix_sock,
+                                               &select_read_cb,
+                                               NULL);
 }
 
 
@@ -748,16 +751,16 @@ select_read_cb (void *cls)
 
   GNUNET_assert (NULL != unix_sock);
   read_task = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
-                                            unix_sock,
-                                            &select_read_cb,
-                                            NULL);
+                                             unix_sock,
+                                             &select_read_cb,
+                                             NULL);
   addrlen = sizeof (un);
   memset (&un,
          0,
          sizeof (un));
   ret = GNUNET_NETWORK_socket_recvfrom (unix_sock,
                                         buf,
-                                       sizeof (buf),
+                                        sizeof (buf),
                                         (struct sockaddr *) &un,
                                         &addrlen);
   if ( (-1 == ret) &&
@@ -771,9 +774,9 @@ select_read_cb (void *cls)
     return;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Read %d bytes from socket %s\n",
-             (int) ret,
-             un.sun_path);
+              "Read %d bytes from socket %s\n",
+              (int) ret,
+              un.sun_path);
   GNUNET_assert (AF_UNIX == (un.sun_family));
   msg = (struct UNIXMessage *) buf;
   msize = ntohs (msg->header.size);
@@ -784,13 +787,13 @@ select_read_cb (void *cls)
     return;
   }
   queue = lookup_queue (&msg->sender,
-                       &un,
-                       addrlen);
+                        &un,
+                        addrlen);
   if (NULL == queue)
     queue = setup_queue (&msg->sender,
-                        GNUNET_TRANSPORT_CS_INBOUND,
-                        &un,
-                        addrlen);
+                         GNUNET_TRANSPORT_CS_INBOUND,
+                         &un,
+                         addrlen);
   else
     reschedule_queue_timeout (queue);
   if (NULL == queue)
@@ -818,16 +821,17 @@ select_read_cb (void *cls)
              sizeof (al_hdr));
       csize = ntohs (al_hdr.size);
       if ( (csize < sizeof (struct GNUNET_MessageHeader)) ||
-          (csize > tsize - offset))
+           (csize > tsize - offset))
       {
-       GNUNET_break_op (0);
-       break;
+        GNUNET_break_op (0);
+        break;
       }
       ret = GNUNET_TRANSPORT_communicator_receive (ch,
-                                                  &msg->sender,
-                                                  currhdr,
-                                                  &receive_complete_cb,
-                                                  NULL);
+                                                   &msg->sender,
+                                                   currhdr,
+                                                   GNUNET_TIME_UNIT_FOREVER_REL,
+                                                   &receive_complete_cb,
+                                                   NULL);
       if (GNUNET_SYSERR == ret)
        return; /* transport not up */
       if (GNUNET_NO == ret)
@@ -895,16 +899,16 @@ mq_init (void *cls,
     return GNUNET_OK;
   }
   queue = setup_queue (peer,
-                      GNUNET_TRANSPORT_CS_OUTBOUND,
-                      un,
-                      un_len);
+                       GNUNET_TRANSPORT_CS_OUTBOUND,
+                       un,
+                       un_len);
   GNUNET_free (un);
   if (NULL == queue)
   {
     GNUNET_log (GNUNET_ERROR_TYPE_INFO,
-               "Failed to setup queue to %s at `%s'\n",
-               GNUNET_i2s (peer),
-               path);
+                "Failed to setup queue to %s at `%s'\n",
+                GNUNET_i2s (peer),
+                path);
     return GNUNET_NO;
   }
   return GNUNET_OK;
@@ -980,6 +984,29 @@ do_shutdown (void *cls)
 }
 
 
+/**
+ * Function called when the transport service has received an
+ * acknowledgement for this communicator (!) via a different return
+ * path.
+ *
+ * Not applicable for UNIX.
+ *
+ * @param cls closure
+ * @param sender which peer sent the notification
+ * @param msg payload
+ */
+static void
+enc_notify_cb (void *cls,
+               const struct GNUNET_PeerIdentity *sender,
+               const struct GNUNET_MessageHeader *msg)
+{
+  (void) cls;
+  (void) sender;
+  (void) msg;
+  GNUNET_break_op (0);
+}
+
+
 /**
  * Setup communicator and launch network interactions.
  *
@@ -1085,7 +1112,9 @@ run (void *cls,
                                              COMMUNICATOR_ADDRESS_PREFIX,
                                               GNUNET_TRANSPORT_CC_RELIABLE,
                                              &mq_init,
-                                             NULL);
+                                             NULL,
+                                              &enc_notify_cb,
+                                              NULL);
   if (NULL == ch)
   {
     GNUNET_break (0);