[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r1153 - in GNUnet: . src/applications/fs/fsui src/include s
From: |
grothoff |
Subject: |
[GNUnet-SVN] r1153 - in GNUnet: . src/applications/fs/fsui src/include src/transports src/util |
Date: |
Thu, 30 Jun 2005 04:37:50 -0700 (PDT) |
Author: grothoff
Date: 2005-06-30 04:37:37 -0700 (Thu, 30 Jun 2005)
New Revision: 1153
Removed:
GNUnet/src/util/identity.c
Modified:
GNUnet/configure.ac
GNUnet/src/applications/fs/fsui/downloadtest.c
GNUnet/src/include/gnunet_util.h
GNUnet/src/transports/http.c
GNUnet/src/transports/ip.c
GNUnet/src/transports/ip6.c
GNUnet/src/transports/tcp.c
GNUnet/src/transports/tcp6.c
GNUnet/src/transports/udp.c
GNUnet/src/transports/udp6.c
GNUnet/src/util/Makefile.am
GNUnet/src/util/initialize.c
GNUnet/src/util/ipcheck.c
Log:
enabling ipv6 by default, plus some refactoring
Modified: GNUnet/configure.ac
===================================================================
--- GNUnet/configure.ac 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/configure.ac 2005-06-30 11:37:37 UTC (rev 1153)
@@ -396,7 +396,7 @@
AC_SUBST(EXT_LIBS)
# check for IPv6
-ipv6=0
+ipv6=1
AC_MSG_CHECKING([whether to enable ipv6])
AC_ARG_ENABLE(ipv6,
[AC_HELP_STRING([--enable-ipv6],[Enable ipv6 support])
Modified: GNUnet/src/applications/fs/fsui/downloadtest.c
===================================================================
--- GNUnet/src/applications/fs/fsui/downloadtest.c 2005-06-30 11:23:11 UTC
(rev 1152)
+++ GNUnet/src/applications/fs/fsui/downloadtest.c 2005-06-30 11:37:37 UTC
(rev 1153)
@@ -211,6 +211,10 @@
/* END OF TEST CODE */
FAILURE:
+ if (fn != NULL) {
+ UNLINK(fn);
+ FREE(fn);
+ }
if (ctx != NULL) {
FSUI_stopSearch(ctx,
uri);
@@ -225,10 +229,6 @@
ECRS_freeUri(uri);
if (kuri != NULL)
ECRS_freeUri(kuri);
- if (fn != NULL) {
- UNLINK(fn);
- FREE(fn);
- }
fn = makeName(43);
/* TODO: verify file 'fn(42)' == file 'fn(43)' */
UNLINK(fn);
Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/include/gnunet_util.h 2005-06-30 11:37:37 UTC (rev 1153)
@@ -1789,31 +1789,7 @@
int sendTCPResult(GNUNET_TCP_SOCKET * sock,
int ret);
-
/**
- * @brief Determine the (external) IP of the local machine.
- *
- * We have many ways to get that IP:
- * a) from the interface (ifconfig)
- * b) via DNS from our HOSTNAME (environment)
- * c) from the configuration (HOSTNAME specification or static IP)
- *
- * Which way applies depends on the OS, the configuration
- * (dynDNS? static IP? NAT?) and at the end what the user
- * needs.
- *
- * @return SYSERR on error, OK on success
- */
-int getPublicIPAddress(IPaddr * address);
-
-/**
- * @brief Get the IPv6 address for the local machine.
- *
- * @return SYSERR on error, OK on success
- */
-int getPublicIP6Address(IP6addr * address);
-
-/**
* Get the load of the CPU relative to what is allowed.
*
* @return the CPU load as a percentage of allowed
Modified: GNUnet/src/transports/http.c
===================================================================
--- GNUnet/src/transports/http.c 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/transports/http.c 2005-06-30 11:37:37 UTC (rev 1153)
@@ -55,6 +55,7 @@
#include "gnunet_protocols.h"
#include "gnunet_transport.h"
#include "platform.h"
+#include "ip.h"
#define DEBUG_HTTP NO
Modified: GNUnet/src/transports/ip.c
===================================================================
--- GNUnet/src/transports/ip.c 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/transports/ip.c 2005-06-30 11:37:37 UTC (rev 1153)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2004 Christian Grothoff (and other contributing authors)
+ (C) 2001, 2002, 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
@@ -19,7 +19,7 @@
*/
/**
- * @file util/identity.c
+ * @file transports/ip.c
* @brief code to determine the IP of the local machine
*
*
@@ -33,10 +33,6 @@
* (dynDNS? static IP? NAT?) and at the end what the user
* needs.
*
- * 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
*/
@@ -44,21 +40,9 @@
#include <stdlib.h>
#include "platform.h"
#include "gnunet_util.h"
+#include "ip.h"
/**
- * @brief our current IPv4 address.
- */
-static IPaddr myAddress;
-
-static int ipv4_init = NO;
-
-#if USE_IPV6
-static IP6addr myAddress6;
-
-static int ipv6_init = NO;
-#endif
-
-/**
* Obtain the identity information for the current node
* (connection information), conInfo.
* @return SYSERR on failure, OK on success
@@ -97,48 +81,6 @@
return OK;
}
-#if USE_IPV6
-/**
- * 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;
- struct hostent * ip;
-
- hostname = MALLOC(1024);
- if (0 != gethostname(hostname, 1024)) {
- LOG_STRERROR(LOG_ERROR, "gethostname");
- FREE(hostname);
- return SYSERR;
- }
- /* LOG(LOG_DEBUG,
- " looking up $HOSTNAME (%s) to obtain local IP\n",
- hostname); */
-
- 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);
- return SYSERR;
- }
- FREE(hostname);
- if (ip->h_addrtype != AF_INET6) {
- BREAK();
- return SYSERR;
- }
- GNUNET_ASSERT(sizeof(struct in6_addr) == sizeof(identity->addr));
- memcpy(&identity->addr[0],
- ip->h_addr_list[0],
- sizeof(struct in6_addr));
- return OK;
-}
-#endif
-
#if LINUX || SOMEBSD || MINGW
#define MAX_INTERFACES 16
static int getAddressFromIOCTL(IPaddr * identity) {
@@ -196,7 +138,8 @@
return OK;
}
LOG(LOG_WARNING,
- _("Could not find interface '%s' in '%s', trying to find another
interface.\n"),
+ _("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 */
@@ -252,7 +195,8 @@
if (memcmp(bPhysAddr, &l, sizeof(l)) == 0) {
for(i = 0; i < pAddrTable->dwNumEntries; i++) {
- if (pAddrTable->table[i].dwIndex == pTable->table[dwIfIdx].dwIndex) {
+ if (pAddrTable->table[i].dwIndex
+ == pTable->table[dwIfIdx].dwIndex) {
iAddrCount++;
dwIP = pAddrTable->table[i].dwAddr;
}
@@ -304,23 +248,31 @@
theHost.sin_family = AF_INET;
theHost.sin_port = htons(80);
- theHost.sin_addr.S_un.S_addr = *((unsigned long *) pHost->h_addr_list[0]);
- if (CONNECT(s, (SOCKADDR *) &theHost, sizeof(theHost)) == SOCKET_ERROR) {
- LOG_STRERROR(LOG_ERROR, "connect");
+ theHost.sin_addr.S_un.S_addr
+ = *((unsigned long *) pHost->h_addr_list[0]);
+ if (CONNECT(s,
+ (SOCKADDR *) &theHost,
+ sizeof(theHost)) == SOCKET_ERROR) {
+ LOG_STRERROR(LOG_ERROR,
+ "connect");
return SYSERR;
}
i = sizeof(theHost);
- if (GETSOCKNAME(s, (SOCKADDR *) &theHost, &i) == SOCKET_ERROR) {
- LOG_STRERROR(LOG_ERROR, "getsockname");
+ if (GETSOCKNAME(s,
+ (SOCKADDR *) &theHost,
+ &i) == SOCKET_ERROR) {
+ LOG_STRERROR(LOG_ERROR,
+ "getsockname");
return SYSERR;
}
closesocket(s);
identity->addr = theHost.sin_addr.S_un.S_addr;
}
- LOG(LOG_DEBUG, _("GNUnet now uses the IP address %u.%u.%u.%u.\n"),
- PRIP(ntohl(identity->addr)));
+ LOG(LOG_DEBUG,
+ _("GNUnet now uses the IP address %u.%u.%u.%u.\n"),
+ PRIP(ntohl(identity->addr)));
return OK;
#endif
@@ -373,149 +325,28 @@
return retval;
}
-#if USE_IPV6
/**
* Get the IP address for the local machine.
* @return SYSERR on error, OK on success
*/
-static int getAddress6(IP6addr * address){
- char * ipString;
- int retval;
- struct hostent * ip; /* for the lookup of the IP in gnunet.conf */
+int getPublicIPAddress(IPaddr * address) {
+ static IPaddr myAddress;
+ static cron_t last;
+ static cron_t lastError;
+ cron_t now;
- retval = SYSERR;
- ipString = getConfigurationString("NETWORK",
- "IP6");
- if (ipString == NULL) {
- retval = getAddress6FromHostname(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));
- retval = SYSERR;
- } else {
- if (ip->h_addrtype != AF_INET6) {
- BREAK();
- retval = SYSERR;
- } else {
- GNUNET_ASSERT(sizeof(struct in6_addr) == sizeof(address->addr));
- memcpy(&address->addr[0],
- ip->h_addr_list[0],
- sizeof(struct in6_addr));
- retval = OK;
- }
+ cronTime(&now);
+ if (last + cronMINUTES < now) {
+ if (lastError + 30 * cronSECONDS < now)
+ return SYSERR;
+ if (SYSERR == getAddress(&myAddress)) {
+ lastError = now;
+ return SYSERR;
}
- FREE(ipString);
+ last = now;
}
- return retval;
-}
-#endif
-
-static void cronRefreshAddress(void * unused) {
- LOG(LOG_CRON,
- "enter cronRefreshAddress\n");
- if (SYSERR == getAddress(&myAddress))
- LOG(LOG_FAILURE,
- _("Could not determine IP address of the local machine!\n"));
- LOG(LOG_CRON,
- "exit cronRefreshAddress\n");
-}
-
-#if USE_IPV6
-static void cronRefreshAddress6(void * unused) {
- LOG(LOG_CRON,
- "enter cronRefreshAddress6\n");
- if (SYSERR == getAddress6(&myAddress6))
- LOG(LOG_FAILURE,
- _("Could not determine IP(v6) address of the local machine!\n"));
- LOG(LOG_CRON,
- "exit cronRefreshAddress6\n");
-}
-#endif
-
-/**
- * Initialize identity module. Requires configuration.
- */
-int initAddress() {
- if (SYSERR == getAddress(&myAddress)) {
- LOG(LOG_ERROR,
- _("Could not find IP(v4) for this host. Please provide the IP in the
configuration file.\n"));
- ipv4_init = NO;
- } else {
- ipv4_init = YES;
- addCronJob(&cronRefreshAddress,
- 2 * cronMINUTES,
- 2 * cronMINUTES,
- NULL);
- }
-#if USE_IPV6
- if (SYSERR == getAddress6(&myAddress6)) {
- LOG(LOG_ERROR,
- _("Could not find IP(v6) for this host. Please provide the IP in the
configuration file.\n"));
- ipv6_init = NO;
- } else {
- addCronJob(&cronRefreshAddress6,
- 2 * cronMINUTES,
- 2 * cronMINUTES,
- NULL);
- ipv6_init = YES;
- }
-#endif
- return OK;
-}
-
-/**
- * Shutdown identity module.
- */
-void doneAddress() {
- if (ipv4_init == YES) {
- delCronJob(&cronRefreshAddress,
- 2 * cronMINUTES,
- NULL);
- ipv4_init = NO;
- }
-#if USE_IPV6
- if (ipv6_init == YES) {
- delCronJob(&cronRefreshAddress6,
- 2 * cronMINUTES,
- NULL);
- ipv6_init = NO;
- }
-#endif
-
-}
-
-/**
- * Get the IP address for the local machine.
- * @return SYSERR on error, OK on success
- */
-int getPublicIPAddress(IPaddr * address) {
- if (ipv4_init == NO)
- return SYSERR;
*address = myAddress;
return OK;
}
-/**
- * Get the IPv6 address for the local machine.
- * @return SYSERR on error, OK on success
- */
-int getPublicIP6Address(IP6addr * address) {
-#if USE_IPV6
- if (ipv6_init == NO)
- return SYSERR;
- *address = myAddress6;
- return OK;
-#else
- return SYSERR;
-#endif
-}
-
-/* end of identity.c */
+/* end of ip.c */
Modified: GNUnet/src/transports/ip6.c
===================================================================
--- GNUnet/src/transports/ip6.c 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/transports/ip6.c 2005-06-30 11:37:37 UTC (rev 1153)
@@ -1,6 +1,6 @@
/*
This file is part of GNUnet.
- (C) 2001, 2002, 2004 Christian Grothoff (and other contributing authors)
+ (C) 2001, 2002, 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
@@ -19,20 +19,9 @@
*/
/**
- * @file util/identity.c
- * @brief code to determine the IP of the local machine
+ * @file transports/ip6.c
+ * @brief code to determine the IP(v6) of the local machine
*
- *
- * Determine the IP of the local machine. We have many
- * ways to get that IP:
- * a) from the interface (ifconfig)
- * b) via DNS from our HOSTNAME (environment)
- * c) from the configuration (HOSTNAME specification or static IP)
- *
- * Which way applies depends on the OS, the configuration
- * (dynDNS? static IP? NAT?) and at the end what the user
- * needs.
- *
* Todo:
* * scanning of network devices for IPv6 (first: find good
* API to do it, doesn't seem to exist!)
@@ -44,65 +33,13 @@
#include <stdlib.h>
#include "platform.h"
#include "gnunet_util.h"
+#include "ip6.h"
/**
- * @brief our current IPv4 address.
- */
-static IPaddr myAddress;
-
-static int ipv4_init = NO;
-
-#if USE_IPV6
-static IP6addr myAddress6;
-
-static int ipv6_init = NO;
-#endif
-
-/**
* 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;
- struct hostent * ip;
-
- hostname = MALLOC(1024);
- if (0 != gethostname(hostname, 1024)) {
- FREE(hostname);
- LOG_STRERROR(LOG_ERROR, "gethostname");
- return SYSERR;
- }
- /* LOG(LOG_DEBUG,
- " looking up $HOSTNAME (%s) to obtain local IP\n",
- hostname); */
-
- ip = GETHOSTBYNAME(hostname);
- if (ip == NULL) {
- LOG(LOG_ERROR,
- _("Could not find IP of host '%s': %s\n"),
- hostname,
- hstrerror(h_errno));
- FREE(hostname);
- return SYSERR;
- }
- FREE(hostname);
- if (ip->h_addrtype != AF_INET) {
- BREAK();
- return SYSERR;
- }
- memcpy(identity,
- &((struct in_addr*)ip->h_addr_list[0])->s_addr,
- sizeof(struct in_addr));
- return OK;
-}
-
-#if USE_IPV6
-/**
- * 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;
struct hostent * ip;
@@ -137,247 +74,11 @@
sizeof(struct in6_addr));
return OK;
}
-#endif
-#if LINUX || SOMEBSD || MINGW
-#define MAX_INTERFACES 16
-static int getAddressFromIOCTL(IPaddr * identity) {
- char * interfaces;
-#ifndef MINGW
- struct ifreq ifr[MAX_INTERFACES];
- struct ifconf ifc;
- int sockfd,ifCount;
-#else
- DWORD dwIP;
-#endif
- int i;
-
- interfaces = getConfigurationString("NETWORK",
- "INTERFACE");
- if (interfaces == NULL) {
- LOG(LOG_ERROR,
- "No interface specified in section NETWORK under INTERFACE!\n");
- 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");
- return SYSERR;
- }
- ifc.ifc_len = sizeof(ifr);
- ifc.ifc_buf = (char*)𝔦
-
- if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
- LOG_STRERROR(LOG_WARNING, "ioctl");
- closefile(sockfd);
- FREE(interfaces);
- return SYSERR;
- }
- ifCount = ifc.ifc_len / sizeof(struct ifreq);
-
- /* first, try to find exatly matching interface */
- for(i=0;i<ifCount;i++){
- if (ioctl(sockfd, SIOCGIFADDR, &ifr[i]) != 0)
- continue;
- if (ioctl(sockfd, SIOCGIFFLAGS, &ifr[i]) != 0)
- continue;
- if (!(ifr[i].ifr_flags & IFF_UP))
- continue;
- if (strcmp((char*) interfaces,
- (char*) ifr[i].ifr_name) != 0)
- continue;
- memcpy(identity,
- &(((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr),
- sizeof(struct in_addr));
- closefile(sockfd);
- FREE(interfaces);
- return OK;
- }
- LOG(LOG_WARNING,
- _("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++){
- if (ioctl(sockfd, SIOCGIFADDR, &ifr[i]) != 0)
- continue;
- if (ioctl(sockfd, SIOCGIFFLAGS, &ifr[i]) != 0)
- continue;
- if (!(ifr[i].ifr_flags & IFF_UP))
- continue;
- if (strncmp("lo",
- (char*) ifr[i].ifr_name, 2) == 0)
- continue;
- memcpy(identity,
- &(((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr),
- sizeof(struct in_addr));
- closefile(sockfd);
- FREE(interfaces);
- return OK;
- }
-
- closefile(sockfd);
- LOG(LOG_WARNING,
- _("Could not obtain IP for interface '%s' using '%s'.\n"),
- "ioctl",
- interfaces);
- FREE(interfaces);
- return SYSERR;
-#else /* MinGW */
-
- /* Win 98 or Win NT SP 4 */
- if (GNGetIpAddrTable)
- {
- PMIB_IFTABLE pTable;
- PMIB_IPADDRTABLE pAddrTable;
- DWORD dwIfIdx;
- unsigned int iAddrCount = 0;
-
- dwIP = 0;
-
- EnumNICs(&pTable, &pAddrTable);
-
- for(dwIfIdx=0; dwIfIdx < pTable->dwNumEntries; dwIfIdx++) {
- unsigned long long l;
- BYTE bPhysAddr[MAXLEN_PHYSADDR];
-
- l = _atoi64(interfaces);
-
- memset(bPhysAddr, 0, MAXLEN_PHYSADDR);
- memcpy(bPhysAddr,
- pTable->table[dwIfIdx].bPhysAddr,
- pTable->table[dwIfIdx].dwPhysAddrLen);
-
- if (memcmp(bPhysAddr, &l, sizeof(l)) == 0) {
- for(i = 0; i < pAddrTable->dwNumEntries; i++) {
- if (pAddrTable->table[i].dwIndex == pTable->table[dwIfIdx].dwIndex) {
- iAddrCount++;
- dwIP = pAddrTable->table[i].dwAddr;
- }
- }
- }
- }
-
- if (! iAddrCount)
- {
- LOG(LOG_WARNING,
- _("Could not find an IP address for "
- "interface '%s'.\n"),
- interfaces);
-
- GlobalFree(pTable);
- GlobalFree(pAddrTable);
- return SYSERR;
- }
- else if (iAddrCount > 1)
- LOG(LOG_WARNING,
- _("There is more than one IP address specified"
- " for interface '%s'.\nGNUnet will "
- "use %u.%u.%u.%u.\n"),
- interfaces,
- PRIP(ntohl(dwIP)));
-
- identity->addr = dwIP;
-
- GlobalFree(pTable);
- GlobalFree(pAddrTable);
- }
- else /* Win 95 */
- {
- SOCKET s;
- HOSTENT *pHost;
- SOCKADDR_IN theHost;
-
- s = SOCKET(PF_INET, SOCK_STREAM, 0);
- pHost = GETHOSTBYNAME("www.example.com");
- if (! pHost) {
- LOG(LOG_ERROR,
- _("Could not resolve '%s' to "
- "determine our IP address: %s\n"),
- "www.example.com",
- STRERROR(errno));
-
- return SYSERR;
- }
-
- theHost.sin_family = AF_INET;
- theHost.sin_port = htons(80);
- theHost.sin_addr.S_un.S_addr = *((unsigned long *) pHost->h_addr_list[0]);
- if (CONNECT(s, (SOCKADDR *) &theHost, sizeof(theHost)) == SOCKET_ERROR) {
- LOG_STRERROR(LOG_ERROR, "connect");
- return SYSERR;
- }
-
- i = sizeof(theHost);
- if (GETSOCKNAME(s, (SOCKADDR *) &theHost, &i) == SOCKET_ERROR) {
- LOG_STRERROR(LOG_ERROR, "getsockname");
- return SYSERR;
- }
- closesocket(s);
- identity->addr = theHost.sin_addr.S_un.S_addr;
- }
-
- LOG(LOG_DEBUG, _("GNUnet now uses the IP address %u.%u.%u.%u.\n"),
- PRIP(ntohl(identity->addr)));
-
- return OK;
-#endif
-}
-
-#endif
-
/**
* Get the IP address for the local machine.
* @return SYSERR on error, OK on success
*/
-static int getAddress(IPaddr * address){
- char * ipString;
- int retval;
- struct hostent * ip; /* for the lookup of the IP in gnunet.conf */
-
- retval = SYSERR;
- ipString = getConfigurationString("NETWORK",
- "IP");
- if (ipString == NULL || !ipString[0]) {
-#if LINUX || SOMEBSD || MINGW
- if (OK == getAddressFromIOCTL(address))
- retval = OK;
- else
-#endif
- retval = getAddressFromHostname(address);
- } else {
- /* LOG(LOG_DEBUG,
- "obtaining local IP address from hostname %s\n",
- ipString); */
- ip = GETHOSTBYNAME(ipString);
- if (ip == NULL) {
- LOG(LOG_ERROR,
- _("Could not resolve '%s': %s\n"),
- ipString, hstrerror(h_errno));
- retval = SYSERR;
- } else {
- if (ip->h_addrtype != AF_INET) {
- BREAK();
- retval = SYSERR;
- } else {
- memcpy (address,
- &((struct in_addr*) ip->h_addr_list[0])->s_addr,
- sizeof(struct in_addr));
- retval = OK;
- }
- }
- FREE(ipString);
- }
- return retval;
-}
-
-#if USE_IPV6
-/**
- * Get the IP address for the local machine.
- * @return SYSERR on error, OK on success
- */
static int getAddress6(IP6addr * address){
char * ipString;
int retval;
@@ -416,106 +117,29 @@
}
return retval;
}
-#endif
-static void cronRefreshAddress(void * unused) {
- LOG(LOG_CRON,
- "enter cronRefreshAddress\n");
- if (SYSERR == getAddress(&myAddress))
- LOG(LOG_FAILURE,
- _("Could not determine IP address of the local machine!\n"));
- LOG(LOG_CRON,
- "exit cronRefreshAddress\n");
-}
-
-#if USE_IPV6
-static void cronRefreshAddress6(void * unused) {
- LOG(LOG_CRON,
- "enter cronRefreshAddress6\n");
- if (SYSERR == getAddress6(&myAddress6))
- LOG(LOG_FAILURE,
- _("Could not determine IP(v6) address of the local machine!\n"));
- LOG(LOG_CRON,
- "exit cronRefreshAddress6\n");
-}
-#endif
-
-/**
- * Initialize identity module. Requires configuration.
- */
-int initAddress() {
- if (SYSERR == getAddress(&myAddress)) {
- LOG(LOG_ERROR,
- _("Could not find IP(v4) for this host. Please provide the IP in the
configuration file.\n"));
- ipv4_init = NO;
- } else {
- ipv4_init = YES;
- addCronJob(&cronRefreshAddress,
- 2 * cronMINUTES,
- 2 * cronMINUTES,
- NULL);
- }
-#if USE_IPV6
- if (SYSERR == getAddress6(&myAddress6)) {
- LOG(LOG_ERROR,
- _("Could not find IP(v6) for this host. Please provide the IP in the
configuration file.\n"));
- ipv6_init = NO;
- } else {
- addCronJob(&cronRefreshAddress6,
- 2 * cronMINUTES,
- 2 * cronMINUTES,
- NULL);
- ipv6_init = YES;
- }
-#endif
- return OK;
-}
-
-/**
- * Shutdown identity module.
- */
-void doneAddress() {
- if (ipv4_init == YES) {
- delCronJob(&cronRefreshAddress,
- 2 * cronMINUTES,
- NULL);
- ipv4_init = NO;
- }
-#if USE_IPV6
- if (ipv6_init == YES) {
- delCronJob(&cronRefreshAddress6,
- 2 * cronMINUTES,
- NULL);
- ipv6_init = NO;
- }
-#endif
-
-}
-
/**
- * Get the IP address for the local machine.
- * @return SYSERR on error, OK on success
- */
-int getPublicIPAddress(IPaddr * address) {
- if (ipv4_init == NO)
- return SYSERR;
- *address = myAddress;
- return OK;
-}
-
-/**
* Get the IPv6 address for the local machine.
* @return SYSERR on error, OK on success
*/
int getPublicIP6Address(IP6addr * address) {
-#if USE_IPV6
- if (ipv6_init == NO)
- return SYSERR;
- *address = myAddress6;
+ static IP6addr myAddress;
+ static cron_t last;
+ static cron_t lastError;
+ cron_t now;
+
+ cronTime(&now);
+ if (last + cronMINUTES < now) {
+ if (lastError + 30 * cronSECONDS < now)
+ return SYSERR;
+ if (SYSERR == getAddress6(&myAddress)) {
+ lastError = now;
+ return SYSERR;
+ }
+ last = now;
+ }
+ *address = myAddress;
return OK;
-#else
- return SYSERR;
-#endif
}
-/* end of identity.c */
+/* end of ip6.c */
Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/transports/tcp.c 2005-06-30 11:37:37 UTC (rev 1153)
@@ -27,6 +27,7 @@
#include "gnunet_protocols.h"
#include "gnunet_transport.h"
#include "platform.h"
+#include "ip.h"
#define DEBUG_TCP NO
Modified: GNUnet/src/transports/tcp6.c
===================================================================
--- GNUnet/src/transports/tcp6.c 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/transports/tcp6.c 2005-06-30 11:37:37 UTC (rev 1153)
@@ -27,6 +27,7 @@
#include "gnunet_protocols.h"
#include "gnunet_transport.h"
#include "platform.h"
+#include "ip6.h"
#define DEBUG_TCP6 NO
Modified: GNUnet/src/transports/udp.c
===================================================================
--- GNUnet/src/transports/udp.c 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/transports/udp.c 2005-06-30 11:37:37 UTC (rev 1153)
@@ -27,6 +27,7 @@
#include "gnunet_protocols.h"
#include "gnunet_transport.h"
#include "platform.h"
+#include "ip.h"
#define DEBUG_UDP NO
Modified: GNUnet/src/transports/udp6.c
===================================================================
--- GNUnet/src/transports/udp6.c 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/transports/udp6.c 2005-06-30 11:37:37 UTC (rev 1153)
@@ -27,6 +27,7 @@
#include "gnunet_protocols.h"
#include "gnunet_transport.h"
#include "platform.h"
+#include "ip6.h"
#define DEBUG_UDP6 NO
Modified: GNUnet/src/util/Makefile.am
===================================================================
--- GNUnet/src/util/Makefile.am 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/util/Makefile.am 2005-06-30 11:37:37 UTC (rev 1153)
@@ -64,7 +64,6 @@
generate_gnunet_conf.c \
hashing.c \
hostkey_gcrypt.c \
- identity.c \
initialize.c \
io.c \
ipcheck.c \
Deleted: GNUnet/src/util/identity.c
===================================================================
--- GNUnet/src/util/identity.c 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/util/identity.c 2005-06-30 11:37:37 UTC (rev 1153)
@@ -1,521 +0,0 @@
-/*
- This file is part of GNUnet.
- (C) 2001, 2002, 2004 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 util/identity.c
- * @brief code to determine the IP of the local machine
- *
- *
- * Determine the IP of the local machine. We have many
- * ways to get that IP:
- * a) from the interface (ifconfig)
- * b) via DNS from our HOSTNAME (environment)
- * c) from the configuration (HOSTNAME specification or static IP)
- *
- * Which way applies depends on the OS, the configuration
- * (dynDNS? static IP? NAT?) and at the end what the user
- * needs.
- *
- * 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
- */
-
-#include <stdlib.h>
-#include "platform.h"
-#include "gnunet_util.h"
-
-/**
- * @brief our current IPv4 address.
- */
-static IPaddr myAddress;
-
-static int ipv4_init = NO;
-
-#if USE_IPV6
-static IP6addr myAddress6;
-
-static int ipv6_init = NO;
-#endif
-
-/**
- * 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;
- struct hostent * ip;
-
- hostname = MALLOC(1024);
- if (0 != gethostname(hostname, 1024)) {
- FREE(hostname);
- LOG_STRERROR(LOG_ERROR, "gethostname");
- return SYSERR;
- }
- /* LOG(LOG_DEBUG,
- " looking up $HOSTNAME (%s) to obtain local IP\n",
- hostname); */
-
- ip = GETHOSTBYNAME(hostname);
- if (ip == NULL) {
- LOG(LOG_ERROR,
- _("Could not find IP of host '%s': %s\n"),
- hostname,
- hstrerror(h_errno));
- FREE(hostname);
- return SYSERR;
- }
- FREE(hostname);
- if (ip->h_addrtype != AF_INET) {
- BREAK();
- return SYSERR;
- }
- memcpy(identity,
- &((struct in_addr*)ip->h_addr_list[0])->s_addr,
- sizeof(struct in_addr));
- return OK;
-}
-
-#if USE_IPV6
-/**
- * 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;
- struct hostent * ip;
-
- hostname = MALLOC(1024);
- if (0 != gethostname(hostname, 1024)) {
- LOG_STRERROR(LOG_ERROR, "gethostname");
- FREE(hostname);
- return SYSERR;
- }
- /* LOG(LOG_DEBUG,
- " looking up $HOSTNAME (%s) to obtain local IP\n",
- hostname); */
-
- 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);
- return SYSERR;
- }
- FREE(hostname);
- if (ip->h_addrtype != AF_INET6) {
- BREAK();
- return SYSERR;
- }
- GNUNET_ASSERT(sizeof(struct in6_addr) == sizeof(identity->addr));
- memcpy(&identity->addr[0],
- ip->h_addr_list[0],
- sizeof(struct in6_addr));
- return OK;
-}
-#endif
-
-#if LINUX || SOMEBSD || MINGW
-#define MAX_INTERFACES 16
-static int getAddressFromIOCTL(IPaddr * identity) {
- char * interfaces;
-#ifndef MINGW
- struct ifreq ifr[MAX_INTERFACES];
- struct ifconf ifc;
- int sockfd,ifCount;
-#else
- DWORD dwIP;
-#endif
- int i;
-
- interfaces = getConfigurationString("NETWORK",
- "INTERFACE");
- if (interfaces == NULL) {
- LOG(LOG_ERROR,
- "No interface specified in section NETWORK under INTERFACE!\n");
- 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");
- return SYSERR;
- }
- ifc.ifc_len = sizeof(ifr);
- ifc.ifc_buf = (char*)𝔦
-
- if (ioctl(sockfd, SIOCGIFCONF, &ifc) == -1) {
- LOG_STRERROR(LOG_WARNING, "ioctl");
- closefile(sockfd);
- FREE(interfaces);
- return SYSERR;
- }
- ifCount = ifc.ifc_len / sizeof(struct ifreq);
-
- /* first, try to find exatly matching interface */
- for(i=0;i<ifCount;i++){
- if (ioctl(sockfd, SIOCGIFADDR, &ifr[i]) != 0)
- continue;
- if (ioctl(sockfd, SIOCGIFFLAGS, &ifr[i]) != 0)
- continue;
- if (!(ifr[i].ifr_flags & IFF_UP))
- continue;
- if (strcmp((char*) interfaces,
- (char*) ifr[i].ifr_name) != 0)
- continue;
- memcpy(identity,
- &(((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr),
- sizeof(struct in_addr));
- closefile(sockfd);
- FREE(interfaces);
- return OK;
- }
- LOG(LOG_WARNING,
- _("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++){
- if (ioctl(sockfd, SIOCGIFADDR, &ifr[i]) != 0)
- continue;
- if (ioctl(sockfd, SIOCGIFFLAGS, &ifr[i]) != 0)
- continue;
- if (!(ifr[i].ifr_flags & IFF_UP))
- continue;
- if (strncmp("lo",
- (char*) ifr[i].ifr_name, 2) == 0)
- continue;
- memcpy(identity,
- &(((struct sockaddr_in *)&ifr[i].ifr_addr)->sin_addr),
- sizeof(struct in_addr));
- closefile(sockfd);
- FREE(interfaces);
- return OK;
- }
-
- closefile(sockfd);
- LOG(LOG_WARNING,
- _("Could not obtain IP for interface '%s' using '%s'.\n"),
- "ioctl",
- interfaces);
- FREE(interfaces);
- return SYSERR;
-#else /* MinGW */
-
- /* Win 98 or Win NT SP 4 */
- if (GNGetIpAddrTable)
- {
- PMIB_IFTABLE pTable;
- PMIB_IPADDRTABLE pAddrTable;
- DWORD dwIfIdx;
- unsigned int iAddrCount = 0;
-
- dwIP = 0;
-
- EnumNICs(&pTable, &pAddrTable);
-
- for(dwIfIdx=0; dwIfIdx < pTable->dwNumEntries; dwIfIdx++) {
- unsigned long long l;
- BYTE bPhysAddr[MAXLEN_PHYSADDR];
-
- l = _atoi64(interfaces);
-
- memset(bPhysAddr, 0, MAXLEN_PHYSADDR);
- memcpy(bPhysAddr,
- pTable->table[dwIfIdx].bPhysAddr,
- pTable->table[dwIfIdx].dwPhysAddrLen);
-
- if (memcmp(bPhysAddr, &l, sizeof(l)) == 0) {
- for(i = 0; i < pAddrTable->dwNumEntries; i++) {
- if (pAddrTable->table[i].dwIndex == pTable->table[dwIfIdx].dwIndex) {
- iAddrCount++;
- dwIP = pAddrTable->table[i].dwAddr;
- }
- }
- }
- }
-
- if (! iAddrCount)
- {
- LOG(LOG_WARNING,
- _("Could not find an IP address for "
- "interface '%s'.\n"),
- interfaces);
-
- GlobalFree(pTable);
- GlobalFree(pAddrTable);
- return SYSERR;
- }
- else if (iAddrCount > 1)
- LOG(LOG_WARNING,
- _("There is more than one IP address specified"
- " for interface '%s'.\nGNUnet will "
- "use %u.%u.%u.%u.\n"),
- interfaces,
- PRIP(ntohl(dwIP)));
-
- identity->addr = dwIP;
-
- GlobalFree(pTable);
- GlobalFree(pAddrTable);
- }
- else /* Win 95 */
- {
- SOCKET s;
- HOSTENT *pHost;
- SOCKADDR_IN theHost;
-
- s = SOCKET(PF_INET, SOCK_STREAM, 0);
- pHost = GETHOSTBYNAME("www.example.com");
- if (! pHost) {
- LOG(LOG_ERROR,
- _("Could not resolve '%s' to "
- "determine our IP address: %s\n"),
- "www.example.com",
- STRERROR(errno));
-
- return SYSERR;
- }
-
- theHost.sin_family = AF_INET;
- theHost.sin_port = htons(80);
- theHost.sin_addr.S_un.S_addr = *((unsigned long *) pHost->h_addr_list[0]);
- if (CONNECT(s, (SOCKADDR *) &theHost, sizeof(theHost)) == SOCKET_ERROR) {
- LOG_STRERROR(LOG_ERROR, "connect");
- return SYSERR;
- }
-
- i = sizeof(theHost);
- if (GETSOCKNAME(s, (SOCKADDR *) &theHost, &i) == SOCKET_ERROR) {
- LOG_STRERROR(LOG_ERROR, "getsockname");
- return SYSERR;
- }
- closesocket(s);
- identity->addr = theHost.sin_addr.S_un.S_addr;
- }
-
- LOG(LOG_DEBUG, _("GNUnet now uses the IP address %u.%u.%u.%u.\n"),
- PRIP(ntohl(identity->addr)));
-
- return OK;
-#endif
-}
-
-#endif
-
-/**
- * Get the IP address for the local machine.
- * @return SYSERR on error, OK on success
- */
-static int getAddress(IPaddr * address){
- char * ipString;
- int retval;
- struct hostent * ip; /* for the lookup of the IP in gnunet.conf */
-
- retval = SYSERR;
- ipString = getConfigurationString("NETWORK",
- "IP");
- if (ipString == NULL || !ipString[0]) {
-#if LINUX || SOMEBSD || MINGW
- if (OK == getAddressFromIOCTL(address))
- retval = OK;
- else
-#endif
- retval = getAddressFromHostname(address);
- } else {
- /* LOG(LOG_DEBUG,
- "obtaining local IP address from hostname %s\n",
- ipString); */
- ip = GETHOSTBYNAME(ipString);
- if (ip == NULL) {
- LOG(LOG_ERROR,
- _("Could not resolve '%s': %s\n"),
- ipString, hstrerror(h_errno));
- retval = SYSERR;
- } else {
- if (ip->h_addrtype != AF_INET) {
- BREAK();
- retval = SYSERR;
- } else {
- memcpy (address,
- &((struct in_addr*) ip->h_addr_list[0])->s_addr,
- sizeof(struct in_addr));
- retval = OK;
- }
- }
- FREE(ipString);
- }
- return retval;
-}
-
-#if USE_IPV6
-/**
- * Get the IP address for the local machine.
- * @return SYSERR on error, OK on success
- */
-static int getAddress6(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);
- } 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));
- retval = SYSERR;
- } else {
- if (ip->h_addrtype != AF_INET6) {
- BREAK();
- retval = SYSERR;
- } else {
- GNUNET_ASSERT(sizeof(struct in6_addr) == sizeof(address->addr));
- memcpy(&address->addr[0],
- ip->h_addr_list[0],
- sizeof(struct in6_addr));
- retval = OK;
- }
- }
- FREE(ipString);
- }
- return retval;
-}
-#endif
-
-static void cronRefreshAddress(void * unused) {
- LOG(LOG_CRON,
- "enter cronRefreshAddress\n");
- if (SYSERR == getAddress(&myAddress))
- LOG(LOG_FAILURE,
- _("Could not determine IP address of the local machine!\n"));
- LOG(LOG_CRON,
- "exit cronRefreshAddress\n");
-}
-
-#if USE_IPV6
-static void cronRefreshAddress6(void * unused) {
- LOG(LOG_CRON,
- "enter cronRefreshAddress6\n");
- if (SYSERR == getAddress6(&myAddress6))
- LOG(LOG_FAILURE,
- _("Could not determine IP(v6) address of the local machine!\n"));
- LOG(LOG_CRON,
- "exit cronRefreshAddress6\n");
-}
-#endif
-
-/**
- * Initialize identity module. Requires configuration.
- */
-int initAddress() {
- if (SYSERR == getAddress(&myAddress)) {
- LOG(LOG_ERROR,
- _("Could not find IP(v4) for this host. Please provide the IP in the
configuration file.\n"));
- ipv4_init = NO;
- } else {
- ipv4_init = YES;
- addCronJob(&cronRefreshAddress,
- 2 * cronMINUTES,
- 2 * cronMINUTES,
- NULL);
- }
-#if USE_IPV6
- if (SYSERR == getAddress6(&myAddress6)) {
- LOG(LOG_ERROR,
- _("Could not find IP(v6) for this host. Please provide the IP in the
configuration file.\n"));
- ipv6_init = NO;
- } else {
- addCronJob(&cronRefreshAddress6,
- 2 * cronMINUTES,
- 2 * cronMINUTES,
- NULL);
- ipv6_init = YES;
- }
-#endif
- return OK;
-}
-
-/**
- * Shutdown identity module.
- */
-void doneAddress() {
- if (ipv4_init == YES) {
- delCronJob(&cronRefreshAddress,
- 2 * cronMINUTES,
- NULL);
- ipv4_init = NO;
- }
-#if USE_IPV6
- if (ipv6_init == YES) {
- delCronJob(&cronRefreshAddress6,
- 2 * cronMINUTES,
- NULL);
- ipv6_init = NO;
- }
-#endif
-
-}
-
-/**
- * Get the IP address for the local machine.
- * @return SYSERR on error, OK on success
- */
-int getPublicIPAddress(IPaddr * address) {
- if (ipv4_init == NO)
- return SYSERR;
- *address = myAddress;
- return OK;
-}
-
-/**
- * Get the IPv6 address for the local machine.
- * @return SYSERR on error, OK on success
- */
-int getPublicIP6Address(IP6addr * address) {
-#if USE_IPV6
- if (ipv6_init == NO)
- return SYSERR;
- *address = myAddress6;
- return OK;
-#else
- return SYSERR;
-#endif
-}
-
-/* end of identity.c */
Modified: GNUnet/src/util/initialize.c
===================================================================
--- GNUnet/src/util/initialize.c 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/util/initialize.c 2005-06-30 11:37:37 UTC (rev 1153)
@@ -81,16 +81,6 @@
*/
void doneStatusCalls();
-/**
- * Initialize identity module. Requries configuration.
- */
-int initAddress();
-
-/**
- * Shutdown identity module.
- */
-void doneAddress();
-
void gnunet_util_initIO();
void gnunet_util_doneIO();
@@ -139,13 +129,8 @@
initLogging();
if (testConfigurationString("GNUNETD",
"_MAGIC_",
- "YES")) {
+ "YES"))
initStatusCalls();
- if (OK != initAddress()) {
- initState();
- return SYSERR;
- }
- }
initState();
return OK;
}
@@ -153,10 +138,8 @@
void doneUtil() {
if (testConfigurationString("GNUNETD",
"_MAGIC_",
- "YES")) {
- doneStatusCalls();
- doneAddress();
- }
+ "YES"))
+ doneStatusCalls();
doneCron();
doneState();
LOG(LOG_MESSAGE,
Modified: GNUnet/src/util/ipcheck.c
===================================================================
--- GNUnet/src/util/ipcheck.c 2005-06-30 11:23:11 UTC (rev 1152)
+++ GNUnet/src/util/ipcheck.c 2005-06-30 11:37:37 UTC (rev 1153)
@@ -198,7 +198,6 @@
return NO;
}
-#if USE_IPV6
/**
* Parse a network specification. The argument specifies
* a list of networks. The format is
@@ -322,6 +321,5 @@
}
return NO;
}
-#endif
/* end of ipcheck.c */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r1153 - in GNUnet: . src/applications/fs/fsui src/include src/transports src/util,
grothoff <=