gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r6220 - in GNUnet: . contrib src/include src/transports


From: gnunet
Subject: [GNUnet-SVN] r6220 - in GNUnet: . contrib src/include src/transports
Date: Sat, 9 Feb 2008 23:45:36 -0700 (MST)

Author: grothoff
Date: 2008-02-09 23:45:34 -0700 (Sat, 09 Feb 2008)
New Revision: 6220

Added:
   GNUnet/src/transports/common.c
Removed:
   GNUnet/src/transports/ip6.c
   GNUnet/src/transports/ip6.h
   GNUnet/src/transports/tcp6.c
   GNUnet/src/transports/tcp_helper.c
   GNUnet/src/transports/udp6.c
   GNUnet/src/transports/udp_helper.c
Modified:
   GNUnet/ChangeLog
   GNUnet/contrib/config-daemon.scm
   GNUnet/src/include/gnunet_protocols.h
   GNUnet/src/include/gnunet_util_network.h
   GNUnet/src/transports/Makefile.am
   GNUnet/src/transports/ip.c
   GNUnet/src/transports/ip.h
   GNUnet/src/transports/tcp.c
   GNUnet/src/transports/udp.c
   GNUnet/todo
Log:
IPv4 IPv6 transport integration

Modified: GNUnet/ChangeLog
===================================================================
--- GNUnet/ChangeLog    2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/ChangeLog    2008-02-10 06:45:34 UTC (rev 6220)
@@ -1,3 +1,18 @@
+Sat Feb  9 22:06:23 MST 2008
+       Minor changes to the ECRS/FSUI APIs for searches
+       (no more timeouts and/or max-results).  Clients who
+       need these features could easily implement them 
+       directly (and they are not really useful to begin
+       with).  
+       Also, the IPv4 and IPv6 protocols are being integrated
+       so that we only listen to one port (running both IPv4
+       and IPv6 over the same port).  This break transport
+       compatibility, but given that we're breaking protocol
+       compatibility for file-sharing already, this may 
+       actually be a bit of a good thing (since it will now
+       be possible to tell if peers running the new GAP code
+       are connected to other peers running the new GAP code).
+       
 Sun Feb  3 13:17:09 MST 2008
        Dramatic changes to the GAP implementation (breaking
        protocol compatibility).  Essentially, we can save

Modified: GNUnet/contrib/config-daemon.scm
===================================================================
--- GNUnet/contrib/config-daemon.scm    2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/contrib/config-daemon.scm    2008-02-10 06:45:34 UTC (rev 6220)
@@ -347,13 +347,13 @@
   "TRANSPORTS"
   (_ "Which transport mechanisms should GNUnet use?")
   (_ 
-"Use space-separated list of the modules, e.g.  \"udp smtp tcp\".  The 
available transports are udp, tcp, http, smtp, tcp6, udp6 and nat.
+"Use space-separated list of the modules, e.g.  \"udp smtp tcp\".  The 
available transports are udp, tcp, http, smtp and nat.
                
-Loading the 'nat' and 'tcp' modules is required for peers behind NAT boxes 
that cannot directly be reached from the outside.  Peers that are NOT behind a 
NAT box and that want to *allow* peers that ARE behind a NAT box to connect 
must ALSO load the 'nat' module.  Note that the actual transfer will always be 
via tcp initiated by the peer behind the NAT box.  The nat transport requires 
the use of tcp, http, smtp and/or tcp6 in addition to nat itself.")
+Loading the 'nat' and 'tcp' modules is required for peers behind NAT boxes 
that cannot directly be reached from the outside.  Peers that are NOT behind a 
NAT box and that want to *allow* peers that ARE behind a NAT box to connect 
must ALSO load the 'nat' module.  Note that the actual transfer will always be 
via tcp initiated by the peer behind the NAT box.  The nat transport requires 
the use of tcp, http and/or smtp in addition to nat itself.")
   '()
   #t
   "udp tcp http nat"
-  (list "MC" "udp" "udp6" "tcp" "tcp6" "nat" "http" "smtp")
+  (list "MC" "udp" "tcp" "nat" "http" "smtp")
   'always) )
  
 
@@ -884,7 +884,7 @@
  (builder
  "TCP"
  "BLACKLIST"
- (_ "Which IPs are not allowed to connect?")
+ (_ "Which IP(v4)s are not allowed to connect?")
  (nohelp)
  '()
  #t
@@ -896,7 +896,7 @@
  (builder
  "TCP"
  "WHITELIST"
- (_ "Which IPs are allowed to connect? Leave empty to use the IP of your 
primary network interface.")
+ (_ "Which IP(v4)s are allowed to connect? Leave empty to use the IP of your 
primary network interface.")
  (nohelp)
  '()
  #t
@@ -904,6 +904,31 @@
  '()
  'advanced))
 
+(define (tcp6-blacklist builder)
+ (builder
+ "TCP"
+ "BLACKLISTV6"
+ (_ "Which IPv6s are not allowed to connect?")
+ (nohelp)
+ '()
+ #t
+ ""
+ '()
+ 'advanced))
+
+(define (tcp6-whitelist builder)
+ (builder
+ "TCP"
+ "WHITELISTV6"
+ (_ "Which IPv6s are allowed to connect? Leave empty to allow any IP to 
connect.")
+ (nohelp)
+ '()
+ #t
+ ""
+ '()
+ 'advanced))
+
+
 (define (tcp builder)
  (builder
  "TCP"
@@ -1132,119 +1157,23 @@
  '()
  'advanced))
 
-(define (udp builder)
+(define (udp6-blacklist builder)
  (builder
  "UDP"
- ""
- (_ "UDP transport")
+ "BLACKLISTV6"
+ (_ "Which IPv6s are not allowed to connect?")
  (nohelp)
- (list 
-   (udp-port builder)
-   (udp-upnp builder)
-   (udp-mtu builder)
-   (udp-blacklist builder)
-   (udp-whitelist builder)
- )
- #t
- #f
- #f
- 'udp-loaded) )
-
-
-(define (tcp6-port builder)
- (builder
- "TCP6"
- "PORT"
- (_ "Which port should be used by the TCP IPv6 transport?")
- (nohelp)
  '()
  #t
- 2088
- (cons 0 65535)
- 'advanced))
-
-(define (tcp6-blacklist builder)
- (builder
- "TCP6"
- "BLACKLIST"
- (_ "Which IPs are not allowed to connect?")
- (nohelp)
- '()
- #t
  ""
  '()
  'advanced))
 
-(define (tcp6-whitelist builder)
- (builder
- "TCP6"
- "WHITELIST"
- (_ "Which IPs are allowed to connect? Leave empty to allow any IP to 
connect.")
- (nohelp)
- '()
- #t
- ""
- '()
- 'advanced))
-
-(define (tcp6 builder)
- (builder
- "TCP6"
- ""
- (_ "TCP6 transport")
- (nohelp)
- (list 
-   (tcp6-port builder)
-   (tcp6-blacklist builder)
-   (tcp6-whitelist builder)
- )
- #t
- #f
- #f
- 'tcp6-loaded) )
-
-
-(define (udp6-port builder)
- (builder
- "UDP6"
- "PORT"
- (_ "Which port should be used by the UDP IPv6 transport?")
- (nohelp)
- '()
- #t
- 2088
- (cons 0 65535)
- 'advanced))
-
-(define (udp6-mtu builder)
- (builder
- "UDP6"
- "MTU"
- (_ "What is the maximum transfer unit for UDP 6?")
- (nohelp)
- '()
- #t
- 1452
- (cons 1200 65500)
- 'rare))
-
-(define (udp6-blacklist builder)
- (builder
- "UDP6"
- "BLACKLIST"
- (_ "Which IPs are not allowed to connect?")
- (nohelp)
- '()
- #t
- ""
- '()
- 'advanced))
-
 (define (udp6-whitelist builder)
  (builder
  "UDP6"
- "WHITELIST"
- (_ "Which IPs are allowed to connect? Leave empty to allow any IP to 
connect.")
+ "WHITELISTV6"
+ (_ "Which IPv6s are allowed to connect? Leave empty to allow any IP to 
connect.")
  (nohelp)
  '()
  #t
@@ -1252,24 +1181,28 @@
  '()
  'advanced))
 
-(define (udp6 builder)
+(define (udp builder)
  (builder
- "UDP6"
+ "UDP"
  ""
- (_ "UDP6 transport")
+ (_ "UDP transport")
  (nohelp)
  (list 
-   (udp6-port builder)
-   (udp6-mtu builder)
+   (udp-port builder)
+   (udp-upnp builder)
+   (udp-mtu builder)
+   (udp-blacklist builder)
+   (udp-whitelist builder)
    (udp6-blacklist builder)
    (udp6-whitelist builder)
  )
  #t
  #f
  #f
- 'udp6-loaded) )
+ 'udp-loaded) )
 
 
+
 (define (network-interface builder)
  (builder
  "NETWORK"
@@ -1317,9 +1250,7 @@
     (network-interface builder)
     (network-ip builder)
     (tcp builder)
-    (tcp6 builder)
     (udp builder)
-    (udp6 builder)
     (http builder)
     (smtp builder)
   )
@@ -1527,8 +1458,6 @@
      (nat-loaded (list? (member "nat" (string-split (get-option ctx "GNUNETD" 
"TRANSPORTS") #\  ) ) ) )
      (tcp-loaded (list? (member "tcp" (string-split (get-option ctx "GNUNETD" 
"TRANSPORTS") #\  ) ) ) )
      (udp-loaded (list? (member "udp" (string-split (get-option ctx "GNUNETD" 
"TRANSPORTS") #\  ) ) ) )
-     (tcp6-loaded (list? (member "tcp6" (string-split (get-option ctx 
"GNUNETD" "TRANSPORTS") #\  ) ) ) )
-     (udp6-loaded (list? (member "udp6" (string-split (get-option ctx 
"GNUNETD" "TRANSPORTS") #\  ) ) ) )
      (http-loaded (list? (member "http" (string-split (get-option ctx 
"GNUNETD" "TRANSPORTS") #\  ) ) ) )
      (smtp-loaded (list? (member "smtp" (string-split (get-option ctx 
"GNUNETD" "TRANSPORTS") #\  ) ) ) )
    )
@@ -1550,9 +1479,6 @@
             ((eq? i 'nat-loaded)   (change-visible ctx a b nat-loaded))
             ((eq? i 'udp-loaded)   (change-visible ctx a b udp-loaded))
             ((eq? i 'tcp-loaded)   (change-visible ctx a b tcp-loaded))
-            ((eq? i 'udp6-loaded)  (change-visible ctx a b udp6-loaded))
-            ((eq? i 'tcp6-loaded)  (change-visible ctx a b tcp6-loaded))
-            ((eq? i 'ip6-loaded)   (change-visible ctx a b (or (tcp6-loaded 
udp6-loaded))))
             ((eq? i 'http-loaded)  (change-visible ctx a b http-loaded))
             ((eq? i 'smtp-loaded)  (change-visible ctx a b smtp-loaded))
             ((eq? i 'nobasiclimit) (change-visible ctx a b nobasiclimit))

Modified: GNUnet/src/include/gnunet_protocols.h
===================================================================
--- GNUnet/src/include/gnunet_protocols.h       2008-02-10 06:35:35 UTC (rev 
6219)
+++ GNUnet/src/include/gnunet_protocols.h       2008-02-10 06:45:34 UTC (rev 
6220)
@@ -66,24 +66,14 @@
 /**
  * protocol number of TCP.
  */
-#define GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP 2
+#define GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP 6
 
 /**
  * protocol number of UDP.
  */
-#define GNUNET_TRANSPORT_PROTOCOL_NUMBER_UDP 3
+#define GNUNET_TRANSPORT_PROTOCOL_NUMBER_UDP 7
 
 /**
- * Protocol number for TCP on IPv6 (TCP+6)
- */
-#define GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP6 4
-
-/**
- * Protocol number for UDP on IPv6 (UDP+6)
- */
-#define GNUNET_TRANSPORT_PROTOCOL_NUMBER_UDP6 5
-
-/**
  * protocol number for HTTP (80 is too big, so 8 will have to do)
  */
 #define GNUNET_TRANSPORT_PROTOCOL_NUMBER_HTTP 8

Modified: GNUnet/src/include/gnunet_util_network.h
===================================================================
--- GNUnet/src/include/gnunet_util_network.h    2008-02-10 06:35:35 UTC (rev 
6219)
+++ GNUnet/src/include/gnunet_util_network.h    2008-02-10 06:45:34 UTC (rev 
6220)
@@ -263,14 +263,15 @@
  * in dotted-decimal (/255.255.0.0).
  * <p>
  * @param routeList a string specifying the forbidden networks
- * @return the converted list, NULL if the synatx is flawed
+ * @return the converted list, NULL if the syntax is flawed
  */
-struct GNUNET_IPv4NetworkSet *GNUNET_parse_ipv4_network_specification (struct
-                                                                       
GNUNET_GE_Context
-                                                                       *ectx,
-                                                                       const
-                                                                       char
-                                                                       
*routeList);
+struct GNUNET_IPv4NetworkSet *
+GNUNET_parse_ipv4_network_specification (struct
+                                        GNUNET_GE_Context
+                                        *ectx,
+                                        const
+                                        char
+                                        *routeList);
 
 /**
  * Parse a network specification. The argument specifies
@@ -281,14 +282,15 @@
  * in dotted-decimal (/255.255.0.0).
  * <p>
  * @param routeList a string specifying the forbidden networks
- * @return the converted list, NULL if the synatx is flawed
+ * @return the converted list, NULL if the syntax is flawed
  */
-struct GNUNET_IPv6NetworkSet *GNUNET_parse_ipv6_network_specification (struct
-                                                                       
GNUNET_GE_Context
-                                                                       *ectx,
-                                                                       const
-                                                                       char
-                                                                       
*routeList);
+struct GNUNET_IPv6NetworkSet *
+GNUNET_parse_ipv6_network_specification (struct
+                                        GNUNET_GE_Context
+                                        *ectx,
+                                        const
+                                        char
+                                        *routeList);
 
 /**
  * Check if the given IP address is in the list of
@@ -330,10 +332,11 @@
  * The OS socket should henceforth be no longer used
  * directly.  GNUNET_socket_destroy will close it.
  */
-struct GNUNET_SocketHandle *GNUNET_socket_create (struct GNUNET_GE_Context
-                                                  *ectx,
-                                                  struct GNUNET_LoadMonitor
-                                                  *mon, int osSocket);
+struct GNUNET_SocketHandle *
+GNUNET_socket_create (struct GNUNET_GE_Context
+                     *ectx,
+                     struct GNUNET_LoadMonitor
+                     *mon, int osSocket);
 
 /**
  * Close the socket (does NOT destroy it)
@@ -435,22 +438,23 @@
  *        accept at most? 0 for unbounded
  * @return NULL on error
  */
-struct GNUNET_SelectHandle *GNUNET_select_create (const char *desc,
-                                                  int is_udp,
-                                                  struct GNUNET_GE_Context
-                                                  *ectx,
-                                                  struct GNUNET_LoadMonitor
-                                                  *mon, int sock,
-                                                  unsigned int max_addr_len,
-                                                  GNUNET_CronTime timeout,
-                                                  GNUNET_SelectMessageHandler
-                                                  mh, void *mh_cls,
-                                                  GNUNET_SelectAcceptHandler
-                                                  ah, void *ah_cls,
-                                                  GNUNET_SelectCloseHandler
-                                                  ch, void *ch_cls,
-                                                  unsigned int memory_quota,
-                                                  int socket_quota);
+struct GNUNET_SelectHandle *
+GNUNET_select_create (const char *desc,
+                     int is_udp,
+                     struct GNUNET_GE_Context
+                     *ectx,
+                     struct GNUNET_LoadMonitor
+                     *mon, int sock,
+                     unsigned int max_addr_len,
+                     GNUNET_CronTime timeout,
+                     GNUNET_SelectMessageHandler
+                     mh, void *mh_cls,
+                     GNUNET_SelectAcceptHandler
+                     ah, void *ah_cls,
+                     GNUNET_SelectCloseHandler
+                     ch, void *ch_cls,
+                     unsigned int memory_quota,
+                     int socket_quota);
 
 /**
  * Terminate the select thread, close the socket and

Modified: GNUnet/src/transports/Makefile.am
===================================================================
--- GNUnet/src/transports/Makefile.am   2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/src/transports/Makefile.am   2008-02-10 06:45:34 UTC (rev 6220)
@@ -1,16 +1,9 @@
 INCLUDES = -I$(top_srcdir)/src/include
 
-EXTRA_DIST = tcp_helper.c udp_helper.c test.conf
+EXTRA_DIST = common.c test.conf
 
 plugindir = $(libdir)/GNUnet
 
-if HAVE_IPV6
- v6transports = \
-  libgnunettransport_tcp6.la \
-  libgnunettransport_udp6.la 
- v6ip = \
-  libgnunetip6.la
-endif
 if HAVE_XML2
   build_upnp=upnp
 endif
@@ -27,9 +20,6 @@
 
 SUBDIRS = . $(build_upnp)
 
-noinst_LTLIBRARIES = \
-  $(v6ip) 
-
 lib_LTLIBRARIES = \
   libgnunetip.la
 
@@ -48,14 +38,11 @@
 libgnunetip_la_LIBADD = \
  $(top_builddir)/src/util/libgnunetutil.la
 
-libgnunetip6_la_SOURCES = \
-  ip6.c ip6.h
-
 plugin_LTLIBRARIES = \
  libgnunettransport_tcp.la \
  libgnunettransport_udp.la \
  libgnunettransport_nat.la \
- $(v6transports) $(httptransport) $(smtptransport)
+ $(httptransport) $(smtptransport)
 
 libgnunettransport_smtp_la_SOURCES = smtp.c
 libgnunettransport_smtp_la_LIBADD = \
@@ -94,26 +81,9 @@
 libgnunettransport_udp_la_LDFLAGS = \
  -export-dynamic -avoid-version -module 
 
-libgnunettransport_tcp6_la_SOURCES = tcp6.c
-libgnunettransport_tcp6_la_LIBADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- libgnunetip.la \
- libgnunetip6.la
-libgnunettransport_tcp6_la_LDFLAGS = \
- -export-dynamic -avoid-version -module 
 
-libgnunettransport_udp6_la_SOURCES = udp6.c
-libgnunettransport_udp6_la_LIBADD = \
- $(top_builddir)/src/util/libgnunetutil.la \
- libgnunetip.la \
- libgnunetip6.la
-libgnunettransport_udp6_la_LDFLAGS = \
- -export-dynamic -avoid-version -module 
 
 
-
-
-
 test_udp_SOURCES = \
  test.c 
 test_udp_LDADD = \

Added: GNUnet/src/transports/common.c
===================================================================
--- GNUnet/src/transports/common.c                              (rev 0)
+++ GNUnet/src/transports/common.c      2008-02-10 06:45:34 UTC (rev 6220)
@@ -0,0 +1,480 @@
+/*
+     This file is part of GNUnet
+     (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Christian Grothoff (and 
other contributing authors)
+
+     GNUnet is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published
+     by the Free Software Foundation; either version 2, or (at your
+     option) any later version.
+
+     GNUnet is distributed in the hope that it will be useful, but
+     WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+     General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with GNUnet; see the file COPYING.  If not, write to the
+     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+     Boston, MA 02111-1307, USA.
+*/
+
+/**
+ * @file transports/common.c
+ * @brief Common features between TCP and UDP transports
+ * @author Christian Grothoff
+ */
+
+
+/**
+ * Constants for which IP versions are
+ * actually available for the peer.
+ */
+#define VERSION_AVAILABLE_NONE 0
+#define VERSION_AVAILABLE_IPV4 1
+#define VERSION_AVAILABLE_IPV6 2
+
+/**
+ * Host-Address in the network.
+ */
+typedef struct
+{
+  /**
+   * IPv6 address of the sender, network byte order
+   */
+  GNUNET_IPv6Address ipv6;
+
+  /**
+   * claimed IP of the sender, network byte order
+   */
+  GNUNET_IPv4Address ipv4;
+
+  /**
+   * claimed port of the sender, network byte order
+   */
+  unsigned short port;
+
+  /**
+   * Availability.  1 for IPv4 only, 2 for IPv6 only,
+   * 3 for IPv4 and IPv6.
+   */
+  unsigned short availability;
+
+} HostAddress;
+
+static GNUNET_UPnP_ServiceAPI *upnp;
+
+static struct GNUNET_IPv4NetworkSet *filteredNetworksIPv4;
+
+static struct GNUNET_IPv4NetworkSet *allowedNetworksIPv4;
+
+static struct GNUNET_IPv6NetworkSet *filteredNetworksIPv6;
+
+static struct GNUNET_IPv6NetworkSet *allowedNetworksIPv6;
+
+static struct GNUNET_GC_Configuration *cfg;
+
+static struct GNUNET_Mutex *lock;
+
+/**
+ * apis (our advertised API and the core api )
+ */
+static GNUNET_CoreAPIForTransport *coreAPI;
+
+static GNUNET_Stats_ServiceAPI *stats;
+
+static int available_protocols;
+
+static GNUNET_TransportAPI myAPI;
+
+
+
+/**
+ * Check if we are allowed to connect to the given IP.
+ */
+static int
+is_blacklisted_ipv6 (const void *addr, unsigned int addr_len)
+{
+  GNUNET_IPv6Address ip;
+  int ret;
+
+  if (addr_len == sizeof (GNUNET_IPv6Address))
+    {
+      memcpy (&ip, addr, sizeof (GNUNET_IPv6Address));
+    }
+  else if (addr_len == sizeof (struct sockaddr_in6))
+    {
+      memcpy (&ip,
+              &((struct sockaddr_in6 *) addr)->sin6_addr,
+              sizeof (GNUNET_IPv6Address));
+    }
+  else
+    {
+      return GNUNET_SYSERR;
+    }
+  GNUNET_mutex_lock (lock);
+  ret = GNUNET_check_ipv6_listed (filteredNetworksIPv6, ip);
+  GNUNET_mutex_unlock (lock);
+  return ret;
+}
+
+/**
+ * Check if we are allowed to connect to the given IP.
+ */
+static int
+is_whitelisted_ipv6 (const void *addr, unsigned int addr_len)
+{
+  GNUNET_IPv6Address ip;
+  int ret;
+
+  if (addr_len == sizeof (GNUNET_IPv6Address))
+    {
+      memcpy (&ip, addr, sizeof (GNUNET_IPv6Address));
+    }
+  else if (addr_len == sizeof (struct sockaddr_in6))
+    {
+      memcpy (&ip,
+              &((struct sockaddr_in6 *) addr)->sin6_addr,
+              sizeof (GNUNET_IPv6Address));
+    }
+  else
+    {
+      return GNUNET_SYSERR;
+    }
+  ret = GNUNET_OK;
+  GNUNET_mutex_lock (lock);
+  if (allowedNetworksIPv6 != NULL)
+    ret = GNUNET_check_ipv6_listed (filteredNetworksIPv6, ip);
+  GNUNET_mutex_unlock (lock);
+  return ret;
+}
+
+static int
+is_rejected_ipv6 (const void *addr, unsigned int addr_len)
+{
+  if ((GNUNET_YES == is_blacklisted_ipv6 (addr,
+                                         addr_len)) ||
+      (GNUNET_YES != is_whitelisted_ipv6 (addr, addr_len)))
+    return GNUNET_YES;
+  return GNUNET_NO;
+}
+
+/**
+ * Check if we are allowed to connect to the given IP.
+ */
+static int
+is_blacklisted_ipv4 (const void *addr, unsigned int addr_len)
+{
+  GNUNET_IPv4Address ip;
+  int ret;
+
+  if (addr_len == sizeof (struct sockaddr_in))
+    {
+      memcpy (&ip, &((struct sockaddr_in *) addr)->sin_addr,
+              sizeof (GNUNET_IPv4Address));
+    }
+  else if (addr_len == sizeof (GNUNET_IPv4Address))
+    {
+      memcpy (&ip, addr, addr_len);
+    }
+  else
+    {
+      return GNUNET_SYSERR;
+    }
+  if (ip.addr == 0)
+    return GNUNET_SYSERR;
+  GNUNET_mutex_lock (lock);
+  ret = GNUNET_check_ipv4_listed (filteredNetworksIPv4, ip);
+  GNUNET_mutex_unlock (lock);
+  return ret;
+}
+
+/**
+ * Check if we are allowed to connect to the given IP.
+ */
+static int
+is_whitelisted_ipv4 (const void *addr, unsigned int addr_len)
+{
+  GNUNET_IPv4Address ip;
+  int ret;
+
+  if (addr_len == sizeof (struct sockaddr_in))
+    {
+      memcpy (&ip, &((struct sockaddr_in *) addr)->sin_addr,
+              sizeof (GNUNET_IPv4Address));
+    }
+  else if (addr_len == sizeof (GNUNET_IPv4Address))
+    {
+      memcpy (&ip, addr, addr_len);
+    }
+  else
+    {
+      return GNUNET_SYSERR;
+    }
+  ret = GNUNET_YES;
+  GNUNET_mutex_lock (lock);
+  if (allowedNetworksIPv4 != NULL)
+    ret = GNUNET_check_ipv4_listed (allowedNetworksIPv4, ip);
+  GNUNET_mutex_unlock (lock);
+  return ret;
+}
+
+static int
+is_rejected_ipv4 (const void *addr, unsigned int addr_len)
+{
+  if ((GNUNET_NO != is_blacklisted_ipv4 (addr,
+                                   addr_len)) ||
+      (GNUNET_YES != is_whitelisted_ipv4 (addr, addr_len)))
+    return GNUNET_YES;
+  return GNUNET_NO;
+}
+
+static int
+is_rejected_tester(const void *addr, 
+                  unsigned int addr_len)
+{
+  if (addr_len == sizeof (struct sockaddr_in))
+    return is_rejected_ipv4(addr, addr_len);
+  return is_rejected_ipv6(addr, addr_len);
+}
+
+/**
+ * Verify that a Hello-Message is correct (a node
+ * is reachable at that address). Since the reply
+ * will be asynchronous, a method must be called on
+ * success.
+ * @param hello the Hello message to verify
+ *        (the signature/crc have been verified before)
+ * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ */
+static int
+verify_hello (const GNUNET_MessageHello * hello)
+{
+  HostAddress *haddr;
+
+  haddr = (HostAddress *) & hello[1];
+  if ((ntohs (hello->senderAddressSize) != sizeof (HostAddress)) ||
+      (ntohs (hello->header.size) != GNUNET_sizeof_hello (hello)) ||
+      (ntohs (hello->header.type) != GNUNET_P2P_PROTO_HELLO) ||
+      (ntohs (hello->protocol) != myAPI.protocolNumber) ||
+      (0 == (ntohs (haddr->availability) & ( VERSION_AVAILABLE_IPV6 | 
VERSION_AVAILABLE_IPV4)) ) ||
+      ( (0 != (ntohs (haddr->availability) & VERSION_AVAILABLE_IPV4)) &&
+       ( (GNUNET_YES == is_blacklisted_ipv4 (&haddr->ipv4,
+                                             sizeof (GNUNET_IPv4Address))) ||
+         (GNUNET_YES != is_whitelisted_ipv4 (&haddr->ipv4, sizeof 
(GNUNET_IPv4Address))) ) ) ||
+      ( (0 != (ntohs (haddr->availability) & VERSION_AVAILABLE_IPV6)) &&
+       ( (GNUNET_YES == is_blacklisted_ipv6 (&haddr->ipv6,
+                                             sizeof (GNUNET_IPv6Address))) ||
+         (GNUNET_YES != is_whitelisted_ipv6 (&haddr->ipv6, sizeof 
(GNUNET_IPv6Address))) ) ) )
+    return GNUNET_SYSERR; /* invalid */    
+  return GNUNET_OK;
+}
+
+
+/**
+ * Reload the configuration. Should never fail (keep old
+ * configuration on error, syslog errors!)
+ */
+static int
+reload_configuration (void *ctx,
+                     struct GNUNET_GC_Configuration *cfg,
+                     struct GNUNET_GE_Context *ectx,
+                     const char *section, const char *option)
+{
+  char *ch;
+
+  if (0 != strcmp (section, MY_TRANSPORT_NAME))
+    return 0;                   /* fast path */
+
+  GNUNET_mutex_lock (lock);
+  GNUNET_free_non_null (filteredNetworksIPv4);
+  GNUNET_free_non_null (allowedNetworksIPv4);
+  ch = NULL;
+  GNUNET_GC_get_configuration_value_string (cfg, MY_TRANSPORT_NAME, 
"BLACKLISTV4", "", &ch);
+  filteredNetworksIPv4 = GNUNET_parse_ipv4_network_specification (ectx, ch);
+  GNUNET_free (ch);
+  ch = NULL;
+  GNUNET_GC_get_configuration_value_string (cfg, MY_TRANSPORT_NAME, 
"WHITELISTV4", "", &ch);
+  if (strlen (ch) > 0)
+    allowedNetworksIPv4 = GNUNET_parse_ipv4_network_specification (ectx, ch);
+  else
+    allowedNetworksIPv4 = NULL;
+  GNUNET_free (ch);
+  GNUNET_free_non_null (filteredNetworksIPv6);
+  GNUNET_free_non_null (allowedNetworksIPv6);
+  GNUNET_GC_get_configuration_value_string (cfg, MY_TRANSPORT_NAME, 
"BLACKLISTV6", "",
+                                            &ch);
+  filteredNetworksIPv6 = GNUNET_parse_ipv6_network_specification (ectx, ch);
+  GNUNET_free (ch);
+  GNUNET_GC_get_configuration_value_string (cfg, MY_TRANSPORT_NAME, 
"WHITELISTV6", "",
+                                            &ch);
+  if (strlen (ch) > 0)
+    allowedNetworksIPv6 = GNUNET_parse_ipv6_network_specification (ectx, ch);
+  else
+    allowedNetworksIPv6 = NULL;
+  GNUNET_free (ch);
+  GNUNET_mutex_unlock (lock);
+  /* TODO: error handling! */
+  return 0;
+}
+
+/**
+ * Get the GNUnet port from the configuration,
+ * or from /etc/services if it is not specified in
+ * the config file.
+ */
+static unsigned short
+get_port ()
+{
+  struct servent *pse;          /* pointer to service information entry        
*/
+  unsigned long long port;
+
+  if (-1 == GNUNET_GC_get_configuration_value_number (cfg,
+                                                      MY_TRANSPORT_NAME,
+                                                      "PORT", 0, 65535, 2086,
+                                                      &port))
+    {
+      if ((pse = getservbyname ("gnunet", MY_TRANSPORT_NAME)))
+        port = htons (pse->s_port);
+      else
+        port = 0;
+    }
+  return (unsigned short) port;
+}
+
+/**
+ * Create a hello-Message for the current node. The hello is
+ * created without signature and without a timestamp. The
+ * GNUnet core will GNUNET_RSA_sign the message and add an expiration time.
+ *
+ * @return hello on success, NULL on error
+ */
+static GNUNET_MessageHello *
+create_hello ()
+{
+  static GNUNET_IPv4Address last_addrv4;
+  GNUNET_MessageHello *msg;
+  HostAddress *haddr;
+  unsigned short port;
+  unsigned short available;
+  
+  port = get_port ();
+  if (0 == port)
+    {
+      static int once = 0;
+      if (once == 0)
+        {
+          once = 1;
+          GNUNET_GE_LOG (coreAPI->ectx,
+                         GNUNET_GE_INFO | GNUNET_GE_USER | GNUNET_GE_BULK,
+                         _("Port is 0, will only send using %s.\n"),
+                        MY_TRANSPORT_NAME);
+        }
+      return NULL;              /* TCP transport is configured SEND-only! */
+    }
+  msg = GNUNET_malloc (sizeof (GNUNET_MessageHello) + sizeof (HostAddress));
+  haddr = (HostAddress *) & msg[1];
+
+  available = VERSION_AVAILABLE_NONE;
+  if ( (((upnp != NULL) &&
+         (GNUNET_OK == upnp->get_ip (port,
+                                     MY_TRANSPORT_NAME,
+                                     &haddr->ipv4))) ||
+        (GNUNET_SYSERR !=
+         GNUNET_IP_get_public_ipv4_address (cfg, coreAPI->ectx, 
&haddr->ipv4))))
+    {
+      if (0 != memcmp (&haddr->ipv4,
+                      &last_addrv4, 
+                      sizeof (GNUNET_IPv4Address)))
+       {
+         GNUNET_GE_LOG (coreAPI->ectx,
+                        GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
+                        "%s uses IPv4 address %u.%u.%u.%u.\n",
+                        MY_TRANSPORT_NAME,
+                        GNUNET_PRIP (ntohl (*(int *) &haddr->ipv4)));
+         last_addrv4 = haddr->ipv4;
+       }
+      available |= VERSION_AVAILABLE_IPV4;
+    }
+  
+  if (GNUNET_SYSERR != GNUNET_IP_get_public_ipv6_address (cfg, coreAPI->ectx, 
&haddr->ipv6))
+    {
+      available |= VERSION_AVAILABLE_IPV6;
+    }
+  if (available == VERSION_AVAILABLE_NONE)
+    {
+      GNUNET_free(msg);
+      return NULL;
+    }
+  haddr->port = htons (port);
+  haddr->availability = htons (available);
+  msg->senderAddressSize = htons (sizeof (HostAddress));
+  msg->protocol = htons (myAPI.protocolNumber);
+  msg->MTU = htonl (myAPI.mtu);
+  return msg;
+}
+
+/**
+ * Convert TCP hello to IP address
+ */
+static int
+hello_to_address (const GNUNET_MessageHello * hello,
+                 void **sa, unsigned int *sa_len)
+{
+  const HostAddress *haddr = (const HostAddress *) &hello[1];
+  struct sockaddr_in *serverAddr4;
+  struct sockaddr_in *serverAddr6;
+  unsigned short available;
+  
+  available = ntohs(haddr->availability);
+  if (0 != (available & VERSION_AVAILABLE_IPV4))
+    {
+      *sa_len = sizeof (struct sockaddr_in);
+      serverAddr4 = GNUNET_malloc (sizeof (struct sockaddr_in));
+      *sa = serverAddr4;
+      memset (serverAddr4, 0, sizeof (struct sockaddr_in));
+      serverAddr4->sin_family = AF_INET;
+      memcpy (&serverAddr4->sin_addr, &haddr->ipv4, sizeof 
(GNUNET_IPv4Address));
+      serverAddr4->sin_port = haddr->port;
+    }
+  else if (0 != (available & VERSION_AVAILABLE_IPV6))
+    {
+      *sa_len = sizeof (struct sockaddr_in6);
+      serverAddr6 = GNUNET_malloc (sizeof (struct sockaddr_in6));
+      *sa = serverAddr6;
+      memset (serverAddr6, 0, sizeof (struct sockaddr_in6));
+      serverAddr6->sin_family = AF_INET6;
+      memcpy (&serverAddr6->sin_addr, &haddr->ipv6, sizeof 
(GNUNET_IPv6Address));
+      serverAddr6->sin_port = haddr->port;
+    }
+  else
+    return GNUNET_SYSERR;
+  return GNUNET_OK;
+}
+
+
+static void 
+do_shutdown()
+{
+  GNUNET_GC_detach_change_listener (cfg, &reload_configuration, NULL);
+  if (stats != NULL)
+    {
+      coreAPI->release_service (stats);
+      stats = NULL;
+    }
+  if (upnp != NULL)
+    {
+      coreAPI->release_service (upnp);
+      upnp = NULL;
+    }
+  GNUNET_free_non_null (filteredNetworksIPv4);
+  filteredNetworksIPv4 = NULL;
+  GNUNET_free_non_null (allowedNetworksIPv4);
+  allowedNetworksIPv4 = NULL;
+  GNUNET_free_non_null (filteredNetworksIPv6);
+  filteredNetworksIPv6 = NULL;
+  GNUNET_free_non_null (allowedNetworksIPv6);
+  allowedNetworksIPv6 = NULL;
+  GNUNET_mutex_destroy (lock);
+  lock = NULL;
+}
+


Property changes on: GNUnet/src/transports/common.c
___________________________________________________________________
Name: svn:eol-style
   + native

Modified: GNUnet/src/transports/ip.c
===================================================================
--- GNUnet/src/transports/ip.c  2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/src/transports/ip.c  2008-02-10 06:45:34 UTC (rev 6220)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2004, 2005, 2006, 2007 Christian Grothoff (and other 
contributing authors)
+     (C) 2001, 2002, 2004, 2005, 2006, 2007, 2008 Christian Grothoff (and 
other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -32,7 +32,16 @@
 #include "platform.h"
 #include "gnunet_util.h"
 #include "ip.h"
+#if HAVE_IFADDRS_H
+#if HAVE_NET_IF_H
+#include <net/if.h>
+#endif
+#include <ifaddrs.h>
+#endif
 
+/* maximum length of hostname */
+#define MAX_HOSTNAME 1024
+
 /**
  * Get the IP address for the local machine.
  * @return GNUNET_SYSERR on error, GNUNET_OK on success
@@ -57,7 +66,7 @@
       if (ips == NULL)
         {
           GNUNET_GE_LOG (ectx,
-                         GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
+                         GNUNET_GE_INFO | GNUNET_GE_USER | GNUNET_GE_BULK,
                          _("Failed to obtain my (external) %s address!\n"),
                          "IP");
           lastError = now;
@@ -197,7 +206,198 @@
 }
 
 
+/**
+ * Obtain the identity information for the current node
+ * (connection information), conInfo.
+ * @return GNUNET_SYSERR on failure, GNUNET_OK on success
+ */
+static int
+getAddress6FromHostname (struct GNUNET_GE_Context *ectx,
+                         GNUNET_IPv6Address * identity)
+{
+  char hostname[MAX_HOSTNAME];
+  struct hostent *ip;
 
+  if (0 != gethostname (hostname, MAX_HOSTNAME))
+    {
+      GNUNET_GE_LOG_STRERROR (ectx,
+                              GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
+                              GNUNET_GE_USER | GNUNET_GE_BULK, "gethostname");
+      return GNUNET_SYSERR;
+    }
+  /* GNUNET_GE_LOG(ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
+     " looking up $HOSTNAME (%s) to obtain local IP\n",
+     hostname); */
+
+  ip = gethostbyname2 (hostname, AF_INET6);
+  if (ip == NULL)
+    {
+      GNUNET_GE_LOG (ectx,
+                     GNUNET_GE_INFO | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+                     GNUNET_GE_BULK,
+                     _("Could not find IPv6 address of host `%s': %s\n"), 
hostname,
+                     hstrerror (h_errno));
+      return GNUNET_SYSERR;
+    }
+  if (ip->h_addrtype != AF_INET6)
+    {
+      GNUNET_GE_BREAK (ectx, 0);
+      return GNUNET_SYSERR;
+    }
+  GNUNET_GE_ASSERT (ectx,
+                    sizeof (struct in6_addr) == sizeof (identity->addr));
+  memcpy (&identity->addr[0], ip->h_addr_list[0], sizeof (struct in6_addr));
+  return GNUNET_OK;
+}
+
+#if HAVE_GETIFADDRS && HAVE_GNUNET_freeIFADDRS
+static int
+getAddress6FromGetIfAddrs (struct GNUNET_GC_Configuration *cfg,
+                           struct GNUNET_GE_Context *ectx,
+                           GNUNET_IPv6Address * identity)
+{
+  char *interfaces;
+  struct ifaddrs *ifa_first;
+
+  if (-1 == GNUNET_GC_get_configuration_value_string (cfg,
+                                                      "NETWORK",
+                                                      "INTERFACE",
+                                                      GNUNET_DEFAULT_INTERFACE,
+                                                      &interfaces))
+    {
+      GNUNET_GE_LOG (ectx,
+                     GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
+                     _
+                     ("No interface specified in section `%s' under `%s'!\n"),
+                     "NETWORK", "INTERFACE");
+      return GNUNET_SYSERR;     /* that won't work! */
+    }
+
+  if (getifaddrs (&ifa_first) == 0)
+    {
+      struct ifaddrs *ifa_ptr;
+
+      ifa_ptr = ifa_first;
+      for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next)
+        {
+          if (ifa_ptr->ifa_name != NULL &&
+              ifa_ptr->ifa_addr != NULL && (ifa_ptr->ifa_flags & IFF_UP) != 0)
+            {
+              if (strcmp (interfaces, (char *) ifa_ptr->ifa_name) != 0)
+                continue;
+              if (ifa_ptr->ifa_addr->sa_family != AF_INET6)
+                continue;
+              memcpy (identity,
+                      &(((struct sockaddr_in6 *) ifa_ptr->ifa_addr)->
+                        sin6_addr), sizeof (struct in6_addr));
+              freeifaddrs (ifa_first);
+              GNUNET_free (interfaces);
+              return GNUNET_OK;
+            }
+        }
+      freeifaddrs (ifa_first);
+    }
+  GNUNET_GE_LOG (ectx,
+                 GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
+                 _("Could not obtain IP for interface `%s' using `%s'.\n"),
+                 interfaces, "getifaddrs");
+  GNUNET_free (interfaces);
+  return GNUNET_SYSERR;
+}
+#endif
+
+/**
+ * Get the IP address for the local machine.
+ * @return GNUNET_SYSERR on error, GNUNET_OK on success
+ */
+static int
+getAddress6 (struct GNUNET_GC_Configuration *cfg,
+             struct GNUNET_GE_Context *ectx, GNUNET_IPv6Address * address)
+{
+  char *ipString;
+  int retval;
+  struct hostent *ip;           /* for the lookup of the IP in gnunet.conf */
+
+  retval = GNUNET_SYSERR;
+  if (GNUNET_GC_have_configuration_value (cfg, "NETWORK", "IP6"))
+    {
+      ipString = NULL;
+      GNUNET_GC_get_configuration_value_string (cfg,
+                                                "NETWORK", "IP6", "",
+                                                &ipString);
+      if (strlen (ipString) > 0)
+        {
+          ip = gethostbyname2 (ipString, AF_INET6);
+          if (ip == NULL)
+            {
+              GNUNET_GE_LOG (ectx,
+                             GNUNET_GE_ERROR | GNUNET_GE_USER |
+                             GNUNET_GE_BULK,
+                             _("Could not resolve `%s': %s\n"), ipString,
+                             hstrerror (h_errno));
+            }
+          else if (ip->h_addrtype != AF_INET6)
+            {
+              GNUNET_GE_ASSERT (ectx, 0);
+              retval = GNUNET_SYSERR;
+            }
+          else
+            {
+              GNUNET_GE_ASSERT (ectx,
+                                sizeof (struct in6_addr) ==
+                                sizeof (address->addr));
+              memcpy (&address->addr[0], ip->h_addr_list[0],
+                      sizeof (struct in6_addr));
+              retval = GNUNET_OK;
+            }
+        }
+      GNUNET_free (ipString);
+    }
+#if HAVE_GETIFADDRS && HAVE_GNUNET_freeIFADDRS
+  if (retval == GNUNET_SYSERR)
+    if (GNUNET_OK == getAddress6FromGetIfAddrs (cfg, ectx, address))
+      retval = GNUNET_OK;
+#endif
+  if (retval == GNUNET_SYSERR)
+    retval = getAddress6FromHostname (ectx, address);
+  return retval;
+}
+
+/**
+ * Get the IPv6 address for the local machine.
+ * @return GNUNET_SYSERR on error, GNUNET_OK on success
+ */
+int
+GNUNET_IP_get_public_ipv6_address (struct GNUNET_GC_Configuration *cfg,
+                                  struct GNUNET_GE_Context *ectx,
+                                  GNUNET_IPv6Address * address)
+{
+  static GNUNET_IPv6Address myAddress;
+  static GNUNET_CronTime last;
+  static GNUNET_CronTime lastError;
+  GNUNET_CronTime now;
+
+  now = GNUNET_get_time ();
+  if (last + GNUNET_CRON_MINUTES < now)
+    {
+      if (lastError + 30 * GNUNET_CRON_SECONDS > now)
+        return GNUNET_SYSERR;
+      if (GNUNET_SYSERR == getAddress6 (cfg, ectx, &myAddress))
+        {
+          lastError = now;
+          GNUNET_GE_LOG (ectx,
+                         GNUNET_GE_INFO | GNUNET_GE_USER | GNUNET_GE_BULK,
+                         _("Failed to obtain my (external) %s address!\n"),
+                         "IPv6");
+          return GNUNET_SYSERR;
+        }
+      last = now;
+    }
+  memcpy (address, &myAddress, sizeof (GNUNET_IPv6Address));
+  return GNUNET_OK;
+}
+
+
 void __attribute__ ((constructor)) GNUNET_IP_ltdl_init ()
 {
   lock = GNUNET_mutex_create (GNUNET_YES);

Modified: GNUnet/src/transports/ip.h
===================================================================
--- GNUnet/src/transports/ip.h  2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/src/transports/ip.h  2008-02-10 06:45:34 UTC (rev 6220)
@@ -50,6 +50,16 @@
                                        GNUNET_IPv4Address * address);
 
 /**
+ * @brief Get the IPv6 address for the local machine.
+ *
+ * @return GNUNET_SYSERR on error, GNUNET_OK on success
+ */
+int GNUNET_IP_get_public_ipv6_address (struct GNUNET_GC_Configuration *cfg,
+                                      struct GNUNET_GE_Context *ectx,
+                                      GNUNET_IPv6Address * address);
+
+
+/**
  * We only have the GNUNET_PeerIdentity.  Do we have any
  * clue about the address based on
  * the "accept" of the connection?  Note that the

Deleted: GNUnet/src/transports/ip6.c
===================================================================
--- GNUnet/src/transports/ip6.c 2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/src/transports/ip6.c 2008-02-10 06:45:34 UTC (rev 6220)
@@ -1,239 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2001, 2002, 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file transports/ip6.c
- * @brief code to determine the IP(v6) of the local machine
- *
- * Todo:
- * * scanning of network devices for IPv6 (first: find good
- *   API to do it, doesn't seem to exist!)
- *
- * @author Christian Grothoff
- * @author Tzvetan Horozov
- * @author Heikki Lindholm
- */
-
-#include <stdlib.h>
-#include "platform.h"
-#include "gnunet_util.h"
-#include "ip6.h"
-#if HAVE_IFADDRS_H
-#if HAVE_NET_IF_H
-#include <net/if.h>
-#endif
-#include <ifaddrs.h>
-#endif
-
-/* maximum length of hostname */
-#define MAX_HOSTNAME 1024
-
-/**
- * Obtain the identity information for the current node
- * (connection information), conInfo.
- * @return GNUNET_SYSERR on failure, GNUNET_OK on success
- */
-static int
-getAddress6FromHostname (struct GNUNET_GE_Context *ectx,
-                         GNUNET_IPv6Address * identity)
-{
-  char hostname[MAX_HOSTNAME];
-  struct hostent *ip;
-
-  if (0 != gethostname (hostname, MAX_HOSTNAME))
-    {
-      GNUNET_GE_LOG_STRERROR (ectx,
-                              GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
-                              GNUNET_GE_USER | GNUNET_GE_BULK, "gethostname");
-      return GNUNET_SYSERR;
-    }
-  /* GNUNET_GE_LOG(ectx, GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
-     " looking up $HOSTNAME (%s) to obtain local IP\n",
-     hostname); */
-
-  ip = gethostbyname2 (hostname, AF_INET6);
-  if (ip == NULL)
-    {
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
-                     GNUNET_GE_BULK,
-                     _("Could not find IP of host `%s': %s\n"), hostname,
-                     hstrerror (h_errno));
-      return GNUNET_SYSERR;
-    }
-  if (ip->h_addrtype != AF_INET6)
-    {
-      GNUNET_GE_BREAK (ectx, 0);
-      return GNUNET_SYSERR;
-    }
-  GNUNET_GE_ASSERT (ectx,
-                    sizeof (struct in6_addr) == sizeof (identity->addr));
-  memcpy (&identity->addr[0], ip->h_addr_list[0], sizeof (struct in6_addr));
-  return GNUNET_OK;
-}
-
-#if HAVE_GETIFADDRS && HAVE_GNUNET_freeIFADDRS
-static int
-getAddress6FromGetIfAddrs (struct GNUNET_GC_Configuration *cfg,
-                           struct GNUNET_GE_Context *ectx,
-                           GNUNET_IPv6Address * identity)
-{
-  char *interfaces;
-  struct ifaddrs *ifa_first;
-
-  if (-1 == GNUNET_GC_get_configuration_value_string (cfg,
-                                                      "NETWORK",
-                                                      "INTERFACE",
-                                                      GNUNET_DEFAULT_INTERFACE,
-                                                      &interfaces))
-    {
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_ERROR | GNUNET_GE_BULK | GNUNET_GE_USER,
-                     _
-                     ("No interface specified in section `%s' under `%s'!\n"),
-                     "NETWORK", "INTERFACE");
-      return GNUNET_SYSERR;     /* that won't work! */
-    }
-
-  if (getifaddrs (&ifa_first) == 0)
-    {
-      struct ifaddrs *ifa_ptr;
-
-      ifa_ptr = ifa_first;
-      for (ifa_ptr = ifa_first; ifa_ptr != NULL; ifa_ptr = ifa_ptr->ifa_next)
-        {
-          if (ifa_ptr->ifa_name != NULL &&
-              ifa_ptr->ifa_addr != NULL && (ifa_ptr->ifa_flags & IFF_UP) != 0)
-            {
-              if (strcmp (interfaces, (char *) ifa_ptr->ifa_name) != 0)
-                continue;
-              if (ifa_ptr->ifa_addr->sa_family != AF_INET6)
-                continue;
-              memcpy (identity,
-                      &(((struct sockaddr_in6 *) ifa_ptr->ifa_addr)->
-                        sin6_addr), sizeof (struct in6_addr));
-              freeifaddrs (ifa_first);
-              GNUNET_free (interfaces);
-              return GNUNET_OK;
-            }
-        }
-      freeifaddrs (ifa_first);
-    }
-  GNUNET_GE_LOG (ectx,
-                 GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
-                 _("Could not obtain IP for interface `%s' using `%s'.\n"),
-                 interfaces, "getifaddrs");
-  GNUNET_free (interfaces);
-  return GNUNET_SYSERR;
-}
-#endif
-
-/**
- * Get the IP address for the local machine.
- * @return GNUNET_SYSERR on error, GNUNET_OK on success
- */
-static int
-getAddress6 (struct GNUNET_GC_Configuration *cfg,
-             struct GNUNET_GE_Context *ectx, GNUNET_IPv6Address * address)
-{
-  char *ipString;
-  int retval;
-  struct hostent *ip;           /* for the lookup of the IP in gnunet.conf */
-
-  retval = GNUNET_SYSERR;
-  if (GNUNET_GC_have_configuration_value (cfg, "NETWORK", "IP6"))
-    {
-      ipString = NULL;
-      GNUNET_GC_get_configuration_value_string (cfg,
-                                                "NETWORK", "IP6", "",
-                                                &ipString);
-      if (strlen (ipString) > 0)
-        {
-          ip = gethostbyname2 (ipString, AF_INET6);
-          if (ip == NULL)
-            {
-              GNUNET_GE_LOG (ectx,
-                             GNUNET_GE_ERROR | GNUNET_GE_USER |
-                             GNUNET_GE_BULK,
-                             _("Could not resolve `%s': %s\n"), ipString,
-                             hstrerror (h_errno));
-            }
-          else if (ip->h_addrtype != AF_INET6)
-            {
-              GNUNET_GE_ASSERT (ectx, 0);
-              retval = GNUNET_SYSERR;
-            }
-          else
-            {
-              GNUNET_GE_ASSERT (ectx,
-                                sizeof (struct in6_addr) ==
-                                sizeof (address->addr));
-              memcpy (&address->addr[0], ip->h_addr_list[0],
-                      sizeof (struct in6_addr));
-              retval = GNUNET_OK;
-            }
-        }
-      GNUNET_free (ipString);
-    }
-#if HAVE_GETIFADDRS && HAVE_GNUNET_freeIFADDRS
-  if (retval == GNUNET_SYSERR)
-    if (GNUNET_OK == getAddress6FromGetIfAddrs (cfg, ectx, address))
-      retval = GNUNET_OK;
-#endif
-  if (retval == GNUNET_SYSERR)
-    retval = getAddress6FromHostname (ectx, address);
-  return retval;
-}
-
-/**
- * Get the IPv6 address for the local machine.
- * @return GNUNET_SYSERR on error, GNUNET_OK on success
- */
-int
-getPublicIP6Address (struct GNUNET_GC_Configuration *cfg,
-                     struct GNUNET_GE_Context *ectx,
-                     GNUNET_IPv6Address * address)
-{
-  static GNUNET_IPv6Address myAddress;
-  static GNUNET_CronTime last;
-  static GNUNET_CronTime lastError;
-  GNUNET_CronTime now;
-
-  now = GNUNET_get_time ();
-  if (last + GNUNET_CRON_MINUTES < now)
-    {
-      if (lastError + 30 * GNUNET_CRON_SECONDS > now)
-        return GNUNET_SYSERR;
-      if (GNUNET_SYSERR == getAddress6 (cfg, ectx, &myAddress))
-        {
-          lastError = now;
-          GNUNET_GE_LOG (ectx,
-                         GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
-                         _("Failed to obtain my (external) %s address!\n"),
-                         "IPv6");
-          return GNUNET_SYSERR;
-        }
-      last = now;
-    }
-  memcpy (address, &myAddress, sizeof (GNUNET_IPv6Address));
-  return GNUNET_OK;
-}
-
-/* end of ip6.c */

Deleted: GNUnet/src/transports/ip6.h
===================================================================
--- GNUnet/src/transports/ip6.h 2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/src/transports/ip6.h 2008-02-10 06:45:34 UTC (rev 6220)
@@ -1,40 +0,0 @@
-/*
-     This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004, 2005 Christian Grothoff (and other 
contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file transports/ip6.h
- * @brief
- *
- * @author Christian Grothoff
- */
-
-#ifndef IP6_H
-#define IP6_H
-
-/**
- * @brief Get the IPv6 address for the local machine.
- *
- * @return GNUNET_SYSERR on error, GNUNET_OK on success
- */
-int getPublicIP6Address (struct GNUNET_GC_Configuration *cfg,
-                         struct GNUNET_GE_Context *ectx,
-                         GNUNET_IPv6Address * address);
-
-#endif

Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/src/transports/tcp.c 2008-02-10 06:45:34 UTC (rev 6220)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other 
contributing authors)
+     (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 Christian Grothoff (and 
other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -54,263 +54,469 @@
 
 #define TARGET_BUFFER_SIZE 4092
 
-#include "tcp_helper.c"
-
 /**
- * Host-Address in a TCP network.
+ * Initial handshake message. Note that the beginning
+ * must match the GNUNET_MessageHeader since we are using tcpio.
  */
 typedef struct
 {
+  GNUNET_MessageHeader header;
+
   /**
-   * claimed IP of the sender, network byte order
+   * Identity of the node connecting (TCP client)
    */
-  GNUNET_IPv4Address ip;
+  GNUNET_PeerIdentity clientIdentity;
 
+} TCPWelcome;
+
+/**
+ * Transport Session handle.
+ */
+typedef struct TCPSession
+{
+
+  struct TCPSession *next;
+
   /**
-   * claimed port of the sender, network byte order
+   * the tcp socket (used to identify this connection with selector)
    */
-  unsigned short port;
+  struct GNUNET_SocketHandle *sock;
 
   /**
-   * reserved (set to 0 for signature verification)
+   * Our tsession.
    */
-  unsigned short reserved;
+  GNUNET_TSession *tsession;
 
-} HostAddress;
+  /**
+   * To whom are we talking to (set to our identity
+   * if we are still waiting for the welcome message)
+   */
+  GNUNET_PeerIdentity sender;
 
+  /**
+   * Are we still expecting the welcome? (GNUNET_YES/GNUNET_NO)
+   */
+  int expectingWelcome;
+
+  /**
+   * number of users of this session (reference count)
+   */
+  int users;
+
+  /**
+   * Is this session active with select?
+   */
+  int in_select;
+
+  /**
+   * Address of the other peer (from accept)
+   */
+  void *accept_addr;
+
+  /**
+   * Length of accept_addr.
+   */
+  unsigned int addr_len;
+
+} TCPSession;
+
+#define MY_TRANSPORT_NAME "TCP"
+#include "common.c"
+
 /* *********** globals ************* */
 
-static GNUNET_TransportAPI tcpAPI;
 
-static GNUNET_UPnP_ServiceAPI *upnp;
+static int stat_bytesReceived;
 
-static struct GNUNET_IPv4NetworkSet *filteredNetworks_;
+static int stat_bytesSent;
 
-static struct GNUNET_IPv4NetworkSet *allowedNetworks_;
+static int stat_bytesDropped;
 
-static struct GNUNET_GC_Configuration *cfg;
+static struct GNUNET_SelectHandle *selector;
 
-static struct GNUNET_Mutex *tcpblacklistlock;
+static struct TCPSession *sessions;
 
 /**
- * Check if we are allowed to connect to the given IP.
+ * You must hold the lock when calling this
+ * function (and should not hold the tcpsession's lock
+ * any more).
  */
-static int
-isBlacklisted (const void *addr, unsigned int addr_len)
+static void
+tcp_session_free (TCPSession * tcpsession)
 {
-  GNUNET_IPv4Address ip;
-  int ret;
+  TCPSession *pos;
+  TCPSession *prev;
 
-  if (addr_len == sizeof (struct sockaddr_in))
+  GNUNET_free_non_null (tcpsession->accept_addr);
+  pos = sessions;
+  prev = NULL;
+  while (pos != NULL)
     {
-      memcpy (&ip, &((struct sockaddr_in *) addr)->sin_addr,
-              sizeof (GNUNET_IPv4Address));
+      if (pos == tcpsession)
+        {
+          if (prev == NULL)
+            sessions = pos->next;
+          else
+            prev->next = pos->next;
+          break;
+        }
+      prev = pos;
+      pos = pos->next;
     }
-  else if (addr_len == sizeof (GNUNET_IPv4Address))
+  GNUNET_mutex_unlock (lock);
+  GNUNET_GE_ASSERT (coreAPI->ectx,
+                    GNUNET_OK ==
+                    coreAPI->
+                    connection_assert_tsession_unused (tcpsession->tsession));
+  GNUNET_mutex_lock (lock);
+  GNUNET_free (tcpsession->tsession);
+  GNUNET_free (tcpsession);
+}
+
+static int
+tcp_disconnect (GNUNET_TSession * tsession)
+{
+  TCPSession *tcpsession = tsession->internal;
+
+  GNUNET_GE_ASSERT (coreAPI->ectx, selector != NULL);
+  GNUNET_mutex_lock (lock);
+  GNUNET_GE_ASSERT (coreAPI->ectx, tcpsession->users > 0);
+  tcpsession->users--;
+  if ((tcpsession->users > 0) || (tcpsession->in_select == GNUNET_YES))
     {
-      memcpy (&ip, addr, addr_len);
+      if (tcpsession->users == 0)
+        GNUNET_select_change_timeout (selector, tcpsession->sock,
+                                      TCP_FAST_TIMEOUT);
+      GNUNET_mutex_unlock (lock);
+      return GNUNET_OK;
     }
-  else
-    {
-#if DEBUG_TCP
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_ADMIN | GNUNET_GE_BULK,
-                     "Rejecting connection (invalid address length %u)\n",
-                     addr_len);
-#endif
-      return GNUNET_SYSERR;
-    }
-  if (ip.addr == 0)
-    return GNUNET_SYSERR;
-  GNUNET_mutex_lock (tcpblacklistlock);
-  ret = GNUNET_check_ipv4_listed (filteredNetworks_, ip);
-  GNUNET_mutex_unlock (tcpblacklistlock);
-#if DEBUG_TCP
-  if (ret != GNUNET_NO)
-    GNUNET_GE_LOG (ectx,
-                   GNUNET_GE_DEBUG | GNUNET_GE_ADMIN | GNUNET_GE_BULK,
-                   "Rejecting connection from address %u.%u.%u.%u 
(blacklisted)\n",
-                   GNUNET_PRIP (ntohl (*(int *) addr)));
-#endif
-  return ret;
+  GNUNET_mutex_unlock (lock);
+  GNUNET_select_disconnect (selector, tcpsession->sock);
+  GNUNET_mutex_lock (lock);
+  tcp_session_free (tcpsession);
+  GNUNET_mutex_unlock (lock);
+  return GNUNET_OK;
 }
 
 /**
- * Check if we are allowed to connect to the given IP.
+ * A (core) Session is to be associated with a transport session. The
+ * transport service may want to know in order to call back on the
+ * core if the connection is being closed. Associate can also be
+ * called to test if it would be possible to associate the session
+ * later, in this case the argument session is NULL. This can be used
+ * to test if the connection must be closed by the core or if the core
+ * can assume that it is going to be self-managed (if associate
+ * returns GNUNET_OK and session was NULL, the transport layer is responsible
+ * for eventually freeing resources associated with the tesession). If
+ * session is not NULL, the core takes responsbility for eventually
+ * calling disconnect.
+ *
+ * @param tsession the session handle passed along
+ *   from the call to receive that was made by the transport
+ *   layer
+ * @return GNUNET_OK if the session could be associated,
+ *         GNUNET_SYSERR if not.
  */
 static int
-isWhitelisted (const void *addr, unsigned int addr_len)
+tcp_associate (GNUNET_TSession * tsession)
 {
-  GNUNET_IPv4Address ip;
-  int ret;
+  TCPSession *tcpSession;
 
-  if (addr_len == sizeof (struct sockaddr_in))
+  GNUNET_GE_ASSERT (coreAPI->ectx, tsession != NULL);
+  tcpSession = tsession->internal;
+  GNUNET_mutex_lock (lock);
+  if ((tcpSession->users == 0) && (tcpSession->in_select == GNUNET_YES))
+    GNUNET_select_change_timeout (selector, tcpSession->sock, TCP_TIMEOUT);
+  tcpSession->users++;
+  GNUNET_mutex_unlock (lock);
+  return GNUNET_OK;
+}
+
+/**
+ * The socket of session has data waiting, process!
+ *
+ * This function may only be called if the lock is
+ * already held by the caller.
+ */
+static int
+select_message_handler (void *mh_cls,
+                        struct GNUNET_SelectHandle *sh,
+                        struct GNUNET_SocketHandle *sock,
+                        void *sock_ctx, const GNUNET_MessageHeader * msg)
+{
+  GNUNET_TSession *tsession = sock_ctx;
+  TCPSession *tcpSession;
+  unsigned int len;
+  GNUNET_TransportPacket *mp;
+  const TCPWelcome *welcome;
+
+  if (GNUNET_SYSERR == tcp_associate (tsession))
     {
-      memcpy (&ip, &((struct sockaddr_in *) addr)->sin_addr,
-              sizeof (GNUNET_IPv4Address));
+      GNUNET_GE_BREAK (coreAPI->ectx, 0);
+      return GNUNET_SYSERR;
     }
-  else if (addr_len == sizeof (GNUNET_IPv4Address))
+  len = ntohs (msg->size);
+  if (stats != NULL)
+    stats->change (stat_bytesReceived, len);
+  tcpSession = tsession->internal;
+  if (GNUNET_YES == tcpSession->expectingWelcome)
     {
-      memcpy (&ip, addr, addr_len);
+      /* at this point, we should be the only user! */
+      GNUNET_GE_ASSERT (NULL, tcpSession->users == 1);
+
+      welcome = (const TCPWelcome *) msg;
+      if ((ntohs (welcome->header.type) != 0) || (len != sizeof (TCPWelcome)))
+        {
+          GNUNET_GE_LOG (coreAPI->ectx,
+                         GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
+                         _("Received malformed message via TCP. Closing.\n"));
+          tcp_disconnect (tsession);
+          return GNUNET_SYSERR;
+        }
+      tcpSession->expectingWelcome = GNUNET_NO;
+      tcpSession->sender = welcome->clientIdentity;
+      tsession->peer = welcome->clientIdentity;
+      if (tcpSession->accept_addr != NULL)
+        GNUNET_IP_set_address_for_peer_identity (&welcome->clientIdentity,
+                                                 tcpSession->accept_addr,
+                                                 tcpSession->addr_len);
     }
   else
     {
-#if DEBUG_TCP
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_ADMIN | GNUNET_GE_BULK,
-                     "Rejecting connection (invalid address length %u)\n",
-                     addr_len);
-#endif
-      return GNUNET_SYSERR;
+      /* send msg to core! */
+      if (len <= sizeof (GNUNET_MessageHeader))
+        {
+          GNUNET_GE_LOG (coreAPI->ectx,
+                         GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
+                         _("Received malformed message via TCP. Closing.\n"));
+          tcp_disconnect (tsession);
+          return GNUNET_SYSERR;
+        }
+      mp = GNUNET_malloc (sizeof (GNUNET_TransportPacket));
+      mp->msg = GNUNET_malloc (len - sizeof (GNUNET_MessageHeader));
+      memcpy (mp->msg, &msg[1], len - sizeof (GNUNET_MessageHeader));
+      mp->sender = tcpSession->sender;
+      mp->size = len - sizeof (GNUNET_MessageHeader);
+      mp->tsession = tsession;
+      coreAPI->receive (mp);
     }
-  ret = GNUNET_YES;
-  GNUNET_mutex_lock (tcpblacklistlock);
-  if (allowedNetworks_ != NULL)
-    ret = GNUNET_check_ipv4_listed (allowedNetworks_, ip);
-  GNUNET_mutex_unlock (tcpblacklistlock);
-  if (ret != GNUNET_YES)
+  tcp_disconnect (tsession);
+  return GNUNET_OK;
+}
+
+
+/**
+ * Create a new session for an inbound connection on the given
+ * socket. Adds the session to the array of sessions watched
+ * by the select thread.
+ */
+static void *
+select_accept_handler (void *ah_cls,
+                       struct GNUNET_SelectHandle *sh,
+                       struct GNUNET_SocketHandle *sock,
+                       const void *addr, unsigned int addr_len)
+{
+  GNUNET_TSession *tsession;
+  TCPSession *tcpSession;
+
+  GNUNET_GE_ASSERT (NULL, sock != NULL);
+  if (GNUNET_NO != is_rejected_tester (addr, addr_len))
+    return NULL;    
+  tcpSession = GNUNET_malloc (sizeof (TCPSession));
+  memset (tcpSession, 0, sizeof (TCPSession));
+  tcpSession->sock = sock;
+  /* fill in placeholder identity to mark that we
+     are waiting for the welcome message */
+  tcpSession->sender = *(coreAPI->myIdentity);
+  tcpSession->expectingWelcome = GNUNET_YES;
+  tcpSession->users = 0;
+  tcpSession->in_select = GNUNET_YES;
+
+  tsession = GNUNET_malloc (sizeof (GNUNET_TSession));
+  memset (tsession, 0, sizeof (GNUNET_TSession));
+  tsession->ttype = GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP;
+  tsession->internal = tcpSession;
+  tcpSession->tsession = tsession;
+  tsession->peer = *(coreAPI->myIdentity);
+  if (addr_len > 0)
     {
-#if DEBUG_TCP
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_ADMIN | GNUNET_GE_BULK,
-                     "Rejecting HELLO from address %u.%u.%u.%u (not 
whitelisted)\n",
-                     GNUNET_PRIP (ntohl (*(int *) addr)));
-#endif
+      tcpSession->accept_addr = GNUNET_malloc (addr_len);
+      memcpy (tcpSession->accept_addr,
+             addr, sizeof (struct sockaddr_in));
     }
-  return ret;
+  tcpSession->addr_len = addr_len;
+  GNUNET_mutex_lock (lock);
+  tcpSession->next = sessions;
+  sessions = tcpSession;
+  GNUNET_mutex_unlock (lock);
+  return tsession;
 }
 
-static int
-isRejected (const void *addr, unsigned int addr_len)
+static void
+select_close_handler (void *ch_cls,
+                      struct GNUNET_SelectHandle *sh,
+                      struct GNUNET_SocketHandle *sock, void *sock_ctx)
 {
-  if ((GNUNET_NO != isBlacklisted (addr,
-                                   addr_len)) ||
-      (GNUNET_YES != isWhitelisted (addr, addr_len)))
-    return GNUNET_YES;
-  return GNUNET_NO;
+  GNUNET_TSession *tsession = sock_ctx;
+  TCPSession *tcpSession = tsession->internal;
+
+  GNUNET_mutex_lock (lock);
+  tcpSession->in_select = GNUNET_NO;
+  if (tcpSession->users == 0)
+      tcp_session_free (tcpSession);
+  GNUNET_mutex_unlock (lock);
 }
 
 /**
- * Get the GNUnet UDP port from the configuration,
- * or from /etc/services if it is not specified in
- * the config file.
+ * Send a message to the specified remote node.
+ *
+ * @param tsession the handle identifying the remote node
+ * @param msg the message
+ * @param size the size of the message
+ * @return GNUNET_SYSERR on error, GNUNET_OK on success
  */
-static unsigned short
-getGNUnetTCPPort ()
+static int
+tcp_send (GNUNET_TSession * tsession,
+         const void *msg, unsigned int size, int important)
 {
-  struct servent *pse;          /* pointer to service information entry        
*/
-  unsigned long long port;
+  TCPSession *tcpSession;
+  GNUNET_MessageHeader *mp;
+  int ok;
 
-  if (-1 == GNUNET_GC_get_configuration_value_number (cfg,
-                                                      "TCP",
-                                                      "PORT", 0, 65535, 2086,
-                                                      &port))
+  tcpSession = tsession->internal;
+  if (size >= GNUNET_MAX_BUFFER_SIZE - sizeof (GNUNET_MessageHeader))
     {
-      if ((pse = getservbyname ("gnunet", "tcp")))
-        port = htons (pse->s_port);
-      else
-        port = 0;
+      GNUNET_GE_BREAK (coreAPI->ectx, 0);
+      return GNUNET_SYSERR;     /* too big */
     }
-  return (unsigned short) port;
+  if (tcpSession->in_select == GNUNET_NO)
+    return GNUNET_SYSERR;
+  if (selector == NULL)
+    {
+      if (stats != NULL)
+        stats->change (stat_bytesDropped, size);
+      return GNUNET_SYSERR;
+    }
+  if (size == 0)
+    {
+      GNUNET_GE_BREAK (coreAPI->ectx, 0);
+      return GNUNET_SYSERR;
+    }
+  if (tcpSession->sock == NULL)
+    {
+      if (stats != NULL)
+        stats->change (stat_bytesDropped, size);
+      return GNUNET_SYSERR;     /* other side closed connection */
+    }
+  mp = GNUNET_malloc (sizeof (GNUNET_MessageHeader) + size);
+  mp->size = htons (size + sizeof (GNUNET_MessageHeader));
+  mp->type = 0;
+  memcpy (&mp[1], msg, size);
+  ok =
+    GNUNET_select_write (selector, tcpSession->sock, mp, GNUNET_NO,
+                         important);
+  if ((GNUNET_OK == ok) && (stats != NULL))
+    stats->change (stat_bytesSent, size + sizeof (GNUNET_MessageHeader));
+
+  GNUNET_free (mp);
+  return ok;
 }
 
 /**
- * Verify that a Hello-Message is correct (a node
- * is reachable at that address). Since the reply
- * will be asynchronous, a method must be called on
- * success.
- * @param hello the Hello message to verify
- *        (the signature/crc have been verified before)
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
+ * Test if the transport would even try to send
+ * a message of the given size and importance
+ * for the given session.<br>
+ * This function is used to check if the core should
+ * even bother to construct (and encrypt) this kind
+ * of message.
+ *
+ * @return GNUNET_YES if the transport would try (i.e. queue
+ *         the message or call the OS to send),
+ *         GNUNET_NO if the transport would just drop the message,
+ *         GNUNET_SYSERR if the size/session is invalid
  */
 static int
-verifyHello (const GNUNET_MessageHello * hello)
+tcp_test_would_try (GNUNET_TSession * tsession, unsigned int size,
+                 int important)
 {
-  HostAddress *haddr;
+  TCPSession *tcpSession = tsession->internal;
 
-  haddr = (HostAddress *) & hello[1];
-  if ((ntohs (hello->senderAddressSize) != sizeof (HostAddress)) ||
-      (ntohs (hello->header.size) != GNUNET_sizeof_hello (hello)) ||
-      (ntohs (hello->header.type) != GNUNET_P2P_PROTO_HELLO) ||
-      (ntohs (hello->protocol) != GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP) ||
-      (GNUNET_YES == isBlacklisted (&haddr->ip,
-                                    sizeof (GNUNET_IPv4Address))) ||
-      (GNUNET_YES != isWhitelisted (&haddr->ip, sizeof (GNUNET_IPv4Address))))
+  if (size >= GNUNET_MAX_BUFFER_SIZE - sizeof (GNUNET_MessageHeader))
     {
-#if DEBUG_TCP
-      GNUNET_EncName enc;
-
-      GNUNET_hash_to_enc (&hello->senderIdentity.hashPubKey, &enc);
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_ADMIN | GNUNET_GE_BULK,
-                     "Rejecting HELLO from `%s'\n", &enc);
-#endif
-      return GNUNET_SYSERR;     /* obviously invalid */
+      GNUNET_GE_BREAK (coreAPI->ectx, 0);
+      return GNUNET_SYSERR;
     }
-  return GNUNET_OK;
+  if (selector == NULL)
+    return GNUNET_SYSERR;
+  if (size == 0)
+    {
+      GNUNET_GE_BREAK (coreAPI->ectx, 0);
+      return GNUNET_SYSERR;
+    }
+  if (tcpSession->sock == NULL)
+    return GNUNET_SYSERR;       /* other side closed connection */
+  return GNUNET_select_test_write_now (selector, tcpSession->sock, size,
+                                       GNUNET_NO, important);
 }
 
+
 /**
- * Create a hello-Message for the current node. The hello is
- * created without signature and without a timestamp. The
- * GNUnet core will GNUNET_RSA_sign the message and add an expiration time.
+ * Establish a connection to a remote node.
  *
- * @return hello on success, NULL on error
+ * @param helo the hello-Message for the target node
+ * @param tsessionPtr the session handle that is set
+ * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
  */
-static GNUNET_MessageHello *
-createhello ()
+static int
+tcp_connect_helper (const GNUNET_MessageHello * hello,
+                  struct GNUNET_SocketHandle *s,
+                  unsigned int protocolNumber, GNUNET_TSession ** tsessionPtr)
 {
-  static HostAddress last_addr;
-  GNUNET_MessageHello *msg;
-  HostAddress *haddr;
-  unsigned short port;
+  TCPWelcome welcome;
+  GNUNET_TSession *tsession;
+  TCPSession *tcpSession;
 
-  port = getGNUnetTCPPort ();
-  if (0 == port)
-    {
-      static int once = 0;
-      if (once == 0)
-        {
-          once = 1;
-#if DEBUG_TCP
-          GNUNET_GE_LOG (ectx,
-                         GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                         "TCP port is 0, will only send using TCP.\n");
-#endif
-        }
-      return NULL;              /* TCP transport is configured SEND-only! */
-    }
-  msg = GNUNET_malloc (sizeof (GNUNET_MessageHello) + sizeof (HostAddress));
-  haddr = (HostAddress *) & msg[1];
+  tcpSession = GNUNET_malloc (sizeof (TCPSession));
+  memset (tcpSession, 0, sizeof (TCPSession));
+  tcpSession->addr_len = 0;
+  tcpSession->accept_addr = NULL;
+  tcpSession->sock = s;
+  tsession = GNUNET_malloc (sizeof (GNUNET_TSession));
+  memset (tsession, 0, sizeof (GNUNET_TSession));
+  tsession->internal = tcpSession;
+  tsession->ttype = protocolNumber;
+  tsession->peer = hello->senderIdentity;
+  tcpSession->tsession = tsession;
+  tcpSession->users = 1;        /* caller */
+  tcpSession->in_select = GNUNET_NO;
+  tcpSession->sender = hello->senderIdentity;
+  tcpSession->expectingWelcome = GNUNET_NO;
+  GNUNET_mutex_lock (lock);
+  if (GNUNET_OK ==
+      GNUNET_select_connect (selector, tcpSession->sock, tsession))
+    tcpSession->in_select = GNUNET_YES;
 
-  if (!(((upnp != NULL) &&
-         (GNUNET_OK == upnp->get_ip (port,
-                                     "TCP",
-                                     &haddr->ip))) ||
-        (GNUNET_SYSERR !=
-         GNUNET_IP_get_public_ipv4_address (cfg, ectx, &haddr->ip))))
+  /* send our node identity to the other side to fully establish the
+     connection! */
+  welcome.header.size = htons (sizeof (TCPWelcome));
+  welcome.header.type = htons (0);
+  welcome.clientIdentity = *(coreAPI->myIdentity);
+  if (GNUNET_OK !=
+      GNUNET_select_write (selector, s, &welcome.header, GNUNET_NO,
+                           GNUNET_YES))
     {
-      GNUNET_free (msg);
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
-                     GNUNET_GE_BULK,
-                     _("TCP: Could not determine my public IP address.\n"));
-      return NULL;
+      /* disconnect caller -- error! */
+      tcp_disconnect (tsession);
+      GNUNET_mutex_unlock (lock);
+      return GNUNET_SYSERR;
     }
-  haddr->port = htons (port);
-  haddr->reserved = htons (0);
-  if (0 != memcmp (haddr, &last_addr, sizeof (HostAddress)))
-    {
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     "TCP uses IP address %u.%u.%u.%u.\n",
-                     GNUNET_PRIP (ntohl (*(int *) &haddr->ip)));
-      last_addr = *haddr;
-    }
-  msg->senderAddressSize = htons (sizeof (HostAddress));
-  msg->protocol = htons (GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP);
-  msg->MTU = htonl (tcpAPI.mtu);
-  return msg;
+  else if (stats != NULL)
+    stats->change (stat_bytesSent, sizeof (TCPWelcome));
+  tcpSession->next = sessions;
+  sessions = tcpSession;
+  GNUNET_mutex_unlock (lock);
+  *tsessionPtr = tsession;
+  return GNUNET_OK;
 }
 
 /**
@@ -321,22 +527,26 @@
  * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
  */
 static int
-tcpConnect (const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr,
+tcp_connect (const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr,
             int may_reuse)
 {
   static int zero = 0;
   HostAddress *haddr;
   int sock;
-  struct sockaddr_in soaddr;
+  struct sockaddr_in soaddr4;
+  struct sockaddr_in6 soaddr6;
+  struct sockaddr * soaddr;
+  socklen_t soaddrlen;
   struct GNUNET_SocketHandle *s;
   int i;
   TCPSession *session;
+  unsigned short available;
 
   if (selector == NULL)
     return GNUNET_SYSERR;
   if (may_reuse != GNUNET_NO)
     {
-      GNUNET_mutex_lock (tcplock);
+      GNUNET_mutex_lock (lock);
       session = sessions;
       while (session != NULL)
         {
@@ -344,38 +554,35 @@
                            &hello->senderIdentity,
                            sizeof (GNUNET_PeerIdentity)))
             {
-              GNUNET_mutex_lock (session->lock);
               if (session->in_select)
                 {
                   session->users++;
-                  GNUNET_mutex_unlock (session->lock);
-                  GNUNET_mutex_unlock (tcplock);
+                  GNUNET_mutex_unlock (lock);
                   *tsessionPtr = session->tsession;
                   return GNUNET_OK;
                 }
-              GNUNET_mutex_unlock (session->lock);
             }
           session = session->next;
         }
-      GNUNET_mutex_unlock (tcplock);
+      GNUNET_mutex_unlock (lock);
     }
   haddr = (HostAddress *) & hello[1];
-#if DEBUG_TCP
-  GNUNET_GE_LOG (ectx,
-                 GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                 "Creating TCP connection to %u.%u.%u.%u:%u.\n",
-                 GNUNET_PRIP (ntohl (*(int *) &haddr->ip.addr)),
-                 ntohs (haddr->port));
-#endif
-  sock = SOCKET (PF_INET, SOCK_STREAM, 6);      /* 6: TCP */
+  available = ntohs(haddr->availability) & available_protocols;
+
+  if ( (available & VERSION_AVAILABLE_IPV4) > 0)
+    sock = SOCKET (PF_INET, SOCK_STREAM, 0);
+  else if ( (available & VERSION_AVAILABLE_IPV6) > 0)
+    sock = SOCKET (PF_INET6, SOCK_STREAM, 0);
+  else
+    return GNUNET_SYSERR; /* incompatible */
   if (sock == -1)
     {
-      GNUNET_GE_LOG_STRERROR (ectx,
+      GNUNET_GE_LOG_STRERROR (coreAPI->ectx,
                               GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
                               GNUNET_GE_BULK, "socket");
       return GNUNET_SYSERR;
     }
-  s = GNUNET_socket_create (ectx, coreAPI->load_monitor, sock);
+  s = GNUNET_socket_create (coreAPI->ectx, coreAPI->load_monitor, sock);
 #if TCP_SYNCNT
   /* only try a single packet to establish connection,
      if that does not work, abort instantly */
@@ -387,33 +594,37 @@
       return GNUNET_SYSERR;
     }
   memset (&soaddr, 0, sizeof (soaddr));
-  soaddr.sin_family = AF_INET;
-
-  GNUNET_GE_ASSERT (ectx,
-                    sizeof (struct in_addr) == sizeof (GNUNET_IPv4Address));
-  memcpy (&soaddr.sin_addr, &haddr->ip, sizeof (GNUNET_IPv4Address));
-  soaddr.sin_port = haddr->port;
-  i = CONNECT (sock, (struct sockaddr *) &soaddr, sizeof (soaddr));
+  if ( (available & VERSION_AVAILABLE_IPV4) > 0)
+    {
+      soaddr4.sin_family = AF_INET;
+      memcpy (&soaddr4.sin_addr, 
+             &haddr->ipv4,
+             sizeof (GNUNET_IPv4Address));
+      soaddr4.sin_port = haddr->port;    
+      soaddr = (struct sockaddr*) &soaddr4;
+      soaddrlen = sizeof(soaddr4);
+    }  
+  else
+    {
+      soaddr6.sin6_family = AF_INET6;
+      memcpy (&soaddr6.sin6_addr, 
+             &haddr->ipv6,
+             sizeof (GNUNET_IPv6Address));
+      soaddr6.sin6_port = haddr->port;    
+      soaddr = (struct sockaddr*) &soaddr6;
+      soaddrlen = sizeof(soaddr6);
+   }
+  i = CONNECT (sock, soaddr, soaddrlen);
   if ((i < 0) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK))
     {
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_ERROR | GNUNET_GE_ADMIN | GNUNET_GE_USER |
-                     GNUNET_GE_BULK,
-                     _("Cannot connect to %u.%u.%u.%u:%u: %s\n"),
-                     GNUNET_PRIP (ntohl (*(int *) &haddr->ip)),
-                     ntohs (haddr->port), STRERROR (errno));
+      GNUNET_GE_LOG_STRERROR (coreAPI->ectx,
+                             GNUNET_GE_ERROR | GNUNET_GE_ADMIN | 
GNUNET_GE_USER |
+                             GNUNET_GE_BULK,
+                             "connect");
       GNUNET_socket_destroy (s);
       return GNUNET_SYSERR;
     }
-#if DEBUG_TCP
-  GNUNET_GE_LOG (ectx,
-                 GNUNET_GE_DEBUG | GNUNET_GE_DEVELOPER | GNUNET_GE_USER |
-                 GNUNET_GE_BULK,
-                 "Establishing connection to %u.%u.%u.%u:%u\n",
-                 GNUNET_PRIP (ntohl (*(int *) &haddr->ip)),
-                 ntohs (haddr->port));
-#endif
-  return tcpConnectHelper (hello, s, tcpAPI.protocolNumber, tsessionPtr);
+  return tcp_connect_helper (hello, s, myAPI.protocolNumber, tsessionPtr);
 }
 
 /**
@@ -421,49 +632,77 @@
  * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
  */
 static int
-startTransportServer ()
+tcp_transport_server_start ()
 {
-  struct sockaddr_in serverAddr;
+  struct sockaddr_in serverAddrv4;
+  struct sockaddr_in6 serverAddrv6;
+  struct sockaddr * serverAddr;
+  socklen_t addrlen;
   const int on = 1;
   unsigned short port;
   int s;
 
   if (selector != NULL)
     {
-      GNUNET_GE_BREAK (ectx, 0);
+      GNUNET_GE_BREAK (coreAPI->ectx, 0);
       return GNUNET_SYSERR;
     }
-  port = getGNUnetTCPPort ();
+  port = get_port ();
   if (port != 0)
     {
-      s = SOCKET (PF_INET, SOCK_STREAM, 0);
+      available_protocols = VERSION_AVAILABLE_NONE;
+      s = SOCKET (PF_INET6, SOCK_STREAM, 0);
       if (s < 0)
-        {
-          GNUNET_GE_LOG_STRERROR (ectx,
-                                  GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
-                                  GNUNET_GE_BULK, "socket");
-          return GNUNET_SYSERR;
-        }
+       {
+         s = SOCKET (PF_INET, SOCK_STREAM, 0);
+         if (s < 0)
+           {
+             GNUNET_GE_LOG_STRERROR (coreAPI->ectx,
+                                     GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
+                                     GNUNET_GE_BULK, "socket");
+             return GNUNET_SYSERR;
+           }
+         available_protocols = VERSION_AVAILABLE_IPV4;
+       }
+      else
+       {
+         available_protocols = VERSION_AVAILABLE_IPV6 | VERSION_AVAILABLE_IPV4;
+       }
       if (SETSOCKOPT (s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0)
-        GNUNET_GE_DIE_STRERROR (ectx,
+        GNUNET_GE_DIE_STRERROR (coreAPI->ectx,
                                 GNUNET_GE_FATAL | GNUNET_GE_ADMIN |
                                 GNUNET_GE_IMMEDIATE, "setsockopt");
-      memset ((char *) &serverAddr, 0, sizeof (serverAddr));
-      serverAddr.sin_family = AF_INET;
-      serverAddr.sin_addr.s_addr = htonl (INADDR_ANY);
-      serverAddr.sin_port = htons (getGNUnetTCPPort ());
-      if (BIND (s, (struct sockaddr *) &serverAddr, sizeof (serverAddr)) < 0)
+      if (available_protocols == VERSION_AVAILABLE_IPV4)
+       {
+         memset (&serverAddr, 0, sizeof (serverAddr));
+         serverAddrv4.sin_family = AF_INET;
+         serverAddrv4.sin_addr.s_addr = INADDR_ANY;
+         serverAddrv4.sin_port = htons (port);
+         serverAddr = (struct sockaddr *) &serverAddrv4;
+         addrlen = sizeof(serverAddrv4);
+       }
+      else
+       {
+         memset (&serverAddrv6, 0, sizeof (serverAddrv6));
+         serverAddrv6.sin6_family = AF_INET6;
+         serverAddrv6.sin6_addr = in6addr_any;
+         serverAddrv6.sin6_port = htons (port);
+         serverAddr = (struct sockaddr *) &serverAddrv6;
+         addrlen = sizeof(serverAddrv6);
+       }
+      if (BIND (s, serverAddr, addrlen) < 0)
         {
-          GNUNET_GE_LOG_STRERROR (ectx,
+          GNUNET_GE_LOG_STRERROR (coreAPI->ectx,
                                   GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
                                   GNUNET_GE_IMMEDIATE, "bind");
-          GNUNET_GE_LOG (ectx,
+          GNUNET_GE_LOG (coreAPI->ectx,
                          GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
                          GNUNET_GE_IMMEDIATE,
-                         _("Failed to start transport service on port %d.\n"),
-                         getGNUnetTCPPort ());
+                         _("Failed to bind to %s port %d.\n"),
+                        MY_TRANSPORT_NAME,
+                         port);
           if (0 != CLOSE (s))
-            GNUNET_GE_LOG_STRERROR (ectx,
+            GNUNET_GE_LOG_STRERROR (coreAPI->ectx,
                                     GNUNET_GE_ERROR | GNUNET_GE_USER |
                                     GNUNET_GE_ADMIN | GNUNET_GE_BULK,
                                     "close");
@@ -476,15 +715,15 @@
     }
   selector = GNUNET_select_create ("tcp",
                                    GNUNET_NO,
-                                   ectx,
+                                   coreAPI->ectx,
                                    coreAPI->load_monitor,
                                    s,
-                                   sizeof (struct sockaddr_in),
+                                   addrlen,
                                    TCP_FAST_TIMEOUT,
                                    &select_message_handler,
                                    NULL,
                                    &select_accept_handler,
-                                   &isRejected,
+                                   NULL,
                                    &select_close_handler,
                                    NULL, 128 * 1024 /* max memory */ ,
                                    128 /* max sockets */ );
@@ -492,60 +731,21 @@
 }
 
 /**
- * Reload the configuration. Should never fail (keep old
- * configuration on error, syslog errors!)
+ * Shutdown the server process (stop receiving inbound
+ * traffic). Maybe restarted later!
  */
 static int
-reloadConfiguration (void *ctx,
-                     struct GNUNET_GC_Configuration *cfg,
-                     struct GNUNET_GE_Context *ectx,
-                     const char *section, const char *option)
+tcp_transport_server_stop ()
 {
-  char *ch;
-
-  if (0 != strcmp (section, "TCP"))
-    return 0;                   /* fast path */
-
-  GNUNET_mutex_lock (tcpblacklistlock);
-  GNUNET_free_non_null (filteredNetworks_);
-  GNUNET_free_non_null (allowedNetworks_);
-  ch = NULL;
-  GNUNET_GC_get_configuration_value_string (cfg, "TCP", "BLACKLIST", "", &ch);
-  filteredNetworks_ = GNUNET_parse_ipv4_network_specification (ectx, ch);
-  GNUNET_free (ch);
-  ch = NULL;
-  GNUNET_GC_get_configuration_value_string (cfg, "TCP", "WHITELIST", "", &ch);
-  if (strlen (ch) > 0)
-    allowedNetworks_ = GNUNET_parse_ipv4_network_specification (ectx, ch);
-  else
-    allowedNetworks_ = NULL;
-  GNUNET_free (ch);
-  GNUNET_mutex_unlock (tcpblacklistlock);
-  /* TODO: error handling! */
-  return 0;
-}
-
-/**
- * Convert TCP hello to IP address
- */
-static int
-helloToAddress (const GNUNET_MessageHello * hello,
-                void **sa, unsigned int *sa_len)
-{
-  const HostAddress *haddr = (const HostAddress *) &hello[1];
-  struct sockaddr_in *serverAddr;
-
-  *sa_len = sizeof (struct sockaddr_in);
-  serverAddr = GNUNET_malloc (sizeof (struct sockaddr_in));
-  *sa = serverAddr;
-  memset (serverAddr, 0, sizeof (struct sockaddr_in));
-  serverAddr->sin_family = AF_INET;
-  memcpy (&serverAddr->sin_addr, haddr, sizeof (GNUNET_IPv4Address));
-  serverAddr->sin_port = haddr->port;
+  if (selector != NULL)
+    {
+      GNUNET_select_destroy (selector);
+      selector = NULL;
+    }
+  available_protocols = VERSION_AVAILABLE_NONE;
   return GNUNET_OK;
 }
 
-
 /* ******************** public API ******************** */
 
 /**
@@ -555,19 +755,14 @@
 GNUNET_TransportAPI *
 inittransport_tcp (GNUNET_CoreAPIForTransport * core)
 {
-  ectx = core->ectx;
   cfg = core->cfg;
-  GNUNET_GE_ASSERT (ectx, sizeof (HostAddress) == 8);
-  GNUNET_GE_ASSERT (ectx, sizeof (GNUNET_MessageHeader) == 4);
-  GNUNET_GE_ASSERT (ectx, sizeof (TCPWelcome) == 68);
-  tcplock = GNUNET_mutex_create (GNUNET_YES);
-  tcpblacklistlock = GNUNET_mutex_create (GNUNET_YES);
-  if (0 != GNUNET_GC_attach_change_listener (cfg, &reloadConfiguration, NULL))
+  GNUNET_GE_ASSERT (coreAPI->ectx, sizeof (GNUNET_MessageHeader) == 4);
+  GNUNET_GE_ASSERT (coreAPI->ectx, sizeof (TCPWelcome) == 68);
+  lock = GNUNET_mutex_create (GNUNET_YES);
+  if (0 != GNUNET_GC_attach_change_listener (cfg, &reload_configuration, NULL))
     {
-      GNUNET_mutex_destroy (tcplock);
-      GNUNET_mutex_destroy (tcpblacklistlock);
-      tcplock = NULL;
-      tcpblacklistlock = NULL;
+      GNUNET_mutex_destroy (lock);
+      lock = NULL;
       return NULL;
     }
   coreAPI = core;
@@ -578,7 +773,7 @@
 
       if (upnp == NULL)
         {
-          GNUNET_GE_LOG (ectx,
+          GNUNET_GE_LOG (coreAPI->ectx,
                          GNUNET_GE_ERROR | GNUNET_GE_USER |
                          GNUNET_GE_IMMEDIATE,
                          _
@@ -596,41 +791,27 @@
       stat_bytesDropped
         = stats->create (gettext_noop ("# bytes dropped by TCP (outgoing)"));
     }
-  tcpAPI.protocolNumber = GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP;
-  tcpAPI.mtu = 0;
-  tcpAPI.cost = 20000;          /* about equal to udp */
-  tcpAPI.verifyHello = &verifyHello;
-  tcpAPI.createhello = &createhello;
-  tcpAPI.connect = &tcpConnect;
-  tcpAPI.associate = &tcpAssociate;
-  tcpAPI.send = &tcpSend;
-  tcpAPI.disconnect = &tcpDisconnect;
-  tcpAPI.startTransportServer = &startTransportServer;
-  tcpAPI.stopTransportServer = &stopTransportServer;
-  tcpAPI.helloToAddress = &helloToAddress;
-  tcpAPI.testWouldTry = &tcpTestWouldTry;
+  myAPI.protocolNumber = GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP;
+  myAPI.mtu = 0;
+  myAPI.cost = 20000;          /* about equal to udp */
+  myAPI.verifyHello = &verify_hello;
+  myAPI.createhello = &create_hello;
+  myAPI.connect = &tcp_connect;
+  myAPI.associate = &tcp_associate;
+  myAPI.send = &tcp_send;
+  myAPI.disconnect = &tcp_disconnect;
+  myAPI.startTransportServer = &tcp_transport_server_start;
+  myAPI.stopTransportServer = &tcp_transport_server_stop;
+  myAPI.helloToAddress = &hello_to_address;
+  myAPI.testWouldTry = &tcp_test_would_try;
 
-  return &tcpAPI;
+  return &myAPI;
 }
 
 void
 donetransport_tcp ()
 {
-  GNUNET_GC_detach_change_listener (cfg, &reloadConfiguration, NULL);
-  if (stats != NULL)
-    {
-      coreAPI->release_service (stats);
-      stats = NULL;
-    }
-  if (upnp != NULL)
-    {
-      coreAPI->release_service (upnp);
-      upnp = NULL;
-    }
-  GNUNET_free_non_null (filteredNetworks_);
-  GNUNET_free_non_null (allowedNetworks_);
-  GNUNET_mutex_destroy (tcplock);
-  GNUNET_mutex_destroy (tcpblacklistlock);
+  do_shutdown();
 }
 
 /* end of tcp.c */

Deleted: GNUnet/src/transports/tcp6.c
===================================================================
--- GNUnet/src/transports/tcp6.c        2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/src/transports/tcp6.c        2008-02-10 06:45:34 UTC (rev 6220)
@@ -1,564 +0,0 @@
-/*
-     This file is part of GNUnet
-     (C) 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other 
contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file transports/tcp6.c
- * @brief Implementation of the TCP6 transport service over IPv6
- * @author Christian Grothoff
- */
-
-#include "gnunet_util.h"
-#include "gnunet_protocols.h"
-#include "gnunet_transport.h"
-#include "gnunet_stats_service.h"
-#include "platform.h"
-#include "ip.h"
-#include "ip6.h"
-
-#define DEBUG_TCP6 GNUNET_NO
-
-/**
- * after how much time of the core not being associated with a tcp6
- * connection anymore do we close it?
- *
- * Needs to be larger than SECONDS_INACTIVE_DROP in
- * core's connection.s
- */
-#define TCP_TIMEOUT 600 * GNUNET_CRON_SECONDS
-
-/**
- * after how much time of the core not being associated with a tcp
- * connection anymore do we close it?
- *
- * Needs to be larger than SECONDS_INACTIVE_DROP in
- * core's connection.s
- */
-#define TCP_FAST_TIMEOUT (5 * GNUNET_CRON_SECONDS)
-
-#define TARGET_BUFFER_SIZE 4092
-
-#include "tcp_helper.c"
-
-/**
- * @brief Host-Address in a TCP6 network.
- */
-typedef struct
-{
-  /**
-   * claimed IP of the sender, network byte order
-   */
-  GNUNET_IPv6Address ip;
-
-  /**
-   * claimed port of the sender, network byte order
-   */
-  unsigned short port;
-
-  /**
-   * reserved (set to 0 for signature verification)
-   */
-  unsigned short reserved;
-
-} Host6Address;
-
-/* *********** globals ************* */
-
-static GNUNET_TransportAPI tcp6API;
-
-static struct GNUNET_IPv6NetworkSet *filteredNetworks_;
-
-static struct GNUNET_IPv6NetworkSet *allowedNetworks_;
-
-static struct GNUNET_GC_Configuration *cfg;
-
-static struct GNUNET_Mutex *tcpblacklistlock;
-
-/* ******************** helper functions *********************** */
-
-/**
- * Check if we are allowed to connect to the given IP.
- */
-static int
-isBlacklisted (const void *addr, unsigned int addr_len)
-{
-  GNUNET_IPv6Address ip;
-  int ret;
-
-  if (addr_len == sizeof (GNUNET_IPv6Address))
-    {
-      memcpy (&ip, addr, sizeof (GNUNET_IPv6Address));
-    }
-  else if (addr_len == sizeof (struct sockaddr_in6))
-    {
-      memcpy (&ip,
-              &((struct sockaddr_in6 *) addr)->sin6_addr,
-              sizeof (GNUNET_IPv6Address));
-    }
-  else
-    {
-      return GNUNET_SYSERR;
-    }
-  GNUNET_mutex_lock (tcpblacklistlock);
-  ret = GNUNET_check_ipv6_listed (filteredNetworks_, ip);
-  GNUNET_mutex_unlock (tcpblacklistlock);
-  return ret;
-}
-
-/**
- * Check if we are allowed to connect to the given IP.
- */
-static int
-isWhitelisted (const void *addr, unsigned int addr_len)
-{
-  GNUNET_IPv6Address ip;
-  int ret;
-
-  if (addr_len == sizeof (GNUNET_IPv6Address))
-    {
-      memcpy (&ip, addr, sizeof (GNUNET_IPv6Address));
-    }
-  else if (addr_len == sizeof (struct sockaddr_in6))
-    {
-      memcpy (&ip,
-              &((struct sockaddr_in6 *) addr)->sin6_addr,
-              sizeof (GNUNET_IPv6Address));
-    }
-  else
-    {
-      return GNUNET_SYSERR;
-    }
-  ret = GNUNET_OK;
-  GNUNET_mutex_lock (tcpblacklistlock);
-  if (allowedNetworks_ != NULL)
-    ret = GNUNET_check_ipv6_listed (filteredNetworks_, ip);
-  GNUNET_mutex_unlock (tcpblacklistlock);
-  return ret;
-}
-
-static int
-isRejected (const void *addr, unsigned int addr_len)
-{
-  if ((GNUNET_YES == isBlacklisted (addr,
-                                    addr_len)) ||
-      (GNUNET_YES != isWhitelisted (addr, addr_len)))
-    return GNUNET_YES;
-  return GNUNET_NO;
-}
-
-/**
- * Get the GNUnet UDP port from the configuration,
- * or from /etc/services if it is not specified in
- * the config file.
- */
-static unsigned short
-getGNUnetTCP6Port ()
-{
-  struct servent *pse;          /* pointer to service information entry        
*/
-  unsigned long long port;
-
-  if (-1 == GNUNET_GC_get_configuration_value_number (cfg,
-                                                      "TCP6",
-                                                      "PORT", 1, 65535, 2086,
-                                                      &port))
-    {
-      if ((pse = getservbyname ("gnunet", "tcp6")))
-        port = htons (pse->s_port);
-      else
-        port = 0;
-    }
-  return (unsigned short) port;
-}
-
-/**
- * Verify that a hello-Message is correct (a node
- * is reachable at that address). Since the reply
- * will be asynchronous, a method must be called on
- * success.
- * @param hello the hello message to verify
- *        (the signature/crc have been verified before)
- * @return GNUNET_OK on success, GNUNET_SYSERR on error
- */
-static int
-verifyHello (const GNUNET_MessageHello * hello)
-{
-  Host6Address *haddr;
-
-  haddr = (Host6Address *) & hello[1];
-  if ((ntohs (hello->senderAddressSize) != sizeof (Host6Address)) ||
-      (ntohs (hello->header.size) != GNUNET_sizeof_hello (hello)) ||
-      (ntohs (hello->header.type) != GNUNET_P2P_PROTO_HELLO) ||
-      (ntohs (hello->protocol) != GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP6) ||
-      (GNUNET_YES == isBlacklisted (&haddr->ip,
-                                    sizeof (GNUNET_IPv6Address))) ||
-      (GNUNET_YES != isWhitelisted (&haddr->ip, sizeof (GNUNET_IPv6Address))))
-    return GNUNET_SYSERR;       /* obviously invalid */
-  else
-    return GNUNET_OK;
-}
-
-/**
- * Create a hello-Message for the current node. The hello is
- * created without signature and without a timestamp. The
- * GNUnet core will GNUNET_RSA_sign the message and add an expiration time.
- *
- * @return hello on success, NULL on error
- */
-static GNUNET_MessageHello *
-createhello ()
-{
-  GNUNET_MessageHello *msg;
-  Host6Address *haddr;
-  unsigned short port;
-
-  port = getGNUnetTCP6Port ();
-  if (0 == port)
-    {
-#if DEBUG_TCP6
-      GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG,
-                     "TCP6 port is 0, will only send using TCP6\n");
-#endif
-      return NULL;              /* TCP6 transport is configured SEND-only! */
-    }
-  msg =
-    (GNUNET_MessageHello *) GNUNET_malloc (sizeof (GNUNET_MessageHello) +
-                                           sizeof (Host6Address));
-  haddr = (Host6Address *) & msg[1];
-
-  if (GNUNET_SYSERR == getPublicIP6Address (cfg, ectx, &haddr->ip))
-    {
-      GNUNET_free (msg);
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     _("Could not determine my public IPv6 address.\n"));
-      return NULL;
-    }
-  haddr->port = htons (port);
-  haddr->reserved = htons (0);
-  msg->senderAddressSize = htons (sizeof (Host6Address));
-  msg->protocol = htons (GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP6);
-  msg->MTU = htonl (tcp6API.mtu);
-  return msg;
-}
-
-/**
- * Establish a connection to a remote node.
- *
- * @param hello the hello-Message for the target node
- * @param tsessionPtr the session handle that is set
- * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
- */
-static int
-tcp6Connect (const GNUNET_MessageHello * hello,
-             GNUNET_TSession ** tsessionPtr, int may_reuse)
-{
-  int i;
-  Host6Address *haddr;
-  int sock;
-  char hostname[INET6_ADDRSTRLEN];
-  struct addrinfo hints, *res, *res0;
-  int rtn;
-  struct GNUNET_SocketHandle *s;
-  TCPSession *session;
-
-  if (selector == NULL)
-    return GNUNET_SYSERR;
-  if (GNUNET_NO != may_reuse)
-    {
-      GNUNET_mutex_lock (tcplock);
-      session = sessions;
-      while (session != NULL)
-        {
-          if (0 == memcmp (&session->sender,
-                           &hello->senderIdentity,
-                           sizeof (GNUNET_PeerIdentity)))
-            {
-              GNUNET_mutex_lock (session->lock);
-              if (session->in_select)
-                {
-                  session->users++;
-                  GNUNET_mutex_unlock (session->lock);
-                  GNUNET_mutex_unlock (tcplock);
-                  *tsessionPtr = session->tsession;
-                  return GNUNET_OK;
-                }
-              GNUNET_mutex_unlock (session->lock);
-            }
-          session = session->next;
-        }
-    }
-  GNUNET_mutex_unlock (tcplock);
-  haddr = (Host6Address *) & hello[1];
-  memset (&hints, 0, sizeof (hints));
-  hints.ai_family = PF_INET6;
-  hints.ai_socktype = SOCK_STREAM;
-  inet_ntop (AF_INET6, haddr, hostname, INET6_ADDRSTRLEN);
-  rtn = getaddrinfo (hostname, NULL, &hints, &res0);
-  if (rtn != 0)
-    {
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_BULK,
-                     _("`%s': unknown service: %s\n"),
-                     __FUNCTION__, gai_strerror (rtn));
-      return GNUNET_SYSERR;
-    }
-
-#if DEBUG_TCP6
-  GNUNET_GE_LOG (ectx,
-                 GNUNET_GE_DEBUG,
-                 "Creating TCP6 connection to %s:%d\n",
-                 inet_ntop (AF_INET6,
-                            haddr,
-                            &hostname, INET6_ADDRSTRLEN),
-                 ntohs (haddr->port));
-#endif
-
-  sock = -1;
-  s = NULL;
-  for (res = res0; res; res = res->ai_next)
-    {
-      if (res->ai_family != PF_INET6)
-        continue;
-      sock = SOCKET (res->ai_family, res->ai_socktype, res->ai_protocol);
-      if (sock < 0)
-        {
-          GNUNET_GE_LOG_STRERROR (ectx,
-                                  GNUNET_GE_WARNING | GNUNET_GE_ADMIN |
-                                  GNUNET_GE_BULK, "socket");
-          sock = -1;
-          continue;
-        }
-      s = GNUNET_socket_create (ectx, coreAPI->load_monitor, sock);
-      if (-1 == GNUNET_socket_set_blocking (s, GNUNET_NO))
-        {
-          GNUNET_socket_destroy (s);
-          freeaddrinfo (res0);
-          return GNUNET_SYSERR;
-        }
-      ((struct sockaddr_in6 *) (res->ai_addr))->sin6_port = haddr->port;
-      i = CONNECT (sock, res->ai_addr, res->ai_addrlen);
-      if ((i < 0) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK))
-        {
-          GNUNET_GE_LOG_STRERROR (ectx,
-                                  GNUNET_GE_WARNING | GNUNET_GE_ADMIN |
-                                  GNUNET_GE_BULK, "connect");
-          GNUNET_socket_destroy (s);
-          s = NULL;
-          sock = -1;
-          continue;
-        }
-      break;
-    }
-  freeaddrinfo (res0);
-  if (sock == -1)
-    return GNUNET_SYSERR;
-  GNUNET_GE_ASSERT (ectx, s != NULL);
-  return tcpConnectHelper (hello, s, tcp6API.protocolNumber, tsessionPtr);
-}
-
-/**
- * Start the server process to receive inbound traffic.
- * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
- */
-static int
-startTransportServer ()
-{
-  struct sockaddr_in6 serverAddr;
-  const int on = 1;
-  unsigned short port;
-  int s;
-
-  if (selector != NULL)
-    {
-      GNUNET_GE_BREAK (ectx, 0);
-      return GNUNET_SYSERR;
-    }
-  port = getGNUnetTCP6Port ();
-  if (port != 0)
-    {
-      s = SOCKET (PF_INET6, SOCK_STREAM, 0);
-      if (s < 0)
-        {
-          GNUNET_GE_LOG_STRERROR (ectx,
-                                  GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
-                                  GNUNET_GE_BULK, "socket");
-          return GNUNET_SYSERR;
-        }
-      if (SETSOCKOPT (s, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0)
-        GNUNET_GE_DIE_STRERROR (ectx,
-                                GNUNET_GE_FATAL | GNUNET_GE_ADMIN |
-                                GNUNET_GE_IMMEDIATE, "setsockopt");
-      memset ((char *) &serverAddr, 0, sizeof (serverAddr));
-      serverAddr.sin6_family = AF_INET6;
-      serverAddr.sin6_flowinfo = 0;
-      serverAddr.sin6_addr = in6addr_any;
-      serverAddr.sin6_port = htons (getGNUnetTCP6Port ());
-      if (BIND (s, (struct sockaddr *) &serverAddr, sizeof (serverAddr)) < 0)
-        {
-          GNUNET_GE_LOG_STRERROR (ectx,
-                                  GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
-                                  GNUNET_GE_IMMEDIATE, "bind");
-          GNUNET_GE_LOG (ectx,
-                         GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
-                         GNUNET_GE_IMMEDIATE,
-                         _("Failed to start transport service on port %d.\n"),
-                         getGNUnetTCP6Port ());
-          if (0 != CLOSE (s))
-            GNUNET_GE_LOG_STRERROR (ectx,
-                                    GNUNET_GE_ERROR | GNUNET_GE_USER |
-                                    GNUNET_GE_ADMIN | GNUNET_GE_BULK,
-                                    "close");
-          return GNUNET_SYSERR;
-        }
-    }
-  else
-    {
-      s = -1;
-    }
-  selector = GNUNET_select_create ("tcp6",
-                                   GNUNET_NO,
-                                   ectx,
-                                   coreAPI->load_monitor,
-                                   s,
-                                   sizeof (GNUNET_IPv4Address),
-                                   TCP_FAST_TIMEOUT,
-                                   &select_message_handler,
-                                   NULL,
-                                   &select_accept_handler,
-                                   &isRejected,
-                                   &select_close_handler,
-                                   NULL, 128 * 1024 /* max memory */ ,
-                                   128 /* max sockets */ );
-  return GNUNET_OK;
-}
-
-/**
- * Reload the configuration. Should never fail (keep old
- * configuration on error, syslog errors!)
- */
-static int
-reloadConfiguration (void *ctx,
-                     struct GNUNET_GC_Configuration *cfg,
-                     struct GNUNET_GE_Context *ectx,
-                     const char *section, const char *option)
-{
-  char *ch;
-
-  if (0 != strcmp (section, "TCP6"))
-    return 0;                   /* fast path */
-  GNUNET_mutex_lock (tcpblacklistlock);
-  GNUNET_free_non_null (filteredNetworks_);
-  GNUNET_free_non_null (allowedNetworks_);
-  GNUNET_GC_get_configuration_value_string (cfg, "TCP6", "BLACKLIST", "",
-                                            &ch);
-  filteredNetworks_ = GNUNET_parse_ipv6_network_specification (ectx, ch);
-  GNUNET_free (ch);
-  GNUNET_GC_get_configuration_value_string (cfg, "TCP6", "WHITELIST", "",
-                                            &ch);
-  if (strlen (ch) > 0)
-    allowedNetworks_ = GNUNET_parse_ipv6_network_specification (ectx, ch);
-  else
-    allowedNetworks_ = NULL;
-  GNUNET_free (ch);
-
-  GNUNET_mutex_unlock (tcpblacklistlock);
-  return 0;
-}
-
-/**
- * Convert TCP6  hello to IPv6 address
- */
-static int
-helloToAddress (const GNUNET_MessageHello * hello,
-                void **sa, unsigned int *sa_len)
-{
-  const Host6Address *haddr = (const Host6Address *) &hello[1];
-  struct sockaddr_in6 *serverAddr;
-
-  *sa_len = sizeof (struct sockaddr_in6);
-  serverAddr = GNUNET_malloc (sizeof (struct sockaddr_in6));
-  *sa = serverAddr;
-  memset (serverAddr, 0, sizeof (struct sockaddr_in6));
-  serverAddr->sin6_family = AF_INET6;
-  memcpy (&serverAddr->sin6_addr, haddr, sizeof (GNUNET_IPv6Address));
-  serverAddr->sin6_port = haddr->port;
-  return GNUNET_OK;
-}
-
-
-/* ******************** public API ******************** */
-
-/**
- * The exported method. Makes the core api available
- * via a global and returns the udp transport API.
- */
-GNUNET_TransportAPI *
-inittransport_tcp6 (GNUNET_CoreAPIForTransport * core)
-{
-  ectx = core->ectx;
-  cfg = core->cfg;
-  tcplock = GNUNET_mutex_create (GNUNET_YES);
-  tcpblacklistlock = GNUNET_mutex_create (GNUNET_YES);
-  if (0 != GNUNET_GC_attach_change_listener (cfg, &reloadConfiguration, NULL))
-    {
-      GNUNET_mutex_destroy (tcplock);
-      GNUNET_mutex_destroy (tcpblacklistlock);
-      tcplock = NULL;
-      tcpblacklistlock = NULL;
-      return NULL;
-    }
-  coreAPI = core;
-  stats = coreAPI->request_service ("stats");
-  if (stats != NULL)
-    {
-      stat_bytesReceived
-        = stats->create (gettext_noop ("# bytes received via TCP6"));
-      stat_bytesSent = stats->create (gettext_noop ("# bytes sent via TCP6"));
-      stat_bytesDropped
-        = stats->create (gettext_noop ("# bytes dropped by TCP6 (outgoing)"));
-    }
-  tcp6API.protocolNumber = GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP6;
-  tcp6API.mtu = 0;
-  tcp6API.cost = 19950;         /* about equal to udp6 */
-  tcp6API.verifyHello = &verifyHello;
-  tcp6API.createhello = &createhello;
-  tcp6API.connect = &tcp6Connect;
-  tcp6API.associate = &tcpAssociate;
-  tcp6API.send = &tcpSend;
-  tcp6API.disconnect = &tcpDisconnect;
-  tcp6API.startTransportServer = &startTransportServer;
-  tcp6API.stopTransportServer = &stopTransportServer;
-  tcp6API.helloToAddress = &helloToAddress;
-  tcp6API.testWouldTry = &tcpTestWouldTry;
-
-  return &tcp6API;
-}
-
-void
-donetransport_tcp6 ()
-{
-  GNUNET_GC_detach_change_listener (cfg, &reloadConfiguration, NULL);
-  coreAPI->release_service (stats);
-  stats = NULL;
-  GNUNET_free_non_null (filteredNetworks_);
-  GNUNET_mutex_destroy (tcplock);
-  GNUNET_mutex_destroy (tcpblacklistlock);
-}
-
-/* end of tcp6.c */

Deleted: GNUnet/src/transports/tcp_helper.c
===================================================================
--- GNUnet/src/transports/tcp_helper.c  2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/src/transports/tcp_helper.c  2008-02-10 06:45:34 UTC (rev 6220)
@@ -1,598 +0,0 @@
-/*
-     This file is part of GNUnet
-     (C) 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and other 
contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file transports/tcp_helper.c
- * @brief common functions for the TCP services
- * @author Christian Grothoff
- */
-
-typedef int (*BlacklistedTester) (const void *addr, unsigned int addr_len);
-
-/**
- * Initial handshake message. Note that the beginning
- * must match the CS_MESSAGE_HEADER since we are using tcpio.
- */
-typedef struct
-{
-  GNUNET_MessageHeader header;
-
-  /**
-   * Identity of the node connecting (TCP client)
-   */
-  GNUNET_PeerIdentity clientIdentity;
-} TCPWelcome;
-
-/**
- * Transport Session handle.
- */
-typedef struct TCPSession
-{
-
-  struct TCPSession *next;
-
-  /**
-   * the tcp socket (used to identify this connection with selector)
-   */
-  struct GNUNET_SocketHandle *sock;
-
-  /**
-   * Our tsession.
-   */
-  GNUNET_TSession *tsession;
-
-  /**
-   * mutex for synchronized access to 'users'
-   */
-  struct GNUNET_Mutex *lock;
-
-  /**
-   * To whom are we talking to (set to our identity
-   * if we are still waiting for the welcome message)
-   */
-  GNUNET_PeerIdentity sender;
-
-  /**
-   * Are we still expecting the welcome? (GNUNET_YES/GNUNET_NO)
-   */
-  int expectingWelcome;
-
-  /**
-   * number of users of this session (reference count)
-   */
-  int users;
-
-  /**
-   * Is this session active with select?
-   */
-  int in_select;
-
-  void *accept_addr;
-
-  unsigned int addr_len;
-
-} TCPSession;
-
-/* *********** globals ************* */
-
-/**
- * apis (our advertised API and the core api )
- */
-static GNUNET_CoreAPIForTransport *coreAPI;
-
-static GNUNET_Stats_ServiceAPI *stats;
-
-static int stat_bytesReceived;
-
-static int stat_bytesSent;
-
-static int stat_bytesDropped;
-
-static struct GNUNET_SelectHandle *selector;
-
-static struct GNUNET_GE_Context *ectx;
-
-static struct GNUNET_Mutex *tcplock;
-
-static struct TCPSession *sessions;
-
-
-/**
- * You must hold the tcplock when calling this
- * function (and should not hold the tcpsession's lock
- * any more).
- */
-static void
-freeTCPSession (TCPSession * tcpsession)
-{
-  TCPSession *pos;
-  TCPSession *prev;
-
-  GNUNET_mutex_destroy (tcpsession->lock);
-  GNUNET_free_non_null (tcpsession->accept_addr);
-  pos = sessions;
-  prev = NULL;
-  while (pos != NULL)
-    {
-      if (pos == tcpsession)
-        {
-          if (prev == NULL)
-            sessions = pos->next;
-          else
-            prev->next = pos->next;
-          break;
-        }
-      prev = pos;
-      pos = pos->next;
-    }
-  GNUNET_mutex_unlock (tcplock);
-  GNUNET_GE_ASSERT (ectx,
-                    GNUNET_OK ==
-                    coreAPI->
-                    connection_assert_tsession_unused (tcpsession->tsession));
-  GNUNET_mutex_lock (tcplock);
-  GNUNET_free (tcpsession->tsession);
-  GNUNET_free (tcpsession);
-}
-
-static int
-tcpDisconnect (GNUNET_TSession * tsession)
-{
-  TCPSession *tcpsession = tsession->internal;
-
-  GNUNET_GE_ASSERT (ectx, selector != NULL);
-  GNUNET_mutex_lock (tcplock);
-  GNUNET_mutex_lock (tcpsession->lock);
-  GNUNET_GE_ASSERT (ectx, tcpsession->users > 0);
-  tcpsession->users--;
-  if ((tcpsession->users > 0) || (tcpsession->in_select == GNUNET_YES))
-    {
-      if (tcpsession->users == 0)
-        GNUNET_select_change_timeout (selector, tcpsession->sock,
-                                      TCP_FAST_TIMEOUT);
-      GNUNET_mutex_unlock (tcpsession->lock);
-      GNUNET_mutex_unlock (tcplock);
-      return GNUNET_OK;
-    }
-  GNUNET_mutex_unlock (tcpsession->lock);
-  GNUNET_mutex_unlock (tcplock);
-#if DEBUG_TCP
-  GNUNET_GE_LOG (ectx,
-                 GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                 "TCP disconnect closes socket session.\n");
-#endif
-  GNUNET_select_disconnect (selector, tcpsession->sock);
-  GNUNET_mutex_lock (tcplock);
-  freeTCPSession (tcpsession);
-  GNUNET_mutex_unlock (tcplock);
-  return GNUNET_OK;
-}
-
-/**
- * A (core) Session is to be associated with a transport session. The
- * transport service may want to know in order to call back on the
- * core if the connection is being closed. Associate can also be
- * called to test if it would be possible to associate the session
- * later, in this case the argument session is NULL. This can be used
- * to test if the connection must be closed by the core or if the core
- * can assume that it is going to be self-managed (if associate
- * returns GNUNET_OK and session was NULL, the transport layer is responsible
- * for eventually freeing resources associated with the tesession). If
- * session is not NULL, the core takes responsbility for eventually
- * calling disconnect.
- *
- * @param tsession the session handle passed along
- *   from the call to receive that was made by the transport
- *   layer
- * @return GNUNET_OK if the session could be associated,
- *         GNUNET_SYSERR if not.
- */
-static int
-tcpAssociate (GNUNET_TSession * tsession)
-{
-  TCPSession *tcpSession;
-
-  GNUNET_GE_ASSERT (ectx, tsession != NULL);
-  tcpSession = tsession->internal;
-  GNUNET_mutex_lock (tcpSession->lock);
-  if ((tcpSession->users == 0) && (tcpSession->in_select == GNUNET_YES))
-    GNUNET_select_change_timeout (selector, tcpSession->sock, TCP_TIMEOUT);
-  tcpSession->users++;
-
-  GNUNET_mutex_unlock (tcpSession->lock);
-  return GNUNET_OK;
-}
-
-/**
- * The socket of session has data waiting, process!
- *
- * This function may only be called if the tcplock is
- * already held by the caller.
- */
-static int
-select_message_handler (void *mh_cls,
-                        struct GNUNET_SelectHandle *sh,
-                        struct GNUNET_SocketHandle *sock,
-                        void *sock_ctx, const GNUNET_MessageHeader * msg)
-{
-  GNUNET_TSession *tsession = sock_ctx;
-  TCPSession *tcpSession;
-  unsigned int len;
-  GNUNET_TransportPacket *mp;
-  const TCPWelcome *welcome;
-
-  if (GNUNET_SYSERR == tcpAssociate (tsession))
-    {
-      GNUNET_GE_BREAK (ectx, 0);
-      return GNUNET_SYSERR;
-    }
-  len = ntohs (msg->size);
-  if (stats != NULL)
-    stats->change (stat_bytesReceived, len);
-  tcpSession = tsession->internal;
-  if (GNUNET_YES == tcpSession->expectingWelcome)
-    {
-      /* at this point, we should be the only user! */
-      GNUNET_GE_ASSERT (NULL, tcpSession->users == 1);
-
-      welcome = (const TCPWelcome *) msg;
-      if ((ntohs (welcome->header.type) != 0) || (len != sizeof (TCPWelcome)))
-        {
-          GNUNET_GE_LOG (ectx,
-                         GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
-                         _
-                         ("Received malformed message instead of welcome 
message. Closing.\n"));
-          tcpDisconnect (tsession);
-          return GNUNET_SYSERR;
-        }
-      tcpSession->expectingWelcome = GNUNET_NO;
-      tcpSession->sender = welcome->clientIdentity;
-      tsession->peer = welcome->clientIdentity;
-      if (tcpSession->accept_addr != NULL)
-        GNUNET_IP_set_address_for_peer_identity (&welcome->clientIdentity,
-                                                 tcpSession->accept_addr,
-                                                 tcpSession->addr_len);
-    }
-  else
-    {
-      /* send msg to core! */
-      if (len <= sizeof (GNUNET_MessageHeader))
-        {
-          GNUNET_GE_LOG (ectx,
-                         GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
-                         _
-                         ("Received malformed message from tcp-peer 
connection. Closing.\n"));
-          tcpDisconnect (tsession);
-          return GNUNET_SYSERR;
-        }
-      mp = GNUNET_malloc (sizeof (GNUNET_TransportPacket));
-      mp->msg = GNUNET_malloc (len - sizeof (GNUNET_MessageHeader));
-      memcpy (mp->msg, &msg[1], len - sizeof (GNUNET_MessageHeader));
-      mp->sender = tcpSession->sender;
-      mp->size = len - sizeof (GNUNET_MessageHeader);
-      mp->tsession = tsession;
-      coreAPI->receive (mp);
-    }
-  tcpDisconnect (tsession);
-  return GNUNET_OK;
-}
-
-
-/**
- * Create a new session for an inbound connection on the given
- * socket. Adds the session to the array of sessions watched
- * by the select thread.
- */
-static void *
-select_accept_handler (void *ah_cls,
-                       struct GNUNET_SelectHandle *sh,
-                       struct GNUNET_SocketHandle *sock,
-                       const void *addr, unsigned int addr_len)
-{
-  BlacklistedTester blt = ah_cls;
-  GNUNET_TSession *tsession;
-  TCPSession *tcpSession;
-
-  GNUNET_GE_ASSERT (NULL, sock != NULL);
-  if (GNUNET_NO != blt (addr, addr_len))
-    {
-#if DEBUG_TCP
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     "Rejecting TCP connection (blacklisted).\n");
-#endif
-      return NULL;
-    }
-#if DEBUG_TCP
-  GNUNET_GE_LOG (ectx, GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                 "Accepting TCP connection.\n");
-#endif
-  tcpSession = GNUNET_malloc (sizeof (TCPSession));
-  memset (tcpSession, 0, sizeof (TCPSession));
-  tcpSession->sock = sock;
-  /* fill in placeholder identity to mark that we
-     are waiting for the welcome message */
-  tcpSession->sender = *(coreAPI->myIdentity);
-  tcpSession->expectingWelcome = GNUNET_YES;
-  tcpSession->lock = GNUNET_mutex_create (GNUNET_YES);
-  tcpSession->users = 0;
-  tcpSession->in_select = GNUNET_YES;
-
-  tsession = GNUNET_malloc (sizeof (GNUNET_TSession));
-  memset (tsession, 0, sizeof (GNUNET_TSession));
-  tsession->ttype = GNUNET_TRANSPORT_PROTOCOL_NUMBER_TCP;
-  tsession->internal = tcpSession;
-  tcpSession->tsession = tsession;
-  tsession->peer = *(coreAPI->myIdentity);
-  if (addr_len > sizeof (GNUNET_IPv4Address))
-    {
-      tcpSession->accept_addr = GNUNET_malloc (addr_len);
-      memcpy (tcpSession->accept_addr,
-              (struct sockaddr_in *) addr, sizeof (struct sockaddr_in));
-      tcpSession->addr_len = addr_len;
-    }
-  else
-    {
-      GNUNET_GE_BREAK (NULL, 0);
-      tcpSession->addr_len = 0;
-      tcpSession->accept_addr = NULL;
-    }
-  GNUNET_mutex_lock (tcplock);
-  tcpSession->next = sessions;
-  sessions = tcpSession;
-  GNUNET_mutex_unlock (tcplock);
-  return tsession;
-}
-
-static void
-select_close_handler (void *ch_cls,
-                      struct GNUNET_SelectHandle *sh,
-                      struct GNUNET_SocketHandle *sock, void *sock_ctx)
-{
-  GNUNET_TSession *tsession = sock_ctx;
-  TCPSession *tcpSession = tsession->internal;
-
-#if DEBUG_TCP
-  GNUNET_EncName enc;
-
-  IF_GELOG (ectx,
-            GNUNET_GE_DEBUG | GNUNET_GE_DEVELOPER | GNUNET_GE_BULK,
-            GNUNET_hash_to_enc (&tcpSession->sender.hashPubKey, &enc));
-  GNUNET_GE_LOG (ectx,
-                 GNUNET_GE_DEBUG | GNUNET_GE_DEVELOPER | GNUNET_GE_BULK,
-                 "Closed TCP socket of `%s'.\n", &enc);
-#endif
-  GNUNET_mutex_lock (tcplock);
-  GNUNET_mutex_lock (tcpSession->lock);
-  tcpSession->in_select = GNUNET_NO;
-  if (tcpSession->users == 0)
-    {
-      GNUNET_mutex_unlock (tcpSession->lock);
-      freeTCPSession (tcpSession);
-    }
-  else
-    {
-      GNUNET_mutex_unlock (tcpSession->lock);
-    }
-  GNUNET_mutex_unlock (tcplock);
-}
-
-/**
- * Send a message to the specified remote node.
- *
- * @param tsession the handle identifying the remote node
- * @param msg the message
- * @param size the size of the message
- * @return GNUNET_SYSERR on error, GNUNET_OK on success
- */
-static int
-tcpSend (GNUNET_TSession * tsession,
-         const void *msg, unsigned int size, int important)
-{
-  TCPSession *tcpSession;
-  GNUNET_MessageHeader *mp;
-  int ok;
-
-  tcpSession = tsession->internal;
-  if (size >= GNUNET_MAX_BUFFER_SIZE - sizeof (GNUNET_MessageHeader))
-    {
-      GNUNET_GE_BREAK (ectx, 0);
-      return GNUNET_SYSERR;     /* too big */
-    }
-  if (tcpSession->in_select == GNUNET_NO)
-    {
-#if DEBUG_TCP
-      GNUNET_EncName enc;
-
-      IF_GELOG (ectx,
-                GNUNET_GE_DEBUG | GNUNET_GE_DEVELOPER | GNUNET_GE_BULK,
-                GNUNET_hash_to_enc (&tcpSession->sender.hashPubKey, &enc));
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_DEVELOPER | GNUNET_GE_BULK,
-                     "Cannot send message - TCP socket of `%s' already 
closed!\n",
-                     &enc);
-#endif
-      return GNUNET_SYSERR;
-    }
-  if (selector == NULL)
-    {
-      if (stats != NULL)
-        stats->change (stat_bytesDropped, size);
-#if DEBUG_TCP
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     "Could not sent TCP message -- tcp transport is down.\n");
-#endif
-      return GNUNET_SYSERR;
-    }
-  if (size == 0)
-    {
-      GNUNET_GE_BREAK (ectx, 0);
-      return GNUNET_SYSERR;
-    }
-  if (tcpSession->sock == NULL)
-    {
-      if (stats != NULL)
-        stats->change (stat_bytesDropped, size);
-#if DEBUG_TCP
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     "Could not sent TCP message -- other side closed 
connection.\n");
-#endif
-      return GNUNET_SYSERR;     /* other side closed connection */
-    }
-  mp = GNUNET_malloc (sizeof (GNUNET_MessageHeader) + size);
-  mp->size = htons (size + sizeof (GNUNET_MessageHeader));
-  mp->type = 0;
-  memcpy (&mp[1], msg, size);
-#if DEBUG_TCP
-  GNUNET_GE_LOG (ectx,
-                 GNUNET_GE_DEBUG | GNUNET_GE_DEVELOPER | GNUNET_GE_BULK,
-                 "Transport asks select to queue message of size %u\n", size);
-#endif
-  ok =
-    GNUNET_select_write (selector, tcpSession->sock, mp, GNUNET_NO,
-                         important);
-  if ((GNUNET_OK == ok) && (stats != NULL))
-    stats->change (stat_bytesSent, size + sizeof (GNUNET_MessageHeader));
-
-  GNUNET_free (mp);
-  return ok;
-}
-
-/**
- * Test if the transport would even try to send
- * a message of the given size and importance
- * for the given session.<br>
- * This function is used to check if the core should
- * even bother to construct (and encrypt) this kind
- * of message.
- *
- * @return GNUNET_YES if the transport would try (i.e. queue
- *         the message or call the OS to send),
- *         GNUNET_NO if the transport would just drop the message,
- *         GNUNET_SYSERR if the size/session is invalid
- */
-static int
-tcpTestWouldTry (GNUNET_TSession * tsession, const unsigned int size,
-                 int important)
-{
-  TCPSession *tcpSession = tsession->internal;
-
-  if (size >= GNUNET_MAX_BUFFER_SIZE - sizeof (GNUNET_MessageHeader))
-    {
-      GNUNET_GE_BREAK (ectx, 0);
-      return GNUNET_SYSERR;
-    }
-  if (selector == NULL)
-    return GNUNET_SYSERR;
-  if (size == 0)
-    {
-      GNUNET_GE_BREAK (ectx, 0);
-      return GNUNET_SYSERR;
-    }
-  if (tcpSession->sock == NULL)
-    return GNUNET_SYSERR;       /* other side closed connection */
-  return GNUNET_select_test_write_now (selector, tcpSession->sock, size,
-                                       GNUNET_NO, important);
-}
-
-
-/**
- * Establish a connection to a remote node.
- *
- * @param helo the hello-Message for the target node
- * @param tsessionPtr the session handle that is set
- * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
- */
-static int
-tcpConnectHelper (const GNUNET_MessageHello * hello,
-                  struct GNUNET_SocketHandle *s,
-                  unsigned int protocolNumber, GNUNET_TSession ** tsessionPtr)
-{
-  TCPWelcome welcome;
-  GNUNET_TSession *tsession;
-  TCPSession *tcpSession;
-
-  tcpSession = GNUNET_malloc (sizeof (TCPSession));
-  memset (tcpSession, 0, sizeof (TCPSession));
-  tcpSession->addr_len = 0;
-  tcpSession->accept_addr = NULL;
-  tcpSession->sock = s;
-  tsession = GNUNET_malloc (sizeof (GNUNET_TSession));
-  memset (tsession, 0, sizeof (GNUNET_TSession));
-  tsession->internal = tcpSession;
-  tsession->ttype = protocolNumber;
-  tsession->peer = hello->senderIdentity;
-  tcpSession->tsession = tsession;
-  tcpSession->lock = GNUNET_mutex_create (GNUNET_YES);
-  tcpSession->users = 1;        /* caller */
-  tcpSession->in_select = GNUNET_NO;
-  tcpSession->sender = hello->senderIdentity;
-  tcpSession->expectingWelcome = GNUNET_NO;
-  GNUNET_mutex_lock (tcplock);
-  if (GNUNET_OK ==
-      GNUNET_select_connect (selector, tcpSession->sock, tsession))
-    tcpSession->in_select = GNUNET_YES;
-
-  /* send our node identity to the other side to fully establish the
-     connection! */
-  welcome.header.size = htons (sizeof (TCPWelcome));
-  welcome.header.type = htons (0);
-  welcome.clientIdentity = *(coreAPI->myIdentity);
-  if (GNUNET_OK !=
-      GNUNET_select_write (selector, s, &welcome.header, GNUNET_NO,
-                           GNUNET_YES))
-    {
-#if DEBUG_TCP
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     "Could not sent TCP welcome message, closing 
connection.\n");
-#endif
-      /* disconnect caller -- error! */
-      tcpDisconnect (tsession);
-      GNUNET_mutex_unlock (tcplock);
-      return GNUNET_SYSERR;
-    }
-  else if (stats != NULL)
-    stats->change (stat_bytesSent, sizeof (TCPWelcome));
-  tcpSession->next = sessions;
-  sessions = tcpSession;
-  GNUNET_mutex_unlock (tcplock);
-  *tsessionPtr = tsession;
-  return GNUNET_OK;
-}
-
-/**
- * Shutdown the server process (stop receiving inbound
- * traffic). Maybe restarted later!
- */
-static int
-stopTransportServer ()
-{
-  if (selector != NULL)
-    {
-      GNUNET_select_destroy (selector);
-      selector = NULL;
-    }
-  return GNUNET_OK;
-}
-
-/* end of tcp_helper.c */

Modified: GNUnet/src/transports/udp.c
===================================================================
--- GNUnet/src/transports/udp.c 2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/src/transports/udp.c 2008-02-10 06:45:34 UTC (rev 6220)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2001, 2002, 2003, 2004, 2005 Christian Grothoff (and other 
contributing authors)
+     (C) 2001, 2002, 2003, 2004, 2005, 2008 Christian Grothoff (and other 
contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -34,288 +34,269 @@
 
 #define DEBUG_UDP GNUNET_NO
 
-static GNUNET_UPnP_ServiceAPI *upnp;
+/**
+ * The default maximum size of each outbound UDP message,
+ * optimal value for Ethernet (10 or 100 MBit).
+ */
+#define MESSAGE_SIZE 1472
 
-#include "udp_helper.c"
-
 /**
- * Host-Address in a UDP network.
+ * Message-Packet header.
  */
 typedef struct
 {
   /**
-   * claimed IP of the sender, network byte order
+   * size of the message, in bytes, including this header.
    */
-  GNUNET_IPv4Address ip;
+  GNUNET_MessageHeader header;
 
   /**
-   * claimed port of the sender, network byte order
+   * What is the identity of the sender (GNUNET_hash of public key)
    */
-  unsigned short port;
+  GNUNET_PeerIdentity sender;
 
-  /**
-   * reserved (set to 0 for signature verification)
-   */
-  unsigned short reserved;
+} UDPMessage;
 
-} HostAddress;
+#define MY_TRANSPORT_NAME "UDP"
+#include "common.c"
 
-static struct GNUNET_GC_Configuration *cfg;
+/* *********** globals ************* */
 
-static struct GNUNET_LoadMonitor *load_monitor;
+static int stat_bytesReceived;
 
-static struct GNUNET_IPv4NetworkSet *filteredNetworks_;
+static int stat_bytesSent;
 
-static struct GNUNET_IPv4NetworkSet *allowedNetworks_;
+static int stat_bytesDropped;
 
-static struct GNUNET_Mutex *configLock;
+static int stat_udpConnected;
 
 /**
- * Get the GNUnet UDP port from the configuration, or from
- * /etc/services if it is not specified in the config file.
+ * thread that listens for inbound messages
+ */
+static struct GNUNET_SelectHandle *selector;
+
+/**
+ * the socket that we transmit all data with
+ */
+static struct GNUNET_SocketHandle *udp_sock;
+
+static struct GNUNET_LoadMonitor *load_monitor;
+
+
+/**
+ * The socket of session has data waiting, process!
  *
- * @return the port in host byte order
+ * This function may only be called if the tcplock is
+ * already held by the caller.
  */
-static unsigned short
-getGNUnetUDPPort ()
+static int
+select_message_handler (void *mh_cls,
+                        struct GNUNET_SelectHandle *sh,
+                        struct GNUNET_SocketHandle *sock,
+                        void *sock_ctx, const GNUNET_MessageHeader * msg)
 {
-  struct servent *pse;          /* pointer to service information entry        
*/
-  unsigned long long port;
+  unsigned int len;
+  GNUNET_TransportPacket *mp;
+  const UDPMessage *um;
 
-  if (-1 == GNUNET_GC_get_configuration_value_number (cfg,
-                                                      "UDP",
-                                                      "PORT", 1, 65535, 2086,
-                                                      &port))
+  len = ntohs (msg->size);
+  if (len <= sizeof (UDPMessage))
     {
-      if ((pse = getservbyname ("gnunet", "udp")))
-        port = htons (pse->s_port);
-      else
-        port = 0;
+      GNUNET_GE_LOG (coreAPI->ectx,
+                     GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
+                    _("Received malformed message via UDP. Ignored.\n"));
+      return GNUNET_SYSERR;
     }
-  return (unsigned short) port;
+  um = (const UDPMessage *) msg;
+  mp = GNUNET_malloc (sizeof (GNUNET_TransportPacket));
+  mp->msg = GNUNET_malloc (len - sizeof (UDPMessage));
+  memcpy (mp->msg, &um[1], len - sizeof (UDPMessage));
+  mp->sender = um->sender;
+  mp->size = len - sizeof (UDPMessage);
+  mp->tsession = NULL;
+  coreAPI->receive (mp);
+  if (stats != NULL)
+    stats->change (stat_bytesReceived, len);
+  return GNUNET_OK;
 }
 
+static void *
+select_accept_handler (void *ah_cls,
+                       struct GNUNET_SelectHandle *sh,
+                       struct GNUNET_SocketHandle *sock,
+                       const void *addr, unsigned int addr_len)
+{
+  static int nonnullpointer;
+
+  if (GNUNET_NO != is_rejected_tester (addr, addr_len))
+    return NULL;    
+  return &nonnullpointer;
+}
+
 /**
- * Allocate and bind a server socket for the UDP transport.
+ * Select has been forced to close a connection.
+ * Free the associated context.
  */
-static int
-listensock (unsigned short port)
+static void
+select_close_handler (void *ch_cls,
+                      struct GNUNET_SelectHandle *sh,
+                      struct GNUNET_SocketHandle *sock, void *sock_ctx)
 {
-  struct sockaddr_in sin;
-  int sock;
-  const int on = 1;
-
-  sock = SOCKET (PF_INET, SOCK_DGRAM, 17);
-  if (sock < 0)
-    {
-      GNUNET_GE_DIE_STRERROR (ectx,
-                              GNUNET_GE_FATAL | GNUNET_GE_ADMIN |
-                              GNUNET_GE_IMMEDIATE, "socket");
-      return -1;
-    }
-  if (SETSOCKOPT (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0)
-    {
-      GNUNET_GE_DIE_STRERROR (ectx,
-                              GNUNET_GE_FATAL | GNUNET_GE_ADMIN |
-                              GNUNET_GE_IMMEDIATE, "setsockopt");
-      return -1;
-    }
-  GNUNET_GE_ASSERT (NULL, port != 0);
-  memset (&sin, 0, sizeof (sin));
-  sin.sin_family = AF_INET;
-  sin.sin_addr.s_addr = INADDR_ANY;
-  sin.sin_port = htons (port);
-  if (BIND (sock, (struct sockaddr *) &sin, sizeof (sin)) < 0)
-    {
-      GNUNET_GE_LOG_STRERROR (ectx,
-                              GNUNET_GE_FATAL | GNUNET_GE_ADMIN |
-                              GNUNET_GE_IMMEDIATE, "bind");
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_FATAL | GNUNET_GE_ADMIN | GNUNET_GE_IMMEDIATE,
-                     _("Failed to bind to UDP port %d.\n"), port);
-      GNUNET_GE_DIE_STRERROR (ectx,
-                              GNUNET_GE_FATAL | GNUNET_GE_USER |
-                              GNUNET_GE_IMMEDIATE, "bind");
-      return -1;
-    }
-  /* do not bind if port == 0, then we use
-     send-only! */
-  return sock;
+  /* do nothing */
 }
 
 /**
- * Check if we are explicitly forbidden to communicate with this IP.
+ * Establish a connection to a remote node.
+ *
+ * @param hello the hello-Message for the target node
+ * @param tsessionPtr the session handle that is to be set
+ * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
  */
 static int
-isBlacklisted (const void *addr, unsigned int addr_len)
+udp_connect (const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr,
+            int may_reuse)
 {
-  GNUNET_IPv4Address ip;
-  int ret;
+  GNUNET_TSession *tsession;
 
-  if (addr_len == sizeof (struct sockaddr_in))
-    {
-      memcpy (&ip, &((struct sockaddr_in *) addr)->sin_addr,
-              sizeof (GNUNET_IPv4Address));
-    }
-  else if (addr_len == sizeof (GNUNET_IPv4Address))
-    {
-      memcpy (&ip, addr, addr_len);
-    }
-  else
-    {
-      return GNUNET_SYSERR;
-    }
-  GNUNET_mutex_lock (configLock);
-  ret = GNUNET_check_ipv4_listed (filteredNetworks_, ip);
-  GNUNET_mutex_unlock (configLock);
-  return ret;
+  tsession = GNUNET_malloc (sizeof (GNUNET_TSession));
+  memset (tsession, 0, sizeof (GNUNET_TSession));
+  tsession->internal = GNUNET_malloc (GNUNET_sizeof_hello (hello));
+  memcpy (tsession->internal, hello, GNUNET_sizeof_hello (hello));
+  tsession->ttype = myAPI.protocolNumber;
+  tsession->peer = hello->senderIdentity;
+  *tsessionPtr = tsession;
+  if (stats != NULL)
+    stats->change (stat_udpConnected, 1);
+  return GNUNET_OK;
 }
 
 /**
- * Check if we are allowed to connect to the given IP.
+ * A (core) Session is to be associated with a transport session. The
+ * transport service may want to know in order to call back on the
+ * core if the connection is being closed.
+ *
+ * @param tsession the session handle passed along
+ *   from the call to receive that was made by the transport
+ *   layer
+ * @return GNUNET_OK if the session could be associated,
+ *         GNUNET_SYSERR if not.
  */
-static int
-isWhitelisted (const void *addr, unsigned int addr_len)
+int
+udp_associate (GNUNET_TSession * tsession)
 {
-  GNUNET_IPv4Address ip;
-  int ret;
+  return GNUNET_SYSERR;         /* UDP connections can never be associated */
+}
 
-  if (addr_len == sizeof (struct sockaddr_in))
+/**
+ * Disconnect from a remote node.
+ *
+ * @param tsession the session that is closed
+ * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
+ */
+static int
+udp_disconnect (GNUNET_TSession * tsession)
+{
+  if (tsession != NULL)
     {
-      memcpy (&ip, &((struct sockaddr_in *) addr)->sin_addr,
-              sizeof (GNUNET_IPv4Address));
+      if (tsession->internal != NULL)
+        GNUNET_free (tsession->internal);
+      GNUNET_free (tsession);
+      if (stats != NULL)
+        stats->change (stat_udpConnected, -1);
     }
-  else if (addr_len == sizeof (GNUNET_IPv4Address))
-    {
-      memcpy (&ip, addr, addr_len);
-    }
-  else
-    {
-      return GNUNET_SYSERR;
-    }
-  ret = GNUNET_OK;
-  GNUNET_mutex_lock (configLock);
-  if (allowedNetworks_ != NULL)
-    ret = GNUNET_check_ipv4_listed (allowedNetworks_, ip);
-  GNUNET_mutex_unlock (configLock);
-  return ret;
+  return GNUNET_OK;
 }
 
+/**
+ * Shutdown the server process (stop receiving inbound traffic). Maybe
+ * restarted later!
+ */
 static int
-isRejected (const void *addr, unsigned int addr_len)
+udp_transport_server_stop ()
 {
-  if ((GNUNET_YES == isBlacklisted (addr,
-                                    addr_len)) ||
-      (GNUNET_YES != isWhitelisted (addr, addr_len)))
+  GNUNET_GE_ASSERT (coreAPI->ectx, udp_sock != NULL);
+  if (selector != NULL)
     {
-#if DEBUG_UDP
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     "Rejecting traffic from %u.%u.%u.%u.\n",
-                     GNUNET_PRIP (ntohl (*(int *) addr)));
-#endif
-      return GNUNET_YES;
+      GNUNET_select_destroy (selector);
+      selector = NULL;
     }
-  return GNUNET_NO;
+  GNUNET_socket_destroy (udp_sock);
+  udp_sock = NULL;
+  return GNUNET_OK;
 }
 
-
 /**
- * Verify that a hello-Message is correct (a node is reachable at that
- * address). Since the reply will be asynchronous, a method must be
- * called on success.
+ * Test if the transport would even try to send
+ * a message of the given size and importance
+ * for the given session.<br>
+ * This function is used to check if the core should
+ * even bother to construct (and encrypt) this kind
+ * of message.
  *
- * @param helo the hello message to verify
- *        (the signature/crc have been verified before)
- * @return GNUNET_OK on success, GNUNET_SYSERR on failure
+ * @return GNUNET_YES if the transport would try (i.e. queue
+ *         the message or call the OS to send),
+ *         GNUNET_NO if the transport would just drop the message,
+ *         GNUNET_SYSERR if the size/session is invalid
  */
 static int
-verifyHello (const GNUNET_MessageHello * hello)
+udp_test_would_try (GNUNET_TSession * tsession, unsigned int size, int 
important)
 {
-  const HostAddress *haddr;
+  const GNUNET_MessageHello *hello;
 
-  haddr = (const HostAddress *) &hello[1];
-  if ((ntohs (hello->senderAddressSize) != sizeof (HostAddress)) ||
-      (ntohs (hello->header.size) != GNUNET_sizeof_hello (hello)) ||
-      (ntohs (hello->header.type) != GNUNET_P2P_PROTO_HELLO))
+  if (udp_sock == NULL)
+    return GNUNET_SYSERR;
+  if (size == 0)
     {
-      GNUNET_GE_BREAK (NULL, 0);
+      GNUNET_GE_BREAK (coreAPI->ectx, 0);
       return GNUNET_SYSERR;
     }
-  if ((GNUNET_YES == isBlacklisted (&haddr->ip,
-                                    sizeof (GNUNET_IPv4Address))) ||
-      (GNUNET_YES != isWhitelisted (&haddr->ip, sizeof (GNUNET_IPv4Address))))
+  if (size > myAPI.mtu)
     {
-#if DEBUG_UDP
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     "Rejecting UDP HELLO from %u.%u.%u.%u:%u due to 
configuration.\n",
-                     GNUNET_PRIP (ntohl (*(int *) &haddr->ip.addr)),
-                     ntohs (haddr->port));
-#endif
-      return GNUNET_SYSERR;     /* obviously invalid */
+      GNUNET_GE_BREAK (coreAPI->ectx, 0);
+      return GNUNET_SYSERR;
     }
-#if DEBUG_UDP
-  GNUNET_GE_LOG (ectx,
-                 GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                 "Verified UDP HELLO from %u.%u.%u.%u:%u.\n",
-                 GNUNET_PRIP (ntohl (*(int *) &haddr->ip.addr)),
-                 ntohs (haddr->port));
-#endif
-  return GNUNET_OK;
+  hello = (const GNUNET_MessageHello *) tsession->internal;
+  if (hello == NULL)
+    return GNUNET_SYSERR;
+  return GNUNET_YES;
 }
 
 /**
- * Create a hello-Message for the current node. The hello is created
- * without signature and without a timestamp. The GNUnet core will
- * GNUNET_RSA_sign the message and add an expiration time.
- *
- * @return hello on success, NULL on error
+ * Create a UDP socket.  If possible, use IPv6, otherwise
+ * try IPv4.  Update available_protocols accordingly.
  */
-static GNUNET_MessageHello *
-createhello ()
+static int
+udp_create_socket()
 {
-  static HostAddress last_addr;
-  GNUNET_MessageHello *msg;
-  HostAddress *haddr;
-  unsigned short port;
+  int s;
 
-  port = getGNUnetUDPPort ();
-  if (port == 0)
-    return NULL;                /* UDP transport configured send-only */
-
-  msg = GNUNET_malloc (sizeof (GNUNET_MessageHello) + sizeof (HostAddress));
-  haddr = (HostAddress *) & msg[1];
-
-
-  if (!(((upnp != NULL) &&
-         (GNUNET_OK == upnp->get_ip (port,
-                                     "UDP",
-                                     &haddr->ip))) ||
-        (GNUNET_SYSERR !=
-         GNUNET_IP_get_public_ipv4_address (cfg, ectx, &haddr->ip))))
+  available_protocols = VERSION_AVAILABLE_NONE;
+#ifndef MINGW
+  s = SOCKET (PF_INET6, SOCK_DGRAM, 17);
+#else
+  s = win_ols_socket (PF_INET6, SOCK_DGRAM, 17);
+#endif
+  if (s < 0)
     {
-      GNUNET_free (msg);
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
-                     GNUNET_GE_BULK,
-                     _("UDP: Could not determine my public IP address.\n"));
-      return NULL;
+#ifndef MINGW
+      s = SOCKET (PF_INET, SOCK_DGRAM, 17);
+#else
+      s = win_ols_socket (PF_INET, SOCK_DGRAM, 17);
+#endif
+      if (s < 0)
+       {
+         GNUNET_GE_LOG_STRERROR (coreAPI->ectx,
+                                 GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
+                                 GNUNET_GE_BULK, "socket");
+         return GNUNET_SYSERR;
+       }
+      available_protocols = VERSION_AVAILABLE_IPV4;
     }
-  haddr->port = htons (port);
-  haddr->reserved = htons (0);
-  if (0 != memcmp (haddr, &last_addr, sizeof (HostAddress)))
+  else
     {
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     "UDP uses IP address %u.%u.%u.%u.\n",
-                     GNUNET_PRIP (ntohl (*(int *) &haddr->ip)));
-      last_addr = *haddr;
-    }
-  msg->senderAddressSize = htons (sizeof (HostAddress));
-  msg->protocol = htons (GNUNET_TRANSPORT_PROTOCOL_NUMBER_UDP);
-  msg->MTU = htonl (udpAPI.mtu);
-  return msg;
+      available_protocols = VERSION_AVAILABLE_IPV6 | VERSION_AVAILABLE_IPV4;
+    } 
+  return s;
 }
 
 /**
@@ -327,13 +308,17 @@
  * @return GNUNET_SYSERR on error, GNUNET_OK on success
  */
 static int
-udpSend (GNUNET_TSession * tsession,
+udp_send (GNUNET_TSession * tsession,
          const void *message, const unsigned int size, int important)
 {
+  const GNUNET_MessageHello *hello;
+  const HostAddress *haddr;
   UDPMessage *mp;
-  GNUNET_MessageHello *hello;
-  HostAddress *haddr;
-  struct sockaddr_in sin;       /* an Internet endpoint address */
+  struct sockaddr_in serverAddrv4;
+  struct sockaddr_in6 serverAddrv6;
+  struct sockaddr * serverAddr;
+  socklen_t addrlen;
+  unsigned short available;
   int ok;
   int ssize;
   size_t sent;
@@ -343,19 +328,23 @@
     return GNUNET_SYSERR;
   if (size == 0)
     {
-      GNUNET_GE_BREAK (ectx, 0);
+      GNUNET_GE_BREAK (coreAPI->ectx, 0);
       return GNUNET_SYSERR;
     }
-  if (size > udpAPI.mtu)
+  if (size > myAPI.mtu)
     {
-      GNUNET_GE_BREAK (ectx, 0);
+      GNUNET_GE_BREAK (coreAPI->ectx, 0);
       return GNUNET_SYSERR;
     }
-  hello = (GNUNET_MessageHello *) tsession->internal;
+  hello = (const GNUNET_MessageHello *) tsession->internal;
   if (hello == NULL)
     return GNUNET_SYSERR;
 
-  haddr = (HostAddress *) & hello[1];
+  available = ntohs(haddr->availability) & available_protocols;
+  if (available  == VERSION_AVAILABLE_NONE)
+    return GNUNET_SYSERR;
+
+  haddr = (const HostAddress *) & hello[1];
   ssize = size + sizeof (UDPMessage);
   mp = GNUNET_malloc (ssize);
   mp->header.size = htons (ssize);
@@ -363,29 +352,37 @@
   mp->sender = *(coreAPI->myIdentity);
   memcpy (&mp[1], message, size);
   ok = GNUNET_SYSERR;
-  memset (&sin, 0, sizeof (sin));
-  sin.sin_family = AF_INET;
-  sin.sin_port = haddr->port;
-
-  GNUNET_GE_ASSERT (ectx,
-                    sizeof (struct in_addr) == sizeof (GNUNET_IPv4Address));
-  memcpy (&sin.sin_addr, &haddr->ip, sizeof (GNUNET_IPv4Address));
-#if DEBUG_UDP
-  GNUNET_GE_LOG (ectx,
-                 GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                 "Sending message of %d bytes via UDP to %u.%u.%u.%u:%u.\n",
-                 ssize, GNUNET_PRIP (ntohl (*(int *) &sin.sin_addr)),
-                 ntohs (sin.sin_port));
-#endif
+  
+  if ((available & VERSION_AVAILABLE_IPV4) > 0)
+    {
+      memset (&serverAddrv4, 0, sizeof (serverAddrv4));
+      serverAddrv4.sin_family = AF_INET;
+      serverAddrv4.sin_port = haddr->port;
+      memcpy (&serverAddrv4.sin_addr, &haddr->ipv4,
+             sizeof (GNUNET_IPv4Address));
+      addrlen = sizeof(serverAddrv4);
+      serverAddr = (struct sockaddr*) &serverAddrv4;
+    } 
+  else
+    {
+      memset (&serverAddrv6, 0, sizeof (serverAddrv6));
+      serverAddrv6.sin6_family = AF_INET;
+      serverAddrv6.sin6_port = haddr->port;
+      memcpy (&serverAddrv6.sin6_addr, &haddr->ipv6,
+             sizeof (GNUNET_IPv6Address));
+      addrlen = sizeof(serverAddrv6);
+      serverAddr = (struct sockaddr*) &serverAddrv6;
+    }
 #ifndef MINGW
   if (GNUNET_YES == GNUNET_socket_send_to (udp_sock,
                                            GNUNET_NC_NONBLOCKING,
                                            mp,
-                                           ssize, &sent, (const char *) &sin,
-                                           sizeof (sin)))
+                                           ssize, &sent, 
+                                          (const char *) serverAddr,
+                                           addrlen))
 #else
   sent =
-    win_ols_sendto (udp_sock, mp, ssize, (const char *) &sin, sizeof (sin));
+    win_ols_sendto (udp_sock, mp, ssize, (const char *) serverAddr, addrlen);
   if (sent != SOCKET_ERROR)
 #endif
     {
@@ -395,12 +392,6 @@
     }
   else
     {
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_BULK,
-                     _
-                     ("Failed to send message of size %d via UDP to 
%u.%u.%u.%u:%u: %s\n"),
-                     ssize, GNUNET_PRIP (ntohl (*(int *) &sin.sin_addr)),
-                     ntohs (sin.sin_port), STRERROR (errno));
       if (stats != NULL)
         stats->change (stat_bytesDropped, ssize);
     }
@@ -414,102 +405,94 @@
  * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
  */
 static int
-startTransportServer ()
+udp_transport_server_start ()
 {
+  struct sockaddr_in serverAddrv4;
+  struct sockaddr_in6 serverAddrv6;
+  struct sockaddr * serverAddr;
+  socklen_t addrlen;
   int sock;
+  const int on = 1;
   unsigned short port;
 
-  GNUNET_GE_ASSERT (ectx, selector == NULL);
+  GNUNET_GE_ASSERT (coreAPI->ectx, selector == NULL);
   /* initialize UDP network */
-  port = getGNUnetUDPPort ();
+  port = get_port ();
   if (port != 0)
-    {
-      sock = listensock (port);
-      if (sock == -1)
-        return GNUNET_SYSERR;
-      selector = GNUNET_select_create ("udp", GNUNET_YES, ectx, load_monitor, 
sock, sizeof (struct sockaddr_in), 0,     /* timeout */
+    {  
+      sock = udp_create_socket();
+      if (sock < 0)
+       return GNUNET_SYSERR;
+      if (SETSOCKOPT (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0)
+       {
+         GNUNET_GE_DIE_STRERROR (coreAPI->ectx,
+                                 GNUNET_GE_FATAL | GNUNET_GE_ADMIN |
+                                 GNUNET_GE_IMMEDIATE, "setsockopt");
+         return GNUNET_SYSERR;
+       }
+      if (available_protocols == VERSION_AVAILABLE_IPV4)
+       {
+         memset (&serverAddrv4, 0, sizeof (serverAddrv4));
+         serverAddrv4.sin_family = AF_INET;
+         serverAddrv4.sin_addr.s_addr = INADDR_ANY;
+         serverAddrv4.sin_port = htons (port);
+         addrlen = sizeof(serverAddrv4);
+         serverAddr = (struct sockaddr*) &serverAddrv4;
+       }
+      else
+       {
+         memset (&serverAddrv6, 0, sizeof (serverAddrv6));
+         serverAddrv6.sin6_family = AF_INET6;
+         serverAddrv6.sin6_addr = in6addr_any;
+         serverAddrv6.sin6_port = htons (port);
+         addrlen = sizeof(serverAddrv6);
+         serverAddr = (struct sockaddr*) &serverAddrv6;
+       }
+      if (BIND (sock, serverAddr, addrlen) < 0)
+       {
+         GNUNET_GE_LOG_STRERROR (coreAPI->ectx,
+                                 GNUNET_GE_FATAL | GNUNET_GE_ADMIN |
+                                 GNUNET_GE_IMMEDIATE, "bind");
+         GNUNET_GE_LOG (coreAPI->ectx,
+                        GNUNET_GE_FATAL | GNUNET_GE_ADMIN | 
GNUNET_GE_IMMEDIATE,
+                        _("Failed to bind to %s port %d.\n"), 
+                        MY_TRANSPORT_NAME,
+                        port);
+         if (0 != CLOSE (sock))
+           GNUNET_GE_LOG_STRERROR (coreAPI->ectx,
+                                   GNUNET_GE_ERROR | GNUNET_GE_USER |
+                                   GNUNET_GE_ADMIN | GNUNET_GE_BULK,
+                                   "close");
+         return GNUNET_SYSERR;
+       }
+      selector = GNUNET_select_create ("udp", GNUNET_YES, coreAPI->ectx, 
load_monitor, sock,
+                                      addrlen, 0,     /* timeout */
                                        &select_message_handler,
                                        NULL,
                                        &select_accept_handler,
-                                       &isRejected,
+                                       NULL,
                                        &select_close_handler,
                                        NULL, 64 * 1024,
                                        16 /* max sockets */ );
       if (selector == NULL)
         return GNUNET_SYSERR;
     }
-#ifndef MINGW
-  sock = SOCKET (PF_INET, SOCK_DGRAM, 17);
-#else
-  sock = win_ols_socket (PF_INET, SOCK_DGRAM, 17);
-#endif
+  sock = udp_create_socket();
   if (sock == -1)
     {
-      GNUNET_GE_LOG_STRERROR (ectx,
+      GNUNET_GE_LOG_STRERROR (coreAPI->ectx,
                               GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
                               GNUNET_GE_BULK, "socket");
       GNUNET_select_destroy (selector);
       selector = NULL;
       return GNUNET_SYSERR;
     }
-  udp_sock = GNUNET_socket_create (ectx, load_monitor, sock);
-  GNUNET_GE_ASSERT (ectx, udp_sock != NULL);
+  udp_sock = GNUNET_socket_create (coreAPI->ectx, load_monitor, sock);
+  GNUNET_GE_ASSERT (coreAPI->ectx, udp_sock != NULL);
   return GNUNET_OK;
 }
 
 /**
- * Reload the configuration. Should never fail.
- */
-static int
-reloadConfiguration ()
-{
-  char *ch;
-
-  GNUNET_mutex_lock (configLock);
-  GNUNET_free_non_null (filteredNetworks_);
-  GNUNET_free_non_null (allowedNetworks_);
-  ch = NULL;
-  GNUNET_GC_get_configuration_value_string (cfg, "UDP", "BLACKLIST", "", &ch);
-  filteredNetworks_ = GNUNET_parse_ipv4_network_specification (ectx, ch);
-  GNUNET_free (ch);
-  ch = NULL;
-  GNUNET_GC_get_configuration_value_string (cfg, "UDP", "WHITELIST", "", &ch);
-  if (strlen (ch) > 0)
-    allowedNetworks_ = GNUNET_parse_ipv4_network_specification (ectx, ch);
-  else
-    allowedNetworks_ = NULL;
-  GNUNET_free (ch);
-  GNUNET_mutex_unlock (configLock);
-  return 0;
-}
-
-/**
- * Convert UDP hello to IP address
- */
-static int
-helloToAddress (const GNUNET_MessageHello * hello,
-                void **sa, unsigned int *sa_len)
-{
-  const HostAddress *haddr = (const HostAddress *) &hello[1];
-  struct sockaddr_in *serverAddr;
-
-  *sa_len = sizeof (struct sockaddr_in);
-  serverAddr = GNUNET_malloc (sizeof (struct sockaddr_in));
-  *sa = serverAddr;
-  memset (serverAddr, 0, sizeof (struct sockaddr_in));
-  serverAddr->sin_family = AF_INET;
-  memcpy (&serverAddr->sin_addr, haddr, sizeof (GNUNET_IPv4Address));
-  serverAddr->sin_port = haddr->port;
-  return GNUNET_OK;
-}
-
-/**
- * The default maximum size of each outbound UDP message,
- * optimal value for Ethernet (10 or 100 MBit).
- */
-#define MESSAGE_SIZE 1472
-
-/**
  * The exported method. Makes the core api available via a global and
  * returns the udp transport API.
  */
@@ -518,11 +501,9 @@
 {
   unsigned long long mtu;
 
-  ectx = core->ectx;
   cfg = core->cfg;
   load_monitor = core->load_monitor;
-  GNUNET_GE_ASSERT (ectx, sizeof (HostAddress) == 8);
-  GNUNET_GE_ASSERT (ectx, sizeof (UDPMessage) == 68);
+  GNUNET_GE_ASSERT (coreAPI->ectx, sizeof (UDPMessage) == 68);
   coreAPI = core;
   if (-1 == GNUNET_GC_get_configuration_value_number (cfg,
                                                       "UDP",
@@ -539,16 +520,22 @@
       return NULL;
     }
   if (mtu < 1200)
-    GNUNET_GE_LOG (ectx,
+    GNUNET_GE_LOG (coreAPI->ectx,
                    GNUNET_GE_ERROR | GNUNET_GE_USER | GNUNET_GE_IMMEDIATE,
                    _("MTU %llu for `%s' is probably too low!\n"), mtu, "UDP");
+  lock = GNUNET_mutex_create (GNUNET_NO);
+  if (0 != GNUNET_GC_attach_change_listener (cfg, &reload_configuration, NULL))
+    {
+      GNUNET_mutex_destroy (lock);
+      lock = NULL;
+      return NULL;
+    }
   if (GNUNET_GC_get_configuration_value_yesno (cfg, "UDP", "UPNP", GNUNET_YES)
       == GNUNET_YES)
     {
       upnp = coreAPI->request_service ("upnp");
-
       if (upnp == NULL)
-        GNUNET_GE_LOG (ectx,
+        GNUNET_GE_LOG (coreAPI->ectx,
                        GNUNET_GE_ERROR | GNUNET_GE_USER | GNUNET_GE_IMMEDIATE,
                        "The UPnP service could not be loaded. To disable UPnP, 
set the "
                        "configuration option \"UPNP\" in section \"UDP\" to 
\"NO\"\n");
@@ -564,42 +551,27 @@
       stat_udpConnected
         = stats->create (gettext_noop ("# UDP connections (right now)"));
     }
-  configLock = GNUNET_mutex_create (GNUNET_NO);
-  reloadConfiguration ();
-  udpAPI.protocolNumber = GNUNET_TRANSPORT_PROTOCOL_NUMBER_UDP;
-  udpAPI.mtu = mtu - sizeof (UDPMessage);
-  udpAPI.cost = 20000;
-  udpAPI.verifyHello = &verifyHello;
-  udpAPI.createhello = &createhello;
-  udpAPI.connect = &udpConnect;
-  udpAPI.send = &udpSend;
-  udpAPI.associate = &udpAssociate;
-  udpAPI.disconnect = &udpDisconnect;
-  udpAPI.startTransportServer = &startTransportServer;
-  udpAPI.stopTransportServer = &stopTransportServer;
-  udpAPI.helloToAddress = &helloToAddress;
-  udpAPI.testWouldTry = &testWouldTry;
+  myAPI.protocolNumber = GNUNET_TRANSPORT_PROTOCOL_NUMBER_UDP;
+  myAPI.mtu = mtu - sizeof (UDPMessage);
+  myAPI.cost = 20000;
+  myAPI.verifyHello = &verify_hello;
+  myAPI.createhello = &create_hello;
+  myAPI.connect = &udp_connect;
+  myAPI.send = &udp_send;
+  myAPI.associate = &udp_associate;
+  myAPI.disconnect = &udp_disconnect;
+  myAPI.startTransportServer = &udp_transport_server_start;
+  myAPI.stopTransportServer = &udp_transport_server_stop;
+  myAPI.helloToAddress = &hello_to_address;
+  myAPI.testWouldTry = &udp_test_would_try;
 
-  return &udpAPI;
+  return &myAPI;
 }
 
 void
 donetransport_udp ()
 {
-  if (stats != NULL)
-    {
-      coreAPI->release_service (stats);
-      stats = NULL;
-    }
-  if (upnp != NULL)
-    {
-      coreAPI->release_service (upnp);
-      upnp = NULL;
-    }
-  GNUNET_mutex_destroy (configLock);
-  configLock = NULL;
-  GNUNET_free_non_null (filteredNetworks_);
-  coreAPI = NULL;
+  do_shutdown();
 }
 
 /* end of udp.c */

Deleted: GNUnet/src/transports/udp6.c
===================================================================
--- GNUnet/src/transports/udp6.c        2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/src/transports/udp6.c        2008-02-10 06:45:34 UTC (rev 6220)
@@ -1,536 +0,0 @@
-/*
-     This file is part of GNUnet
-     (C) 2003, 2004, 2005, 2007 Christian Grothoff (and other contributing 
authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file transports/udp6.c
- * @brief Implementation of the UDP transport service over IPv6
- * @author Christian Grothoff
- */
-
-#include "gnunet_util.h"
-#include "gnunet_protocols.h"
-#include "gnunet_transport.h"
-#include "gnunet_stats_service.h"
-#include "platform.h"
-#include "ip.h"
-#include "ip6.h"
-
-#define DEBUG_UDP6 GNUNET_NO
-
-#include "udp_helper.c"
-
-/**
- * Host-Address in a UDP6 network.
- */
-typedef struct
-{
-  /**
-   * claimed IP of the sender, network byte order
-   */
-  GNUNET_IPv6Address ip;
-
-  /**
-   * claimed port of the sender, network byte order
-   */
-  unsigned short port;
-
-  /**
-   * reserved (set to 0 for signature verification)
-   */
-  unsigned short reserved;
-
-} Host6Address;
-
-/* *********** globals ************* */
-
-static struct GNUNET_GC_Configuration *cfg;
-
-static struct GNUNET_LoadMonitor *load_monitor;
-
-static struct GNUNET_IPv6NetworkSet *filteredNetworks_;
-
-static struct GNUNET_IPv6NetworkSet *allowedNetworks_;
-
-static struct GNUNET_Mutex *configLock;
-
-/**
- * Get the GNUnet UDP6 port from the configuration, or from
- * /etc/services if it is not specified in the config file.
- *
- * @return the port in host byte order
- */
-static unsigned short
-getGNUnetUDP6Port ()
-{
-  struct servent *pse;          /* pointer to service information entry        
*/
-  unsigned long long port;
-
-  if (-1 == GNUNET_GC_get_configuration_value_number (cfg,
-                                                      "UDP6",
-                                                      "PORT", 1, 65535, 2086,
-                                                      &port))
-    {
-      if ((pse = getservbyname ("gnunet", "udp")))
-        port = htons (pse->s_port);
-      else
-        port = 0;
-    }
-  return (unsigned short) port;
-}
-
-/**
- * Allocate and bind a server socket for the UDP6 transport.
- */
-static int
-passivesock (unsigned short port)
-{
-  struct sockaddr_in6 sin;
-  int sock;
-  const int on = 1;
-
-  sock = SOCKET (PF_INET6, SOCK_DGRAM, 17);
-  if (sock < 0)
-    GNUNET_GE_DIE_STRERROR (ectx,
-                            GNUNET_GE_FATAL | GNUNET_GE_ADMIN |
-                            GNUNET_GE_IMMEDIATE, "socket");
-  if (SETSOCKOPT (sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) < 0)
-    GNUNET_GE_DIE_STRERROR (ectx,
-                            GNUNET_GE_FATAL | GNUNET_GE_ADMIN |
-                            GNUNET_GE_IMMEDIATE, "setsockopt");
-  if (port != 0)
-    {
-      memset (&sin, 0, sizeof (sin));
-      sin.sin6_family = AF_INET6;
-      sin.sin6_port = htons (port);
-      memcpy (&sin.sin6_addr, &in6addr_any, sizeof (GNUNET_IPv6Address));
-      if (BIND (sock, (struct sockaddr *) &sin, sizeof (sin)) < 0)
-        {
-          GNUNET_GE_LOG_STRERROR (ectx,
-                                  GNUNET_GE_FATAL | GNUNET_GE_ADMIN |
-                                  GNUNET_GE_IMMEDIATE, "bind");
-          GNUNET_GE_LOG (ectx,
-                         GNUNET_GE_FATAL | GNUNET_GE_ADMIN |
-                         GNUNET_GE_IMMEDIATE,
-                         _("Failed to bind to UDP port %d.\n"), port);
-          GNUNET_GE_DIE_STRERROR (ectx,
-                                  GNUNET_GE_FATAL | GNUNET_GE_USER |
-                                  GNUNET_GE_IMMEDIATE, "bind");
-        }
-    }                           /* do not bind if port == 0, then we use 
send-only! */
-  return sock;
-}
-
-/**
- * Check if we are explicitly forbidden to communicate with this IP.
- */
-static int
-isBlacklisted (const void *addr, unsigned int addr_len)
-{
-  GNUNET_IPv6Address ip;
-  int ret;
-
-  if (addr_len == sizeof (GNUNET_IPv6Address))
-    {
-      memcpy (&ip, addr, sizeof (GNUNET_IPv6Address));
-    }
-  else if (addr_len == sizeof (struct sockaddr_in6))
-    {
-      memcpy (&ip,
-              &((struct sockaddr_in6 *) addr)->sin6_addr,
-              sizeof (GNUNET_IPv6Address));
-    }
-  else
-    {
-      return GNUNET_SYSERR;
-    }
-  GNUNET_mutex_lock (configLock);
-  ret = GNUNET_check_ipv6_listed (filteredNetworks_, ip);
-  GNUNET_mutex_unlock (configLock);
-  return ret;
-}
-
-/**
- * Check if we are allowed to connect to the given IP.
- */
-static int
-isWhitelisted (const void *addr, unsigned int addr_len)
-{
-  GNUNET_IPv6Address ip;
-  int ret;
-
-  if (addr_len == sizeof (GNUNET_IPv6Address))
-    {
-      memcpy (&ip, addr, sizeof (GNUNET_IPv6Address));
-    }
-  else if (addr_len == sizeof (struct sockaddr_in6))
-    {
-      memcpy (&ip,
-              &((struct sockaddr_in6 *) addr)->sin6_addr,
-              sizeof (GNUNET_IPv6Address));
-    }
-  else
-    {
-      return GNUNET_SYSERR;
-    }
-  ret = GNUNET_OK;
-  GNUNET_mutex_lock (configLock);
-  if (allowedNetworks_ != NULL)
-    ret = GNUNET_check_ipv6_listed (filteredNetworks_, ip);
-  GNUNET_mutex_unlock (configLock);
-  return ret;
-}
-
-
-static int
-isRejected (const void *addr, unsigned int addr_len)
-{
-  if ((GNUNET_YES == isBlacklisted (addr,
-                                    addr_len)) ||
-      (GNUNET_YES != isWhitelisted (addr, addr_len)))
-    return GNUNET_YES;
-  return GNUNET_NO;
-}
-
-
-/* *************** API implementation *************** */
-
-/**
- * Verify that a hello-Message is correct (a node is reachable at that
- * address). Since the reply will be asynchronous, a method must be
- * called on success.
- *
- * @param hello the hello message to verify
- *        (the signature/crc have been verified before)
- * @return GNUNET_OK on success, GNUNET_SYSERR on failure
- */
-static int
-verifyHello (const GNUNET_MessageHello * hello)
-{
-  Host6Address *haddr;
-
-  haddr = (Host6Address *) & hello[1];
-  if ((ntohs (hello->senderAddressSize) != sizeof (Host6Address)) ||
-      (ntohs (hello->header.size) != GNUNET_sizeof_hello (hello)) ||
-      (ntohs (hello->header.type) != GNUNET_P2P_PROTO_HELLO) ||
-      (GNUNET_YES == isBlacklisted (&haddr->ip,
-                                    sizeof (GNUNET_IPv6Address))) ||
-      (GNUNET_YES != isWhitelisted (&haddr->ip, sizeof (GNUNET_IPv6Address))))
-    return GNUNET_SYSERR;       /* obviously invalid */
-  else
-    {
-#if DEBUG_UDP6
-      char inet6[INET6_ADDRSTRLEN];
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_DEBUG | GNUNET_GE_REQUEST | GNUNET_GE_USER,
-                     "Verified UDP6 hello from %u.%u.%u.%u:%u.\n",
-                     inet_ntop (AF_INET6, &haddr->ip, inet6,
-                                INET6_ADDRSTRLEN), ntohs (haddr->port));
-#endif
-      return GNUNET_OK;
-    }
-}
-
-/**
- * Create a hello-Message for the current node. The hello is created
- * without signature and without a timestamp. The GNUnet core will
- * GNUNET_RSA_sign the message and add an expiration time.
- *
- * @return hello on success, NULL on error
- */
-static GNUNET_MessageHello *
-createhello ()
-{
-  GNUNET_MessageHello *msg;
-  Host6Address *haddr;
-  unsigned short port;
-
-  port = getGNUnetUDP6Port ();
-  if (port == 0)
-    return NULL;                /* UDP6 transport configured send-only */
-
-  msg = GNUNET_malloc (sizeof (GNUNET_MessageHello) + sizeof (Host6Address));
-  haddr = (Host6Address *) & msg[1];
-
-  if (GNUNET_SYSERR == getPublicIP6Address (cfg, ectx, &haddr->ip))
-    {
-      GNUNET_free (msg);
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_WARNING,
-                     _
-                     ("UDP6: Could not determine my public IPv6 address.\n"));
-      return NULL;
-    }
-  haddr->port = htons (port);
-  haddr->reserved = htons (0);
-  msg->senderAddressSize = htons (sizeof (Host6Address));
-  msg->protocol = htons (GNUNET_TRANSPORT_PROTOCOL_NUMBER_UDP6);
-  msg->MTU = htonl (udpAPI.mtu);
-  return msg;
-}
-
-/**
- * Send a message to the specified remote node.
- *
- * @param tsession the GNUNET_MessageHello identifying the remote node
- * @param message what to send
- * @param size the size of the message
- * @return GNUNET_SYSERR on error, GNUNET_OK on success
- */
-static int
-udp6Send (GNUNET_TSession * tsession,
-          const void *message, const unsigned int size, int importance)
-{
-  UDPMessage *mp;
-  GNUNET_MessageHello *hello;
-  Host6Address *haddr;
-  struct sockaddr_in6 sin;      /* an Internet endpoint address */
-  int ok;
-  size_t ssize;
-#if DEBUG_UDP6
-  char inet6[INET6_ADDRSTRLEN];
-#endif
-
-  if (udp_sock == NULL)
-    return GNUNET_SYSERR;
-  if (size == 0)
-    {
-      GNUNET_GE_BREAK (ectx, 0);
-      return GNUNET_SYSERR;
-    }
-  if (size > udpAPI.mtu)
-    {
-      GNUNET_GE_BREAK (ectx, 0);
-      return GNUNET_SYSERR;
-    }
-  hello = (GNUNET_MessageHello *) tsession->internal;
-  if (hello == NULL)
-    return GNUNET_SYSERR;
-
-  haddr = (Host6Address *) & hello[1];
-  ssize = size + sizeof (UDPMessage);
-  mp = GNUNET_malloc (ssize);
-  mp->header.size = htons (ssize);
-  mp->header.type = 0;
-  mp->sender = *coreAPI->myIdentity;
-  memcpy (&mp[1], message, size);
-  ok = GNUNET_SYSERR;
-  memset (&sin, 0, sizeof (sin));
-  sin.sin6_family = AF_INET6;
-  sin.sin6_port = haddr->port;
-  memcpy (&sin.sin6_addr, &haddr->ip.addr, sizeof (GNUNET_IPv6Address));
-#if DEBUG_UDP6
-  GNUNET_GE_LOG (ectx,
-                 GNUNET_GE_DEBUG,
-                 "Sending message of %u bytes via UDP6 to %s:%d..\n",
-                 ssize,
-                 inet_ntop (AF_INET6,
-                            &sin, inet6, INET6_ADDRSTRLEN),
-                 ntohs (sin.sin_port));
-#endif
-  if (GNUNET_YES == GNUNET_socket_send_to (udp_sock,
-                                           GNUNET_NC_NONBLOCKING,
-                                           mp,
-                                           ssize,
-                                           &ssize, (const char *) &sin,
-                                           sizeof (sin)))
-    {
-      ok = GNUNET_OK;
-      if (stats != NULL)
-        stats->change (stat_bytesSent, ssize);
-    }
-  else
-    {
-      GNUNET_GE_LOG_STRERROR (ectx, GNUNET_GE_WARNING, "sendto");
-      if (stats != NULL)
-        stats->change (stat_bytesDropped, ssize);
-    }
-  GNUNET_free (mp);
-  return ok;
-}
-
-/**
- * Start the server process to receive inbound traffic.
- *
- * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
- */
-static int
-startTransportServer ()
-{
-  int sock;
-  unsigned short port;
-
-  /* initialize UDP6 network */
-  port = getGNUnetUDP6Port ();
-  if (port != 0)
-    {
-      sock = passivesock (port);
-      if (sock == -1)
-        return GNUNET_SYSERR;
-      selector = GNUNET_select_create ("udp6", GNUNET_YES, ectx, load_monitor, 
sock, sizeof (struct sockaddr_in6), 0,   /* timeout */
-                                       &select_message_handler,
-                                       NULL,
-                                       &select_accept_handler,
-                                       &isRejected,
-                                       &select_close_handler,
-                                       NULL, 64 * 1024,
-                                       16 /* max sockets */ );
-      if (selector == NULL)
-        return GNUNET_SYSERR;
-    }
-  sock = SOCKET (PF_INET, SOCK_DGRAM, 17);
-  if (sock == -1)
-    {
-      GNUNET_GE_LOG_STRERROR (ectx,
-                              GNUNET_GE_ERROR | GNUNET_GE_ADMIN |
-                              GNUNET_GE_BULK, "socket");
-      GNUNET_select_destroy (selector);
-      selector = NULL;
-      return GNUNET_SYSERR;
-    }
-  udp_sock = GNUNET_socket_create (ectx, load_monitor, sock);
-  return GNUNET_OK;
-}
-
-/**
- * Reload the configuration. Should never fail.
- */
-static int
-reloadConfiguration ()
-{
-  char *ch;
-
-  GNUNET_mutex_lock (configLock);
-  GNUNET_free_non_null (filteredNetworks_);
-  GNUNET_GC_get_configuration_value_string (cfg, "UDP6", "BLACKLIST", "",
-                                            &ch);
-  filteredNetworks_ = GNUNET_parse_ipv6_network_specification (ectx, ch);
-  GNUNET_free (ch);
-  GNUNET_GC_get_configuration_value_string (cfg, "UDP6", "WHITELIST", "",
-                                            &ch);
-  if (strlen (ch) > 0)
-    allowedNetworks_ = GNUNET_parse_ipv6_network_specification (ectx, ch);
-  else
-    allowedNetworks_ = NULL;
-  GNUNET_free (ch);
-  GNUNET_mutex_unlock (configLock);
-  return 0;
-}
-
-/**
- * Convert UDP6 hello to IPv6 address
- */
-static int
-helloToAddress (const GNUNET_MessageHello * hello,
-                void **sa, unsigned int *sa_len)
-{
-  const Host6Address *haddr = (const Host6Address *) &hello[1];
-  struct sockaddr_in6 *serverAddr;
-
-  *sa_len = sizeof (struct sockaddr_in6);
-  serverAddr = GNUNET_malloc (sizeof (struct sockaddr_in6));
-  *sa = serverAddr;
-  memset (serverAddr, 0, sizeof (struct sockaddr_in6));
-  serverAddr->sin6_family = AF_INET6;
-  memcpy (&serverAddr->sin6_addr, haddr, sizeof (GNUNET_IPv6Address));
-  serverAddr->sin6_port = haddr->port;
-  return GNUNET_OK;
-}
-
-/**
- * The default maximum size of each outbound UDP6 message,
- * optimal value for Ethernet (10 or 100 MBit).
- */
-#define MESSAGE_SIZE 1452
-
-/**
- * The exported method. Makes the core api available via a global and
- * returns the udp6 transport API.
- */
-GNUNET_TransportAPI *
-inittransport_udp6 (GNUNET_CoreAPIForTransport * core)
-{
-  unsigned long long mtu;
-
-  GNUNET_GE_ASSERT (ectx, sizeof (UDPMessage) == 68);
-  coreAPI = core;
-  ectx = core->ectx;
-  cfg = core->cfg;
-  configLock = GNUNET_mutex_create (GNUNET_NO);
-
-  reloadConfiguration ();
-  if (-1 == GNUNET_GC_get_configuration_value_number (cfg,
-                                                      "UDP6",
-                                                      "MTU",
-                                                      sizeof (UDPMessage) +
-                                                      
GNUNET_P2P_MESSAGE_OVERHEAD
-                                                      +
-                                                      sizeof
-                                                      (GNUNET_MessageHeader) +
-                                                      32, 65500,
-                                                      MESSAGE_SIZE, &mtu))
-    {
-      return NULL;
-    }
-  if (mtu < 1200)
-    GNUNET_GE_LOG (ectx,
-                   GNUNET_GE_ERROR | GNUNET_GE_USER | GNUNET_GE_IMMEDIATE,
-                   _("MTU %llu for `%s' is probably too low!\n"), mtu,
-                   "UDP6");
-  stats = coreAPI->request_service ("stats");
-  if (stats != NULL)
-    {
-      stat_bytesReceived
-        = stats->create (gettext_noop ("# bytes received via UDP6"));
-      stat_bytesSent = stats->create (gettext_noop ("# bytes sent via UDP6"));
-      stat_bytesDropped
-        = stats->create (gettext_noop ("# bytes dropped by UDP6 (outgoing)"));
-      stat_udpConnected
-        = stats->create (gettext_noop ("# UDP6 connections (right now)"));
-    }
-  udpAPI.protocolNumber = GNUNET_TRANSPORT_PROTOCOL_NUMBER_UDP6;
-  udpAPI.mtu = mtu - sizeof (UDPMessage);
-  udpAPI.cost = 19950;
-  udpAPI.verifyHello = &verifyHello;
-  udpAPI.createhello = &createhello;
-  udpAPI.connect = &udpConnect;
-  udpAPI.send = &udp6Send;
-  udpAPI.associate = &udpAssociate;
-  udpAPI.disconnect = &udpDisconnect;
-  udpAPI.startTransportServer = &startTransportServer;
-  udpAPI.stopTransportServer = &stopTransportServer;
-  udpAPI.helloToAddress = &helloToAddress;
-  udpAPI.testWouldTry = &testWouldTry;
-
-  return &udpAPI;
-}
-
-void
-donetransport_udp6 ()
-{
-  if (stats != NULL)
-    {
-      coreAPI->release_service (stats);
-      stats = NULL;
-    }
-  GNUNET_mutex_destroy (configLock);
-  GNUNET_free_non_null (filteredNetworks_);
-}
-
-/* end of udp6.c */

Deleted: GNUnet/src/transports/udp_helper.c
===================================================================
--- GNUnet/src/transports/udp_helper.c  2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/src/transports/udp_helper.c  2008-02-10 06:45:34 UTC (rev 6220)
@@ -1,259 +0,0 @@
-/*
-     This file is part of GNUnet
-     (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 Christian Grothoff (and 
other contributing authors)
-
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 2, or (at your
-     option) any later version.
-
-     GNUnet is distributed in the hope that it will be useful, but
-     WITHOUT ANY WARRANTY; without even the implied warranty of
-     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
-
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-     Boston, MA 02111-1307, USA.
-*/
-
-/**
- * @file transports/udp_helper.c
- * @brief common code for UDP transports
- * @author Christian Grothoff
- */
-
-typedef int (*BlacklistedTester) (const void *addr, unsigned int addr_len);
-
-/**
- * Message-Packet header.
- */
-typedef struct
-{
-  /**
-   * size of the message, in bytes, including this header.
-   */
-  GNUNET_MessageHeader header;
-
-  /**
-   * What is the identity of the sender (GNUNET_hash of public key)
-   */
-  GNUNET_PeerIdentity sender;
-
-} UDPMessage;
-
-/* *********** globals ************* */
-
-static GNUNET_CoreAPIForTransport *coreAPI;
-
-static GNUNET_TransportAPI udpAPI;
-
-static GNUNET_Stats_ServiceAPI *stats;
-
-static int stat_bytesReceived;
-
-static int stat_bytesSent;
-
-static int stat_bytesDropped;
-
-static int stat_udpConnected;
-
-static struct GNUNET_GE_Context *ectx;
-
-/**
- * thread that listens for inbound messages
- */
-static struct GNUNET_SelectHandle *selector;
-
-/**
- * the socket that we transmit all data with
- */
-static struct GNUNET_SocketHandle *udp_sock;
-
-/**
- * The socket of session has data waiting, process!
- *
- * This function may only be called if the tcplock is
- * already held by the caller.
- */
-static int
-select_message_handler (void *mh_cls,
-                        struct GNUNET_SelectHandle *sh,
-                        struct GNUNET_SocketHandle *sock,
-                        void *sock_ctx, const GNUNET_MessageHeader * msg)
-{
-  unsigned int len;
-  GNUNET_TransportPacket *mp;
-  const UDPMessage *um;
-
-  len = ntohs (msg->size);
-  if (len <= sizeof (UDPMessage))
-    {
-      GNUNET_GE_LOG (ectx,
-                     GNUNET_GE_WARNING | GNUNET_GE_USER | GNUNET_GE_BULK,
-                     _
-                     ("Received malformed message from udp-peer connection. 
Closing.\n"));
-      return GNUNET_SYSERR;
-    }
-#if DEBUG_UDP
-  GNUNET_GE_LOG (ectx,
-                 GNUNET_GE_DEBUG | GNUNET_GE_USER | GNUNET_GE_BULK,
-                 "Received %d bytes via UDP\n", len);
-#endif
-  um = (const UDPMessage *) msg;
-  mp = GNUNET_malloc (sizeof (GNUNET_TransportPacket));
-  mp->msg = GNUNET_malloc (len - sizeof (UDPMessage));
-  memcpy (mp->msg, &um[1], len - sizeof (UDPMessage));
-  mp->sender = um->sender;
-  mp->size = len - sizeof (UDPMessage);
-  mp->tsession = NULL;
-  coreAPI->receive (mp);
-  if (stats != NULL)
-    stats->change (stat_bytesReceived, len);
-  return GNUNET_OK;
-}
-
-static void *
-select_accept_handler (void *ah_cls,
-                       struct GNUNET_SelectHandle *sh,
-                       struct GNUNET_SocketHandle *sock,
-                       const void *addr, unsigned int addr_len)
-{
-  static int nonnullpointer;
-  BlacklistedTester blt = ah_cls;
-  if (GNUNET_NO != blt (addr, addr_len))
-    return NULL;
-  return &nonnullpointer;
-}
-
-/**
- * Select has been forced to close a connection.
- * Free the associated context.
- */
-static void
-select_close_handler (void *ch_cls,
-                      struct GNUNET_SelectHandle *sh,
-                      struct GNUNET_SocketHandle *sock, void *sock_ctx)
-{
-  /* do nothing */
-}
-
-/**
- * Establish a connection to a remote node.
- *
- * @param hello the hello-Message for the target node
- * @param tsessionPtr the session handle that is to be set
- * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
- */
-static int
-udpConnect (const GNUNET_MessageHello * hello, GNUNET_TSession ** tsessionPtr,
-            int may_reuse)
-{
-  GNUNET_TSession *tsession;
-
-  tsession = GNUNET_malloc (sizeof (GNUNET_TSession));
-  memset (tsession, 0, sizeof (GNUNET_TSession));
-  tsession->internal = GNUNET_malloc (GNUNET_sizeof_hello (hello));
-  memcpy (tsession->internal, hello, GNUNET_sizeof_hello (hello));
-  tsession->ttype = udpAPI.protocolNumber;
-  tsession->peer = hello->senderIdentity;
-  *tsessionPtr = tsession;
-  if (stats != NULL)
-    stats->change (stat_udpConnected, 1);
-  return GNUNET_OK;
-}
-
-/**
- * A (core) Session is to be associated with a transport session. The
- * transport service may want to know in order to call back on the
- * core if the connection is being closed.
- *
- * @param tsession the session handle passed along
- *   from the call to receive that was made by the transport
- *   layer
- * @return GNUNET_OK if the session could be associated,
- *         GNUNET_SYSERR if not.
- */
-int
-udpAssociate (GNUNET_TSession * tsession)
-{
-  return GNUNET_SYSERR;         /* UDP connections can never be associated */
-}
-
-/**
- * Disconnect from a remote node.
- *
- * @param tsession the session that is closed
- * @return GNUNET_OK on success, GNUNET_SYSERR if the operation failed
- */
-static int
-udpDisconnect (GNUNET_TSession * tsession)
-{
-  if (tsession != NULL)
-    {
-      if (tsession->internal != NULL)
-        GNUNET_free (tsession->internal);
-      GNUNET_free (tsession);
-      if (stats != NULL)
-        stats->change (stat_udpConnected, -1);
-    }
-  return GNUNET_OK;
-}
-
-/**
- * Shutdown the server process (stop receiving inbound traffic). Maybe
- * restarted later!
- */
-static int
-stopTransportServer ()
-{
-  GNUNET_GE_ASSERT (ectx, udp_sock != NULL);
-  if (selector != NULL)
-    {
-      GNUNET_select_destroy (selector);
-      selector = NULL;
-    }
-  GNUNET_socket_destroy (udp_sock);
-  udp_sock = NULL;
-  return GNUNET_OK;
-}
-
-/**
- * Test if the transport would even try to send
- * a message of the given size and importance
- * for the given session.<br>
- * This function is used to check if the core should
- * even bother to construct (and encrypt) this kind
- * of message.
- *
- * @return GNUNET_YES if the transport would try (i.e. queue
- *         the message or call the OS to send),
- *         GNUNET_NO if the transport would just drop the message,
- *         GNUNET_SYSERR if the size/session is invalid
- */
-static int
-testWouldTry (GNUNET_TSession * tsession, unsigned int size, int important)
-{
-  const GNUNET_MessageHello *hello;
-
-  if (udp_sock == NULL)
-    return GNUNET_SYSERR;
-  if (size == 0)
-    {
-      GNUNET_GE_BREAK (ectx, 0);
-      return GNUNET_SYSERR;
-    }
-  if (size > udpAPI.mtu)
-    {
-      GNUNET_GE_BREAK (ectx, 0);
-      return GNUNET_SYSERR;
-    }
-  hello = (const GNUNET_MessageHello *) tsession->internal;
-  if (hello == NULL)
-    return GNUNET_SYSERR;
-  return GNUNET_YES;
-}
-
-
-/* end of udp_helper.c */

Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2008-02-10 06:35:35 UTC (rev 6219)
+++ GNUnet/todo 2008-02-10 06:45:34 UTC (rev 6220)
@@ -5,8 +5,10 @@
 
 0.7.4 [4'08] (aka "fix search"):
 - modify datastore to return diverse subsets of large response sets,
-  except when processing for loopback!
-- make sure core polls whenever outbound bandwidth is available
+  except when processing for loopback! [RC]
+- make sure core polls whenever outbound bandwidth is available [RC]
+- complete IPv4/IPv6 integration of transports (http is missing!) [RC]
+- integrated hostlist server application using libmicrohttpd [RC]
 - Insert/Index a "shared directory" automatically [Nils]
   See also: https://gnunet.org/drupal/?q=node/97 [RC]
   Furthermore: Blake suggested indexing a document only after





reply via email to

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