[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r13676 - gnunet/src/core
From: |
gnunet |
Subject: |
[GNUnet-SVN] r13676 - gnunet/src/core |
Date: |
Sun, 14 Nov 2010 14:26:50 +0100 |
Author: grothoff
Date: 2010-11-14 14:26:50 +0100 (Sun, 14 Nov 2010)
New Revision: 13676
Modified:
gnunet/src/core/core_api.c
gnunet/src/core/test_core_api.c
Log:
more checks
Modified: gnunet/src/core/core_api.c
===================================================================
--- gnunet/src/core/core_api.c 2010-11-14 06:59:21 UTC (rev 13675)
+++ gnunet/src/core/core_api.c 2010-11-14 13:26:50 UTC (rev 13676)
@@ -237,6 +237,11 @@
struct GNUNET_CONTAINER_MultiHashMap *peers;
/**
+ * Identity of this peer.
+ */
+ struct GNUNET_PeerIdentity me;
+
+ /**
* ID of reconnect task (if any).
*/
GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
@@ -781,7 +786,6 @@
const struct GNUNET_CORE_MessageHandler *mh;
GNUNET_CORE_StartupCallback init;
GNUNET_CORE_PeerConfigurationInfoCallback pcic;
- struct GNUNET_PeerIdentity my_identity;
struct PeerRecord *pr;
struct GNUNET_CORE_TransmitHandle *th;
unsigned int hpos;
@@ -832,8 +836,8 @@
GNUNET_CRYPTO_hash (&m->publicKey,
sizeof (struct
GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded),
- &my_identity.hashPubKey);
- init (h->cls, h, &my_identity, &m->publicKey);
+ &h->me.hashPubKey);
+ init (h->cls, h, &h->me, &m->publicKey);
}
break;
case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT:
@@ -849,6 +853,14 @@
"Received notification about connection from `%s'.\n",
GNUNET_i2s (&cnm->peer));
#endif
+ if (0 == memcmp (&h->me,
+ &cnm->peer,
+ sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* disconnect from self!? */
+ GNUNET_break (0);
+ return;
+ }
pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
&cnm->peer.hashPubKey);
if (pr != NULL)
@@ -878,6 +890,14 @@
return;
}
dnm = (const struct DisconnectNotifyMessage *) msg;
+ if (0 == memcmp (&h->me,
+ &dnm->peer,
+ sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* connection to self!? */
+ GNUNET_break (0);
+ return;
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received notification about disconnect from `%s'.\n",
@@ -911,6 +931,14 @@
return;
}
psnm = (const struct PeerStatusNotifyMessage *) msg;
+ if (0 == memcmp (&h->me,
+ &psnm->peer,
+ sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received notification about status change by `%s'.\n",
@@ -941,6 +969,14 @@
return;
}
ntm = (const struct NotifyTrafficMessage *) msg;
+ if (0 == memcmp (&h->me,
+ &ntm->peer,
+ sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
em = (const struct GNUNET_MessageHeader *) &ntm[1];
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -998,6 +1034,14 @@
return;
}
ntm = (const struct NotifyTrafficMessage *) msg;
+ if (0 == memcmp (&h->me,
+ &ntm->peer,
+ sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
em = (const struct GNUNET_MessageHeader *) &ntm[1];
pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
&ntm->peer.hashPubKey);
@@ -1035,6 +1079,14 @@
return;
}
smr = (const struct SendMessageReady *) msg;
+ if (0 == memcmp (&h->me,
+ &smr->peer,
+ sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
pr = GNUNET_CONTAINER_multihashmap_get (h->peers,
&smr->peer.hashPubKey);
if (pr == NULL)
@@ -1077,6 +1129,14 @@
return;
}
cim = (const struct ConfigurationInfoMessage*) msg;
+ if (0 == memcmp (&h->me,
+ &cim->peer,
+ sizeof (struct GNUNET_PeerIdentity)))
+ {
+ /* self-change!? */
+ GNUNET_break (0);
+ return;
+ }
#if DEBUG_CORE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received notification about configuration update for
`%s'.\n",
Modified: gnunet/src/core/test_core_api.c
===================================================================
--- gnunet/src/core/test_core_api.c 2010-11-14 06:59:21 UTC (rev 13675)
+++ gnunet/src/core/test_core_api.c 2010-11-14 13:26:50 UTC (rev 13676)
@@ -57,6 +57,7 @@
static struct PeerContext p2;
+static GNUNET_SCHEDULER_TaskIdentifier err_task;
static int ok;
@@ -95,6 +96,27 @@
}
+static size_t
+transmit_ready (void *cls, size_t size, void *buf)
+{
+ struct PeerContext *p = cls;
+ struct GNUNET_MessageHeader *m;
+
+ GNUNET_assert (ok == 4);
+ OKPP;
+ GNUNET_assert (p == &p1);
+ GNUNET_assert (buf != NULL);
+ m = (struct GNUNET_MessageHeader *) buf;
+ m->type = htons (MTYPE);
+ m->size = htons (sizeof (struct GNUNET_MessageHeader));
+ err_task =
+ GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120),
+ &terminate_task_error, NULL);
+
+ return sizeof (struct GNUNET_MessageHeader);
+}
+
+
static void
connect_notify (void *cls,
const struct GNUNET_PeerIdentity *peer,
@@ -106,6 +128,20 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Encrypted connection established to peer `%4s'\n",
GNUNET_i2s (peer));
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking core (1) for transmission to peer `%4s'\n",
+ GNUNET_i2s (&p2.id));
+ if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch,
+ 0,
+ GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 45),
+ &p2.id,
+ sizeof (struct
GNUNET_MessageHeader),
+ &transmit_ready, &p1))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "RECEIVED NULL when asking core (1) for transmission to peer
`%4s'\n",
+ GNUNET_i2s (&p2.id));
+ }
}
@@ -145,9 +181,7 @@
}
-static GNUNET_SCHEDULER_TaskIdentifier err_task;
-
static int
process_mtype (void *cls,
const struct GNUNET_PeerIdentity *peer,
@@ -170,27 +204,6 @@
};
-static size_t
-transmit_ready (void *cls, size_t size, void *buf)
-{
- struct PeerContext *p = cls;
- struct GNUNET_MessageHeader *m;
-
- GNUNET_assert (ok == 4);
- OKPP;
- GNUNET_assert (p == &p1);
- GNUNET_assert (buf != NULL);
- m = (struct GNUNET_MessageHeader *) buf;
- m->type = htons (MTYPE);
- m->size = htons (sizeof (struct GNUNET_MessageHeader));
- err_task =
- GNUNET_SCHEDULER_add_delayed
(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120),
&terminate_task_error, NULL);
-
- return sizeof (struct GNUNET_MessageHeader);
-}
-
-
-
static void
init_notify (void *cls,
struct GNUNET_CORE_Handle *server,
@@ -226,21 +239,12 @@
OKPP;
GNUNET_assert (cls == &p2);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking core (1) for transmission to peer `%4s'\n",
+ "Asking core (1) to connect to peer `%4s'\n",
GNUNET_i2s (&p2.id));
-
- if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch,
- 0,
- GNUNET_TIME_relative_multiply
(GNUNET_TIME_UNIT_SECONDS, 45),
- &p2.id,
- sizeof (struct GNUNET_MessageHeader),
- &transmit_ready, &p1))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "RECEIVED NULL when asking core (1) for transmission to
peer `%4s'\n",
- GNUNET_i2s (&p2.id));
- }
-
+ GNUNET_CORE_peer_request_connect (p1.ch,
+ GNUNET_TIME_UNIT_SECONDS,
+ &p2.id,
+ NULL, NULL);
}
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r13676 - gnunet/src/core,
gnunet <=