[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r3351 - in GNUnet/src: applications/session server transpor
From: |
grothoff |
Subject: |
[GNUnet-SVN] r3351 - in GNUnet/src: applications/session server transports util/network |
Date: |
Mon, 4 Sep 2006 16:14:55 -0700 (PDT) |
Author: grothoff
Date: 2006-09-04 16:14:47 -0700 (Mon, 04 Sep 2006)
New Revision: 3351
Modified:
GNUnet/src/applications/session/connect.c
GNUnet/src/server/connection.c
GNUnet/src/server/handler.c
GNUnet/src/transports/http.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/select.c
Log:
various bugfixes -- peers now again establish tcp p2p sessions
Modified: GNUnet/src/applications/session/connect.c
===================================================================
--- GNUnet/src/applications/session/connect.c 2006-09-04 21:32:50 UTC (rev
3350)
+++ GNUnet/src/applications/session/connect.c 2006-09-04 23:14:47 UTC (rev
3351)
@@ -452,10 +452,12 @@
#endif
if (stats != NULL)
stats->change(stat_skeySent, 1);
+ printf("Sending session key via plaintext!\n");
coreAPI->sendPlaintext(tsession,
sendBuffer,
size);
FREE(sendBuffer);
+ printf("Offering TSession to core!\n");
coreAPI->offerTSessionFor(receiver,
tsession);
coreAPI->assignSessionKey(&sk,
Modified: GNUnet/src/server/connection.c
===================================================================
--- GNUnet/src/server/connection.c 2006-09-04 21:32:50 UTC (rev 3350)
+++ GNUnet/src/server/connection.c 2006-09-04 23:14:47 UTC (rev 3351)
@@ -1463,7 +1463,7 @@
}
freeSelectedEntries(be);
}
- if((ret == SYSERR) && (be->session.tsession != NULL)) {
+ if ((ret == SYSERR) && (be->session.tsession != NULL)) {
transport->disconnect(be->session.tsession);
be->session.tsession = NULL;
}
@@ -1610,26 +1610,33 @@
* @param hostId for which peer should we get/create a connection
* @return the table entry for the host
*/
-static BufferEntry *addHost(const PeerIdentity * hostId, int establishSession)
{
+static BufferEntry *addHost(const PeerIdentity * hostId,
+ int establishSession) {
BufferEntry *root;
BufferEntry *prev;
#if DEBUG_CONNECTION
EncName enc;
- IFLOG(LOG_EVERYTHING, hash2enc(&hostId->hashPubKey, &enc));
- LOG(LOG_EVERYTHING, "Adding host `%s' to the connection table.\n", &enc);
+ GE_IFLOG(ectx,
+ GE_DEBUG,
+ hash2enc(&hostId->hashPubKey,
+ &enc));
+ GE_LOG(ectx,
+ GE_DEBUG,
+ "Adding host `%s' to the connection table.\n",
+ &enc);
#endif
ENTRY();
root = lookForHost(hostId);
- if(root == NULL) {
+ if (root == NULL) {
root = CONNECTION_buffer_[computeIndex(hostId)];
prev = NULL;
- while(NULL != root) {
+ while (NULL != root) {
/* settle for entry in the linked list that is down */
- if((root->status == STAT_DOWN) ||
- (equalsHashCode512(&hostId->hashPubKey,
- &root->session.sender.hashPubKey)))
+ if ( (root->status == STAT_DOWN) ||
+ (equalsHashCode512(&hostId->hashPubKey,
+ &root->session.sender.hashPubKey)))
break;
prev = root;
root = root->overflowChain;
@@ -1643,7 +1650,8 @@
}
root->session.sender = *hostId;
}
- if((root->status == STAT_DOWN) && (establishSession == YES)) {
+ if ( (root->status == STAT_DOWN) &&
+ (establishSession == YES) ) {
root->lastSequenceNumberReceived = 0;
session->tryConnect(hostId);
}
@@ -1731,8 +1739,13 @@
ENTRY();
#if DEBUG_CONNECTION
- IF_GELOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
hash2enc(&be->session.sender.hashPubKey, &enc));
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER, "Shutting down connection with
`%s'\n", &enc);
+ IF_GELOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ hash2enc(&be->session.sender.hashPubKey, &enc));
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "Shutting down connection with `%s'\n",
+ &enc);
#endif
if(be->status == STAT_DOWN)
return; /* nothing to do */
@@ -2288,9 +2301,10 @@
be = lookForHost(sender);
if((be == NULL) ||
(be->status == STAT_DOWN) || (be->status == STAT_SETKEY_SENT)) {
- GE_LOG(ectx, GE_INFO | GE_BULK | GE_USER,
- "Decrypting message from host `%s' failed, no sessionkey (yet)!\n",
- &enc);
+ GE_LOG(ectx,
+ GE_INFO | GE_BULK | GE_USER,
+ "Decrypting message from host `%s' failed, no sessionkey (yet)!\n",
+ &enc);
/* try to establish a connection, that way, we don't keep
getting bogus messages until the other one times out. */
if((be == NULL) || (be->status == STAT_DOWN))
@@ -2581,42 +2595,43 @@
*/
void considerTakeover(const PeerIdentity * sender,
TSession * tsession) {
- BufferEntry *be;
+ BufferEntry * be;
+ unsigned int cost;
ENTRY();
if(tsession == NULL)
return;
MUTEX_LOCK(lock);
- be = lookForHost(sender);
- if(be != NULL) {
- if(be->status != STAT_DOWN) {
- unsigned int cost = -1;
- if(be->session.tsession != NULL)
- cost = transport->getCost(be->session.tsession->ttype);
- /* Question: doesn't this always do takeover in tcp/udp
- case, which have the same costs? Should it? -IW
-
- Answer: this will always switch to TCP in the long run (if
- that is possible) since udpAssociate always
- returns SYSERR. This is intended since for long-running
- sessions, TCP is the better choice. UDP is only better for
- sending very few messages (e.g. attempting an initial exchange
- to get to know each other). See also transport paper and the
- data on throughput. - CG
- */
- if(transport->getCost(tsession->ttype) < cost) {
- if(transport->associate(tsession) == OK) {
- if(be->session.tsession != NULL)
- transport->disconnect(be->session.tsession);
- be->session.tsession = tsession;
- be->session.mtu = transport->getMTU(tsession->ttype);
- fragmentIfNecessary(be);
- }
- } /* end if cheaper AND possible */
- } /* end if connected */
+ be = addHost(sender, NO);
+ if (be == NULL) {
+ MUTEX_UNLOCK(lock);
+ transport->disconnect(tsession);
+ return;
}
+ cost = -1;
+ if (be->session.tsession != NULL)
+ cost = transport->getCost(be->session.tsession->ttype);
+ /* Question: doesn't this always do takeover in tcp/udp
+ case, which have the same costs? Should it? -IW
+
+ Answer: this will always switch to TCP in the long run (if
+ that is possible) since udpAssociate always
+ returns SYSERR. This is intended since for long-running
+ sessions, TCP is the better choice. UDP is only better for
+ sending very few messages (e.g. attempting an initial exchange
+ to get to know each other). See also transport paper and the
+ data on throughput. - CG
+ */
+ if ( (transport->getCost(tsession->ttype) < cost) &&
+ (transport->associate(tsession) == OK) ) {
+ if (be->session.tsession != NULL)
+ transport->disconnect(be->session.tsession);
+ be->session.tsession = tsession;
+ be->session.mtu = transport->getMTU(tsession->ttype);
+ fragmentIfNecessary(be);
+ }
+ transport->disconnect(tsession);
MUTEX_UNLOCK(lock);
- transport->disconnect(tsession);
}
@@ -3054,10 +3069,15 @@
#if DEBUG_CONNECTION
EncName enc;
- IF_GELOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
hash2enc(&hostId->hashPubKey, &enc));
- GE_LOG(ectx, GE_DEBUG | GE_REQUEST | GE_USER,
- "%s: sending message to host %s message of size %d\n",
- __FUNCTION__, &enc, len);
+ IF_GELOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ hash2enc(&hostId->hashPubKey, &enc));
+ GE_LOG(ectx,
+ GE_DEBUG | GE_REQUEST | GE_USER,
+ "%s: sending message to host %s message of size %d\n",
+ __FUNCTION__,
+ &enc,
+ len);
#endif
ENTRY();
MUTEX_LOCK(lock);
Modified: GNUnet/src/server/handler.c
===================================================================
--- GNUnet/src/server/handler.c 2006-09-04 21:32:50 UTC (rev 3350)
+++ GNUnet/src/server/handler.c 2006-09-04 23:14:47 UTC (rev 3351)
@@ -529,7 +529,6 @@
MUTEX_UNLOCK(globalLock_);
/* end of sync */
SEMAPHORE_UP(bufferQueueWrite_);
-
/* handle buffer - now out of sync */
handleMessage(mp->tsession,
&mp->sender,
Modified: GNUnet/src/transports/http.c
===================================================================
--- GNUnet/src/transports/http.c 2006-09-04 21:32:50 UTC (rev 3350)
+++ GNUnet/src/transports/http.c 2006-09-04 23:14:47 UTC (rev 3351)
@@ -286,9 +286,22 @@
/**
* Check if we are allowed to connect to the given IP.
*/
-static int isBlacklisted(IPaddr ip) {
+static int isBlacklisted(const void * addr,
+ unsigned int addr_len) {
+ IPaddr ip;
int ret;
+ if (addr_len == sizeof(struct sockaddr_in)) {
+ memcpy(&ip,
+ &((struct sockaddr_in*) addr)->sin_addr,
+ sizeof(IPaddr));
+ } else if (addr_len == sizeof(IPaddr)) {
+ memcpy(&ip,
+ addr,
+ addr_len);
+ } else {
+ return SYSERR;
+ }
MUTEX_LOCK(&httplock);
ret = checkIPListed(filteredNetworks_,
ip);
Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2006-09-04 21:32:50 UTC (rev 3350)
+++ GNUnet/src/transports/tcp.c 2006-09-04 23:14:47 UTC (rev 3351)
@@ -80,11 +80,17 @@
IPaddr ip;
int ret;
- if (addr_len != sizeof(IPaddr))
+ if (addr_len == sizeof(struct sockaddr_in)) {
+ memcpy(&ip,
+ &((struct sockaddr_in*) addr)->sin_addr,
+ sizeof(IPaddr));
+ } else if (addr_len == sizeof(IPaddr)) {
+ memcpy(&ip,
+ addr,
+ addr_len);
+ } else {
return SYSERR;
- memcpy(&ip,
- addr,
- addr_len);
+ }
MUTEX_LOCK(tcplock);
ret = check_ipv4_listed(filteredNetworks_,
ip);
Modified: GNUnet/src/transports/tcp6.c
===================================================================
--- GNUnet/src/transports/tcp6.c 2006-09-04 21:32:50 UTC (rev 3350)
+++ GNUnet/src/transports/tcp6.c 2006-09-04 23:14:47 UTC (rev 3351)
@@ -79,14 +79,23 @@
*/
static int isBlacklisted(const void * addr,
unsigned int addr_len) {
- const IP6addr * ip = addr;
+ IP6addr ip;
int ret;
- if (addr_len != sizeof(IP6addr))
+ if (addr_len == sizeof(IP6addr)) {
+ memcpy(&ip,
+ addr,
+ sizeof(IP6addr));
+ } else if (addr_len == sizeof(struct sockaddr_in6)) {
+ memcpy(&ip,
+ &((struct sockaddr_in6*) addr)->sin6_addr,
+ sizeof(IP6addr));
+ } else {
return SYSERR;
+ }
MUTEX_LOCK(tcplock);
ret = check_ipv6_listed(filteredNetworks_,
- *ip);
+ ip);
MUTEX_UNLOCK(tcplock);
return ret;
}
Modified: GNUnet/src/transports/tcp_helper.c
===================================================================
--- GNUnet/src/transports/tcp_helper.c 2006-09-04 21:32:50 UTC (rev 3350)
+++ GNUnet/src/transports/tcp_helper.c 2006-09-04 23:14:47 UTC (rev 3351)
@@ -103,6 +103,10 @@
MUTEX_UNLOCK(tcpsession->lock);
return OK;
}
+ GE_LOG(ectx,
+ GE_DEBUG | GE_USER | GE_BULK,
+ "TCP disconnect closes socket session.\n");
+
select_disconnect(selector,
tcpsession->sock);
MUTEX_UNLOCK(tcpsession->lock);
@@ -176,7 +180,7 @@
GE_LOG(ectx,
GE_WARNING | GE_USER | GE_BULK,
_("Received malformed message instead of welcome message.
Closing.\n"));
- tcpDisconnect(tsession);
+ tcpDisconnect(tsession);
return SYSERR;
}
tcpSession->expectingWelcome = NO;
@@ -357,10 +361,11 @@
= htons(0);
welcome.clientIdentity
= *(coreAPI->myIdentity);
- if (SYSERR == tcpSend(tsession,
- &welcome.header,
- sizeof(TCPWelcome),
- YES)) {
+ if (SYSERR == select_write(selector,
+ s,
+ &welcome.header,
+ NO,
+ YES)) {
#if DEBUG_TCP
GE_LOG(ectx,
GE_DEBUG | GE_USER | GE_BULK,
Modified: GNUnet/src/transports/udp.c
===================================================================
--- GNUnet/src/transports/udp.c 2006-09-04 21:32:50 UTC (rev 3350)
+++ GNUnet/src/transports/udp.c 2006-09-04 23:14:47 UTC (rev 3351)
@@ -140,15 +140,21 @@
* Check if we are explicitly forbidden to communicate with this IP.
*/
static int isBlacklisted(const void * addr,
- unsigned int len) {
+ unsigned int addr_len) {
IPaddr ip;
int ret;
- if (len != sizeof(IPaddr))
+ if (addr_len == sizeof(struct sockaddr_in)) {
+ memcpy(&ip,
+ &((struct sockaddr_in*) addr)->sin_addr,
+ sizeof(IPaddr));
+ } else if (addr_len == sizeof(IPaddr)) {
+ memcpy(&ip,
+ addr,
+ addr_len);
+ } else {
return SYSERR;
- memcpy(&ip,
- addr,
- sizeof(IPaddr));
+ }
MUTEX_LOCK(configLock);
ret = check_ipv4_listed(filteredNetworks_,
ip);
Modified: GNUnet/src/transports/udp6.c
===================================================================
--- GNUnet/src/transports/udp6.c 2006-09-04 21:32:50 UTC (rev 3350)
+++ GNUnet/src/transports/udp6.c 2006-09-04 23:14:47 UTC (rev 3351)
@@ -137,15 +137,21 @@
* Check if we are explicitly forbidden to communicate with this IP.
*/
static int isBlacklisted(const void * addr,
- unsigned int len) {
+ unsigned int addr_len) {
IP6addr ip;
int ret;
- if (len != sizeof(IP6addr))
+ if (addr_len == sizeof(IP6addr)) {
+ memcpy(&ip,
+ addr,
+ sizeof(IP6addr));
+ } else if (addr_len == sizeof(struct sockaddr_in6)) {
+ memcpy(&ip,
+ &((struct sockaddr_in6*) addr)->sin6_addr,
+ sizeof(IP6addr));
+ } else {
return SYSERR;
- memcpy(&ip,
- addr,
- sizeof(IP6addr));
+ }
MUTEX_LOCK(configLock);
ret = check_ipv6_listed(filteredNetworks_,
ip);
Modified: GNUnet/src/util/network/select.c
===================================================================
--- GNUnet/src/util/network/select.c 2006-09-04 21:32:50 UTC (rev 3350)
+++ GNUnet/src/util/network/select.c 2006-09-04 23:14:47 UTC (rev 3351)
@@ -189,9 +189,11 @@
#if DEBUG_SELECT
GE_LOG(sh->ectx,
GE_DEBUG | GE_DEVELOPER | GE_BULK,
- "Destroying session %p of select %p.\n",
+ "Destroying session %p of select %p with %u in read and %u in write
buffer.\n",
+ s,
sh,
- s);
+ s->rsize,
+ s->wsize);
#endif
sh->ch(sh->ch_cls,
sh,
@@ -247,17 +249,20 @@
#if DEBUG_SELECT
GE_LOG(sh->ectx,
GE_DEBUG | GE_DEVELOPER | GE_BULK,
- "Receiving from session %p of select %p return %d.\n",
+ "Receiving from session %p of select %p return %d-%u (%s).\n",
sh,
session,
- ret);
+ ret,
+ recvd,
+ STRERROR(errno));
#endif
if (ret != OK) {
destroySession(sh, session);
return SYSERR; /* other side closed connection */
}
session->pos += recvd;
- while (sh->shutdown == NO) {
+ while ( (sh->shutdown == NO) &&
+ (session->pos >= sizeof(MESSAGE_HEADER)) ) {
pack = (const MESSAGE_HEADER*) &session->rbuff[0];
len = ntohs(pack->size);
/* check minimum size */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r3351 - in GNUnet/src: applications/session server transports util/network,
grothoff <=