[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r1203 - in GNUnet/src: applications/advertising application
From: |
grothoff |
Subject: |
[GNUnet-SVN] r1203 - in GNUnet/src: applications/advertising applications/pingpong applications/session applications/transport include server transports |
Date: |
Sat, 2 Jul 2005 05:01:05 -0700 (PDT) |
Author: grothoff
Date: 2005-07-02 05:00:55 -0700 (Sat, 02 Jul 2005)
New Revision: 1203
Modified:
GNUnet/src/applications/advertising/advertising.c
GNUnet/src/applications/pingpong/pingpong.c
GNUnet/src/applications/session/connect.c
GNUnet/src/applications/transport/transport.c
GNUnet/src/include/gnunet_transport_service.h
GNUnet/src/server/connection.c
GNUnet/src/server/gnunet-transport-check.c
GNUnet/src/transports/tcp.c
Log:
connect improvements and code cleanup
Modified: GNUnet/src/applications/advertising/advertising.c
===================================================================
--- GNUnet/src/applications/advertising/advertising.c 2005-07-02 10:33:44 UTC
(rev 1202)
+++ GNUnet/src/applications/advertising/advertising.c 2005-07-02 12:00:55 UTC
(rev 1203)
@@ -261,16 +261,9 @@
/* Establish session as advertised in the HELO */
- copy = MALLOC(HELO_Message_size(msg));
- memcpy(copy,
- msg,
- HELO_Message_size(msg));
- if (SYSERR == transport->connect(copy, /* copy is freed by callee,
- except on SYSERR! */
- &tsession)) {
- FREE(copy);
- return SYSERR; /* could not connect */
- }
+ tsession = transport->connect(msg);
+ if (tsession == NULL)
+ return SYSERR; /* could not connect */
/* build message to send, ping must contain return-information,
such as a selection of our HELOs... */
@@ -395,10 +388,9 @@
#endif
return;
}
- if (SYSERR == transport->connect(helo, /* helo is freed by callee,
- except on SYSERR! */
- &tsession)) {
- FREE(helo);
+ tsession = transport->connect(helo);
+ FREE(helo);
+ if (tsession == NULL) {
#if DEBUG_HELOEXCHANGE
LOG(LOG_DEBUG,
"Exit from '%s' (%s error).\n",
@@ -494,7 +486,7 @@
if (randomi(fcc->prob) != 0)
return; /* only forward with a certain chance */
if (equalsHashCode512(&peer->hashPubKey,
- &fcc->msg->senderIdentity))
+ &fcc->msg->senderIdentity.hashPubKey))
return; /* do not bounce the HELO of a peer back
to the same peer! */
if (stats != NULL)
Modified: GNUnet/src/applications/pingpong/pingpong.c
===================================================================
--- GNUnet/src/applications/pingpong/pingpong.c 2005-07-02 10:33:44 UTC (rev
1202)
+++ GNUnet/src/applications/pingpong/pingpong.c 2005-07-02 12:00:55 UTC (rev
1203)
@@ -143,26 +143,17 @@
static int sendPlaintext(const PeerIdentity * peer,
const PINGPONG_Message * msg) {
- HELO_Message * helo;
TSession * mytsession;
-
- if (SYSERR == identity->identity2Helo(peer,
- ANY_PROTOCOL_NUMBER,
- YES,
- &helo))
- return SYSERR;
- if (SYSERR == transport->connect(helo, &mytsession)) {
- FREE(helo);
- return SYSERR;
- }
- if (OK != coreAPI->sendPlaintext(mytsession,
- (char*)msg,
- sizeof(PINGPONG_Message))) {
- transport->disconnect(mytsession);
- return SYSERR;
- }
+ int ret;
+
+ mytsession = transport->connectFreely(peer, YES);
+ if (mytsession == NULL)
+ return SYSERR;
+ ret = coreAPI->sendPlaintext(mytsession,
+ (char*)msg,
+ sizeof(PINGPONG_Message));
transport->disconnect(mytsession);
- return OK;
+ return ret;
}
/**
Modified: GNUnet/src/applications/session/connect.c
===================================================================
--- GNUnet/src/applications/session/connect.c 2005-07-02 10:33:44 UTC (rev
1202)
+++ GNUnet/src/applications/session/connect.c 2005-07-02 12:00:55 UTC (rev
1203)
@@ -32,12 +32,15 @@
#include "gnunet_identity_service.h"
#include "gnunet_pingpong_service.h"
#include "gnunet_session_service.h"
+#include "gnunet_stats_service.h"
#include "gnunet_topology_service.h"
#define HELO_HELPER_TABLE_START_SIZE 64
#define DEBUG_SESSION YES
+#define EXTRA_CHECKS YES
+
static CoreAPIForApplication * coreAPI;
static Identity_ServiceAPI * identity;
@@ -48,6 +51,16 @@
static Topology_ServiceAPI * topology;
+static Stats_ServiceAPI * stats;
+
+static int stat_skeySent;
+
+static int stat_skeyRejected;
+
+static int stat_skeyAccepted;
+
+static int stat_sessionEstablished;
+
/**
* @brief message for session key exchange.
*/
@@ -115,11 +128,90 @@
&enc);
#endif
GNUNET_ASSERT(hostId != NULL);
+ if (stats != NULL)
+ stats->change(stat_sessionEstablished,
+ 1);
coreAPI->confirmSessionUp(hostId);
FREE(hostId);
}
+
/**
+ * Check if the received session key is properly signed
+ * and if connections to this peer are allowed according
+ * to policy.
+ *
+ * @param hostId the sender of the key
+ * @param sks the session key message
+ * @return SYSERR if invalid, OK if valid
+ */
+static int verifySKS(const PeerIdentity * hostId,
+ SKEY_Message * sks) {
+ char * limited;
+
+ if ( (sks == NULL) ||
+ (hostId == NULL) ) {
+ BREAK();
+ return SYSERR;
+ }
+ /* check if we are allowed to accept connections
+ from that peer */
+ limited = getConfigurationString("GNUNETD",
+ "LIMIT-ALLOW");
+ if (limited != NULL) {
+ EncName enc;
+ hash2enc(&hostId->hashPubKey,
+ &enc);
+ if (NULL == strstr(limited,
+ (char*) &enc)) {
+#if DEBUG_SESSION
+ LOG(LOG_DEBUG,
+ "Connection from peer '%s' was rejected.\n",
+ &enc);
+#endif
+ FREE(limited);
+ return SYSERR;
+ }
+ FREE(limited);
+ }
+ limited = getConfigurationString("GNUNETD",
+ "LIMIT-DENY");
+ if (limited != NULL) {
+ EncName enc;
+ hash2enc(&hostId->hashPubKey,
+ &enc);
+ if (NULL != strstr(limited,
+ (char*) &enc)) {
+#if DEBUG_SESSION
+ LOG(LOG_DEBUG,
+ "Connection from peer '%s' was rejected.\n",
+ &enc);
+#endif
+ FREE(limited);
+ return SYSERR;
+ }
+ FREE(limited);
+ }
+
+ if (OK != identity->verifyPeerSignature
+ (hostId,
+ sks,
+ sizeof(SKEY_Message) - sizeof(Signature),
+ &sks->signature)) {
+ EncName enc;
+
+ IFLOG(LOG_INFO,
+ hash2enc(&hostId->hashPubKey,
+ &enc));
+ LOG(LOG_INFO,
+ _("Session key from peer '%s' could not be verified.\n"),
+ &enc);
+ return SYSERR; /*reject!*/
+ }
+ return OK; /* ok */
+}
+
+/**
* Force creation of a new Session key for the given host.
*
* @param hostId the identity of the other host
@@ -184,12 +276,14 @@
msg->header.size = htons(size);
msg->header.type = htons(p2p_PROTO_SKEY);
msg->creationTime = htonl(created);
- GNUNET_ASSERT(SYSERR != identity->signData(msg,
- sizeof(SKEY_Message) -
sizeof(Signature),
- &msg->signature));
+ GNUNET_ASSERT(SYSERR !=
+ identity->signData(msg,
+ sizeof(SKEY_Message)
+ - sizeof(Signature),
+ &msg->signature));
#if EXTRA_CHECKS
/* verify signature/SKS */
- GNUNET_ASSERT(OK == verifySKS(coreAPI->myIdentity, ret));
+ GNUNET_ASSERT(OK == verifySKS(coreAPI->myIdentity, msg));
#endif
size = 0;
@@ -226,81 +320,6 @@
}
/**
- * Check if the received session key is properly signed
- * and if connections to this peer are allowed according
- * to policy.
- *
- * @param hostId the sender of the key
- * @param sks the session key message
- * @return SYSERR if invalid, OK if valid
- */
-static int verifySKS(const PeerIdentity * hostId,
- SKEY_Message * sks) {
- char * limited;
-
- if ( (sks == NULL) ||
- (hostId == NULL) ) {
- BREAK();
- return SYSERR;
- }
- /* check if we are allowed to accept connections
- from that peer */
- limited = getConfigurationString("GNUNETD",
- "LIMIT-ALLOW");
- if (limited != NULL) {
- EncName enc;
- hash2enc(&hostId->hashPubKey,
- &enc);
- if (NULL == strstr(limited,
- (char*) &enc)) {
-#if DEBUG_SESSION
- LOG(LOG_DEBUG,
- "Connection from peer '%s' was rejected.\n",
- &enc);
-#endif
- FREE(limited);
- return SYSERR;
- }
- FREE(limited);
- }
- limited = getConfigurationString("GNUNETD",
- "LIMIT-DENY");
- if (limited != NULL) {
- EncName enc;
- hash2enc(&hostId->hashPubKey,
- &enc);
- if (NULL != strstr(limited,
- (char*) &enc)) {
-#if DEBUG_SESSION
- LOG(LOG_DEBUG,
- "Connection from peer '%s' was rejected.\n",
- &enc);
-#endif
- FREE(limited);
- return SYSERR;
- }
- FREE(limited);
- }
-
- if (OK != identity->verifyPeerSignature
- (hostId,
- sks,
- sizeof(SKEY_Message) - sizeof(Signature),
- &sks->signature)) {
- EncName enc;
-
- IFLOG(LOG_INFO,
- hash2enc(&hostId->hashPubKey,
- &enc));
- LOG(LOG_INFO,
- _("Session key from peer '%s' could not be verified.\n"),
- &enc);
- return SYSERR; /*reject!*/
- }
- return OK; /* ok */
-}
-
-/**
* Perform a session key exchange for entry be. First sends a HELO
* and then the new SKEY (in two plaintext packets). When called, the
* semaphore of at the given index must already be down
@@ -313,7 +332,6 @@
TSession * tsession,
p2p_HEADER * pong) {
HELO_Message * helo;
- HELO_Message * targetHelo;
SKEY_Message * skey;
char * sendBuffer;
SESSIONKEY sk;
@@ -329,27 +347,12 @@
return SYSERR;
hash2enc(&receiver->hashPubKey,
&enc);
- /* first: do we have a HELO for the other guy? */
- targetHelo = NULL;
- if (SYSERR == identity->identity2Helo(receiver,
- ANY_PROTOCOL_NUMBER,
- YES,
- &targetHelo)) {
-#if DEBUG_SESSION
- LOG(LOG_DEBUG,
- "Key exchange with '%s' failed: no HELO known.\n",
- &enc);
-#endif
- return SYSERR;
- }
-
/* then try to connect on the transport level */
if ( (tsession == NULL) ||
(transport->associate(tsession) == SYSERR) ) {
- tsession = NULL;
- if (SYSERR == transport->connect(targetHelo, /* callee frees except on
SYSERR */
- &tsession)) {
- FREE(targetHelo);
+ tsession = transport->connectFreely(receiver,
+ YES);
+ if (tsession == NULL) {
#if DEBUG_SESSION
LOG(LOG_DEBUG,
"Key exchange with '%s' failed: could not connect.\n",
@@ -359,6 +362,19 @@
}
}
+ /* create our ping */
+ sndr = MALLOC(sizeof(PeerIdentity));
+ *sndr = *receiver;
+ ping = pingpong->pingUser(receiver,
+ (CronJob)¬ifyPONG,
+ sndr,
+ NO);
+ if (ping == NULL) {
+ FREE(sndr);
+ transport->disconnect(tsession);
+ return SYSERR;
+ }
+
/* get or create out session key */
if (OK != coreAPI->getCurrentSessionKey(receiver,
&sk,
@@ -371,25 +387,8 @@
"Created fresh sessionkey %u.\n",
*(int*) &sk);
#endif
- coreAPI->assignSessionKey(&sk,
- receiver,
- age,
- YES);
}
- /* create our ping */
- sndr = MALLOC(sizeof(PeerIdentity));
- *sndr = *receiver;
- ping = pingpong->pingUser(receiver,
- (CronJob)¬ifyPONG,
- sndr,
- NO);
- if (ping == NULL) {
- FREE(sndr);
- transport->disconnect(tsession);
- return SYSERR;
- }
-
/* build SKEY message */
skey = makeSessionKeySigned(receiver,
&sk,
@@ -399,6 +398,7 @@
if (skey == NULL) {
FREE(ping);
transport->disconnect(tsession);
+ BREAK();
return SYSERR;
}
@@ -418,9 +418,12 @@
memcpy(sendBuffer,
helo,
HELO_Message_size(helo));
+ FREE(helo);
+ helo = NULL;
} else {
size = 0;
}
+
memcpy(&sendBuffer[size],
skey,
ntohs(skey->header.size));
@@ -431,13 +434,18 @@
"Sending session key to peer '%s'.\n",
&enc);
#endif
+ if (stats != NULL)
+ stats->change(stat_skeySent, 1);
coreAPI->sendPlaintext(tsession,
sendBuffer,
size);
FREE(sendBuffer);
- FREENONNULL(helo);
coreAPI->offerTSessionFor(receiver,
tsession);
+ coreAPI->assignSessionKey(&sk,
+ receiver,
+ age,
+ YES);
return OK;
}
@@ -477,7 +485,8 @@
#endif
if (ntohs(msg->size) < sizeof(SKEY_Message)) {
LOG(LOG_WARNING,
- "Session key received from peer '%s' has invalid format (discarded).\n",
+ "Session key received from peer '%s' "
+ "has invalid format (discarded).\n",
&enc);
return SYSERR;
}
@@ -485,8 +494,12 @@
if (SYSERR == verifySKS(sender,
sessionkeySigned)) {
LOG(LOG_INFO,
- "Signature of session key from '%s' failed verification (discarded).\n",
+ "Signature of session key from '%s' failed"
+ " verification (discarded).\n",
&enc);
+ if (stats != NULL)
+ stats->change(stat_skeyRejected,
+ 1);
return SYSERR; /* rejected */
}
size = identity->decryptData(&sessionkeySigned->key,
@@ -506,6 +519,8 @@
&enc,
ntohl(key.crc32),
crc32N(&key, SESSIONKEY_LEN));
+ stats->change(stat_skeyRejected,
+ 1);
return SYSERR;
}
@@ -515,6 +530,9 @@
ntohs(sessionkeySigned->header.size),
*(int*)&key);
#endif
+ if (stats != NULL)
+ stats->change(stat_skeyAccepted,
+ 1);
/* notify core about session key */
coreAPI->assignSessionKey(&key,
sender,
@@ -535,11 +553,13 @@
*(int*)&key,
*(int*)&sessionkeySigned->signature);
#endif
- GNUNET_ASSERT(-1 != decryptBlock(&key,
-
&((char*)sessionkeySigned)[sizeof(SKEY_Message)],
- size,
- (const INITVECTOR*)
&sessionkeySigned->signature,
- plaintext));
+ GNUNET_ASSERT(-1 !=
+ decryptBlock
+ (&key,
+ &((char*)sessionkeySigned)[sizeof(SKEY_Message)],
+ size,
+ (const INITVECTOR*) &sessionkeySigned->signature,
+ plaintext));
pos = 0;
/* find pings & pongs! */
while (pos + sizeof(p2p_HEADER) < size) {
@@ -547,7 +567,8 @@
hdr = (p2p_HEADER*) &plaintext[pos];
if (htons(hdr->size) + pos > size) {
LOG(LOG_WARNING,
- _("Error parsing encrypted session key, given message part size is
invalid.\n"));
+ _("Error parsing encrypted session key, "
+ "given message part size is invalid.\n"));
break;
}
if (htons(hdr->type) == p2p_PROTO_PING)
@@ -579,7 +600,8 @@
/* pong can go out over ordinary channels */
#if DEBUG_SESSION
LOG(LOG_DEBUG,
- "Received ping in session key, sending pong over normal encrypted
session!\n",
+ "Received ping in session key, "
+ "sending pong over normal encrypted session!\n",
&enc);
#endif
ping->type = htons(p2p_PROTO_PONG);
@@ -592,7 +614,8 @@
if (ping != NULL) {
#if DEBUG_SESSION
LOG(LOG_DEBUG,
- "Received ping in session key, sending pong together with my session
key!\n",
+ "Received ping in session key, "
+ "sending pong together with my session key!\n",
&enc);
#endif
ping->type = htons(p2p_PROTO_PONG);
@@ -687,6 +710,17 @@
return NULL;
}
topology = capi->requestService("topology");
+ stats = capi->requestService("stats");
+ if (stats != NULL) {
+ stat_skeySent
+ = stats->create(_("# session keys sent"));
+ stat_skeyRejected
+ = stats->create(_("# session keys rejected"));
+ stat_skeyAccepted
+ = stats->create(_("# session keys accepted"));
+ stat_sessionEstablished
+ = stats->create(_("# sessions established"));
+ }
LOG(LOG_DEBUG,
_("'%s' registering handler %d (plaintext and ciphertext)\n"),
Modified: GNUnet/src/applications/transport/transport.c
===================================================================
--- GNUnet/src/applications/transport/transport.c 2005-07-02 10:33:44 UTC
(rev 1202)
+++ GNUnet/src/applications/transport/transport.c 2005-07-02 12:00:55 UTC
(rev 1203)
@@ -172,20 +172,20 @@
* @param helo the HELO of the target node. The
* callee is responsible for freeing the HELO (!), except
* if SYSERR is returned!
- * @param tsession the transport session to create
* @return OK on success, SYSERR on error
*/
-static int transportConnect(HELO_Message * helo,
- TSession ** tsession) {
+static TSession * transportConnect(const HELO_Message * helo) {
TransportAPI * tapi;
unsigned short prot;
+ TSession * tsession;
+ HELO_Message * heloCpy;
if (ntohs(helo->protocol) >= tapis_count) {
LOG(LOG_INFO,
"%s failed, transport type %d not supported\n",
__FUNCTION__,
ntohs(helo->protocol));
- return SYSERR;
+ return NULL;
}
prot = ntohs(helo->protocol);
tapi = tapis[prot];
@@ -194,23 +194,59 @@
"%s failed, transport type %d not supported\n",
__FUNCTION__,
ntohs(helo->protocol));
- return SYSERR;
+ return NULL;
} else {
-
- if (OK == tapi->connect(helo,
- tsession)) {
- (*tsession)->ttype = prot;
+ heloCpy = MALLOC(HELO_Message_size(helo));
+ memcpy(heloCpy,
+ helo,
+ HELO_Message_size(helo));
+ if (OK == tapi->connect(heloCpy,
+ &tsession)) {
+ tsession->ttype = prot;
#if DEBUG_TRANSPORT
LOG(LOG_DEBUG,
"Core connected to tsession %p.\n",
*tsession);
#endif
- return OK;
+ return tsession;
} else
- return SYSERR;
+ FREE(heloCpy);
+ return NULL;
}
}
+static TSession * transportConnectFreely(const PeerIdentity * peer,
+ int useTempList) {
+ int i;
+ HELO_Message * helo;
+ int * perm;
+ TSession * ret;
+
+ MUTEX_LOCK(&tapis_lock);
+ ret = NULL;
+ perm = permute(tapis_count);
+ for (i=0;i<tapis_count;i++) {
+ if (tapis[perm[i]] == NULL)
+ continue;
+ if (OK ==
+ identity->identity2Helo(peer,
+ perm[i],
+ useTempList,
+ &helo)) {
+ ret = transportConnect(helo);
+ FREE(helo);
+ if (ret != NULL) {
+ FREE(perm);
+ MUTEX_UNLOCK(&tapis_lock);
+ return ret;
+ }
+ }
+ }
+ FREE(perm);
+ MUTEX_UNLOCK(&tapis_lock);
+ return NULL;
+}
+
/**
* A (core) Session is to be associated with a transport session. The
* transport service may want to know in order to call back on the
@@ -675,6 +711,7 @@
ret.add = &addTransport;
ret.forEach = &forEachTransport;
ret.connect = &transportConnect;
+ ret.connectFreely = &transportConnectFreely;
ret.associate = &transportAssociate;
ret.getCost = &transportGetCost;
ret.send = &transportSend;
Modified: GNUnet/src/include/gnunet_transport_service.h
===================================================================
--- GNUnet/src/include/gnunet_transport_service.h 2005-07-02 10:33:44 UTC
(rev 1202)
+++ GNUnet/src/include/gnunet_transport_service.h 2005-07-02 12:00:55 UTC
(rev 1203)
@@ -76,16 +76,24 @@
* layer. This may fail if the appropriate transport mechanism is
* not available.
*
- * @param helo the HELO of the target node. The
- * callee is responsible for freeing the HELO (!),
- * except if SYSERR is returned!
- * @param tsession the transport session to create
- * @return OK on success, SYSERR on error
+ * @param helo the HELO of the target node
+ * @return session handle on success, NULL on error
*/
- int (*connect)(HELO_Message * helo,
- TSession ** tsession);
+ TSession * (*connect)(const HELO_Message * helo);
/**
+ * Connect to another peer, picking any transport that
+ * works.
+ *
+ * @param peer which peer to connect to
+ * @param allowTempLists may we even select HELOs that have
+ * not yet been confirmed?
+ * @return session handle on success, NULL on error
+ */
+ TSession * (*connectFreely)(const PeerIdentity * peer,
+ int allowTempList);
+
+ /**
* A (core) Session is to be associated with a transport session. The
* transport service may want to know in order to call back on the
* core if the connection is being closed. Associate can also be
Modified: GNUnet/src/server/connection.c
===================================================================
--- GNUnet/src/server/connection.c 2005-07-02 10:33:44 UTC (rev 1202)
+++ GNUnet/src/server/connection.c 2005-07-02 12:00:55 UTC (rev 1203)
@@ -1528,10 +1528,15 @@
static void shutdownConnection(BufferEntry * be) {
HANGUP_Message hangup;
unsigned int i;
+ EncName enc;
ENTRY();
+ IFLOG(LOG_DEBUG,
+ hash2enc(&be->session.sender.hashPubKey,
+ &enc));
LOG(LOG_DEBUG,
- "Shutting down connection\n");
+ "Shutting down connection with '%s'\n",
+ &enc);
if (be->status == STAT_DOWN)
return; /* nothing to do */
if (be->status == STAT_UP) {
@@ -2159,6 +2164,8 @@
*/
void confirmSessionUp(const PeerIdentity * peer) {
BufferEntry * be;
+ EncName enc;
+
MUTEX_LOCK(&lock);
be = lookForHost(peer);
if (be != NULL) {
@@ -2166,43 +2173,26 @@
identity->whitelistHost(peer);
if ( ( (be->status & STAT_SKEY_SENT) > 0) &&
( (be->status & STAT_SKEY_RECEIVED) > 0) ) {
- if (be->session.tsession == NULL) {
- int i;
- HELO_Message * helo;
-
- i = 0;
- while (i < MAX_PROTOCOL_NUMBER) {
- helo = NULL;
- if (OK ==
- identity->identity2Helo(&be->session.sender,
- i,
- YES,
- &helo)) {
- if (OK ==
- transport->connect(helo,
- &be->session.tsession)) {
- be->session.mtu
- = transport->getMTU(be->session.tsession->ttype);
- break;
- } else {
- FREE(helo);
- i++;
- }
- } else {
- i++;
- }
- }
- if (i == MAX_PROTOCOL_NUMBER) {
- LOG(LOG_WARNING,
- _("Session confirmed, but cannot connect! (bug?)\n"));
- }
- }
+ if (be->session.tsession == NULL)
+ be->session.tsession
+ = transport->connectFreely(&be->session.sender,
+ YES);
if (be->session.tsession != NULL) {
+ be->session.mtu
+ = transport->getMTU(be->session.tsession->ttype);
if (be->status != STAT_UP) {
be->status = STAT_UP;
be->lastSequenceNumberReceived = 0;
be->lastSequenceNumberSend = 1;
}
+ } else {
+ IFLOG(LOG_WARNING,
+ hash2enc(&be->session.sender.hashPubKey,
+ &enc));
+ LOG(LOG_WARNING,
+ _("Session with peer '%s' confirmed, "
+ "but I cannot connect! (bug?)\n"),
+ &enc);
}
}
}
Modified: GNUnet/src/server/gnunet-transport-check.c
===================================================================
--- GNUnet/src/server/gnunet-transport-check.c 2005-07-02 10:33:44 UTC (rev
1202)
+++ GNUnet/src/server/gnunet-transport-check.c 2005-07-02 12:00:55 UTC (rev
1203)
@@ -247,9 +247,9 @@
stats[1]++; /* one more with transport 'available' */
tsession = NULL;
peer = helo->senderIdentity;
- if (OK != transport->connect(helo,
- &tsession)) {
- FREE(helo);
+ tsession = transport->connect(helo);
+ FREE(helo);
+ if (tsession == NULL) {
fprintf(stderr,
_(" Connection failed\n"));
return;
Modified: GNUnet/src/transports/tcp.c
===================================================================
--- GNUnet/src/transports/tcp.c 2005-07-02 10:33:44 UTC (rev 1202)
+++ GNUnet/src/transports/tcp.c 2005-07-02 12:00:55 UTC (rev 1203)
@@ -30,7 +30,7 @@
#include "platform.h"
#include "ip.h"
-#define DEBUG_TCP NO
+#define DEBUG_TCP YES
/**
* after how much time of the core not being associated with a tcp
@@ -431,7 +431,8 @@
tcpSession->pos += ret;
while (tcpSession->pos > 2) {
- len = ntohs(((TCPMessagePack*)&tcpSession->rbuff[0])->size) +
sizeof(TCPMessagePack);
+ len = ntohs(((TCPMessagePack*)&tcpSession->rbuff[0])->size)
+ + sizeof(TCPMessagePack);
if (len > tcpSession->rsize) /* if message larger than read buffer, grow!
*/
GROW(tcpSession->rbuff,
tcpSession->rsize,
@@ -457,9 +458,11 @@
welcome = (TCPWelcome*) &tcpSession->rbuff[0];
if ( (ntohs(welcome->header.reserved) != 0) ||
- (ntohs(welcome->header.size) != sizeof(TCPWelcome) -
sizeof(TCPMessagePack)) ) {
+ (ntohs(welcome->header.size)
+ != sizeof(TCPWelcome) - sizeof(TCPMessagePack)) ) {
LOG(LOG_WARNING,
- _("Expected welcome message on tcp connection, got garbage (%u,
%u). Closing.\n"),
+ _("Expected welcome message on tcp connection, "
+ "got garbage (%u, %u). Closing.\n"),
ntohs(welcome->header.reserved),
ntohs(welcome->header.size));
tcpDisconnect(tsession);
@@ -472,14 +475,15 @@
hash2enc(&tcpSession->sender.hashPubKey,
&enc));
LOG(LOG_DEBUG,
- "tcp welcome message from %s received\n",
+ "tcp welcome message from '%s' received\n",
&enc);
#endif
memmove(&tcpSession->rbuff[0],
&tcpSession->rbuff[sizeof(TCPWelcome)],
tcpSession->pos - sizeof(TCPWelcome));
tcpSession->pos -= sizeof(TCPWelcome);
- len = ntohs(((TCPMessagePack*)&tcpSession->rbuff[0])->size) +
sizeof(TCPMessagePack);
+ len = ntohs(((TCPMessagePack*)&tcpSession->rbuff[0])->size)
+ + sizeof(TCPMessagePack);
}
if ( (tcpSession->pos < 2) ||
(tcpSession->pos < len) ) {
@@ -491,7 +495,8 @@
/* send msg to core! */
if (len <= sizeof(TCPMessagePack)) {
LOG(LOG_WARNING,
- _("Received malformed message (size %u) from tcp-peer connection.
Closing.\n"),
+ _("Received malformed message (size %u)"
+ " from tcp-peer connection. Closing.\n"),
len);
tcpDisconnect(tsession);
return SYSERR;
@@ -1152,9 +1157,12 @@
/* send our node identity to the other side to fully establish the
connection! */
- welcome.header.size = htons(sizeof(TCPWelcome) - sizeof(TCPMessagePack));
- welcome.header.reserved = htons(0);
- welcome.clientIdentity = *(coreAPI->myIdentity);
+ welcome.header.size
+ = htons(sizeof(TCPWelcome) - sizeof(TCPMessagePack));
+ welcome.header.reserved
+ = htons(0);
+ welcome.clientIdentity
+ = *(coreAPI->myIdentity);
if (SYSERR == tcpDirectSend(tcpSession,
&welcome,
sizeof(TCPWelcome))) {
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r1203 - in GNUnet/src: applications/advertising applications/pingpong applications/session applications/transport include server transports,
grothoff <=