-makefile for new test_stream_local (commented)
[oweals/gnunet.git] / src / transport / plugin_transport_http.c
index ecf32c943f0fc4b98b455dbff51f29af85ba45bf..076bef13019dccf7899aa2f7360e825bf9e790cd 100644 (file)
@@ -151,6 +151,9 @@ append_port (void *cls, const char *hostname)
 }
 
 
+
+
+
 /**
  * Convert the transports address to a nice, human-readable
  * format.
@@ -318,6 +321,91 @@ http_plugin_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
   return delay;
 }
 
+
+/**
+ * Function called to convert a string address to
+ * a binary address.
+ *
+ * @param cls closure ('struct Plugin*')
+ * @param addr string address
+ * @param addrlen length of the address
+ * @param buf location to store the buffer
+ *        If the function returns GNUNET_SYSERR, its contents are undefined.
+ * @param added length of created address
+ * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ */
+int http_string_to_address (void *cls,
+                           const char *addr,
+                           uint16_t addrlen,
+                           void **buf,
+                           size_t *added)
+{
+#if !BUILD_HTTPS
+  char *protocol = "http";
+#else
+  char *protocol = "https";
+#endif
+  char *addr_str = NULL;
+  struct sockaddr_in addr_4;
+  struct sockaddr_in6 addr_6;
+  struct IPv4HttpAddress * http_4addr;
+  struct IPv6HttpAddress * http_6addr;
+  if ((addr == NULL) || (addrlen == 0) || (buf == NULL))
+    return GNUNET_SYSERR;
+
+  /* protocoll + "://" + ":" */
+  if (addrlen <= (strlen (protocol) + 4))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                     "Invalid address string `%s' to convert to address\n",
+                     addr);
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+
+  if (NULL == (addr_str = strstr(addr, "://")))
+  {
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               "Invalid address string `%s' to convert to address\n",
+               addr);
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+  addr_str = &addr_str[3];
+
+  if (addr_str[strlen(addr_str)-1] == '/')
+    addr_str[strlen(addr_str)-1] = '\0';
+
+  if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv4(addr_str, strlen(addr_str), &addr_4))
+  {
+    http_4addr = GNUNET_malloc (sizeof (struct IPv4HttpAddress));
+    http_4addr->u4_port = addr_4.sin_port;
+    http_4addr->ipv4_addr = (uint32_t) addr_4.sin_addr.s_addr;
+    (*buf) = http_4addr;
+    (*added) = sizeof (struct IPv4HttpAddress);
+    return GNUNET_OK;
+  }
+  else if (GNUNET_OK == GNUNET_STRINGS_to_address_ipv6(addr_str, strlen(addr_str), &addr_6))
+  {
+    http_6addr = GNUNET_malloc (sizeof (struct IPv6HttpAddress));
+    http_6addr->u6_port = addr_6.sin6_port;
+    http_6addr->ipv6_addr = addr_6.sin6_addr;
+    (*buf) = http_6addr;
+    (*added) = sizeof (struct IPv6HttpAddress);
+    return GNUNET_OK;
+  }
+  else
+  {
+    GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+                     "Invalid address string `%s' to convert to address\n",
+                     addr);
+    GNUNET_break (0);
+    return GNUNET_SYSERR;
+  }
+}
+
+
+
 /**
  * Function called for a quick conversion of the binary address to
  * a numeric address.  Note that the caller must not free the
@@ -390,15 +478,11 @@ lookup_session_old (struct Plugin *plugin, const struct GNUNET_PeerIdentity *tar
                 struct Session *session, const void *addr, size_t addrlen,
                 int force_address)
 {
-  struct Session *s = NULL;
-  struct Session *t = NULL;
+  struct Session *t;
   int e_peer;
   int e_addr;
 
-  t = plugin->head;
-  if (t == NULL)
-    return NULL;
-  while (t != NULL)
+  for (t = plugin->head; NULL != t; t = t->next)
   {
 #if 0
     GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
@@ -414,73 +498,37 @@ lookup_session_old (struct Plugin *plugin, const struct GNUNET_PeerIdentity *tar
 #endif
     e_peer = GNUNET_NO;
     e_addr = GNUNET_NO;
-
     if (0 == memcmp (target, &t->target, sizeof (struct GNUNET_PeerIdentity)))
     {
       e_peer = GNUNET_YES;
-      if (addrlen == t->addrlen)
-      {
-        if (0 == memcmp (addr, t->addr, addrlen))
-        {
-          e_addr = GNUNET_YES;
-        }
-      }
-      if ((t == session))
-      {
-        if (t->addrlen == session->addrlen)
-        {
-          if (0 == memcmp (session->addr, t->addr, t->addrlen))
-          {
-            e_addr = GNUNET_YES;
-          }
-        }
-      }
+      if ( (addrlen == t->addrlen) &&
+          (0 == memcmp (addr, t->addr, addrlen)) )
+       e_addr = GNUNET_YES;    
+      if ( (t == session) &&
+          (t->addrlen == session->addrlen) &&
+          (0 == memcmp (session->addr, t->addr, t->addrlen)) )
+       e_addr = GNUNET_YES;
     }
 
-    if ((e_peer == GNUNET_YES) && (force_address == GNUNET_NO))
-    {
-      s = t;
-      break;
-    }
-    if ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) &&
-        (e_addr == GNUNET_YES))
-    {
-      s = t;
-      break;
-    }
-    if ((e_peer == GNUNET_YES) && (force_address == GNUNET_SYSERR))
-    {
-      s = t;
-      break;
-    }
-    if (s != NULL)
-      break;
-    t = t->next;
+    if ( ((e_peer == GNUNET_YES) && (force_address == GNUNET_NO)) ||
+        ((e_peer == GNUNET_YES) && (force_address == GNUNET_YES) && (e_addr == GNUNET_YES)) ||
+        ((e_peer == GNUNET_YES) && (force_address == GNUNET_SYSERR)) )
+      return t;
   }
-
-
-  return s;
+  return NULL;
 }
 
 struct Session *
 lookup_session (struct Plugin *plugin,
                 const struct GNUNET_HELLO_Address *address)
 {
-  struct Session *tmp = NULL;
-
-  tmp = plugin->head;
-  if (tmp == NULL)
-    return NULL;
-  while (tmp != NULL)
-  {
-    if (0 != memcmp (&address->peer, &tmp->target, sizeof (struct GNUNET_PeerIdentity)))
-      continue;
-    if ((address->address_length != tmp->addrlen) &&
-        (0 != memcmp (address->address, tmp->addr, tmp->addrlen)))
-      continue;
+  struct Session *pos;
 
-    return tmp;
-  }
+  for (pos = plugin->head; NULL != pos; pos = pos->next)
+    if ( (0 == memcmp (&address->peer, &pos->target, sizeof (struct GNUNET_PeerIdentity))) &&
+        (address->address_length == pos->addrlen) &&
+        (0 == memcmp (address->address, pos->addr, pos->addrlen)) )
+      return pos;
   return NULL;
 }
 
@@ -532,7 +580,7 @@ notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
 }
 
 /**
- * Creates a new session the transport service will use to send data to the
+ * Creates a new outbound session the transport service will use to send data to the
  * peer
  *
  * @param cls the plugin
@@ -540,7 +588,7 @@ notify_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
  * @return the session or NULL of max connections exceeded
  */
 
-static const struct Session *
+static struct Session *
 http_get_session (void *cls,
                   const struct GNUNET_HELLO_Address *address)
 {
@@ -551,6 +599,10 @@ http_get_session (void *cls,
 
   GNUNET_assert (plugin != NULL);
   GNUNET_assert (address != NULL);
+  GNUNET_assert (address->address != NULL);
+
+  ats.type = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
+  ats.value = htonl (GNUNET_ATS_ARRAY_TERMINATOR);
 
   /* find existing session */
   s = lookup_session (plugin, address);
@@ -579,11 +631,11 @@ http_get_session (void *cls,
   s->addrlen = addrlen;
   s->next = NULL;
   s->next_receive = GNUNET_TIME_absolute_get_zero ();
-
+  s->inbound = GNUNET_NO;
   s->ats_address_network_type = htonl (GNUNET_ATS_NET_UNSPECIFIED);
 
   /* Get ATS type */
-  if ((addrlen == sizeof (struct IPv4HttpAddress)) && (address->address != NULL))
+  if (addrlen == sizeof (struct IPv4HttpAddress))
   {
     struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) address->address;
     struct sockaddr_in s4;
@@ -596,7 +648,7 @@ http_get_session (void *cls,
 #endif
     ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s4, sizeof (struct sockaddr_in));
   }
-  if ((addrlen == sizeof (struct IPv6HttpAddress)) && (address->address != NULL))
+  if (addrlen == sizeof (struct IPv6HttpAddress))
   {
     struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) address->address;
     struct sockaddr_in6 s6;
@@ -616,11 +668,12 @@ http_get_session (void *cls,
   /* initiate new connection */
   if (GNUNET_SYSERR == client_connect (s))
   {
-    if (s != NULL)
-    {
-      GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
-      delete_session (s);
-    }
+    GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, plugin->name,
+                     "Cannot connect to peer `%s' address `%s''\n",
+                     http_plugin_address_to_string(NULL, s->addr, s->addrlen),
+                     GNUNET_i2s (&s->target));
+    GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
+    delete_session (s);
     return NULL;
   }
 
@@ -676,8 +729,8 @@ http_plugin_send (void *cls,
   {
     if ((tmp == session) &&
        (0 == memcmp (&session->target, &tmp->target, sizeof (struct GNUNET_PeerIdentity))) &&
-       (session->addrlen != tmp->addrlen) &&
-       (0 != memcmp (session->addr, tmp->addr, tmp->addrlen)))
+       (session->addrlen == tmp->addrlen) &&
+       (0 == memcmp (session->addr, tmp->addr, tmp->addrlen)))
       break;
     tmp = tmp->next;
   }
@@ -724,189 +777,6 @@ http_plugin_send (void *cls,
 
 }
 
-/**
- * Function that can be used by the transport service to transmit
- * a message using the plugin.   Note that in the case of a
- * peer disconnecting, the continuation MUST be called
- * prior to the disconnect notification itself.  This function
- * will be called with this peer's HELLO message to initiate
- * a fresh connection to another peer.
- *
- * @param cls closure
- * @param target who should receive this message
- * @param msgbuf the message to transmit
- * @param msgbuf_size number of bytes in 'msgbuf'
- * @param priority how important is the message (most plugins will
- *                 ignore message priority and just FIFO)
- * @param to how long to wait at most for the transmission (does not
- *                require plugins to discard the message after the timeout,
- *                just advisory for the desired delay; most plugins will ignore
- *                this as well)
- * @param session which session must be used (or NULL for "any")
- * @param addr the address to use (can be NULL if the plugin
- *                is "on its own" (i.e. re-use existing TCP connection))
- * @param addrlen length of the address in bytes
- * @param force_address GNUNET_YES if the plugin MUST use the given address,
- *                GNUNET_NO means the plugin may use any other address and
- *                GNUNET_SYSERR means that only reliable existing
- *                bi-directional connections should be used (regardless
- *                of address)
- * @param cont continuation to call once the message has
- *        been transmitted (or if the transport is ready
- *        for the next transmission call; or if the
- *        peer disconnected...); can be NULL
- * @param cont_cls closure for cont
- * @return number of bytes used (on the physical network, with overheads);
- *         -1 on hard errors (i.e. address invalid); 0 is a legal value
- *         and does NOT mean that the message was not transmitted (DV)
- */
-static ssize_t
-http_plugin_send_old (void *cls, const struct GNUNET_PeerIdentity *target,
-                  const char *msgbuf, size_t msgbuf_size, unsigned int priority,
-                  struct GNUNET_TIME_Relative to, struct Session *session,
-                  const void *addr, size_t addrlen, int force_address,
-                  GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
-{
-  struct Plugin *plugin = cls;
-  struct HTTP_Message *msg;
-  struct Session *s;
-
-  GNUNET_assert (plugin != NULL);
-
-  int res = GNUNET_SYSERR;
-
-#if DEBUG_HTTP
-  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
-                   "Sending %u bytes to peer `%s' on address `%s' %X %i\n",
-                   msgbuf_size, GNUNET_i2s (target), ((addr != NULL) &&
-                                                      (addrlen !=
-                                                       0)) ?
-                   http_plugin_address_to_string (plugin, addr,
-                                                  addrlen) : "<inbound>",
-                   session, force_address);
-#endif
-
-
-
-  if (addrlen != 0)
-    GNUNET_assert ((addrlen == sizeof (struct IPv4HttpAddress)) ||
-                   (addrlen == sizeof (struct IPv6HttpAddress)));
-  /* look for existing connection */
-  s = lookup_session_old (plugin, target, session, addr, addrlen, 1);
-#if DEBUG_HTTP
-  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
-                   "%s existing session: %s\n",
-                   (s != NULL) ? "Found" : "NOT Found", ((s != NULL) &&
-                                                         (s->inbound ==
-                                                          GNUNET_YES)) ?
-                   "inbound" : "outbound");
-#endif
-  /* create new outbound connection */
-  if (s == NULL)
-  {
-    if (plugin->max_connections <= plugin->cur_connections)
-    {
-      GNUNET_log_from (GNUNET_ERROR_TYPE_WARNING, plugin->name,
-                       "Maximum number of connections reached, "
-                       "cannot connect to peer `%s'\n", GNUNET_i2s (target));
-      return res;
-    }
-
-#if DEBUG_HTTP
-    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
-                     "Initiiating new connection to peer `%s'\n",
-                     GNUNET_i2s (target));
-#endif
-/* AAAAAAAAAAAAAAAAAAA */
-    int res = GNUNET_OK;
-    struct GNUNET_ATS_Information ats;
-    if ((addrlen == sizeof (struct IPv4HttpAddress)) && (addr != NULL))
-    {
-      struct IPv4HttpAddress *a4 = (struct IPv4HttpAddress *) addr;
-      struct sockaddr_in s4;
-
-      s4.sin_family = AF_INET;
-      s4.sin_addr.s_addr = a4->ipv4_addr;
-      s4.sin_port = a4->u4_port;
-#if HAVE_SOCKADDR_IN_SIN_LEN
-      s4.sin_len = sizeof (struct sockaddr_in);
-#endif
-      ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s4, sizeof (struct sockaddr_in));
-
-      if ((ntohs (a4->u4_port) == 0) || (plugin->ipv4 == GNUNET_NO))
-        res = GNUNET_SYSERR;
-    }
-    if ((addrlen == sizeof (struct IPv6HttpAddress)) && (addr != NULL))
-    {
-      struct IPv6HttpAddress *a6 = (struct IPv6HttpAddress *) addr;
-      struct sockaddr_in6 s6;
-
-      s6.sin6_family = AF_INET6;
-      s6.sin6_addr = a6->ipv6_addr;
-      s6.sin6_port = a6->u6_port;
-#if HAVE_SOCKADDR_IN_SIN_LEN
-      s6.sin6_len = sizeof (struct sockaddr_in6);
-#endif
-      ats = plugin->env->get_address_type (plugin->env->cls, (const struct sockaddr *) &s6, sizeof (struct sockaddr_in6));
-
-      if ((ntohs (a6->u6_port) == 0) || (plugin->ipv6 == GNUNET_NO))
-        res = GNUNET_SYSERR;
-    }
-    if (res == GNUNET_OK)
-    {
-      s = create_session (plugin, target, addr, addrlen, cont, cont_cls);
-      s->ats_address_network_type = ats.value;
-      GNUNET_CONTAINER_DLL_insert (plugin->head, plugin->tail, s);
-      // initiate new connection
-      res = client_connect (s);
-    }
-    if (res == GNUNET_SYSERR)
-    {
-      if (s != NULL)
-      {
-        GNUNET_CONTAINER_DLL_remove (plugin->head, plugin->tail, s);
-        delete_session (s);
-      }
-      return GNUNET_SYSERR;
-    }
-  }
-
-  /* real sending */
-
-  msg = GNUNET_malloc (sizeof (struct HTTP_Message) + msgbuf_size);
-  msg->next = NULL;
-  msg->size = msgbuf_size;
-  msg->pos = 0;
-  msg->buf = (char *) &msg[1];
-  msg->transmit_cont = cont;
-  msg->transmit_cont_cls = cont_cls;
-  memcpy (msg->buf, msgbuf, msgbuf_size);
-
-  if (s->inbound == GNUNET_NO)
-  {
-#if DEBUG_HTTP
-    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
-                     "Using outbound client session %p to send to `%s'\n", s,
-                     GNUNET_i2s (target));
-#endif
-
-    client_send (s, msg);
-    res = msgbuf_size;
-  }
-  if (s->inbound == GNUNET_YES)
-  {
-#if DEBUG_HTTP
-    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
-                     "Using inbound server %p session to send to `%s'\n", s,
-                     GNUNET_i2s (target));
-#endif
-
-    server_send (s, msg);
-    res = msgbuf_size;
-  }
-  return res;
-}
-
 
 /**
  * Function that can be used to force the plugin to disconnect
@@ -959,14 +829,12 @@ http_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
   }
 }
 
-static void
-nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
-                 socklen_t addrlen)
+static void *
+find_address (struct Plugin *plugin, const struct sockaddr *addr, socklen_t addrlen)
 {
-  struct Plugin *plugin = cls;
+  int af;
   struct IPv4HttpAddressWrapper *w_t4 = NULL;
   struct IPv6HttpAddressWrapper *w_t6 = NULL;
-  int af;
 
   af = addr->sa_family;
   switch (af)
@@ -991,25 +859,7 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
         break;
       w_t4 = w_t4->next;
     }
-    if (w_t4 == NULL)
-    {
-      w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
-      memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr));
-      w_t4->addr.u4_port = a4->sin_port;
-
-      GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
-                                   plugin->ipv4_addr_tail, w_t4);
-    }
-#if DEBUG_HTTP
-    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
-                     "Notifying transport to add IPv4 address `%s'\n",
-                     http_plugin_address_to_string (NULL, &w_t4->addr,
-                                                    sizeof (struct
-                                                            IPv4HttpAddress)));
-#endif
-    plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
-                                 sizeof (struct IPv4HttpAddress));
-
+    return w_t4;
     break;
   case AF_INET6:
     w_t6 = plugin->ipv6_addr_head;
@@ -1029,25 +879,67 @@ nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
         break;
       w_t6 = w_t6->next;
     }
+    return w_t6;
+    break;
+  default:
+    return NULL;
+  }
+  return NULL;
+}
+
+static void
+nat_add_address (void *cls, int add_remove, const struct sockaddr *addr,
+                 socklen_t addrlen)
+{
+  struct Plugin *plugin = cls;
+  struct IPv4HttpAddressWrapper *w_t4 = NULL;
+  struct IPv6HttpAddressWrapper *w_t6 = NULL;
+  int af;
+
+  af = addr->sa_family;
+  switch (af)
+  {
+  case AF_INET:
+    w_t4 = find_address (plugin, addr, addrlen);
+    if (w_t4 == NULL)
+    {
+      struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
+      w_t4 = GNUNET_malloc (sizeof (struct IPv4HttpAddressWrapper));
+      memcpy (&w_t4->addr.ipv4_addr, &a4->sin_addr, sizeof (struct in_addr));
+      w_t4->addr.u4_port = a4->sin_port;
+
+      GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
+                                   plugin->ipv4_addr_tail, w_t4);
+
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+                     "Notifying transport to add IPv4 address `%s'\n",
+                     http_plugin_address_to_string (NULL, &w_t4->addr,
+                                                    sizeof (struct
+                                                            IPv4HttpAddress)));
+    plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
+                                 sizeof (struct IPv4HttpAddress));
+    }
+    break;
+  case AF_INET6:
+    w_t6 = find_address (plugin, addr, addrlen);
     if (w_t6 == NULL)
     {
       w_t6 = GNUNET_malloc (sizeof (struct IPv6HttpAddressWrapper));
-
+      struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
       memcpy (&w_t6->addr6.ipv6_addr, &a6->sin6_addr, sizeof (struct in6_addr));
       w_t6->addr6.u6_port = a6->sin6_port;
 
       GNUNET_CONTAINER_DLL_insert (plugin->ipv6_addr_head,
                                    plugin->ipv6_addr_tail, w_t6);
-    }
-#if DEBUG_HTTP
-    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
+
+      GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Notifying transport to add IPv6 address `%s'\n",
                      http_plugin_address_to_string (NULL, &w_t6->addr6,
                                                     sizeof (struct
                                                             IPv6HttpAddress)));
-#endif
-    plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
+      plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
                                  sizeof (struct IPv6HttpAddress));
+    }
     break;
   default:
     return;
@@ -1068,35 +960,16 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
   switch (af)
   {
   case AF_INET:
-    w_t4 = plugin->ipv4_addr_head;
-    struct sockaddr_in *a4 = (struct sockaddr_in *) addr;
-
-    while (w_t4 != NULL)
-    {
-      int res = memcmp (&w_t4->addr.ipv4_addr,
-                        &a4->sin_addr,
-                        sizeof (struct in_addr));
-
-      if (res == 0)
-      {
-        if (a4->sin_port != w_t4->addr.u4_port)
-          res = -1;
-      }
-
-      if (0 == res)
-        break;
-      w_t4 = w_t4->next;
-    }
+    w_t4 = find_address (plugin, addr, addrlen);
     if (w_t4 == NULL)
       return;
 
-#if DEBUG_HTTP
+
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Notifying transport to remove IPv4 address `%s'\n",
                      http_plugin_address_to_string (NULL, &w_t4->addr,
                                                     sizeof (struct
                                                             IPv4HttpAddress)));
-#endif
     plugin->env->notify_address (plugin->env->cls, add_remove, &w_t4->addr,
                                  sizeof (struct IPv4HttpAddress));
 
@@ -1105,32 +978,16 @@ nat_remove_address (void *cls, int add_remove, const struct sockaddr *addr,
     GNUNET_free (w_t4);
     break;
   case AF_INET6:
-    w_t6 = plugin->ipv6_addr_head;
-    struct sockaddr_in6 *a6 = (struct sockaddr_in6 *) addr;
-
-    while (w_t6)
-    {
-      int res = memcmp (&w_t6->addr6.ipv6_addr, &a6->sin6_addr,
-                        sizeof (struct in6_addr));
-
-      if (res == 0)
-      {
-        if (a6->sin6_port != w_t6->addr6.u6_port)
-          res = -1;
-      }
-      if (0 == res)
-        break;
-      w_t6 = w_t6->next;
-    }
+    w_t6 = find_address (plugin, addr, addrlen);
     if (w_t6 == NULL)
       return;
-#if DEBUG_HTTP
+
     GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                      "Notifying transport to remove IPv6 address `%s'\n",
                      http_plugin_address_to_string (NULL, &w_t6->addr6,
                                                     sizeof (struct
                                                             IPv6HttpAddress)));
-#endif
+
     plugin->env->notify_address (plugin->env->cls, add_remove, &w_t6->addr6,
                                  sizeof (struct IPv6HttpAddress));
 
@@ -1158,15 +1015,13 @@ nat_port_map_callback (void *cls, int add_remove, const struct sockaddr *addr,
                        socklen_t addrlen)
 {
   GNUNET_assert (cls != NULL);
-#if DEBUG_HTTP
   struct Plugin *plugin = cls;
-#endif
-#if DEBUG_HTTP
+
   GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name,
                    "NPMC called %s to address `%s'\n",
                    (add_remove == GNUNET_NO) ? "remove" : "add",
                    GNUNET_a2s (addr, addrlen));
-#endif
+
   switch (add_remove)
   {
   case GNUNET_YES:
@@ -1591,17 +1446,29 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls)
   struct Plugin *plugin;
   int res;
 
+  if (NULL == env->receive)
+  {
+    /* run in 'stub' mode (i.e. as part of gnunet-peerinfo), don't fully
+       initialze the plugin or the API */
+    api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
+    api->cls = NULL;
+    api->address_pretty_printer = &http_plugin_address_pretty_printer;
+    api->address_to_string = &http_plugin_address_to_string;
+    api->string_to_address = &http_string_to_address;
+    return api;
+  }
+
   plugin = GNUNET_malloc (sizeof (struct Plugin));
   plugin->env = env;
   api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
   api->cls = plugin;
-  api->send = &http_plugin_send_old;
   api->disconnect = &http_plugin_disconnect;
   api->address_pretty_printer = &http_plugin_address_pretty_printer;
   api->check_address = &http_plugin_address_suggested;
   api->address_to_string = &http_plugin_address_to_string;
+  api->string_to_address = &http_string_to_address;
   api->get_session = &http_get_session;
-  api->send_with_session =   &http_plugin_send;
+  api->send = &http_plugin_send;
 
 #if BUILD_HTTPS
   plugin->name = "transport-https";
@@ -1671,7 +1538,13 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls)
 {
   struct GNUNET_TRANSPORT_PluginFunctions *api = cls;
   struct Plugin *plugin = api->cls;
-  struct Session *s = NULL;
+  struct Session *s;
+
+  if (NULL == plugin)
+  {
+    GNUNET_free (api);
+    return NULL;
+  }
 
   /* Stop reporting addresses to transport service */
   stop_report_addresses (plugin);