gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [gnunet] branch master updated (9ba4c1d -> f28533e)


From: gnunet
Subject: [GNUnet-SVN] [gnunet] branch master updated (9ba4c1d -> f28533e)
Date: Mon, 02 Jan 2017 19:15:57 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a change to branch master
in repository gnunet.

    from 9ba4c1d  notes for next steps with NAT
     new ab31d0d  fix compiler warning for format string
     new 1082a8e  improve/fix handling of NAT server logic for ICMP-based 
autonomous NAT traversal
     new f28533e  preparations for proper manual hole punching support in new 
NAT API

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 doc/man/gnunet-nat.1                |  10 ++-
 src/gns/gnunet-gns-proxy.c          |   3 +-
 src/include/gnunet_nat_service.h    |   9 +--
 src/nat/gnunet-nat.c                |  25 +++---
 src/nat/gnunet-service-nat.c        | 155 ++++++++++++++++++++++++++++++------
 src/nat/gnunet-service-nat_helper.c |  17 ++--
 src/nat/gnunet-service-nat_helper.h |   2 +-
 src/nat/nat.h                       |  24 ++----
 src/nat/nat_api.c                   |  31 ++++----
 9 files changed, 190 insertions(+), 86 deletions(-)

diff --git a/doc/man/gnunet-nat.1 b/doc/man/gnunet-nat.1
index 2ba2363..5bdbb21 100644
--- a/doc/man/gnunet-nat.1
+++ b/doc/man/gnunet-nat.1
@@ -39,8 +39,8 @@ Assuming we are listening at ADDRESS for connection reversal 
requests.
 Ask the peer at ADDRESS for connection reversal, using the local address for 
the target address of the reversal.
 
 .B
-.IP "\-p PORT,  \-\-port=PORT"
-Use PORT as our external port for advertising for incoming requests.
+.IP "\-p ADDRESS,  \-\-punch=ADDRESS"
+A hole was punched manually through the NAT. We should use ADDRESS as our 
external hostname and port for advertising for incoming requests. The special 
hostname 'AUTO' can be used to indicate that GNUnet should determine the 
external IP address by other means (such as upnpc), and just take the port 
number from ADDRESS.
 
 .B
 .IP "\-s,  \-\-stun"
@@ -89,6 +89,12 @@ Initiate connection reversal request:
 
   # gnunet-nat FIXME
 
+\fBManual hole punching:\fR
+
+Assume manually punched NAT, but determine external IP automatically:
+
+  # gnunet-nat -t -p AUTO:8080
+
 \fBSTUN-based XXX:\fR
 
 XXX:
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index ef9c7bf..3a38970 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -1761,7 +1761,8 @@ create_response (void *cls,
   {
 
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Processing %lu bytes UPLOAD\n", *upload_data_size);
+                "Processing %u bytes UPLOAD\n",
+               (unsigned int) *upload_data_size);
     
     /* FIXME: This must be set or a header with Transfer-Encoding: chunked. 
Else
      * upload callback is not called!
diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h
index 4df17b5..1620c94 100644
--- a/src/include/gnunet_nat_service.h
+++ b/src/include/gnunet_nat_service.h
@@ -155,15 +155,11 @@ typedef void
  * reversal.
  *
  * @param cls closure
- * @param local_addr address where we received the request
- * @param local_addrlen actual length of the @a local_addr
  * @param remote_addr public IP address of the other peer
  * @param remote_addrlen actual length of the @a remote_addr
  */
 typedef void
 (*GNUNET_NAT_ReversalCallback) (void *cls,
-                                const struct sockaddr *local_addr,
-                                socklen_t local_addrlen,
                                const struct sockaddr *remote_addr,
                                 socklen_t remote_addrlen);
 
@@ -184,8 +180,7 @@ struct GNUNET_NAT_Handle;
  *
  * @param cfg configuration to use
  * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP
- * @param adv_port advertised port (port we are either bound to or that our OS
- *                 locally performs redirection from to our bound port).
+ * @param hole_external hostname and port of manually punched hole in NAT, 
otherwise NULL (or empty string)
  * @param num_addrs number of addresses in @a addrs
  * @param addrs list of local addresses packets should be redirected to
  * @param addrlens actual lengths of the addresses in @a addrs
@@ -198,7 +193,7 @@ struct GNUNET_NAT_Handle;
 struct GNUNET_NAT_Handle *
 GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
                      uint8_t proto,
-                     uint16_t adv_port,
+                     const char *hole_external,
                      unsigned int num_addrs,
                      const struct sockaddr **addrs,
                      const socklen_t *addrlens,
diff --git a/src/nat/gnunet-nat.c b/src/nat/gnunet-nat.c
index 4d0ed57..81e4549 100644
--- a/src/nat/gnunet-nat.c
+++ b/src/nat/gnunet-nat.c
@@ -39,9 +39,10 @@ static int global_ret;
 static struct GNUNET_NAT_AutoHandle *ah;
 
 /**
- * Port we advertise.
+ * External hostname and port, if user manually punched
+ * the NAT.  
  */ 
-static unsigned int adv_port;
+static char *hole_external;
 
 /**
  * Flag set to 1 if we use IPPROTO_UDP.
@@ -338,15 +339,11 @@ address_cb (void *cls,
  * reversal.
  *
  * @param cls closure, NULL
- * @param local_addr address where we received the request
- * @param local_addrlen actual length of the @a local_addr
  * @param remote_addr public IP address of the other peer
  * @param remote_addrlen actual length of the @a remote_addr
  */
 static void
 reversal_cb (void *cls,
-            const struct sockaddr *local_addr,
-            socklen_t local_addrlen,
             const struct sockaddr *remote_addr,
             socklen_t remote_addrlen)
 {
@@ -572,7 +569,7 @@ run (void *cls,
   {
     nh = GNUNET_NAT_register (c,
                              proto,
-                             (uint16_t) adv_port,
+                             hole_external,
                              1,
                              (const struct sockaddr **) &local_sa,
                              &local_len,
@@ -580,6 +577,14 @@ run (void *cls,
                              (listen_reversal) ? &reversal_cb : NULL,
                              NULL);
   }
+  else if (listen_reversal)
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_MESSAGE,
+               "Use of `-W` only effective in combination with `-i`\n");    
+    global_ret = 1;
+    GNUNET_SCHEDULER_shutdown ();
+    return;
+  }
 
   if (NULL != remote_addr)
   {
@@ -693,9 +698,9 @@ main (int argc,
     {'r', "remote", "ADDRESS",
      gettext_noop ("which remote IP and port should be asked for connection 
reversal"),
      GNUNET_YES, &GNUNET_GETOPT_set_string, &remote_addr },
-    {'p', "port", NULL,
-     gettext_noop ("port to use to advertise"),
-     GNUNET_YES, &GNUNET_GETOPT_set_uint, &adv_port },
+    {'p', "punched", NULL,
+     gettext_noop ("external hostname and port of NAT, if punched manually; 
use AUTO for hostname for automatic determination of the external IP"),
+     GNUNET_YES, &GNUNET_GETOPT_set_string, &hole_external },
     {'s', "stun", NULL,
      gettext_noop ("enable STUN processing"),
      GNUNET_NO, &GNUNET_GETOPT_set_one, &do_stun },
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c
index 7621754..f432eca 100644
--- a/src/nat/gnunet-service-nat.c
+++ b/src/nat/gnunet-service-nat.c
@@ -1,6 +1,6 @@
 /*
   This file is part of GNUnet.
-  Copyright (C) 2016 GNUnet e.V.
+  Copyright (C) 2016, 2017 GNUnet e.V.
 
   GNUnet is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published
@@ -28,9 +28,12 @@
  * knowledge about the local network topology.
  *
  * TODO:
- * - test ICMP based NAT traversal
+ * - test and document (!) ICMP based NAT traversal
+ * - implement manual hole punching support (incl. DNS
+ *   lookup for DynDNS setups!)
  * - implement "more" autoconfig:
  *   re-work gnunet-nat-server & integrate!
+ *   + test manually punched NAT (how?)
  * - implement & test STUN processing to classify NAT;
  *   basically, open port & try different methods.
  * - implement NEW logic for external IP detection
@@ -129,6 +132,16 @@ struct ClientHandle
    * Array of addresses used by the service.
    */
   struct ClientAddress *caddrs;
+
+  /**
+   * External DNS name and port given by user due to manual
+   * hole punching.  Special DNS name 'AUTO' is used to indicate
+   * desire for automatic determination of the external IP 
+   * (instead of DNS or manual configuration, i.e. to be used 
+   * if the IP keeps changing and we have no DynDNS, but we do
+   * have a hole punched).
+   */
+  char *hole_external;
   
   /**
    * What does this client care about?
@@ -141,12 +154,6 @@ struct ClientHandle
   int natted_address;
   
   /**
-   * Port we would like as we are configured to use this one for
-   * advertising (in addition to the one we are binding to).
-   */
-  uint16_t adv_port;
-
-  /**
    * Number of addresses that this service is bound to.
    * Length of the @e caddrs array.
    */
@@ -176,6 +183,12 @@ struct LocalAddressList
   struct LocalAddressList *prev;
 
   /**
+   * Context for a gnunet-helper-nat-server used to listen
+   * for ICMP messages to this client for connection reversal.
+   */
+  struct HelperContext *hc;
+  
+  /**
    * The address itself (i.e. `struct sockaddr_in` or `struct
    * sockaddr_in6`, in the respective byte order).
    */
@@ -395,6 +408,11 @@ destroy_lal ()
     GNUNET_CONTAINER_DLL_remove (lal_head,
                                 lal_tail,
                                 lal);
+    if (NULL != lal->hc)
+    {
+      GN_stop_gnunet_nat_server_ (lal->hc);
+      lal->hc = NULL;
+    }
     GNUNET_free (lal);
   }
 }
@@ -448,7 +466,14 @@ check_register (void *cls,
       GNUNET_break (0);
       return GNUNET_SYSERR;      
     }
-  }  
+    off += alen;
+    left -= alen;
+  }
+  if (left != ntohs (message->hole_external_len))
+  {
+    GNUNET_break (0);
+    return GNUNET_SYSERR;      
+  }
   return GNUNET_OK; 
 }
 
@@ -718,10 +743,12 @@ check_notify_client (struct LocalAddressList *delta,
     GNUNET_memcpy (&v4,
                   &delta->addr,
                   alen);
+    
+    /* Check for client notifications */
     for (unsigned int i=0;i<ch->num_caddrs;i++)
     {
       const struct sockaddr_in *c4;
-      
+
       if (AF_INET != ch->caddrs[i].ss.ss_family)
        return; /* IPv4 not relevant */
       c4 = (const struct sockaddr_in *) &ch->caddrs[i].ss;
@@ -857,40 +884,37 @@ check_notify_client_external_ipv4_change (const struct 
in_addr *v4,
                                          int add)
 {
   struct sockaddr_in sa;
-  uint16_t port;
-  uint16_t bport;
+  int have_v4;
 
   /* (1) check if client cares. */
   if (! ch->natted_address)
     return;
   if (0 == (GNUNET_NAT_RF_ADDRESSES & ch->flags))
     return;
-  bport = 0;
+  have_v4 = GNUNET_NO;
   for (unsigned int i=0;i<ch->num_caddrs;i++)
   {
     const struct sockaddr_storage *ss = &ch->caddrs[i].ss;
 
     if (AF_INET != ss->ss_family)
       continue;
-    bport = ntohs (((const struct sockaddr_in *) ss)->sin_port);
+    have_v4 = GNUNET_YES;
+    break;
   }
-  if (0 == bport)
+  if (GNUNET_NO == have_v4)
     return; /* IPv6-only */
-  
-  /* (2) figure out external port, build sockaddr */
-  port = ch->adv_port;
-  if (0 == port)
-    port = bport;
+
+  /* build address info */
   memset (&sa,
          0,
          sizeof (sa));
   sa.sin_family = AF_INET;
   sa.sin_addr = *v4;
-  sa.sin_port = htons (port);
+  sa.sin_port = htons (0);
   
   /* (3) notify client of change */
   notify_client (is_nat_v4 (v4)
-                ? GNUNET_NAT_AC_EXTERN | GNUNET_NAT_AC_LAN_PRIVATE 
+                ? GNUNET_NAT_AC_EXTERN | GNUNET_NAT_AC_LAN 
                 : GNUNET_NAT_AC_EXTERN | GNUNET_NAT_AC_GLOBAL,
                 ch,
                 add,
@@ -1006,6 +1030,65 @@ run_external_ip (void *cls)
 
 
 /**
+ * We got a connection reversal request from another peer.
+ * Notify applicable clients.
+ *
+ * @param cls closure with the `struct LocalAddressList` 
+ * @param ra IP address of the peer who wants us to connect to it 
+ */
+static void
+reversal_callback (void *cls,
+                  const struct sockaddr_in *ra)
+{
+  struct LocalAddressList *lal = cls;
+  const struct sockaddr_in *l4;
+
+  GNUNET_assert (AF_INET == lal->af);
+  l4 = (const struct sockaddr_in *) &lal->addr;
+  for (struct ClientHandle *ch = ch_head;
+       NULL != ch;
+       ch = ch->next)
+  {    
+    struct GNUNET_NAT_ConnectionReversalRequestedMessage *crrm;
+    struct GNUNET_MQ_Envelope *env;
+    int match;
+
+    /* Check if client is in applicable range for ICMP NAT traversal
+       for this local address */
+    if (! ch->natted_address)
+      continue;
+    match = GNUNET_NO;
+    for (unsigned int i=0;i<ch->num_caddrs;i++)
+    {
+      struct ClientAddress *ca = &ch->caddrs[i];
+      const struct sockaddr_in *c4;
+      
+      if (AF_INET != ca->ss.ss_family)
+       continue;
+      c4 = (const struct sockaddr_in *) &ca->ss;
+      if ( (0 != c4->sin_addr.s_addr) &&
+          (l4->sin_addr.s_addr != c4->sin_addr.s_addr) )
+       continue;
+      match = GNUNET_YES;
+      break;
+    }
+    if (! match)
+      continue;
+
+    /* Notify applicable client about connection reversal request */
+    env = GNUNET_MQ_msg_extra (crrm,
+                              sizeof (struct sockaddr_in),
+                              
GNUNET_MESSAGE_TYPE_NAT_CONNECTION_REVERSAL_REQUESTED);
+    GNUNET_memcpy (&crrm[1],
+                  ra,
+                  sizeof (struct sockaddr_in));
+    GNUNET_MQ_send (ch->mq,
+                   env);
+  }
+}
+
+
+/**
  * Task we run periodically to scan for network interfaces.
  *
  * @param cls NULL
@@ -1041,7 +1124,11 @@ run_scan (void *cls)
                         (AF_INET == lal->af)
                         ? sizeof (struct sockaddr_in)
                         : sizeof (struct sockaddr_in6))) )
+      {
        found = GNUNET_YES;
+       pos->hc = lal->hc;
+       lal->hc = NULL;
+      }
     }
     if (GNUNET_NO == found)
       notify_clients (lal,
@@ -1072,6 +1159,17 @@ run_scan (void *cls)
     if (GNUNET_NO == found)
       notify_clients (pos,
                      GNUNET_YES);
+    if ( (AF_INET == pos->af) &&
+        (NULL == pos->hc) &&
+        (0 != (GNUNET_NAT_AC_LAN & pos->ac)) )
+    {
+      const struct sockaddr_in *s4
+       = (const struct sockaddr_in *) &pos->addr;
+      
+      pos->hc = GN_start_gnunet_nat_server_ (&s4->sin_addr,
+                                            &reversal_callback,
+                                            pos);
+    }
   }
   if ( (GNUNET_YES == have_nat) &&
        (GNUNET_YES == enable_upnp) &&
@@ -1164,12 +1262,12 @@ upnp_addr_change_cb (void *cls,
   {
   case AF_INET:
     ac = is_nat_v4 (&((const struct sockaddr_in *) addr)->sin_addr)
-      ? GNUNET_NAT_AC_LAN_PRIVATE
+      ? GNUNET_NAT_AC_LAN
       : GNUNET_NAT_AC_EXTERN;
     break;
   case AF_INET6:
     ac = is_nat_v6 (&((const struct sockaddr_in6 *) addr)->sin6_addr)
-      ? GNUNET_NAT_AC_LAN_PRIVATE
+      ? GNUNET_NAT_AC_LAN
       : GNUNET_NAT_AC_EXTERN;
     break;
   default:
@@ -1216,7 +1314,6 @@ handle_register (void *cls,
              "Received REGISTER message from client\n");
   ch->flags = message->flags;
   ch->proto = message->proto;
-  ch->adv_port = ntohs (message->adv_port);
   ch->num_caddrs = ntohs (message->num_addrs);
   ch->caddrs = GNUNET_new_array (ch->num_caddrs,
                                 struct ClientAddress);
@@ -1292,6 +1389,11 @@ handle_register (void *cls,
 
     off += alen;
   }
+
+  ch->hole_external
+    = GNUNET_strndup (off,
+                     ntohs (message->hole_external_len));
+    
   /* Actually send IP address list to client */
   for (struct LocalAddressList *lal = lal_head;
        NULL != lal;
@@ -1363,7 +1465,7 @@ notify_clients_stun_change (const struct sockaddr_in *ip,
     if (! ch->natted_address)
       continue;
     v4 = *ip;
-    v4.sin_port = htons (ch->adv_port);
+    v4.sin_port = htons (0);
     env = GNUNET_MQ_msg_extra (msg,
                               sizeof (v4),
                               GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE);
@@ -2045,6 +2147,7 @@ client_disconnect_cb (void *cls,
     }
   }
   GNUNET_free_non_null (ch->caddrs);
+  GNUNET_free (ch->hole_external);
   GNUNET_free (ch);
 }
 
diff --git a/src/nat/gnunet-service-nat_helper.c 
b/src/nat/gnunet-service-nat_helper.c
index 379603a..febc3c2 100644
--- a/src/nat/gnunet-service-nat_helper.c
+++ b/src/nat/gnunet-service-nat_helper.c
@@ -39,7 +39,7 @@ struct HelperContext
   /**
    * IP address we pass to the NAT helper.
    */
-  const char *internal_address;
+  struct in_addr internal_address;
 
   /**
    * Function to call if we receive a reversal request.
@@ -220,6 +220,7 @@ restart_nat_server (void *cls)
 {
   struct HelperContext *h = cls;
   char *binary;
+  char ia[INET_ADDRSTRLEN];
   
   h->server_read_task = NULL;
   h->server_stdout 
@@ -232,10 +233,15 @@ restart_nat_server (void *cls)
     try_again (h);
     return;
   }
+  GNUNET_assert (NULL !=
+                inet_ntop (AF_INET,
+                           &h->internal_address,
+                           ia,
+                           sizeof (ia)));
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Starting `%s' at `%s'\n",
        "gnunet-helper-nat-server",
-       h->internal_address);
+       ia);
   /* Start the server process */
   binary
     = GNUNET_OS_get_libexec_binary_path ("gnunet-helper-nat-server");
@@ -247,7 +253,7 @@ restart_nat_server (void *cls)
                               NULL,
                               binary,
                               "gnunet-helper-nat-server",
-                              h->internal_address,
+                              ia,
                               NULL);
   GNUNET_free (binary);
   if (NULL == h->server_proc)
@@ -285,7 +291,7 @@ restart_nat_server (void *cls)
  * @return NULL on error
  */
 struct HelperContext *
-GN_start_gnunet_nat_server_ (const char *internal_address,
+GN_start_gnunet_nat_server_ (const struct in_addr *internal_address,
                             GN_ReversalCallback cb,
                             void *cb_cls)
 {
@@ -294,8 +300,7 @@ GN_start_gnunet_nat_server_ (const char *internal_address,
   h = GNUNET_new (struct HelperContext);
   h->cb = cb;
   h->cb_cls = cb_cls;
-  h->internal_address
-    = internal_address;
+  h->internal_address = *internal_address;
   if (NULL == h->server_stdout)
   {
     GN_stop_gnunet_nat_server_ (h);
diff --git a/src/nat/gnunet-service-nat_helper.h 
b/src/nat/gnunet-service-nat_helper.h
index d3f1a75..026526b 100644
--- a/src/nat/gnunet-service-nat_helper.h
+++ b/src/nat/gnunet-service-nat_helper.h
@@ -56,7 +56,7 @@ typedef void
  * @return NULL on error
  */
 struct HelperContext *
-GN_start_gnunet_nat_server_ (const char *internal_address,
+GN_start_gnunet_nat_server_ (const struct in_addr *internal_address,
                             GN_ReversalCallback cb,
                             void *cb_cls);
 
diff --git a/src/nat/nat.h b/src/nat/nat.h
index 3356b19..af418c7 100644
--- a/src/nat/nat.h
+++ b/src/nat/nat.h
@@ -110,10 +110,11 @@ struct GNUNET_NAT_RegisterMessage
   uint8_t proto;
 
   /**
-   * Port we would like as we are configured to use this one for
-   * advertising (in addition to the one we are binding to).
+   * Number of bytes in the string that follow which
+   * specify the hostname and port of a manually punched
+   * hole for this client.
    */
-  uint16_t adv_port GNUNET_PACKED;
+  uint16_t hole_external_len GNUNET_PACKED;
 
   /**
    * Number of addresses that this service is bound to that follow.
@@ -124,6 +125,9 @@ struct GNUNET_NAT_RegisterMessage
 
   /* Followed by @e num_addrs addresses of type 'struct
      sockaddr' */
+
+  /* Followed by @e hole_external_len bytes giving a hostname
+     and port */
   
 };
 
@@ -191,19 +195,7 @@ struct GNUNET_NAT_ConnectionReversalRequestedMessage
    */
   struct GNUNET_MessageHeader header;
 
-  /**
-   * Size of the local address where we received the request, in NBO.
-   */
-  uint16_t local_addr_size;
-
-  /**
-   * Size of the remote address making the request, in NBO.
-   */
-  uint16_t remote_addr_size;
-
-  /* followed by a `struct sockaddr` of @e local_addr_size bytes */
-
-  /* followed by a `struct sockaddr` of @e remote_addr_size bytes */
+  /* followed by a `struct sockaddr_in` */
   
 };
 
diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c
index 481bc6f..e4dfc16 100644
--- a/src/nat/nat_api.c
+++ b/src/nat/nat_api.c
@@ -176,14 +176,7 @@ check_connection_reversal_request (void *cls,
 {
   if (ntohs (crm->header.size) !=
       sizeof (*crm) +
-      ntohs (crm->local_addr_size) +
-      ntohs (crm->remote_addr_size) )
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
-  if ( (sizeof (struct sockaddr_in) != ntohs (crm->local_addr_size)) ||
-       (sizeof (struct sockaddr_in) != ntohs (crm->remote_addr_size)) )
+      sizeof (struct sockaddr_in) )
   {
     GNUNET_break (0);
     return GNUNET_SYSERR;
@@ -203,13 +196,9 @@ handle_connection_reversal_request (void *cls,
                                    const struct 
GNUNET_NAT_ConnectionReversalRequestedMessage *crm)
 {
   struct GNUNET_NAT_Handle *nh = cls;
-  const struct sockaddr_in *local_sa = (const struct sockaddr_in *) &crm[1];
-  const struct sockaddr_in *remote_sa = &local_sa[1];
 
   nh->reversal_callback (nh->callback_cls,
-                        (const struct sockaddr *) local_sa,
-                        sizeof (struct sockaddr_in),
-                        (const struct sockaddr *) remote_sa,
+                        (const struct sockaddr *) &crm[1],
                         sizeof (struct sockaddr_in));
 }
 
@@ -380,8 +369,7 @@ do_connect (void *cls)
  *
  * @param cfg configuration to use
  * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP
- * @param adv_port advertised port (port we are either bound to or that our OS
- *                 locally performs redirection from to our bound port).
+ * @param hole_external hostname and port of manually punched hole in NAT, 
otherwise NULL (or empty string)
  * @param num_addrs number of addresses in @a addrs
  * @param addrs list of local addresses packets should be redirected to
  * @param addrlens actual lengths of the addresses in @a addrs
@@ -394,7 +382,7 @@ do_connect (void *cls)
 struct GNUNET_NAT_Handle *
 GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
                      uint8_t proto,
-                     uint16_t adv_port,
+                     const char *hole_external,
                      unsigned int num_addrs,
                      const struct sockaddr **addrs,
                      const socklen_t *addrlens,
@@ -405,11 +393,17 @@ GNUNET_NAT_register (const struct 
GNUNET_CONFIGURATION_Handle *cfg,
   struct GNUNET_NAT_Handle *nh;
   struct GNUNET_NAT_RegisterMessage *rm;
   size_t len;
+  size_t hole_external_len;
   char *off;
   
   len = 0;
   for (unsigned int i=0;i<num_addrs;i++)
     len += addrlens[i];
+  hole_external_len
+    = (NULL == hole_external)
+    ? 0
+    : strlen (hole_external);
+  len += hole_external_len;
   if ( (len > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*rm)) ||
        (num_addrs > UINT16_MAX) )
   {
@@ -425,7 +419,7 @@ GNUNET_NAT_register (const struct 
GNUNET_CONFIGURATION_Handle *cfg,
   if (NULL != reversal_callback)
     rm->flags |= GNUNET_NAT_RF_REVERSAL;
   rm->proto = proto;
-  rm->adv_port = htons (adv_port);
+  rm->hole_external_len = htons (hole_external_len);
   rm->num_addrs = htons ((uint16_t) num_addrs);
   off = (char *) &rm[1];
   for (unsigned int i=0;i<num_addrs;i++)
@@ -464,6 +458,9 @@ GNUNET_NAT_register (const struct 
GNUNET_CONFIGURATION_Handle *cfg,
                   addrlens[i]);
     off += addrlens[i];
   }
+  GNUNET_memcpy (off,
+                hole_external,
+                hole_external_len);
 
   nh = GNUNET_new (struct GNUNET_NAT_Handle);
   nh->reg = &rm->header;

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]