[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3133 - in GNUnet: . src/include src/transports src/util/co
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3133 - in GNUnet: . src/include src/transports src/util/config_impl src/util/network |
Date: |
Tue, 25 Jul 2006 02:03:14 -0700 (PDT) |
Author: grothoff
Date: 2006-07-25 02:03:10 -0700 (Tue, 25 Jul 2006)
New Revision: 3133
Modified:
GNUnet/src/include/gnunet_core.h
GNUnet/src/include/gnunet_transport.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/ip6.c
GNUnet/src/transports/ip6.h
GNUnet/src/transports/tcp.c
GNUnet/src/util/config_impl/impl.c
GNUnet/src/util/network/io.c
GNUnet/todo
Log:
towards tcp transport compiling
Modified: GNUnet/src/include/gnunet_core.h
===================================================================
--- GNUnet/src/include/gnunet_core.h 2006-07-25 07:09:30 UTC (rev 3132)
+++ GNUnet/src/include/gnunet_core.h 2006-07-25 09:03:10 UTC (rev 3133)
@@ -28,6 +28,8 @@
#define COREAPI_H
#include "gnunet_util.h"
+#include "gnunet_util_cron.h"
+#include "gnunet_util_crypto.h"
#ifdef __cplusplus
extern "C" {
@@ -47,7 +49,7 @@
* roughly the main GNUnet version scheme, but is
* more a compatibility ID.
*/
-#define GNUNET_CORE_VERSION 0x00070005
+#define GNUNET_CORE_VERSION 0x00070100
/**
@@ -89,7 +91,7 @@
* long, what is actually signed is the hash of these bytes.
*/
typedef struct {
- P2P_MESSAGE_HEADER header;
+ MESSAGE_HEADER header;
/**
* The signature
@@ -145,7 +147,7 @@
* Type of a handler for messages from clients.
*/
typedef int (*CSHandler)(ClientHandle client,
- const CS_MESSAGE_HEADER * message);
+ const MESSAGE_HEADER * message);
/**
* Method called whenever a given client disconnects.
@@ -156,7 +158,7 @@
* Type of a handler for some message type.
*/
typedef int (*MessagePartHandler)(const PeerIdentity * sender,
- const P2P_MESSAGE_HEADER * message);
+ const MESSAGE_HEADER * message);
/**
* Type of a handler for plaintext messages. Since we cannot
@@ -164,7 +166,7 @@
* the callback.
*/
typedef int (*PlaintextMessagePartHandler)(const PeerIdentity * sender,
- const P2P_MESSAGE_HEADER * message,
+ const MESSAGE_HEADER * message,
TSession * session);
/**
@@ -212,7 +214,7 @@
* transfer happens asynchronously.
*/
typedef int (*SendToClientCallback)(ClientHandle handle,
- const CS_MESSAGE_HEADER * message);
+ const MESSAGE_HEADER * message);
/**
* GNUnet CORE API for applications and services that are implemented
@@ -230,6 +232,27 @@
*/
PeerIdentity * myIdentity;
+ /**
+ * System error context
+ */
+ struct GE_Context * ectx;
+
+ /**
+ * System configuration
+ */
+ struct GC_Configuration * cfg;
+
+ /**
+ * System load monitor
+ */
+ struct LoadMonitor * load_monitor;
+
+ /**
+ * System cron Manager.
+ */
+ struct CronManager * cron;
+
+
/* ****************** services and applications **************** */
/**
@@ -306,7 +329,7 @@
* @param maxdelay how long can the message be delayed?
*/
void (*unicast)(const PeerIdentity * receiver,
- const P2P_MESSAGE_HEADER * msg,
+ const MESSAGE_HEADER * msg,
unsigned int importance,
unsigned int maxdelay);
@@ -631,7 +654,7 @@
* The the lock of the connection module. A module that registers
* callbacks may need this.
*/
- Mutex * (*getConnectionModuleLock)(void);
+ struct Mutex * (*getConnectionModuleLock)(void);
/**
* Get the current number of slots in the connection table (as computed
Modified: GNUnet/src/include/gnunet_transport.h
===================================================================
--- GNUnet/src/include/gnunet_transport.h 2006-07-25 07:09:30 UTC (rev
3132)
+++ GNUnet/src/include/gnunet_transport.h 2006-07-25 09:03:10 UTC (rev
3133)
@@ -108,6 +108,26 @@
PeerIdentity * myIdentity;
/**
+ * System error context
+ */
+ struct GE_Context * ectx;
+
+ /**
+ * System configuration
+ */
+ struct GC_Configuration * cfg;
+
+ /**
+ * System load monitor
+ */
+ struct LoadMonitor * load_monitor;
+
+ /**
+ * System cron Manager.
+ */
+ struct CronManager * cron;
+
+ /**
* Data was received (potentially encrypted), make the core process
* it.
*/
Modified: GNUnet/src/include/gnunet_util_network.h
===================================================================
--- GNUnet/src/include/gnunet_util_network.h 2006-07-25 07:09:30 UTC (rev
3132)
+++ GNUnet/src/include/gnunet_util_network.h 2006-07-25 09:03:10 UTC (rev
3133)
@@ -407,6 +407,15 @@
void socket_destroy(struct SocketHandle * s);
+void socket_add_to_select_set(struct SocketHandle * s,
+ fd_set * set,
+ int * max);
+
+int socket_test_select_set(struct SocketHandle * sock,
+ fd_set * set);
+
+int socket_get_os_socket(struct SocketHandle * sock);
+
/**
* Depending on doBlock, enable or disable the nonblocking mode
* of socket s.
Modified: GNUnet/src/transports/Makefile.am
===================================================================
--- GNUnet/src/transports/Makefile.am 2006-07-25 07:09:30 UTC (rev 3132)
+++ GNUnet/src/transports/Makefile.am 2006-07-25 09:03:10 UTC (rev 3133)
@@ -15,7 +15,7 @@
libip.la
if !MINGW
- smtptransport = libgnunettransport_smtp.la
+# smtptransport = libgnunettransport_smtp.la
endif
libip_la_SOURCES = \
@@ -24,21 +24,20 @@
libip6_la_SOURCES = \
ip6.c ip6.h
-plugin_LTLIBRARIES = \
- $(smtptransport) \
- libgnunettransport_http.la \
+plugin_LTLIBRARIES = $(smtptransport) \
libgnunettransport_tcp.la \
libgnunettransport_udp.la \
libgnunettransport_nat.la \
- $(v6transports)
+ $(v6transports) \
+ libgnunettransport_http.la
libgnunettransport_smtp_la_SOURCES = smtp.c
libgnunettransport_smtp_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la
libgnunettransport_smtp_la_LDFLAGS = \
-export-dynamic -avoid-version -module
-
+
libgnunettransport_http_la_SOURCES = http.c
libgnunettransport_http_la_LIBADD = \
$(top_builddir)/src/util/libgnunetutil.la \
Modified: GNUnet/src/transports/ip.c
===================================================================
--- GNUnet/src/transports/ip.c 2006-07-25 07:09:30 UTC (rev 3132)
+++ GNUnet/src/transports/ip.c 2006-07-25 09:03:10 UTC (rev 3133)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2004, 2005 Christian Grothoff (and other contributing
authors)
+ (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
@@ -42,30 +42,36 @@
#include "gnunet_util.h"
#include "ip.h"
+/* maximum length of hostname */
+#define MAX_HOSTNAME 1024
+
/**
* Obtain the identity information for the current node
* (connection information), conInfo.
* @return SYSERR on failure, OK on success
*/
-static int getAddressFromHostname(IPaddr * identity) {
- char * hostname;
+static int getAddressFromHostname(struct GE_Context * ectx,
+ IPaddr * identity) {
+ char hostname[MAX_HOSTNAME];
int ret;
- hostname = MALLOC(1024);
- if (0 != gethostname(hostname, 1024)) {
- FREE(hostname);
- LOG_STRERROR(LOG_ERROR, "gethostname");
+ if (0 != gethostname(hostname, MAX_HOSTNAME)) {
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_ADMIN | GE_USER | GE_BULK,
+ "gethostname");
return SYSERR;
}
- ret = GN_getHostByName(hostname,
+ ret = get_host_by_name(ectx,
+ hostname,
identity);
- FREE(hostname);
return ret;
}
#if LINUX || SOMEBSD || MINGW
#define MAX_INTERFACES 16
-static int getAddressFromIOCTL(IPaddr * identity) {
+static int getAddressFromIOCTL(struct GC_Configuration * cfg,
+ struct GE_Context * ectx,
+ IPaddr * identity) {
char * interfaces;
#ifndef MINGW
struct ifreq ifr[MAX_INTERFACES];
@@ -76,34 +82,50 @@
#endif
int i;
- interfaces = getConfigurationString("NETWORK",
- "INTERFACE");
- if (interfaces == NULL) {
- LOG(LOG_ERROR,
- "No interface specified in section NETWORK under INTERFACE!\n");
+ if (-1 == GC_get_configuration_value_string(cfg,
+ "NETWORK",
+ "INTERFACE",
+ "eth0",
+ &interfaces)) {
+ GE_LOG(ectx,
+ GE_ERROR | GE_BULK | GE_USER,
+ _("No interface specified in section `%s' under `%s'!\n"),
+ "NETWORK",
+ "INTERFACE");
return SYSERR; /* that won't work! */
}
#ifndef MINGW
sockfd = SOCKET(PF_INET, SOCK_DGRAM, 0);
if (sockfd == -1) {
FREE(interfaces);
- LOG_STRERROR(LOG_ERROR, "socket");
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_ADMIN | GE_USER | GE_BULK,
+ "socket");
return SYSERR;
}
- memset(&ifc, 0, sizeof(struct ifconf));
+ memset(&ifc,
+ 0,
+ sizeof(struct ifconf));
ifc.ifc_len = sizeof(ifr);
ifc.ifc_buf = (char*)𝔦
- if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
- LOG_STRERROR(LOG_WARNING, "ioctl");
- closefile(sockfd);
+ if (ioctl(sockfd,
+ SIOCGIFCONF,
+ &ifc) == -1) {
+ GE_LOG_STRERROR(ectx,
+ GE_WARNING | GE_ADMIN | GE_USER | GE_BULK,
+ "ioctl");
+ if (0 != CLOSE(sockfd))
+ GE_LOG_STRERROR(ectx,
+ GE_WARNING | GE_ADMIN | GE_BULK,
+ "close");
FREE(interfaces);
return SYSERR;
}
ifCount = ifc.ifc_len / sizeof(struct ifreq);
/* first, try to find exatly matching interface */
- for(i=0;i<ifCount;i++){
+ for (i=0;i<ifCount;i++){
if (ioctl(sockfd, SIOCGIFADDR, &ifr[i]) != 0)
continue;
if (ioctl(sockfd, SIOCGIFFLAGS, &ifr[i]) != 0)
@@ -116,17 +138,21 @@
memcpy(identity,
&(((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr),
sizeof(struct in_addr));
- closefile(sockfd);
+ if (0 != CLOSE(sockfd))
+ GE_LOG_STRERROR(ectx,
+ GE_WARNING | GE_ADMIN | GE_BULK,
+ "close");
FREE(interfaces);
return OK;
}
- LOG(LOG_WARNING,
- _("Could not find interface `%s' in `%s', "
- "trying to find another interface.\n"),
- "ioctl",
+ GE_LOG(ectx,
+ GE_WARNING | GE_ADMIN | GE_USER | GE_BULK,
+ _("Could not find interface `%s' in `%s', "
+ "trying to find another interface.\n"),
+ "ioctl",
interfaces);
/* if no such interface exists, take any interface but loopback */
- for(i=0;i<ifCount;i++){
+ for (i=0;i<ifCount;i++){
if (ioctl(sockfd, SIOCGIFADDR, &ifr[i]) != 0)
continue;
if (ioctl(sockfd, SIOCGIFFLAGS, &ifr[i]) != 0)
@@ -139,15 +165,22 @@
memcpy(identity,
&(((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr),
sizeof(struct in_addr));
- closefile(sockfd);
+ if (0 != CLOSE(sockfd))
+ GE_LOG_STRERROR(ectx,
+ GE_WARNING | GE_ADMIN | GE_BULK,
+ "close");
FREE(interfaces);
return OK;
}
- closefile(sockfd);
- LOG(LOG_WARNING,
- _("Could not obtain IP for interface `%s' using `%s'.\n"),
- "ioctl",
+ if (0 != CLOSE(sockfd))
+ GE_LOG_STRERROR(ectx,
+ GE_WARNING | GE_ADMIN | GE_BULK,
+ "close");
+ GE_LOG(ectx,
+ GE_WARNING | GE_USER | GE_BULK,
+ _("Could not obtain IP for interface `%s' using `%s'.\n"),
+ "ioctl",
interfaces);
FREE(interfaces);
return SYSERR;
@@ -266,24 +299,32 @@
* Get the IP address for the local machine.
* @return SYSERR on error, OK on success
*/
-static int getAddress(IPaddr * address){
+static int getAddress(struct GC_Configuration * cfg,
+ struct GE_Context * ectx,
+ IPaddr * address){
char * ipString;
int retval;
- ipString = getConfigurationString("NETWORK",
- "IP");
- if ( (ipString == NULL) || (ipString[0] == '\0') ) {
+ if (0 != GC_get_configuration_value_string(cfg,
+ "NETWORK",
+ "IP",
+ NULL,
+ &ipString)) {
#if LINUX || SOMEBSD || MINGW
- if (OK == getAddressFromIOCTL(address))
+ if (OK == getAddressFromIOCTL(cfg,
+ ectx,
+ address))
retval = OK;
else
#endif
- retval = getAddressFromHostname(address);
+ retval = getAddressFromHostname(ectx,
+ address);
} else {
- retval = GN_getHostByName(ipString,
+ retval = get_host_by_name(ectx,
+ ipString,
address);
+ FREE(ipString);
}
- FREENONNULL(ipString);
return retval;
}
@@ -291,19 +332,25 @@
* Get the IP address for the local machine.
* @return SYSERR on error, OK on success
*/
-int getPublicIPAddress(IPaddr * address) {
+int getPublicIPAddress(struct GC_Configuration * cfg,
+ struct GE_Context * ectx,
+ IPaddr * address) {
static IPaddr myAddress;
static cron_t last;
static cron_t lastError;
cron_t now;
- cronTime(&now);
+ now = get_time();
if (last + cronMINUTES < now) {
if (lastError + 30 * cronSECONDS > now)
return SYSERR;
- if (SYSERR == getAddress(&myAddress)) {
- LOG(LOG_WARNING,
- _("Failed to obtain my (external) IP address!\n"));
+ if (SYSERR == getAddress(cfg,
+ ectx,
+ &myAddress)) {
+ GE_LOG(ectx,
+ GE_WARNING | GE_USER | GE_BULK,
+ _("Failed to obtain my (external) %s address!\n"),
+ "IP");
lastError = now;
return SYSERR;
}
Modified: GNUnet/src/transports/ip.h
===================================================================
--- GNUnet/src/transports/ip.h 2006-07-25 07:09:30 UTC (rev 3132)
+++ GNUnet/src/transports/ip.h 2006-07-25 09:03:10 UTC (rev 3133)
@@ -42,13 +42,8 @@
*
* @return SYSERR on error, OK on success
*/
-int getPublicIPAddress(IPaddr * address);
+int getPublicIPAddress(struct GC_Configuration * cfg,
+ struct GE_Context * ectx,
+ IPaddr * address);
-/**
- * @brief Get the IPv6 address for the local machine.
- *
- * @return SYSERR on error, OK on success
- */
-int getPublicIP6Address(IP6addr * address);
-
#endif
Modified: GNUnet/src/transports/ip6.c
===================================================================
--- GNUnet/src/transports/ip6.c 2006-07-25 07:09:30 UTC (rev 3132)
+++ GNUnet/src/transports/ip6.c 2006-07-25 09:03:10 UTC (rev 3133)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2004, 2005 Christian Grothoff (and other contributing
authors)
+ (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
@@ -35,19 +35,23 @@
#include "gnunet_util.h"
#include "ip6.h"
+/* maximum length of hostname */
+#define MAX_HOSTNAME 1024
+
/**
* Obtain the identity information for the current node
* (connection information), conInfo.
* @return SYSERR on failure, OK on success
*/
-static int getAddress6FromHostname(IP6addr * identity) {
- char * hostname;
+static int getAddress6FromHostname(struct GE_Context * ectx,
+ IP6addr * identity) {
+ char hostname[MAX_HOSTNAME];
struct hostent * ip;
- hostname = MALLOC(1024);
- if (0 != gethostname(hostname, 1024)) {
- LOG_STRERROR(LOG_ERROR, "gethostname");
- FREE(hostname);
+ if (0 != gethostname(hostname, MAX_HOSTNAME)) {
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_ADMIN | GE_USER | GE_BULK,
+ "gethostname");
return SYSERR;
}
/* LOG(LOG_DEBUG,
@@ -56,19 +60,20 @@
ip = gethostbyname2(hostname, AF_INET6);
if (ip == NULL) {
- LOG(LOG_ERROR,
- _("Could not find IP of host `%s': %s\n"),
- hostname,
- hstrerror(h_errno));
- FREE(hostname);
+ GE_LOG(ectx,
+ GE_ERROR | GE_ADMIN | GE_USER | GE_BULK,
+ _("Could not find IP of host `%s': %s\n"),
+ hostname,
+ hstrerror(h_errno));
return SYSERR;
}
- FREE(hostname);
if (ip->h_addrtype != AF_INET6) {
- BREAK();
+ GE_BREAK(ectx,
+ 0);
return SYSERR;
}
- GNUNET_ASSERT(sizeof(struct in6_addr) == sizeof(identity->addr));
+ GE_ASSERT(ectx,
+ sizeof(struct in6_addr) == sizeof(identity->addr));
memcpy(&identity->addr[0],
ip->h_addr_list[0],
sizeof(struct in6_addr));
@@ -79,34 +84,39 @@
* Get the IP address for the local machine.
* @return SYSERR on error, OK on success
*/
-static int getAddress6(IP6addr * address){
+static int getAddress6(struct GC_Configuration * cfg,
+ struct GE_Context * ectx,
+ IP6addr * address){
char * ipString;
int retval;
struct hostent * ip; /* for the lookup of the IP in gnunet.conf */
retval = SYSERR;
- ipString = getConfigurationString("NETWORK",
- "IP6");
- if (ipString == NULL) {
- retval = getAddress6FromHostname(address);
+ if (0 != GC_get_configuration_value_string(cfg,
+ "NETWORK",
+ "IP",
+ NULL,
+ &ipString)) {
+ retval = getAddress6FromHostname(ectx,
+ address);
} else {
- /* LOG(LOG_DEBUG,
- " obtaining local IP address from hostname %s\n",
- ipString); */
ip = gethostbyname2(ipString,
AF_INET6);
if (ip == NULL) {
- LOG(LOG_ERROR,
- _("Could not resolve `%s': %s\n"),
- ipString,
- hstrerror(h_errno));
+ GE_LOG(ectx,
+ GE_ERROR | GE_USER | GE_BULK,
+ _("Could not resolve `%s': %s\n"),
+ ipString,
+ hstrerror(h_errno));
retval = SYSERR;
} else {
if (ip->h_addrtype != AF_INET6) {
- BREAK();
+ GE_ASSERT(ectx,
+ 0);
retval = SYSERR;
} else {
- GNUNET_ASSERT(sizeof(struct in6_addr) == sizeof(address->addr));
+ GE_ASSERT(ectx,
+ sizeof(struct in6_addr) == sizeof(address->addr));
memcpy(&address->addr[0],
ip->h_addr_list[0],
sizeof(struct in6_addr));
@@ -122,20 +132,26 @@
* Get the IPv6 address for the local machine.
* @return SYSERR on error, OK on success
*/
-int getPublicIP6Address(IP6addr * address) {
+int getPublicIP6Address(struct GC_Configuration * cfg,
+ struct GE_Context * ectx,
+ IP6addr * address) {
static IP6addr myAddress;
static cron_t last;
static cron_t lastError;
cron_t now;
- cronTime(&now);
+ now = get_time();
if (last + cronMINUTES < now) {
if (lastError + 30 * cronSECONDS > now)
return SYSERR;
- if (SYSERR == getAddress6(&myAddress)) {
+ if (SYSERR == getAddress6(cfg,
+ ectx,
+ &myAddress)) {
lastError = now;
- LOG(LOG_WARNING,
- _("Failed to obtain my (external) IPv6 address!\n"));
+ GE_LOG(ectx,
+ GE_WARNING | GE_USER | GE_BULK,
+ _("Failed to obtain my (external) %s address!\n"),
+ "IPv6");
return SYSERR;
}
last = now;
Modified: GNUnet/src/transports/ip6.h
===================================================================
--- GNUnet/src/transports/ip6.h 2006-07-25 07:09:30 UTC (rev 3132)
+++ GNUnet/src/transports/ip6.h 2006-07-25 09:03:10 UTC (rev 3133)
@@ -33,6 +33,8 @@
*
* @return SYSERR on error, OK on success
*/
-int getPublicIP6Address(IP6addr * address);
+int getPublicIP6Address(struct GC_Configuration * cfg,
+ struct GE_Context * ectx,
+ IP6addr * address);
#endif
Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2006-07-25 07:09:30 UTC (rev 3132)
+++ GNUnet/src/transports/tcp.c 2006-07-25 09:03:10 UTC (rev 3133)
@@ -106,7 +106,7 @@
/**
* the tcp socket
*/
- int sock;
+ struct SocketHandle * sock;
/**
* number of users of this session
@@ -121,7 +121,7 @@
/**
* mutex for synchronized access to 'users'
*/
- Mutex lock;
+ struct MUTEX * lock;
/**
* To whom are we talking to (set to our identity
@@ -172,6 +172,7 @@
* apis (our advertised API and the core api )
*/
static CoreAPIForTransport * coreAPI;
+
static TransportAPI tcpAPI;
static Stats_ServiceAPI * stats;
@@ -186,13 +187,13 @@
* one thread for listening for new connections,
* and for reading on all open sockets
*/
-static PTHREAD_T listenThread;
+static struct PTHREAD * listenThread;
/**
* sock is the tcp socket that we listen on for new inbound
* connections.
*/
-static int tcp_sock;
+static struct SocketHandle * tcp_sock;
/**
* tcp_pipe is used to signal the thread that is
@@ -205,7 +206,9 @@
* Array of currently active TCP sessions.
*/
static TSession ** tsessions = NULL;
+
static unsigned int tsessionCount;
+
static unsigned int tsessionArrayLength;
/* configuration */
@@ -223,16 +226,23 @@
* prevent the select thread from operating and removing
* is done by the only therad that reads from the array.
*/
-static Mutex tcplock;
+static struct MUTEX * tcplock;
/**
* Semaphore used by the server-thread to signal that
* the server has been started -- and later again to
* signal that the server has been stopped.
*/
-static Semaphore * serverSignal = NULL;
+static struct SEMAPHORE * serverSignal;
+
static int tcp_shutdown = YES;
+static struct GE_Context * ectx;
+
+static struct GC_Configuration * cfg;
+
+static struct LoadMonitor * load_monitor;
+
/* ******************** helper functions *********************** */
/**
@@ -241,10 +251,10 @@
static int isBlacklisted(IPaddr ip) {
int ret;
- MUTEX_LOCK(&tcplock);
- ret = checkIPListed(filteredNetworks_,
- ip);
- MUTEX_UNLOCK(&tcplock);
+ MUTEX_LOCK(tcplock);
+ ret = check_ipv4_listed(filteredNetworks_,
+ ip);
+ MUTEX_UNLOCK(tcplock);
return ret;
}
@@ -260,7 +270,9 @@
&i,
sizeof(char));
if (ret != sizeof(char))
- LOG_STRERROR(LOG_ERROR, "write");
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_ADMIN | GE_BULK,
+ "write");
}
/**
@@ -277,14 +289,14 @@
if (tsession->internal != NULL) {
TCPSession * tcpsession = tsession->internal;
- MUTEX_LOCK(&tcpsession->lock);
+ MUTEX_LOCK(tcpsession->lock);
tcpsession->users--;
if (tcpsession->users > 0) {
- MUTEX_UNLOCK(&tcpsession->lock);
+ MUTEX_UNLOCK(tcpsession->lock);
return OK;
}
- MUTEX_UNLOCK(&tcpsession->lock);
- MUTEX_DESTROY(&tcpsession->lock);
+ MUTEX_UNLOCK(tcpsession->lock);
+ MUTEX_DESTROY(tcpsession->lock);
FREE(tcpsession->rbuff);
FREENONNULL(tcpsession->wbuff);
tcpsession->wbuff = NULL;
@@ -311,11 +323,9 @@
TCPSession * tcpSession;
tcpSession = tsessions[i]->internal;
- if (tcpSession->sock != -1)
- if (0 != SHUTDOWN(tcpSession->sock, SHUT_RDWR))
- LOG_STRERROR(LOG_EVERYTHING, "shutdown");
- closefile(tcpSession->sock);
- tcpSession->sock = -1;
+ if (tcpSession->sock != NULL)
+ socket_destroy(tcpSession->sock);
+ tcpSession->sock = NULL;
tcpDisconnect(tsessions[i]);
tsessions[i] = tsessions[--tsessionCount];
tsessions[tsessionCount] = NULL;
@@ -328,15 +338,21 @@
*/
static unsigned short getGNUnetTCPPort() {
struct servent * pse; /* pointer to service information entry */
- unsigned short port;
+ unsigned long long port;
- port = (unsigned short) getConfigurationInt("TCP",
- "PORT");
- if (port == 0) { /* try lookup in services */
+ if (-1 == GC_get_configuration_value_number(cfg,
+ "TCP",
+ "PORT",
+ 1,
+ 65535,
+ 2086,
+ &port)) {
if ((pse = getservbyname("gnunet", "tcp")))
port = htons(pse->s_port);
+ else
+ port = 0;
}
- return port;
+ return (unsigned short) port;
}
/**
@@ -362,13 +378,13 @@
TCPSession * tcpSession;
if (tsession == NULL) {
- BREAK();
+ GE_BREAK(ectx, 0);
return SYSERR;
}
tcpSession = (TCPSession*) tsession->internal;
- MUTEX_LOCK(&tcpSession->lock);
+ MUTEX_LOCK(tcpSession->lock);
tcpSession->users++;
- MUTEX_UNLOCK(&tcpSession->lock);
+ MUTEX_UNLOCK(tcpSession->lock);
return OK;
}
@@ -385,6 +401,7 @@
int ret;
TCPP2P_PACKET * pack;
P2P_PACKET * mp;
+ size_t recvd;
tsession = tsessions[i];
if (SYSERR == tcpAssociate(tsession))
@@ -396,40 +413,23 @@
tcpSession->rsize,
tcpSession->rsize * 2);
}
- ret = READ(tcpSession->sock,
- &tcpSession->rbuff[tcpSession->pos],
- tcpSession->rsize - tcpSession->pos);
- if ( (ret > 0) &&
- (stats != NULL) )
- stats->change(stat_bytesReceived,
- ret);
- cronTime(&tcpSession->lastUse);
- if (ret == 0) {
+ ret = socket_recv(tcpSession->sock,
+ NC_Blocking | NC_IgnoreInt,
+ &tcpSession->rbuff[tcpSession->pos],
+ tcpSession->rsize - tcpSession->pos,
+ &recvd);
+ tcpSession->lastUse = get_time();
+ if (ret != OK) {
tcpDisconnect(tsession);
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "READ on socket %d returned 0 bytes, closing connection\n",
- tcpSession->sock);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "READ on socket %d returned 0 bytes, closing connection\n",
+ tcpSession->sock);
#endif
return SYSERR; /* other side closed connection */
}
- if (ret < 0) {
- if ( (errno == EINTR) ||
- (errno == EAGAIN) ) {
-#if DEBUG_TCP
- LOG_STRERROR(LOG_DEBUG, "read");
-#endif
- tcpDisconnect(tsession);
- return OK;
- }
-#if DEBUG_TCP
- LOG_STRERROR(LOG_INFO, "read");
-#endif
- tcpDisconnect(tsession);
- return SYSERR;
- }
- incrementBytesReceived(ret);
- tcpSession->pos += ret;
+ tcpSession->pos += recvd;
while (tcpSession->pos > 2) {
len = ntohs(((TCPP2P_PACKET*)&tcpSession->rbuff[0])->size)
@@ -439,11 +439,12 @@
tcpSession->rsize,
len);
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "Read %d bytes on socket %d, expecting %d for full message\n",
- tcpSession->pos,
- tcpSession->sock,
- len);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "Read %d bytes on socket %d, expecting %d for full message\n",
+ tcpSession->pos,
+ tcpSession->sock,
+ len);
#endif
if (tcpSession->pos < len) {
tcpDisconnect(tsession);
@@ -461,23 +462,26 @@
if ( (ntohs(welcome->header.reserved) != 0) ||
(ntohs(welcome->header.size)
!= sizeof(TCPWelcome) - sizeof(TCPP2P_PACKET)) ) {
- LOG(LOG_WARNING,
- _("Expected welcome message on tcp connection, "
- "got garbage (%u, %u). Closing.\n"),
- ntohs(welcome->header.reserved),
- ntohs(welcome->header.size));
+ GE_LOG(ectx,
+ GE_WARNING | GE_USER | GE_BULK,
+ _("Expected welcome message on tcp connection, "
+ "got garbage (%u, %u). Closing.\n"),
+ ntohs(welcome->header.reserved),
+ ntohs(welcome->header.size));
tcpDisconnect(tsession);
return SYSERR;
}
tcpSession->expectingWelcome = NO;
tcpSession->sender = welcome->clientIdentity;
#if DEBUG_TCP
- IFLOG(LOG_DEBUG,
- hash2enc(&tcpSession->sender.hashPubKey,
- &enc));
- LOG(LOG_DEBUG,
- "tcp welcome message from `%s' received\n",
- &enc);
+ IF_GELOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ hash2enc(&tcpSession->sender.hashPubKey,
+ &enc));
+ GE_LOG(etcx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "tcp welcome message from `%s' received\n",
+ &enc);
#endif
memmove(&tcpSession->rbuff[0],
&tcpSession->rbuff[sizeof(TCPWelcome)],
@@ -495,10 +499,11 @@
pack = (TCPP2P_PACKET*)&tcpSession->rbuff[0];
/* send msg to core! */
if (len <= sizeof(TCPP2P_PACKET)) {
- LOG(LOG_WARNING,
- _("Received malformed message (size %u)"
- " from tcp-peer connection. Closing.\n"),
- len);
+ GE_LOG(ectx,
+ GE_WARNING | GE_USER | GE_BULK,
+ _("Received malformed message (size %u)"
+ " from tcp-peer connection. Closing.\n"),
+ len);
tcpDisconnect(tsession);
return SYSERR;
}
@@ -514,11 +519,17 @@
{
EncName enc;
- hash2enc(&mp->sender.hashPubKey, &enc);
-
- LOG(LOG_DEBUG,
- "tcp transport received %u bytes from %s (CRC %u), forwarding to
core\n",
- mp->size, &enc, crc32N(tcpSession->rbuff, tcpSession->pos));
+ IF_GELOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ hash2enc(&mp->sender.hashPubKey,
+ &enc);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "tcp transport received %u bytes from %s (CRC %u), forwarding to
core\n",
+ mp->size,
+ &enc,
+ crc32N(tcpSession->rbuff,
+ tcpSession->pos));
}
#endif
coreAPI->receive(mp);
@@ -549,14 +560,14 @@
static unsigned int addTSession(TSession * tsession) {
unsigned int i;
- MUTEX_LOCK(&tcplock);
+ MUTEX_LOCK(tcplock);
if (tsessionCount == tsessionArrayLength)
GROW(tsessions,
tsessionArrayLength,
tsessionArrayLength * 2);
i = tsessionCount;
tsessions[tsessionCount++] = tsession;
- MUTEX_UNLOCK(&tcplock);
+ MUTEX_UNLOCK(tcplock);
return i;
}
@@ -576,14 +587,16 @@
tcpSession->wpos = 0;
tcpSession->wbuff = NULL;
tcpSession->wsize = 0;
- tcpSession->sock = sock;
+ tcpSession->sock = socket_create(ectx,
+ load_monitor,
+ sock);
/* fill in placeholder identity to mark that we
are waiting for the welcome message */
tcpSession->sender = *(coreAPI->myIdentity);
tcpSession->expectingWelcome = YES;
- MUTEX_CREATE_RECURSIVE(&tcpSession->lock);
+ tcpSession->lock = MUTEX_CREATE(YES);
tcpSession->users = 1; /* us only, core has not seen this tsession! */
- cronTime(&tcpSession->lastUse);
+ tcpSession->lastUse = get_time();
tsession = MALLOC(sizeof(TSession));
tsession->ttype = TCP_PROTOCOL_NUMBER;
tsession->internal = tcpSession;
@@ -597,7 +610,7 @@
* and processes deferred (async) writes and buffers reads until an
* entire message has been received.
*/
-static void * tcpListenMain() {
+static void * tcpListenMain(void * unused) {
struct sockaddr_in clientAddr;
fd_set readSet;
fd_set errorSet;
@@ -608,78 +621,82 @@
int max;
int ret;
- if (tcp_sock != -1)
- if (0 != LISTEN(tcp_sock, 5))
- LOG_STRERROR(LOG_ERROR, "listen");
SEMAPHORE_UP(serverSignal); /* we are there! */
- MUTEX_LOCK(&tcplock);
+ MUTEX_LOCK(tcplock);
while (tcp_shutdown == NO) {
FD_ZERO(&readSet);
FD_ZERO(&errorSet);
FD_ZERO(&writeSet);
- if (tcp_sock != -1) {
- if (isSocketValid(tcp_sock)) {
- FD_SET(tcp_sock, &readSet);
- } else {
- LOG_STRERROR(LOG_ERROR, "isSocketValid");
- tcp_sock = -1; /* prevent us from error'ing all the time */
- }
- }
-#if DEBUG_TCP
- else
- LOG(LOG_DEBUG,
- "TCP server socket not open!\n");
-#endif
if (tcp_pipe[0] != -1) {
if (-1 != FSTAT(tcp_pipe[0], &buf)) {
- FD_SET(tcp_pipe[0], &readSet);
+ FD_SET(tcp_pipe[0],
+ &readSet);
} else {
- LOG_STRERROR(LOG_ERROR, "fstat");
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_ADMIN | GE_USER | GE_BULK,
+ "fstat");
tcp_pipe[0] = -1; /* prevent us from error'ing all the time */
}
}
max = tcp_pipe[0];
- if (tcp_sock > tcp_pipe[0])
- max = tcp_sock;
+ if (tcp_sock != NULL) {
+ if (socket_test_valid(tcp_sock)) {
+ socket_add_to_select_set(tcp_sock, &readSet, &max);
+ } else {
+ socket_destroy(tcp_sock);
+ tcp_sock = NULL; /* prevent us from error'ing all the time */
+ }
+ }
+#if DEBUG_TCP
+ else
+ GE_LOG(ectx,
+ GE_USER | GE_WARNING | GE_BULK,
+ _("TCP server socket not open!\n"));
+#endif
for (i=0;i<tsessionCount;i++) {
TCPSession * tcpSession = tsessions[i]->internal;
- int sock = tcpSession->sock;
- if (sock != -1) {
- if (isSocketValid(sock)) {
- FD_SET(sock, &readSet);
- FD_SET(sock, &errorSet);
+ struct SocketHandle * sock = tcpSession->sock;
+ if (sock != NULL) {
+ if (socket_test_valid(sock)) {
+ socket_add_to_select_set(sock, &readSet, &max);
+ socket_add_to_select_set(sock, &errorSet, &max);
if (tcpSession->wpos > 0)
- FD_SET(sock, &writeSet); /* do we have a pending write request? */
+ socket_add_to_select_set(sock, &writeSet, &max); /* do we have a
pending write request? */
} else {
- LOG_STRERROR(LOG_ERROR, "isSocketValid");
destroySession(i);
}
} else {
- BREAK(); /* sock in tsessions array should never be -1 */
+ GE_BREAK(ectx, 0); /* sock in tsessions array should never be -1 */
destroySession(i);
}
- if (sock > max)
- max = sock;
}
- MUTEX_UNLOCK(&tcplock);
- ret = SELECT(max+1, &readSet, &writeSet, &errorSet, NULL);
- MUTEX_LOCK(&tcplock);
+ MUTEX_UNLOCK(tcplock);
+ ret = SELECT(max+1,
+ &readSet,
+ &writeSet,
+ &errorSet,
+ NULL);
+ MUTEX_LOCK(tcplock);
if ( (ret == -1) &&
( (errno == EAGAIN) || (errno == EINTR) ) )
continue;
if (ret == -1) {
if (errno == EBADF) {
- LOG_STRERROR(LOG_ERROR, "select");
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_ADMIN | GE_USER | GE_BULK,
+ "select");
} else {
- DIE_STRERROR("select");
+ GE_DIE_STRERROR(ectx,
+ GE_FATAL | GE_ADMIN | GE_USER | GE_IMMEDIATE,
+ "select");
}
}
- if (tcp_sock != -1) {
- if (FD_ISSET(tcp_sock, &readSet)) {
+ if (tcp_sock != NULL) {
+ if (socket_test_select_set(tcp_sock, &readSet)) {
int sock;
lenOfIncomingAddr = sizeof(clientAddr);
- sock = ACCEPT(tcp_sock,
+ sock = ACCEPT(socket_get_os_socket(tcp_sock),
(struct sockaddr *)&clientAddr,
&lenOfIncomingAddr);
if (sock != -1) {
@@ -688,29 +705,40 @@
otherwise we just close and reject the communication! */
IPaddr ipaddr;
- GNUNET_ASSERT(sizeof(struct in_addr) == sizeof(IPaddr));
+ GE_ASSERT(ectx,
+ sizeof(struct in_addr) == sizeof(IPaddr));
memcpy(&ipaddr,
&clientAddr.sin_addr,
sizeof(struct in_addr));
if (YES == isBlacklisted(ipaddr)) {
- LOG(LOG_INFO,
- _("%s: Rejected connection from blacklisted "
- "address %u.%u.%u.%u.\n"),
- "TCP",
- PRIP(ntohl(*(int*)&clientAddr.sin_addr)));
- SHUTDOWN(sock, 2);
- closefile(sock);
+ GE_LOG(ectx,
+ GE_INFO | GE_USER | GE_ADMIN | GE_REQUEST,
+ _("%s: Rejected connection from blacklisted "
+ "address %u.%u.%u.%u.\n"),
+ "TCP",
+ PRIP(ntohl(*(int*)&clientAddr.sin_addr)));
+ if (0 != SHUTDOWN(sock, 2))
+ GE_LOG_STRERROR(ectx,
+ GE_USER | GE_ADMIN | GE_WARNING | GE_BULK,
+ "shutdown");
+ if (0 != CLOSE(sock))
+ GE_LOG_STRERROR(ectx,
+ GE_USER | GE_ADMIN | GE_WARNING | GE_BULK,
+ "close");
} else {
#if DEBUG_TCP
- LOG(LOG_INFO,
- "Accepted connection from %u.%u.%u.%u.\n",
- PRIP(ntohl(*(int*)&clientAddr.sin_addr)));
+ GE_LOG(ectx,
+ GE_INFO,
+ "Accepted connection from %u.%u.%u.%u.\n",
+ PRIP(ntohl(*(int*)&clientAddr.sin_addr)));
#endif
createNewSession(sock);
}
} else {
- LOG_STRERROR(LOG_INFO, "accept");
+ GE_LOG_STRERROR(ectx,
+ GE_WARNING | GE_ADMIN | GE_BULK,
+ "accept");
}
}
}
@@ -723,35 +751,41 @@
if (0 >= READ(tcp_pipe[0],
&buf[0],
MAXSIG_BUF)) {
- LOG_STRERROR(LOG_WARNING, "read");
+ GE_LOG_STRERROR(ectx,
+ GE_WARNING | GE_USER | GE_BULK,
+ "read");
}
}
for (i=0;i<tsessionCount;i++) {
TCPSession * tcpSession = tsessions[i]->internal;
- int sock = tcpSession->sock;
- if (FD_ISSET(sock, &readSet)) {
+ struct SocketHandle * sock = tcpSession->sock;
+ if (socket_test_select_set(sock, &readSet)) {
if (SYSERR == readAndProcess(i)) {
destroySession(i);
i--;
continue;
}
}
- if (FD_ISSET(sock, &writeSet)) {
+ if (socket_test_select_set(sock, &writeSet)) {
size_t ret;
int success;
try_again_1:
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "TCP: trying to send %u bytes\n",
- tcpSession->wpos);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "TCP: trying to send %u bytes\n",
+ tcpSession->wpos);
#endif
- success = SEND_NONBLOCKING(sock,
- tcpSession->wbuff,
- tcpSession->wpos,
- &ret);
- if ( (success == SYSERR) || (ret == (size_t) -1) ) {
- LOG_STRERROR(LOG_WARNING, "send");
+ success = socket_send(sock,
+ NC_Nonblocking,
+ tcpSession->wbuff,
+ tcpSession->wpos,
+ &ret);
+ if (success == SYSERR) {
+ GE_LOG_STRERROR(ectx,
+ GE_WARNING | GE_USER | GE_ADMIN | GE_BULK,
+ "send");
destroySession(i);
i--;
continue;
@@ -759,7 +793,7 @@
/* this should only happen under Win9x because
of a bug in the socket implementation (KB177346).
Let's sleep and try again. */
- gnunet_util_sleep(20);
+ PTHREAD_SLEEP(20 * cronMILLIS);
goto try_again_1;
}
if (stats != NULL)
@@ -767,9 +801,10 @@
ret);
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "TCP: transmitted %u bytes\n",
- ret);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "TCP: transmitted %u bytes\n",
+ ret);
#endif
if (ret == 0) {
/* send only returns 0 on error (other side closed connection),
@@ -790,13 +825,13 @@
tcpSession->wpos -= ret;
}
}
- if (FD_ISSET(sock, &errorSet)) {
+ if (socket_test_select_set(sock, &errorSet)) {
destroySession(i);
i--;
continue;
}
if ( ( tcpSession->users == 1) &&
- (cronTime(NULL) > tcpSession->lastUse + TCP_TIMEOUT) ) {
+ (get_time() > tcpSession->lastUse + TCP_TIMEOUT) ) {
destroySession(i);
i--;
continue;
@@ -804,14 +839,14 @@
}
}
/* shutdown... */
- if (tcp_sock != -1) {
- closefile(tcp_sock);
- tcp_sock = -1;
+ if (tcp_sock != NULL) {
+ socket_destroy(tcp_sock);
+ tcp_sock = NULL;
}
/* close all sessions */
while (tsessionCount > 0)
destroySession(0);
- MUTEX_UNLOCK(&tcplock);
+ MUTEX_UNLOCK(tcplock);
SEMAPHORE_UP(serverSignal); /* we are there! */
return NULL;
} /* end of tcp listen main */
@@ -836,21 +871,27 @@
{
EncName enc;
- hash2enc(&tcpSession->sender.hashPubKey, &enc);
-
- LOG(LOG_DEBUG,
- "tcpDirectSend called to transmit %u bytes to %s (CRC %u).\n",
- ssize, &enc, crc32N(mp, ssize));
+ IF_GELOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ hash2enc(&tcpSession->sender.hashPubKey,
+ &enc));
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "tcpDirectSend called to transmit %u bytes to %s (CRC %u).\n",
+ ssize,
+ &enc,
+ crc32N(mp, ssize));
}
#endif
if (tcp_shutdown == YES) {
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "tcpDirectSend called while TCP transport is shutdown.\n");
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "tcpDirectSend called while TCP transport is shutdown.\n");
#endif
return SYSERR;
}
- if (tcpSession->sock == -1) {
+ if (tcpSession->sock == NULL) {
#if DEBUG_TCP
LOG(LOG_INFO,
"tcpDirectSend called, but socket is closed\n");
@@ -858,36 +899,39 @@
return SYSERR;
}
if (ssize == 0) {
- BREAK(); /* size 0 not allowed */
+ GE_BREAK(ectx, 0); /* size 0 not allowed */
return SYSERR;
}
- MUTEX_LOCK(&tcplock);
+ MUTEX_LOCK(tcplock);
if (tcpSession->wpos > 0) {
/* select already pending... */
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "write already pending, will not take additional message.\n");
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "write already pending, will not take additional message.\n");
#endif
if (stats != NULL)
stats->change(stat_bytesDropped,
ssize);
- MUTEX_UNLOCK(&tcplock);
+ MUTEX_UNLOCK(tcplock);
return NO;
}
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "TCP: trying to send %u bytes\n",
- ssize);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "TCP: trying to send %u bytes\n",
+ ssize);
#endif
- success = SEND_NONBLOCKING(tcpSession->sock,
- mp,
- ssize,
- &ret);
+ success = socket_send(tcpSession->sock,
+ NC_Nonblocking,
+ mp,
+ ssize,
+ &ret);
if (success == SYSERR) {
#if DEBUG_TCP
LOG_STRERROR(LOG_INFO, "send");
#endif
- MUTEX_UNLOCK(&tcplock);
+ MUTEX_UNLOCK(tcplock);
return SYSERR;
}
if (success == NO)
@@ -897,9 +941,10 @@
ret);
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "TCP: transmitted %u bytes\n",
- ret);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "TCP: transmitted %u bytes\n",
+ ret);
#endif
if (ret < ssize) {/* partial send */
@@ -914,9 +959,8 @@
tcpSession->wpos = ssize - ret;
signalSelect(); /* select set changed! */
}
- cronTime(&tcpSession->lastUse);
- MUTEX_UNLOCK(&tcplock);
- incrementBytesSent(ssize);
+ tcpSession->lastUse = get_time();
+ MUTEX_UNLOCK(tcplock);
return OK;
}
@@ -939,11 +983,16 @@
{
EncName enc;
- hash2enc(&tcpSession->sender.hashPubKey, &enc);
-
- LOG(LOG_DEBUG,
- "tcpDirectSendReliable called to transmit %u bytes to %s (CRC %u).\n",
- ssize, &enc, crc32N(mp, ssize));
+ IF_GELOC(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ hash2enc(&tcpSession->sender.hashPubKey,
+ &enc));
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "tcpDirectSendReliable called to transmit %u bytes to %s (CRC
%u).\n",
+ ssize,
+ &enc,
+ crc32N(mp, ssize));
}
#endif
if (tcp_shutdown == YES) {
@@ -953,7 +1002,7 @@
#endif
return SYSERR;
}
- if (tcpSession->sock == -1) {
+ if (tcpSession->sock == NULL) {
#if DEBUG_TCP
LOG(LOG_INFO,
"tcpDirectSendReliable called, but socket is closed\n");
@@ -961,10 +1010,10 @@
return SYSERR;
}
if (ssize == 0) {
- BREAK();
+ GE_BREAK(ectx, 0);
return SYSERR;
}
- MUTEX_LOCK(&tcplock);
+ MUTEX_LOCK(tcplock);
if (tcpSession->wpos > 0) {
unsigned int old = tcpSession->wpos;
GROW(tcpSession->wbuff,
@@ -975,8 +1024,9 @@
mp,
ssize);
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "tcpDirectSendReliable appended message to send buffer.\n");
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "tcpDirectSendReliable appended message to send buffer.\n");
#endif
ok = OK;
@@ -985,7 +1035,7 @@
mp,
ssize);
}
- MUTEX_UNLOCK(&tcplock);
+ MUTEX_UNLOCK(tcplock);
return ok;
}
@@ -1010,10 +1060,10 @@
if (tcp_shutdown == YES)
return SYSERR;
if (size == 0) {
- BREAK();
+ GE_BREAK(ectx, 0);
return SYSERR;
}
- if (((TCPSession*)tsession->internal)->sock == -1)
+ if (((TCPSession*)tsession->internal)->sock == NULL)
return SYSERR; /* other side closed connection */
mp = MALLOC(sizeof(TCPP2P_PACKET) + size);
memcpy(&mp[1],
@@ -1068,23 +1118,28 @@
static int once = 0;
if (once == 0) {
once = 1;
- LOG(LOG_DEBUG,
- "TCP port is 0, will only send using TCP.\n");
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "TCP port is 0, will only send using TCP.\n");
}
return NULL; /* TCP transport is configured SEND-only! */
}
msg = (P2P_hello_MESSAGE *) MALLOC(sizeof(P2P_hello_MESSAGE) +
sizeof(HostAddress));
haddr = (HostAddress*) &msg[1];
- if (SYSERR == getPublicIPAddress(&haddr->ip)) {
+ if (SYSERR == getPublicIPAddress(cfg,
+ ectx,
+ &haddr->ip)) {
FREE(msg);
- LOG(LOG_WARNING,
- _("Could not determine my public IP address.\n"));
+ GE_LOG(ectx,
+ GE_WARNING | GE_ADMIN | GE_USER | GE_BULK,
+ _("Could not determine my public IP address.\n"));
return NULL;
}
- LOG(LOG_DEBUG,
- "TCP uses IP address %u.%u.%u.%u.\n",
- PRIP(ntohl(*(int*)&haddr->ip)));
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "TCP uses IP address %u.%u.%u.%u.\n",
+ PRIP(ntohl(*(int*)&haddr->ip)));
haddr->port = htons(port);
haddr->reserved = htons(0);
msg->senderAddressSize = htons(sizeof(HostAddress));
@@ -1109,26 +1164,32 @@
TSession * tsession;
TCPSession * tcpSession;
struct sockaddr_in soaddr;
+ struct SocketHandle * s;
if (tcp_shutdown == YES)
return SYSERR;
haddr = (HostAddress*) &helo[1];
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "Creating TCP connection to %u.%u.%u.%u:%u.\n",
- PRIP(ntohl(*(int*)&haddr->ip.addr)),
- ntohs(haddr->port));
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "Creating TCP connection to %u.%u.%u.%u:%u.\n",
+ PRIP(ntohl(*(int*)&haddr->ip.addr)),
+ ntohs(haddr->port));
#endif
sock = SOCKET(PF_INET,
SOCK_STREAM,
6); /* 6: TCP */
if (sock == -1) {
- LOG_STRERROR(LOG_FAILURE, "socket");
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_ADMIN | GE_BULK,
+ "socket");
return SYSERR;
}
- if (0 != setBlocking(sock, NO)) {
- closefile(sock);
- LOG_STRERROR(LOG_FAILURE, "setBlocking");
+ s = socket_create(ectx,
+ load_monitor,
+ sock);
+ if (-1 == socket_set_blocking(s, NO)) {
+ socket_destroy(s);
return SYSERR;
}
memset(&soaddr,
@@ -1136,7 +1197,7 @@
sizeof(soaddr));
soaddr.sin_family = AF_INET;
- GNUNET_ASSERT(sizeof(struct in_addr) == sizeof(IPaddr));
+ GE_ASSERT(ectx, sizeof(struct in_addr) == sizeof(IPaddr));
memcpy(&soaddr.sin_addr,
&haddr->ip,
sizeof(IPaddr));
@@ -1146,21 +1207,17 @@
sizeof(soaddr));
if ( (i < 0) &&
(errno != EINPROGRESS) ) {
- LOG(LOG_ERROR,
- _("Cannot connect to %u.%u.%u.%u:%u: %s\n"),
- PRIP(ntohl(*(int*)&haddr->ip)),
- ntohs(haddr->port),
- STRERROR(errno));
- closefile(sock);
+ GE_LOG(ectx,
+ GE_ERROR | GE_ADMIN | GE_USER | GE_BULK,
+ _("Cannot connect to %u.%u.%u.%u:%u: %s\n"),
+ PRIP(ntohl(*(int*)&haddr->ip)),
+ ntohs(haddr->port),
+ STRERROR(errno));
+ socket_destroy(s);
return SYSERR;
}
- if (0 != setBlocking(sock, NO)) {
- LOG_STRERROR(LOG_FAILURE, "setBlocking");
- closefile(sock);
- return SYSERR;
- }
tcpSession = MALLOC(sizeof(TCPSession));
- tcpSession->sock = sock;
+ tcpSession->sock = s;
tcpSession->wpos = 0;
tcpSession->wbuff = NULL;
tcpSession->wsize = 0;
@@ -1169,13 +1226,13 @@
tsession = MALLOC(sizeof(TSession));
tsession->internal = tcpSession;
tsession->ttype = tcpAPI.protocolNumber;
- MUTEX_CREATE_RECURSIVE(&tcpSession->lock);
+ tcpSession->lock = MUTEX_CREATE(YES);
tcpSession->users = 2; /* caller + us */
tcpSession->pos = 0;
- cronTime(&tcpSession->lastUse);
+ tcpSession->lastUse = get_time();
tcpSession->sender = helo->senderIdentity;
tcpSession->expectingWelcome = NO;
- MUTEX_LOCK(&tcplock);
+ MUTEX_LOCK(tcplock);
i = addTSession(tsession);
/* send our node identity to the other side to fully establish the
@@ -1191,10 +1248,10 @@
sizeof(TCPWelcome))) {
destroySession(i);
tcpDisconnect(tsession);
- MUTEX_UNLOCK(&tcplock);
+ MUTEX_UNLOCK(tcplock);
return SYSERR;
}
- MUTEX_UNLOCK(&tcplock);
+ MUTEX_UNLOCK(tcplock);
signalSelect();
*tsessionPtr = tsession;
@@ -1216,19 +1273,21 @@
int ok;
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "tcpSend called to transmit %u bytes.\n",
- size);
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "tcpSend called to transmit %u bytes.\n",
+ size);
#endif
if (size >= MAX_BUFFER_SIZE) {
- BREAK();
+ GE_BREAK(ectx, 0);
return SYSERR;
}
if (tcp_shutdown == YES) {
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "tcpSend called while TCP is shutdown.\n");
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "tcpSend called while TCP is shutdown.\n");
#endif
if (stats != NULL)
stats->change(stat_bytesDropped,
@@ -1236,13 +1295,14 @@
return SYSERR;
}
if (size == 0) {
- BREAK();
+ GE_BREAK(ectx, 0);
return SYSERR;
}
- if (((TCPSession*)tsession->internal)->sock == -1) {
+ if (((TCPSession*)tsession->internal)->sock == NULL) {
#if DEBUG_TCP
- LOG(LOG_DEBUG,
- "tcpSend called after other side closed connection.\n");
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "tcpSend called after other side closed connection.\n");
#endif
if (stats != NULL)
stats->change(stat_bytesDropped,
@@ -1277,16 +1337,19 @@
struct sockaddr_in serverAddr;
const int on = 1;
unsigned short port;
+ int s;
if (serverSignal != NULL) {
- BREAK();
+ GE_BREAK(ectx, 0);
return SYSERR;
}
- serverSignal = SEMAPHORE_NEW(0);
+ serverSignal = SEMAPHORE_CREATE(0);
tcp_shutdown = NO;
if (0 != PIPE(tcp_pipe)) {
- LOG_STRERROR(LOG_ERROR, "pipe");
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_ADMIN | GE_BULK,
+ "pipe");
return SYSERR;
}
setBlocking(tcp_pipe[1], NO);
@@ -1294,24 +1357,34 @@
port = getGNUnetTCPPort();
if (port != 0) { /* if port == 0, this is a read-only
business! */
- tcp_sock = SOCKET(PF_INET,
- SOCK_STREAM,
- 0);
- if (tcp_sock < 0) {
- LOG_STRERROR(LOG_FAILURE, "socket");
- closefile(tcp_pipe[0]);
- closefile(tcp_pipe[1]);
- SEMAPHORE_FREE(serverSignal);
+ s = SOCKET(PF_INET,
+ SOCK_STREAM,
+ 0);
+ if (s < 0) {
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_ADMIN | GE_BULK,
+ "socket");
+ if (0 != CLOSE(tcp_pipe[0]))
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_USER | GE_ADMIN | GE_BULK,
+ "close");
+ if (0 != CLOSE(tcp_pipe[1]))
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_USER | GE_ADMIN | GE_BULK,
+ "close");
+ SEMAPHORE_DESTROY(serverSignal);
serverSignal = NULL;
tcp_shutdown = YES;
return SYSERR;
}
- if (SETSOCKOPT(tcp_sock,
+ if (SETSOCKOPT(s,
SOL_SOCKET,
SO_REUSEADDR,
&on,
sizeof(on)) < 0 )
- DIE_STRERROR("setsockopt");
+ GE_DIE_STRERROR(ectx,
+ GE_FATAL | GE_ADMIN | GE_IMMEDIATE,
+ "setsockopt");
memset((char *) &serverAddr,
0,
sizeof(serverAddr));
@@ -1319,39 +1392,53 @@
serverAddr.sin_addr.s_addr = htonl(INADDR_ANY);
serverAddr.sin_port = htons(getGNUnetTCPPort());
#if DEBUG_TCP
- LOG(LOG_INFO,
- "starting %s peer server on port %d\n",
- "tcp",
- ntohs(serverAddr.sin_port));
+ GE_LOG(ectx,
+ GE_INFO | GE_USER | GE_BULK,
+ "starting %s peer server on port %d\n",
+ "tcp",
+ ntohs(serverAddr.sin_port));
#endif
- if (BIND(tcp_sock,
+ if (BIND(s,
(struct sockaddr *) &serverAddr,
sizeof(serverAddr)) < 0) {
- LOG_STRERROR(LOG_ERROR, "bind");
- LOG(LOG_ERROR,
- _("Failed to start transport service on port %d.\n"),
- getGNUnetTCPPort());
- closefile(tcp_sock);
- tcp_sock = -1;
- SEMAPHORE_FREE(serverSignal);
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_ADMIN | GE_IMMEDIATE,
+ "bind");
+ GE_LOG(ectx,
+ GE_ERROR | GE_ADMIN | GE_IMMEDIATE,
+ _("Failed to start transport service on port %d.\n"),
+ getGNUnetTCPPort());
+ if (0 != CLOSE(s))
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_USER | GE_ADMIN | GE_BULK,
+ "close");
+ SEMAPHORE_DESTROY(serverSignal);
serverSignal = NULL;
return SYSERR;
}
+ if (0 != LISTEN(s, 5))
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_USER | GE_ADMIN | GE_IMMEDIATE,
+ "listen");
+ tcp_sock = socket_create(ectx,
+ load_monitor,
+ s);
} else
- tcp_sock = -1;
- if (0 == PTHREAD_CREATE(&listenThread,
- (PThreadMain) &tcpListenMain,
- NULL,
- 4092)) {
- SEMAPHORE_DOWN(serverSignal); /* wait for server to be up */
- } else {
- LOG_STRERROR(LOG_ERROR,
- "pthread_create");
- closefile(tcp_sock);
- SEMAPHORE_FREE(serverSignal);
+ tcp_sock = NULL;
+ listenThread = PTHREAD_CREATE(&tcpListenMain,
+ NULL,
+ 5 * 1024);
+ if (listenThread == NULL) {
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_IMMEDIATE | GE_ADMIN,
+ "pthread_create");
+ socket_destroy(tcp_sock);
+ tcp_sock = NULL;
+ SEMAPHORE_DESTROY(serverSignal);
serverSignal = NULL;
return SYSERR;
}
+ SEMAPHORE_DOWN(serverSignal, YES); /* wait for server to be up */
return OK;
}
@@ -1369,19 +1456,25 @@
signalSelect();
if (serverSignal != NULL) {
haveThread = YES;
- SEMAPHORE_DOWN(serverSignal);
- SEMAPHORE_FREE(serverSignal);
+ SEMAPHORE_DOWN(serverSignal, YES);
+ SEMAPHORE_DESTROY(serverSignal);
} else
haveThread = NO;
serverSignal = NULL;
- closefile(tcp_pipe[1]);
- closefile(tcp_pipe[0]);
- if (tcp_sock != -1) {
- closefile(tcp_sock);
- tcp_sock = -1;
+ if (0 != CLOSE(tcp_pipe[1]))
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_USER | GE_ADMIN | GE_BULK,
+ "close");
+ if (0 != CLOSE(tcp_pipe[0]))
+ GE_LOG_STRERROR(ectx,
+ GE_ERROR | GE_USER | GE_ADMIN | GE_BULK,
+ "close");
+ if (tcp_sock != NULL) {
+ socket_destroy(tcp_sock);
+ tcp_sock = NULL;
}
if (haveThread == YES)
- PTHREAD_JOIN(&listenThread, &unused);
+ PTHREAD_JOIN(listenThread, &unused);
return OK;
}
@@ -1392,17 +1485,21 @@
static void reloadConfiguration(void) {
char * ch;
- MUTEX_LOCK(&tcplock);
+ MUTEX_LOCK(tcplock);
FREENONNULL(filteredNetworks_);
- ch = getConfigurationString("TCP",
- "BLACKLIST");
- if (ch == NULL)
- filteredNetworks_ = parseRoutes("");
+ if (0 != GC_get_configuration_value_string(cfg,
+ "TCP",
+ "BLACKLIST",
+ NULL,
+ &ch))
+ filteredNetworks_ = parse_ipv4_network_specification(ectx,
+ "");
else {
- filteredNetworks_ = parseRoutes(ch);
+ filteredNetworks_ = parse_ipv4_network_specification(ectx,
+ ch);
FREE(ch);
}
- MUTEX_UNLOCK(&tcplock);
+ MUTEX_UNLOCK(tcplock);
}
/**
@@ -1432,10 +1529,13 @@
* via a global and returns the udp transport API.
*/
TransportAPI * inittransport_tcp(CoreAPIForTransport * core) {
- GNUNET_ASSERT(sizeof(HostAddress) == 8);
- GNUNET_ASSERT(sizeof(TCPP2P_PACKET) == 4);
- GNUNET_ASSERT(sizeof(TCPWelcome) == 68);
- MUTEX_CREATE_RECURSIVE(&tcplock);
+ ectx = core->ectx;
+ cfg = core->cfg;
+ load_monitor = core->load_monitor;
+ GE_ASSERT(ectx, sizeof(HostAddress) == 8);
+ GE_ASSERT(ectx, sizeof(TCPP2P_PACKET) == 4);
+ GE_ASSERT(ectx, sizeof(TCPWelcome) == 68);
+ tcplock = MUTEX_CREATE(YES);
reloadConfiguration();
tsessionCount = 0;
tsessionArrayLength = 0;
@@ -1481,7 +1581,7 @@
tsessionArrayLength,
0);
FREENONNULL(filteredNetworks_);
- MUTEX_DESTROY(&tcplock);
+ MUTEX_DESTROY(tcplock);
}
/* end of tcp.c */
Modified: GNUnet/src/util/config_impl/impl.c
===================================================================
--- GNUnet/src/util/config_impl/impl.c 2006-07-25 07:09:30 UTC (rev 3132)
+++ GNUnet/src/util/config_impl/impl.c 2006-07-25 09:03:10 UTC (rev 3133)
@@ -456,6 +456,8 @@
val = (e->dirty_val != NULL) ? e->dirty_val : e->val;
*value = STRDUP(val);
} else {
+ if (def == NULL)
+ return -1;
*value = STRDUP(def);
ret = 1; /* default */
}
@@ -503,7 +505,10 @@
}
} else {
*value = def;
- ret = 1; /* default */
+ if (def == NULL)
+ ret = -1;
+ else
+ ret = 1; /* default */
}
MUTEX_UNLOCK(cfg->data->lock);
return ret;
Modified: GNUnet/src/util/network/io.c
===================================================================
--- GNUnet/src/util/network/io.c 2006-07-25 07:09:30 UTC (rev 3132)
+++ GNUnet/src/util/network/io.c 2006-07-25 09:03:10 UTC (rev 3133)
@@ -37,6 +37,25 @@
} SocketHandle;
+
+void socket_add_to_select_set(struct SocketHandle * s,
+ fd_set * set,
+ int * max) {
+ FD_SET(s->handle,
+ set);
+ if (*max < s->handle)
+ *max = s->handle;
+}
+
+int socket_test_select_set(struct SocketHandle * sock,
+ fd_set * set) {
+ return FD_ISSET(sock->handle, set);
+}
+
+int socket_get_os_socket(struct SocketHandle * sock) {
+ return sock->handle;
+}
+
struct SocketHandle *
socket_create(struct GE_Context * ectx,
struct LoadMonitor * mon,
@@ -51,6 +70,12 @@
}
void socket_destroy(struct SocketHandle * s) {
+ GE_ASSERT(NULL, s != NULL);
+ if (0 != SHUTDOWN(s->handle,
+ SHUT_RDWR))
+ GE_LOG_STRERROR(s->ectx,
+ GE_WARNING | GE_ADMIN | GE_BULK,
+ "shutdown");
if (0 != CLOSE(s->handle))
GE_LOG_STRERROR(s->ectx,
GE_WARNING | GE_USER | GE_DEVELOPER | GE_BULK,
Modified: GNUnet/todo
===================================================================
--- GNUnet/todo 2006-07-25 07:09:30 UTC (rev 3132)
+++ GNUnet/todo 2006-07-25 09:03:10 UTC (rev 3133)
@@ -12,7 +12,17 @@
0.7.1 ['06] (aka "stabilization")
-- finish util refactoring
+- finish util refactoring:
+ * transports:
+ + TCP: setBlocking for select pipe
+ + UDP/SMTP/HTTP/IPv6: do not yet compile
+ * core:
+ + nothing compiles
+ + add support for extended core API fields
+ * applications:
+ + nothing compiles
+ * setup:
+ + nothing compiles
- adapt util testcases and main GNUnet codebase
- use new util to improve error handling capabilities
- use new util to clean up gnunet-setup
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3133 - in GNUnet: . src/include src/transports src/util/config_impl src/util/network,
grothoff <=