[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r5324 - in GNUnet/src: applications/session applications/tr
From: |
gnunet |
Subject: |
[GNUnet-SVN] r5324 - in GNUnet/src: applications/session applications/transport transports |
Date: |
Fri, 20 Jul 2007 09:59:36 -0600 (MDT) |
Author: grothoff
Date: 2007-07-20 09:59:36 -0600 (Fri, 20 Jul 2007)
New Revision: 5324
Added:
GNUnet/src/applications/transport/check.c
Modified:
GNUnet/src/applications/session/connect.c
GNUnet/src/applications/transport/transport.c
GNUnet/src/transports/tcp_helper.c
Log:
dbg
Modified: GNUnet/src/applications/session/connect.c
===================================================================
--- GNUnet/src/applications/session/connect.c 2007-07-20 05:59:38 UTC (rev
5323)
+++ GNUnet/src/applications/session/connect.c 2007-07-20 15:59:36 UTC (rev
5324)
@@ -435,8 +435,8 @@
return SYSERR;
hash2enc (&receiver->hashPubKey, &enc);
/* then try to connect on the transport level */
- if ((tsession == NULL)
- || (transport->associate (tsession, __FILE__) == SYSERR))
+ if ( (tsession == NULL)
+ || (transport->associate (tsession, __FILE__) == SYSERR))
tsession = transport->connectFreely (receiver, YES, __FILE__);
if (tsession == NULL)
{
Added: GNUnet/src/applications/transport/check.c
===================================================================
--- GNUnet/src/applications/transport/check.c (rev 0)
+++ GNUnet/src/applications/transport/check.c 2007-07-20 15:59:36 UTC (rev
5324)
@@ -0,0 +1,62 @@
+
+/**
+ * Transport Session handle.
+ */
+typedef struct TCPSession
+{
+
+ struct TCPSession *next;
+
+ /**
+ * the tcp socket (used to identify this connection with selector)
+ */
+ struct SocketHandle *sock;
+
+ /**
+ * Our tsession.
+ */
+ TSession *tsession;
+
+ /**
+ * mutex for synchronized access to 'users'
+ */
+ struct MUTEX *lock;
+
+ /**
+ * To whom are we talking to (set to our identity
+ * if we are still waiting for the welcome message)
+ */
+ PeerIdentity sender;
+
+ /**
+ * Are we still expecting the welcome? (YES/NO)
+ */
+ int expectingWelcome;
+
+ /**
+ * number of users of this session (reference count)
+ */
+ int users;
+
+ /**
+ * Is this session active with select?
+ */
+ int in_select;
+
+ void *accept_addr;
+
+ unsigned int addr_len;
+
+} TCPSession;
+
+static void check(TSession * session) {
+ TCPSession * tcp;
+
+ if (session->ttype != TCP_PROTOCOL_NUMBER)
+ return;
+ tcp = session->internal;
+ GE_ASSERT(NULL,
+ tcp->users >= session->token_count);
+}
+
+#define CHECK(s) check(s)
Property changes on: GNUnet/src/applications/transport/check.c
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: GNUnet/src/applications/transport/transport.c
===================================================================
--- GNUnet/src/applications/transport/transport.c 2007-07-20 05:59:38 UTC
(rev 5323)
+++ GNUnet/src/applications/transport/transport.c 2007-07-20 15:59:36 UTC
(rev 5324)
@@ -59,8 +59,13 @@
#define HELLO_RECREATE_FREQ (5 * cronMINUTES)
+#define CHECK_IT YES
+#if CHECK_IT
+#include "check.c"
+#else
+#define CHECK(s) do {} while(0)
+#endif
-
/**
* Create signed hello for this transport and put it into
* the cache tapi->hello.
@@ -204,13 +209,13 @@
return NULL;
}
tsession = NULL;
- if (OK != tapis[prot]->connect (hello, &tsession))
- return NULL;
+ if (OK != tapis[prot]->connect (hello, &tsession))
+ return NULL;
tsession->ttype = prot;
MUTEX_LOCK (lock);
APPEND (tsession->tokens, tsession->token_count, token);
+ CHECK(tsession);
MUTEX_UNLOCK (lock);
-
return tsession;
}
@@ -241,10 +246,7 @@
ret = transportConnect (hello, token);
FREE (hello);
if (ret != NULL)
- {
- ret->ttype = perm[i];
break;
- }
}
FREE (perm);
if (ret == NULL)
@@ -281,12 +283,11 @@
(tsession->ttype >= tapis_count) || (tapis[tsession->ttype] == NULL))
return SYSERR;
ret = tapis[tsession->ttype]->associate (tsession);
- if (ret == OK)
- {
- MUTEX_LOCK (lock);
- APPEND (tsession->tokens, tsession->token_count, token);
- MUTEX_UNLOCK (lock);
- }
+ MUTEX_LOCK (lock);
+ if (ret == OK)
+ APPEND (tsession->tokens, tsession->token_count, token);
+ CHECK(tsession);
+ MUTEX_UNLOCK (lock);
return ret;
}
@@ -322,6 +323,9 @@
return SYSERR; /* can't do that, can happen for
unidirectional pipes
that call core with TSession being NULL. */
}
+ MUTEX_LOCK (lock);
+ CHECK(tsession);
+ MUTEX_UNLOCK (lock);
if ((tsession->ttype >= tapis_count) || (tapis[tsession->ttype] == NULL))
{
GE_LOG (ectx,
@@ -353,6 +357,7 @@
return SYSERR;
}
MUTEX_LOCK (lock);
+ CHECK(tsession);
for (i = 0; i < tsession->token_count; i++)
{
if (0 == strcmp (tsession->tokens[i], token))
@@ -375,7 +380,12 @@
return SYSERR;
}
MUTEX_UNLOCK (lock);
- return tapis[tsession->ttype]->disconnect (tsession);
+ i = tapis[tsession->ttype]->disconnect (tsession);
+ GE_BREAK(NULL, i == OK); /* should never fail */
+ MUTEX_LOCK (lock);
+ CHECK(tsession);
+ MUTEX_UNLOCK (lock);
+ return i;
}
/**
Modified: GNUnet/src/transports/tcp_helper.c
===================================================================
--- GNUnet/src/transports/tcp_helper.c 2007-07-20 05:59:38 UTC (rev 5323)
+++ GNUnet/src/transports/tcp_helper.c 2007-07-20 15:59:36 UTC (rev 5324)
@@ -142,6 +142,10 @@
prev = pos;
pos = pos->next;
}
+ MUTEX_UNLOCK (tcplock);
+ GE_ASSERT(ectx,
+ OK != coreAPI->assertUnused (tcpsession->tsession));
+ MUTEX_LOCK (tcplock);
FREE (tcpsession->tsession);
FREE (tcpsession);
}
@@ -158,26 +162,15 @@
tcpsession->users--;
if ((tcpsession->users > 0) || (tcpsession->in_select == YES))
{
+ if (tcpsession->users == 0)
+ select_change_timeout (selector, tcpsession->sock,
+ TCP_FAST_TIMEOUT);
MUTEX_UNLOCK (tcpsession->lock);
MUTEX_UNLOCK (tcplock);
- if (tcpsession->users == 0)
- {
- select_change_timeout (selector, tcpsession->sock,
- TCP_FAST_TIMEOUT);
- GE_ASSERT (ectx, OK == coreAPI->assertUnused (tsession));
- }
return OK;
}
MUTEX_UNLOCK (tcpsession->lock);
MUTEX_UNLOCK (tcplock);
- if (OK != coreAPI->assertUnused (tsession))
- {
- GE_BREAK (ectx, 0);
- abort (); /* for now */
- /* recovery attempt */
- tcpsession->users = 1;
- return OK;
- }
#if DEBUG_TCP
GE_LOG (ectx,
GE_DEBUG | GE_USER | GE_BULK,
@@ -239,7 +232,6 @@
{
TSession *tsession = sock_ctx;
TCPSession *tcpSession;
- TCPSession *pos;
unsigned int len;
P2P_PACKET *mp;
const TCPWelcome *welcome;
@@ -274,57 +266,6 @@
if (tcpSession->accept_addr != NULL)
setIPaddressFromPID (&welcome->clientIdentity,
tcpSession->accept_addr, tcpSession->addr_len);
- /* check that we do not already have
- a connection from this peer; if so,
- close the old one! */
- MUTEX_LOCK (tcplock);
- pos = sessions;
- while (pos != NULL)
- {
- if (pos == tcpSession)
- {
- pos = pos->next;
- continue;
- }
- if (0 == memcmp (&pos->sender,
- &tcpSession->sender, sizeof (PeerIdentity)))
- {
- /* replace existing socket in pos with
- the new socket in tcpSession; then
- delete the new tcpSession -- we have
- the old one! */
- MUTEX_LOCK (pos->lock);
- if (SYSERR == tcpAssociate (pos->tsession))
- {
- GE_BREAK (ectx, 0);
- MUTEX_UNLOCK (pos->lock);
- MUTEX_UNLOCK (tcplock);
- return SYSERR;
- }
- if (pos->in_select)
- select_disconnect (sh, pos->sock);
- pos->in_select = YES;
- pos->sock = tcpSession->sock;
- select_update_closure (sh, pos->sock, tsession, pos->tsession);
- FREENONNULL (pos->accept_addr);
- pos->accept_addr = tcpSession->accept_addr;
- pos->addr_len = tcpSession->addr_len;
- tcpSession->accept_addr = NULL;
- tcpSession->addr_len = 0;
- MUTEX_UNLOCK (pos->lock);
- MUTEX_UNLOCK (tcplock);
- tcpDisconnect (tsession);
- tcpSession->in_select = NO;
- freeTCPSession (tcpSession);
- tcpSession = pos;
- tsession = pos->tsession;
- MUTEX_LOCK (tcplock);
- break;
- }
- pos = pos->next;
- }
- MUTEX_UNLOCK (tcplock);
-
}
else
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r5324 - in GNUnet/src: applications/session applications/transport transports,
gnunet <=