[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r5070 - in GNUnet/src: applications/fs/tools applications/i
From: |
gnunet |
Subject: |
[GNUnet-SVN] r5070 - in GNUnet/src: applications/fs/tools applications/identity applications/transport include server setup/ncurses transports util/network |
Date: |
Fri, 15 Jun 2007 19:03:36 -0600 (MDT) |
Author: grothoff
Date: 2007-06-15 19:03:35 -0600 (Fri, 15 Jun 2007)
New Revision: 5070
Modified:
GNUnet/src/applications/fs/tools/gnunet-download.c
GNUnet/src/applications/identity/clientapi.c
GNUnet/src/applications/identity/identity.c
GNUnet/src/applications/transport/transport.c
GNUnet/src/include/gnunet_identity_lib.h
GNUnet/src/include/gnunet_transport.h
GNUnet/src/include/gnunet_transport_service.h
GNUnet/src/include/gnunet_util_network.h
GNUnet/src/server/gnunet-peer-info.c
GNUnet/src/server/gnunet-transport-check.c
GNUnet/src/setup/ncurses/wizard_curs.c
GNUnet/src/transports/http.c
GNUnet/src/transports/ip.c
GNUnet/src/transports/ip.h
GNUnet/src/transports/nat.c
GNUnet/src/transports/tcp.c
GNUnet/src/transports/tcp6.c
GNUnet/src/transports/tcp_helper.c
GNUnet/src/transports/udp.c
GNUnet/src/transports/udp6.c
GNUnet/src/util/network/Makefile.am
Log:
changing APIs, moving resolution out of gnunetd into clients
Modified: GNUnet/src/applications/fs/tools/gnunet-download.c
===================================================================
--- GNUnet/src/applications/fs/tools/gnunet-download.c 2007-06-16 00:05:52 UTC
(rev 5069)
+++ GNUnet/src/applications/fs/tools/gnunet-download.c 2007-06-16 01:03:35 UTC
(rev 5070)
@@ -80,6 +80,7 @@
1, &gnunet_getopt_configure_set_string, &filename },
{ 'p', "parallelism", "DOWNLOADS",
gettext_noop("set the maximum number of parallel downloads that are
allowed"),
+ 1, &gnunet_getopt_configure_set_uint, ¶llelism },
{ 'R', "recursive", NULL,
gettext_noop("download a GNUnet directory recursively"),
0, &gnunet_getopt_configure_set_one, &do_recursive },
Modified: GNUnet/src/applications/identity/clientapi.c
===================================================================
--- GNUnet/src/applications/identity/clientapi.c 2007-06-16 00:05:52 UTC
(rev 5069)
+++ GNUnet/src/applications/identity/clientapi.c 2007-06-16 01:03:35 UTC
(rev 5070)
@@ -198,8 +198,7 @@
}
count++;
if ( (ntohs(reply->type) != CS_PROTO_identity_INFO) ||
- (ntohs(reply->size) <= sizeof(CS_identity_peer_info_MESSAGE)) ||
- ( ((char*)reply)[ntohs(reply->size)-1] != '\0') ) {
+ (ntohs(reply->size) <= sizeof(CS_identity_peer_info_MESSAGE)) ) {
GE_BREAK(NULL, 0);
FREE(reply);
return SYSERR;
@@ -208,7 +207,8 @@
info = (CS_identity_peer_info_MESSAGE *) reply;
if (OK != callback(cls,
&info->peer,
- (const char*) &info[1],
+ &info[1],
+ ntohs(reply->size) -
sizeof(CS_identity_peer_info_MESSAGE),
ntohll(info->last_message),
ntohl(info->trust),
ntohl(info->bpm))) {
Modified: GNUnet/src/applications/identity/identity.c
===================================================================
--- GNUnet/src/applications/identity/identity.c 2007-06-16 00:05:52 UTC (rev
5069)
+++ GNUnet/src/applications/identity/identity.c 2007-06-16 01:03:35 UTC (rev
5070)
@@ -1253,8 +1253,9 @@
Transport_ServiceAPI * transport;
CS_identity_peer_info_MESSAGE * reply;
P2P_hello_MESSAGE * hello;
- char * address;
+ void * address;
int ret;
+ unsigned int len;
unsigned int bpm;
cron_t last;
@@ -1266,15 +1267,17 @@
if (hello == NULL)
return OK; /* ignore -- happens if HELLO just expired */
transport = coreAPI->requestService("transport");
- address = transport->helloToString(hello,
- YES);
+ len = 0;
+ address = NULL;
+ transport->helloToAddress(hello,
+ &address,
+ &len);
FREE(hello);
coreAPI->releaseService(transport);
- if (address == NULL)
- address = STRDUP("");
- if (strlen(address)+1 >= MAX_BUFFER_SIZE -
sizeof(CS_identity_peer_info_MESSAGE) ) {
+ if (len >= MAX_BUFFER_SIZE - sizeof(CS_identity_peer_info_MESSAGE) ) {
FREE(address);
- address = STRDUP(_("invalid"));
+ address = NULL;
+ len = 0;
}
if (OK != coreAPI->queryPeerStatus(identity,
&bpm,
@@ -1282,8 +1285,8 @@
last = 0;
bpm = 0;
}
- reply = MALLOC(sizeof(CS_identity_peer_info_MESSAGE) + strlen(address) + 1);
- reply->header.size = htons(sizeof(CS_identity_peer_info_MESSAGE) +
strlen(address) + 1);
+ reply = MALLOC(sizeof(CS_identity_peer_info_MESSAGE) + len);
+ reply->header.size = htons(sizeof(CS_identity_peer_info_MESSAGE) + len);
reply->header.type = htons(CS_PROTO_identity_INFO);
reply->peer = *identity;
reply->last_message = htonll(last);
@@ -1291,8 +1294,8 @@
reply->bpm = htonl(bpm);
memcpy(&reply[1],
address,
- strlen(address) + 1);
- FREE(address);
+ len);
+ FREENONNULL(address);
ret = coreAPI->sendToClient(sock,
&reply->header);
FREE(reply);
Modified: GNUnet/src/applications/transport/transport.c
===================================================================
--- GNUnet/src/applications/transport/transport.c 2007-06-16 00:05:52 UTC
(rev 5069)
+++ GNUnet/src/applications/transport/transport.c 2007-06-16 01:03:35 UTC
(rev 5070)
@@ -134,9 +134,10 @@
/**
* Convert hello to string.
*/
-static char *
-helloToString(const P2P_hello_MESSAGE * hello,
- int resolve_ip) {
+static int
+helloToAddress(const P2P_hello_MESSAGE * hello,
+ void ** sa,
+ unsigned int * sa_len) {
unsigned short prot;
prot = ntohs(hello->protocol);
@@ -146,9 +147,11 @@
GE_INFO | GE_REQUEST | GE_USER,
_("Converting peer address to string failed, transport type %d not
supported\n"),
ntohs(hello->protocol));
- return NULL;
+ return SYSERR;
}
- return tapis[prot]->addressToString(hello, resolve_ip);
+ return tapis[prot]->helloToAddress(hello,
+ sa,
+ sa_len);
}
/**
@@ -733,7 +736,7 @@
ret.send = &transportSend;
ret.disconnect = &transportDisconnect;
ret.verifyhello = &transportVerifyHello;
- ret.helloToString = &helloToString;
+ ret.helloToAddress = &helloToAddress;
ret.getMTU = &transportGetMTU;
ret.createhello = &transportCreatehello;
ret.getAdvertisedhellos = &getAdvertisedhellos;
Modified: GNUnet/src/include/gnunet_identity_lib.h
===================================================================
--- GNUnet/src/include/gnunet_identity_lib.h 2007-06-16 00:05:52 UTC (rev
5069)
+++ GNUnet/src/include/gnunet_identity_lib.h 2007-06-16 01:03:35 UTC (rev
5070)
@@ -95,7 +95,8 @@
*/
typedef int (*GNUnetIdentityPeerInfoCallback)(void * data,
const PeerIdentity * identity,
- const char * address,
+ const void * address,
+ unsigned int addr_len,
cron_t last_message,
unsigned int trust,
unsigned int bpmFromPeer);
Modified: GNUnet/src/include/gnunet_transport.h
===================================================================
--- GNUnet/src/include/gnunet_transport.h 2007-06-16 00:05:52 UTC (rev
5069)
+++ GNUnet/src/include/gnunet_transport.h 2007-06-16 01:03:35 UTC (rev
5070)
@@ -323,12 +323,12 @@
int (*stopTransportServer)(void);
/**
- * Convert transport address to human readable string.
- *
- * @param resolve_ip should we try to resolve the IP?
+ * Convert hello to network address.
+ * @return OK on success, SYSERR on error
*/
- char * (*addressToString)(const P2P_hello_MESSAGE * hello,
- int resolve_ip);
+ int (*helloToAddress)(const P2P_hello_MESSAGE * hello,
+ void ** sa,
+ unsigned int * sa_len);
/**
* Test if the transport would even try to send
Modified: GNUnet/src/include/gnunet_transport_service.h
===================================================================
--- GNUnet/src/include/gnunet_transport_service.h 2007-06-16 00:05:52 UTC
(rev 5069)
+++ GNUnet/src/include/gnunet_transport_service.h 2007-06-16 01:03:35 UTC
(rev 5070)
@@ -152,12 +152,13 @@
int (*verifyhello)(const P2P_hello_MESSAGE * hello);
/**
- * Convert hello to string.
+ * Get the network address from a HELLO.
*
- * @param resolve_ip should we try to resovle the IP?
+ * @return OK on success, SYSERR on error
*/
- char * (*helloToString)(const P2P_hello_MESSAGE * hello,
- int resolve_ip);
+ int (*helloToAddress)(const P2P_hello_MESSAGE * hello,
+ void ** sa,
+ unsigned int * sa_len);
/**
* Get the MTU for a given transport type.
Modified: GNUnet/src/include/gnunet_util_network.h
===================================================================
--- GNUnet/src/include/gnunet_util_network.h 2007-06-16 00:05:52 UTC (rev
5069)
+++ GNUnet/src/include/gnunet_util_network.h 2007-06-16 01:03:35 UTC (rev
5070)
@@ -501,6 +501,18 @@
/**
+ * Get an IP address as a string (works for both IPv4 and IPv6). Note
+ * that the resolution happens asynchronously and that the first call
+ * may not immediately result in the FQN (but instead in a
+ * human-readable IP address).
+ *
+ * @param sa should be of type "struct sockaddr*"
+ */
+char * network_get_ip_as_string(const void * sa,
+ unsigned int salen,
+ int do_resolve);
+
+/**
* Get the IP address for the local machine.
* @return NULL on error, IP as string otherwise
*/
Modified: GNUnet/src/server/gnunet-peer-info.c
===================================================================
--- GNUnet/src/server/gnunet-peer-info.c 2007-06-16 00:05:52 UTC (rev
5069)
+++ GNUnet/src/server/gnunet-peer-info.c 2007-06-16 01:03:35 UTC (rev
5070)
@@ -70,7 +70,10 @@
int verified,
void * data) {
P2P_hello_MESSAGE * hello;
+ void * addr;
+ unsigned int addr_len;
char * info;
+ int have_addr;
EncName enc;
if (GNUNET_SHUTDOWN_TEST()==YES)
@@ -95,9 +98,18 @@
GE_WARNING | GE_BULK | GE_USER,
_("hello message invalid (signature invalid).\n"));
}
- info = transport->helloToString(hello,
- ! no_resolve);
+ have_addr = transport->helloToAddress(hello,
+ &addr,
+ &addr_len);
FREE(hello);
+ if (have_addr == NO) {
+ info = STRDUP("NAT"); /* most likely */
+ } else {
+ info = network_get_ip_as_string(addr,
+ addr_len,
+ ! no_resolve);
+ FREE(addr);
+ }
if (info == NULL) {
GE_LOG(ectx,
GE_WARNING | GE_BULK | GE_USER,
Modified: GNUnet/src/server/gnunet-transport-check.c
===================================================================
--- GNUnet/src/server/gnunet-transport-check.c 2007-06-16 00:05:52 UTC (rev
5069)
+++ GNUnet/src/server/gnunet-transport-check.c 2007-06-16 01:03:35 UTC (rev
5070)
@@ -246,9 +246,21 @@
&verbose);
if (verbose > 0) {
char * str;
-
- str = transport->helloToString(xhello,
- YES);
+ void * addr;
+ unsigned int addr_len;
+ int have_addr;
+
+ have_addr = transport->helloToAddress(xhello,
+ &addr,
+ &addr_len);
+ if (have_addr == NO) {
+ str = STRDUP("NAT"); /* most likely */
+ } else {
+ str = network_get_ip_as_string(addr,
+ addr_len,
+ YES);
+ FREE(addr);
+ }
fprintf(stderr,
_("\nContacting `%s'."),
str);
Modified: GNUnet/src/setup/ncurses/wizard_curs.c
===================================================================
--- GNUnet/src/setup/ncurses/wizard_curs.c 2007-06-16 00:05:52 UTC (rev
5069)
+++ GNUnet/src/setup/ncurses/wizard_curs.c 2007-06-16 01:03:35 UTC (rev
5070)
@@ -604,8 +604,13 @@
dir = save_config();
break;
case 11:
+ dir = 0;
ret = OK;
break;
+ default:
+ GE_BREAK(NULL, 0);
+ dir = 0;
+ break;
}
phase += dir;
last = dir;
Modified: GNUnet/src/transports/http.c
===================================================================
--- GNUnet/src/transports/http.c 2007-06-16 00:05:52 UTC (rev 5069)
+++ GNUnet/src/transports/http.c 2007-06-16 01:03:35 UTC (rev 5070)
@@ -1143,48 +1143,27 @@
}
/**
- * Convert HTTP address to a string.
+ * Convert HTTP hello to IP address
*/
-static char *
-addressToString(const P2P_hello_MESSAGE * hello,
- int do_resolve) {
- char * ret;
+static int
+helloToAddress(const P2P_hello_MESSAGE * hello,
+ void ** sa,
+ unsigned int * sa_len) {
const HostAddress * haddr = (const HostAddress*) &hello[1];
- size_t n;
- char * hn;
- struct sockaddr_in serverAddr;
-
- if (do_resolve) {
- memset((char *) &serverAddr,
- 0,
- sizeof(serverAddr));
- serverAddr.sin_family = AF_INET;
- memcpy(&serverAddr.sin_addr,
- haddr,
- sizeof(IPaddr));
- serverAddr.sin_port = haddr->port;
- hn = getIPaddressAsString((const struct sockaddr*) &serverAddr,
- sizeof(struct sockaddr_in));
- } else
- hn = NULL;
- n = 4*4+6+6 + (hn == NULL ? 0 : strlen(hn)) + 10;
- ret = MALLOC(n);
- if (hn != NULL) {
- SNPRINTF(ret,
- n,
- "%s (%u.%u.%u.%u) HTTP (%u)",
- hn,
- PRIP(ntohl(*(int*)&haddr->ip.addr)),
- ntohs(haddr->port));
- } else {
- SNPRINTF(ret,
- n,
- "%u.%u.%u.%u HTTP (%u)",
- PRIP(ntohl(*(int*)&haddr->ip.addr)),
- ntohs(haddr->port));
- }
- FREENONNULL(hn);
- return ret;
+ struct sockaddr_in * serverAddr;
+
+ *sa_len = sizeof(struct sockaddr_in);
+ serverAddr = 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(IPaddr));
+ serverAddr->sin_port = haddr->port;
+ return OK;
}
@@ -1259,7 +1238,7 @@
httpAPI.disconnect = &httpDisconnect;
httpAPI.startTransportServer = &startTransportServer;
httpAPI.stopTransportServer = &stopTransportServer;
- httpAPI.addressToString = &addressToString;
+ httpAPI.helloToAddress = &helloToAddress;
return &httpAPI;
}
Modified: GNUnet/src/transports/ip.c
===================================================================
--- GNUnet/src/transports/ip.c 2007-06-16 00:05:52 UTC (rev 5069)
+++ GNUnet/src/transports/ip.c 2007-06-16 01:03:35 UTC (rev 5070)
@@ -34,14 +34,6 @@
#include "ip.h"
/**
- * Disable DNS resolutions. The existing DNS resolution
- * code is synchronous and introduces ~500ms delays while
- * holding an important lock. As a result, it makes
- * GNUnet laggy. This should be fixed in the future.
- */
-#define NO_RESOLVE YES
-
-/**
* Get the IP address for the local machine.
* @return SYSERR on error, OK on success
*/
@@ -78,150 +70,18 @@
return OK;
}
-struct IPCache {
- struct IPCache * next;
- char * addr;
- struct sockaddr * sa;
- cron_t last_refresh;
- cron_t last_request;
- unsigned int salen;
-};
-
-static struct IPCache * head;
-
-static struct MUTEX * lock;
-
-static void cache_resolve(struct IPCache * cache) {
-#if NO_RESOLVE
- if (cache->sa->sa_family == AF_INET) {
- cache->addr = STRDUP("255.255.255.255");
- SNPRINTF(cache->addr,
- strlen("255.255.255.255")+1,
- "%u.%u.%u.%u",
- PRIP(ntohl(*(int*)&((struct sockaddr_in*) cache->sa)->sin_addr)));
- } else {
- cache->addr = STRDUP("IPv6");
- }
-#else
-#if HAVE_GETNAMEINFO
- char hostname[256];
-
- if (0 == getnameinfo(cache->sa,
- cache->salen,
- hostname,
- 255,
- NULL, 0,
- 0))
- cache->addr = STRDUP(hostname);
-#else
-#if HAVE_GETHOSTBYADDR
- struct hostent * ent;
-
- switch (cache->sa->sa_family) {
- case AF_INET:
- ent = gethostbyaddr(&((struct sockaddr_in*) cache->sa)->sin_addr,
- sizeof(IPaddr),
- AF_INET);
- break;
- case AF_INET6:
- ent = gethostbyaddr(&((struct sockaddr_in6*) cache->sa)->sin6_addr,
- sizeof(IPaddr6),
- AF_INET6);
- break;
- default:
- ent = NULL;
- }
- if (ent != NULL)
- cache->addr = STRDUP(ent->h_name);
-#endif
-#endif
-#endif
-}
-
-static struct IPCache *
-resolve(const struct sockaddr * sa,
- unsigned int salen) {
- struct IPCache * ret;
-
- ret = MALLOC(sizeof(struct IPCache));
- ret->next = head;
- ret->salen = salen;
- ret->sa = salen == 0 ? NULL : MALLOC(salen);
- memcpy(ret->sa,
- sa,
- salen);
- ret->last_request = get_time();
- ret->last_refresh = get_time();
- ret->addr = NULL;
- cache_resolve(ret);
- head = ret;
- return ret;
-}
-
-
-/**
- * Get an IP address as a string
- * (works for both IPv4 and IPv6).
- */
-char * getIPaddressAsString(const void * sav,
- unsigned int salen) {
- const struct sockaddr * sa = sav;
- char * ret;
- struct IPCache * cache;
- struct IPCache * prev;
- cron_t now;
-
- now = get_time();
- MUTEX_LOCK(lock);
- cache = head;
- prev = NULL;
- while ( (cache != NULL) &&
- ( (cache->salen != salen) ||
- (0 != memcmp(cache->sa,
- sa,
- salen) ) ) ) {
- if (cache->last_request + 60 * cronMINUTES < now) {
- if (prev != NULL) {
- prev->next = cache->next;
- FREENONNULL(cache->addr);
- FREE(cache->sa);
- FREE(cache);
- cache = prev->next;
- } else {
- head = cache->next;
- FREENONNULL(cache->addr);
- FREE(cache->sa);
- FREE(cache);
- cache = head;
- }
- continue;
- }
- prev = cache;
- cache = cache->next;
- }
- if (cache != NULL) {
- cache->last_request = now;
- if (cache->last_refresh + 12 * cronHOURS < now) {
- FREENONNULL(cache->addr);
- cache->addr = NULL;
- cache_resolve(cache);
- }
- } else
- cache = resolve(sa, salen);
- ret = (cache->addr == NULL) ? NULL : STRDUP(cache->addr);
- MUTEX_UNLOCK(lock);
- return ret;
-}
-
struct PICache {
struct PICache * next;
- char * address;
+ void * address;
+ unsigned int len;
PeerIdentity peer;
cron_t expire;
};
static struct PICache * pi_head;
+static struct MUTEX * lock;
+
static void expirePICache() {
struct PICache * pos;
struct PICache * next;
@@ -246,17 +106,21 @@
}
}
+
/**
* We only have the PeerIdentity. Do we have any
- * clue about the address (as a string) based on
+ * clue about the address based on
* the "accept" of the connection? Note that the
* response is just the best guess.
+ *
+ * @param sa set to the address
+ * @return OK if we found an address, SYSERR if not
*/
-char * getIPaddressFromPID(const PeerIdentity * peer) {
- char * ret;
+int getIPaddressFromPID(const PeerIdentity * peer,
+ void ** sa,
+ unsigned int * salen) {
struct PICache * cache;
- ret = NULL;
MUTEX_LOCK(lock);
expirePICache();
cache = pi_head;
@@ -264,13 +128,18 @@
if (0 == memcmp(peer,
&cache->peer,
sizeof(PeerIdentity))) {
- ret = STRDUP(cache->address);
- break;
+ *salen = cache->len;
+ *sa = MALLOC(cache->len);
+ memcpy(*sa,
+ cache->address,
+ cache->len);
+ MUTEX_UNLOCK(lock);
+ return OK;
}
cache = cache->next;
}
MUTEX_UNLOCK(lock);
- return ret;
+ return SYSERR;
}
/**
@@ -282,7 +151,8 @@
* us to validate the address).
*/
void setIPaddressFromPID(const PeerIdentity * peer,
- const char * address) {
+ const void * sa,
+ unsigned int salen) {
struct PICache * next;
MUTEX_LOCK(lock);
@@ -292,13 +162,19 @@
&next->peer,
sizeof(PeerIdentity))) {
next->expire = get_time() + 12 * cronHOURS;
- if (0 == strcmp(address,
- next->address)) {
+ if ( (salen == next->len) &&
+ (0 == memcmp(sa,
+ next->address,
+ salen)) ) {
MUTEX_UNLOCK(lock);
return;
}
FREE(next->address);
- next->address = STRDUP(address);
+ next->address = MALLOC(salen);
+ next->len = salen;
+ memcpy(next->address,
+ sa,
+ salen);
MUTEX_UNLOCK(lock);
return;
}
@@ -306,7 +182,11 @@
}
next = MALLOC(sizeof(struct PICache));
next->peer = *peer;
- next->address = STRDUP(address);
+ next->address = MALLOC(salen);
+ memcpy(next->address,
+ sa,
+ salen);
+ next->len = salen;
next->expire = get_time() + 12 * cronHOURS;
expirePICache();
next->next = pi_head;
@@ -322,16 +202,8 @@
}
void __attribute__ ((destructor)) gnunet_ip_ltdl_fini() {
- struct IPCache * pos;
struct PICache * ppos;
MUTEX_DESTROY(lock);
- while (head != NULL) {
- pos = head->next;
- FREENONNULL(head->addr);
- FREE(head->sa);
- FREE(head);
- head = pos;
- }
while (pi_head != NULL) {
ppos = pi_head->next;
FREE(pi_head->address);
Modified: GNUnet/src/transports/ip.h
===================================================================
--- GNUnet/src/transports/ip.h 2007-06-16 00:05:52 UTC (rev 5069)
+++ GNUnet/src/transports/ip.h 2007-06-16 01:03:35 UTC (rev 5070)
@@ -49,22 +49,18 @@
struct GE_Context * ectx,
IPaddr * address);
-
/**
- * Get an IP address as a string
- * (works for both IPv4 and IPv6).
- * @param sa should be of type "struct sockaddr*"
- */
-char * getIPaddressAsString(const void * sa,
- unsigned int salen);
-
-/**
* We only have the PeerIdentity. Do we have any
- * clue about the address (as a string) based on
+ * clue about the address based on
* the "accept" of the connection? Note that the
* response is just the best guess.
+ *
+ * @param sa set to the address
+ * @return OK if we found an address, SYSERR if not
*/
-char * getIPaddressFromPID(const PeerIdentity * peer);
+int getIPaddressFromPID(const PeerIdentity * peer,
+ void ** sa,
+ unsigned int * salen);
/**
* We have accepted a connection from a particular
@@ -75,6 +71,7 @@
* us to validate the address).
*/
void setIPaddressFromPID(const PeerIdentity * peer,
- const char * address);
+ const void * sa,
+ unsigned int salen);
#endif
Modified: GNUnet/src/transports/nat.c
===================================================================
--- GNUnet/src/transports/nat.c 2007-06-16 00:05:52 UTC (rev 5069)
+++ GNUnet/src/transports/nat.c 2007-06-16 01:03:35 UTC (rev 5070)
@@ -171,23 +171,12 @@
/**
* Convert NAT address to a string.
*/
-static char * addressToString(const P2P_hello_MESSAGE * hello,
- int do_resolve) {
- char * addr;
- char * ret;
- size_t n;
-
- addr = getIPaddressFromPID(&hello->senderIdentity);
- if (addr == NULL)
- return STRDUP("NAT");
- n = strlen(addr) + 10;
- ret = MALLOC(n);
- SNPRINTF(ret,
- n,
- "%s NAT",
- addr);
- FREE(addr);
- return ret;
+static int helloToAddress(const P2P_hello_MESSAGE * hello,
+ void ** sa,
+ unsigned int * sa_len) {
+ return getIPaddressFromPID(&hello->senderIdentity,
+ sa,
+ sa_len);
}
static int testWouldTry(TSession * tsession,
@@ -213,7 +202,7 @@
natAPI.disconnect = &natDisconnect;
natAPI.startTransportServer = &startTransportServer;
natAPI.stopTransportServer = &stopTransportServer;
- natAPI.addressToString = &addressToString;
+ natAPI.helloToAddress = &helloToAddress;
natAPI.testWouldTry = &testWouldTry;
return &natAPI;
Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2007-06-16 00:05:52 UTC (rev 5069)
+++ GNUnet/src/transports/tcp.c 2007-06-16 01:03:35 UTC (rev 5070)
@@ -494,48 +494,27 @@
}
/**
- * Convert TCP address to a string.
+ * Convert TCP hello to IP address
*/
-static char *
-addressToString(const P2P_hello_MESSAGE * hello,
- int do_resolve) {
- char * ret;
+static int
+helloToAddress(const P2P_hello_MESSAGE * hello,
+ void ** sa,
+ unsigned int * sa_len) {
const HostAddress * haddr = (const HostAddress*) &hello[1];
- size_t n;
- char * hn;
- struct sockaddr_in serverAddr;
-
- if (do_resolve) {
- memset((char *) &serverAddr,
- 0,
- sizeof(serverAddr));
- serverAddr.sin_family = AF_INET;
- memcpy(&serverAddr.sin_addr,
- haddr,
- sizeof(IPaddr));
- serverAddr.sin_port = haddr->port;
- hn = getIPaddressAsString((const struct sockaddr*) &serverAddr,
- sizeof(struct sockaddr_in));
- } else
- hn = NULL;
- n = 4*4+6+6 + (hn == NULL ? 0 : strlen(hn)) + 10;
- ret = MALLOC(n);
- if (hn != NULL) {
- SNPRINTF(ret,
- n,
- "%s (%u.%u.%u.%u) TCP (%u)",
- hn,
- PRIP(ntohl(*(int*)&haddr->ip.addr)),
- ntohs(haddr->port));
- } else {
- SNPRINTF(ret,
- n,
- "%u.%u.%u.%u TCP (%u)",
- PRIP(ntohl(*(int*)&haddr->ip.addr)),
- ntohs(haddr->port));
- }
- FREENONNULL(hn);
- return ret;
+ struct sockaddr_in * serverAddr;
+
+ *sa_len = sizeof(struct sockaddr_in);
+ serverAddr = 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(IPaddr));
+ serverAddr->sin_port = haddr->port;
+ return OK;
}
@@ -597,7 +576,7 @@
tcpAPI.disconnect = &tcpDisconnect;
tcpAPI.startTransportServer = &startTransportServer;
tcpAPI.stopTransportServer = &stopTransportServer;
- tcpAPI.addressToString = &addressToString;
+ tcpAPI.helloToAddress = &helloToAddress;
tcpAPI.testWouldTry = &tcpTestWouldTry;
return &tcpAPI;
Modified: GNUnet/src/transports/tcp6.c
===================================================================
--- GNUnet/src/transports/tcp6.c 2007-06-16 00:05:52 UTC (rev 5069)
+++ GNUnet/src/transports/tcp6.c 2007-06-16 01:03:35 UTC (rev 5070)
@@ -449,56 +449,27 @@
}
/**
- * Convert TCP6 address to a string.
+ * Convert TCP6 hello to IPv6 address
*/
-static char *
-addressToString(const P2P_hello_MESSAGE * hello,
- int do_resolve) {
-
- char * ret;
- char inet6[INET6_ADDRSTRLEN];
+static int
+helloToAddress(const P2P_hello_MESSAGE * hello,
+ void ** sa,
+ unsigned int * sa_len) {
const Host6Address * haddr = (const Host6Address*) &hello[1];
- char * hn;
- size_t n;
- struct sockaddr_in6 serverAddr;
-
- if (do_resolve) {
- memset((char *) &serverAddr,
- 0,
- sizeof(serverAddr));
- serverAddr.sin6_family = AF_INET6;
- memcpy(&serverAddr.sin6_addr,
- haddr,
- sizeof(IP6addr));
- serverAddr.sin6_port = haddr->port;
- hn = getIPaddressAsString((const struct sockaddr*) &serverAddr,
- sizeof(struct sockaddr_in));
- } else
- hn = NULL;
- n = INET6_ADDRSTRLEN + 16 + (hn == NULL ? 0 : strlen(hn)) + 10;
- ret = MALLOC(n);
- if (hn != NULL) {
- SNPRINTF(ret,
- n,
- "%s (%s) TCP6 (%u)",
- hn,
- inet_ntop(AF_INET6,
- haddr,
- inet6,
- INET6_ADDRSTRLEN),
- ntohs(haddr->port));
- } else {
- SNPRINTF(ret,
- n,
- "%s TCP6 (%u)",
- inet_ntop(AF_INET6,
- haddr,
- inet6,
- INET6_ADDRSTRLEN),
- ntohs(haddr->port));
- }
- FREENONNULL(hn);
- return ret;
+ struct sockaddr_in6 * serverAddr;
+
+ *sa_len = sizeof(struct sockaddr_in6);
+ serverAddr = 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(IP6addr));
+ serverAddr->sin6_port = haddr->port;
+ return OK;
}
@@ -543,7 +514,7 @@
tcp6API.disconnect = &tcpDisconnect;
tcp6API.startTransportServer = &startTransportServer;
tcp6API.stopTransportServer = &stopTransportServer;
- tcp6API.addressToString = &addressToString;
+ tcp6API.helloToAddress = &helloToAddress;
tcp6API.testWouldTry = &tcpTestWouldTry;
return &tcp6API;
Modified: GNUnet/src/transports/tcp_helper.c
===================================================================
--- GNUnet/src/transports/tcp_helper.c 2007-06-16 00:05:52 UTC (rev 5069)
+++ GNUnet/src/transports/tcp_helper.c 2007-06-16 01:03:35 UTC (rev 5070)
@@ -179,7 +179,6 @@
unsigned int len;
P2P_PACKET * mp;
const TCPWelcome * welcome;
- char * addr;
if (SYSERR == tcpAssociate(tsession)) {
GE_BREAK(ectx, 0);
@@ -203,15 +202,10 @@
tcpSession->expectingWelcome = NO;
tcpSession->sender = welcome->clientIdentity;
tsession->peer = welcome->clientIdentity;
- if (tcpSession->accept_addr != NULL) {
- addr = getIPaddressAsString(tcpSession->accept_addr,
- tcpSession->addr_len);
- if (addr != NULL) {
- setIPaddressFromPID(&welcome->clientIdentity,
- addr);
- FREE(addr);
- }
- }
+ if (tcpSession->accept_addr != NULL)
+ setIPaddressFromPID(&welcome->clientIdentity,
+ tcpSession->accept_addr,
+ tcpSession->addr_len);
} else {
/* send msg to core! */
if (len <= sizeof(MESSAGE_HEADER)) {
Modified: GNUnet/src/transports/udp.c
===================================================================
--- GNUnet/src/transports/udp.c 2007-06-16 00:05:52 UTC (rev 5069)
+++ GNUnet/src/transports/udp.c 2007-06-16 01:03:35 UTC (rev 5070)
@@ -476,48 +476,27 @@
}
/**
- * Convert UDP address to a string.
+ * Convert UDP hello to IP address
*/
static char *
-addressToString(const P2P_hello_MESSAGE * hello,
- int do_resolve) {
- char * ret;
+helloToAddress(const P2P_hello_MESSAGE * hello,
+ void ** sa,
+ unsigned int * sa_len) {
const HostAddress * haddr = (const HostAddress*) &hello[1];
- size_t n;
- char * hn;
- struct sockaddr_in serverAddr;
-
- if (do_resolve) {
- memset((char *) &serverAddr,
- 0,
- sizeof(serverAddr));
- serverAddr.sin_family = AF_INET;
- memcpy(&serverAddr.sin_addr,
- haddr,
- sizeof(IPaddr));
- serverAddr.sin_port = haddr->port;
- hn = getIPaddressAsString((const struct sockaddr*) &serverAddr,
- sizeof(struct sockaddr_in));
- } else
- hn = NULL;
- n = 4*4+6+6 + (hn == NULL ? 0 : strlen(hn)) + 10;
- ret = MALLOC(n);
- if (hn != NULL) {
- SNPRINTF(ret,
- n,
- "%s (%u.%u.%u.%u) UDP (%u)",
- hn,
- PRIP(ntohl(*(int*)&haddr->ip.addr)),
- ntohs(haddr->port));
- } else {
- SNPRINTF(ret,
- n,
- "%u.%u.%u.%u UDP (%u)",
- PRIP(ntohl(*(int*)&haddr->ip.addr)),
- ntohs(haddr->port));
- }
- FREENONNULL(hn);
- return ret;
+ struct sockaddr_in * serverAddr;
+
+ *sa_len = sizeof(struct sockaddr_in);
+ serverAddr = 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(IPaddr));
+ serverAddr->sin_port = haddr->port;
+ return OK;
}
/**
@@ -591,7 +570,7 @@
udpAPI.disconnect = &udpDisconnect;
udpAPI.startTransportServer = &startTransportServer;
udpAPI.stopTransportServer = &stopTransportServer;
- udpAPI.addressToString = &addressToString;
+ udpAPI.helloToAddress = &helloToAddress;
udpAPI.testWouldTry = &testWouldTry;
return &udpAPI;
Modified: GNUnet/src/transports/udp6.c
===================================================================
--- GNUnet/src/transports/udp6.c 2007-06-16 00:05:52 UTC (rev 5069)
+++ GNUnet/src/transports/udp6.c 2007-06-16 01:03:35 UTC (rev 5070)
@@ -441,55 +441,27 @@
}
/**
- * Convert UDP6 address to a string.
+ * Convert UDP6 hello to IPv6 address
*/
-static char *
-addressToString(const P2P_hello_MESSAGE * hello,
- int do_resolve) {
- char * ret;
- char inet6[INET6_ADDRSTRLEN];
+static int
+helloToAddress(const P2P_hello_MESSAGE * hello,
+ void ** sa,
+ unsigned int * sa_len) {
const Host6Address * haddr = (const Host6Address*) &hello[1];
- char * hn;
- size_t n;
- struct sockaddr_in6 serverAddr;
-
- if (do_resolve) {
- memset((char *) &serverAddr,
- 0,
- sizeof(serverAddr));
- serverAddr.sin6_family = AF_INET6;
- memcpy(&serverAddr.sin6_addr,
- haddr,
- sizeof(IP6addr));
- serverAddr.sin6_port = haddr->port;
- hn = getIPaddressAsString((const struct sockaddr*) &serverAddr,
- sizeof(struct sockaddr_in));
- } else
- hn = NULL;
- n = INET6_ADDRSTRLEN + 16 + (hn == NULL ? 0 : strlen(hn)) + 10;
- ret = MALLOC(n);
- if (hn != NULL) {
- SNPRINTF(ret,
- n,
- "%s (%s) TCP6 (%u)",
- hn,
- inet_ntop(AF_INET6,
- haddr,
- inet6,
- INET6_ADDRSTRLEN),
- ntohs(haddr->port));
- } else {
- SNPRINTF(ret,
- n,
- "%s TCP6 (%u)",
- inet_ntop(AF_INET6,
- haddr,
- inet6,
- INET6_ADDRSTRLEN),
- ntohs(haddr->port));
- }
- FREENONNULL(hn);
- return ret;
+ struct sockaddr_in6 * serverAddr;
+
+ *sa_len = sizeof(struct sockaddr_in6);
+ serverAddr = 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(IP6addr));
+ serverAddr->sin6_port = haddr->port;
+ return OK;
}
/**
@@ -539,7 +511,7 @@
udpAPI.disconnect = &udpDisconnect;
udpAPI.startTransportServer = &startTransportServer;
udpAPI.stopTransportServer = &stopTransportServer;
- udpAPI.addressToString = &addressToString;
+ udpAPI.helloToAddress = &helloToAddress;
udpAPI.testWouldTry = &testWouldTry;
return &udpAPI;
Modified: GNUnet/src/util/network/Makefile.am
===================================================================
--- GNUnet/src/util/network/Makefile.am 2007-06-16 00:05:52 UTC (rev 5069)
+++ GNUnet/src/util/network/Makefile.am 2007-06-16 01:03:35 UTC (rev 5070)
@@ -6,6 +6,7 @@
libnetwork.la
libnetwork_la_SOURCES = \
+ dns.c \
endian.c network.h \
io.c \
ip.c \
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r5070 - in GNUnet/src: applications/fs/tools applications/identity applications/transport include server setup/ncurses transports util/network,
gnunet <=