diff options
author | Christian Grothoff <christian@grothoff.org> | 2010-07-21 20:48:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2010-07-21 20:48:40 +0000 |
commit | b05f920bfa907476b618a24bd78487db8873d2a1 (patch) | |
tree | fad22297a66787044837faa4c2c3459f48d6bb85 /src/transport/transport_api.c | |
parent | afec51a8dd5d9f77a00d902acd7b5efc04675298 (diff) | |
download | gnunet-b05f920bfa907476b618a24bd78487db8873d2a1.tar.gz gnunet-b05f920bfa907476b618a24bd78487db8873d2a1.zip |
add code to enable checking if transport's idea of our peer identity matches that of core, etc -- might help diagnose certain bugs
Diffstat (limited to 'src/transport/transport_api.c')
-rw-r--r-- | src/transport/transport_api.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/src/transport/transport_api.c b/src/transport/transport_api.c index eb8868d98..db96d1800 100644 --- a/src/transport/transport_api.c +++ b/src/transport/transport_api.c | |||
@@ -278,7 +278,7 @@ struct GNUNET_TRANSPORT_Handle | |||
278 | /** | 278 | /** |
279 | * Closure for the callbacks. | 279 | * Closure for the callbacks. |
280 | */ | 280 | */ |
281 | void *cls; | 281 | void *cls; |
282 | 282 | ||
283 | /** | 283 | /** |
284 | * Function to call for received data. | 284 | * Function to call for received data. |
@@ -342,6 +342,11 @@ struct GNUNET_TRANSPORT_Handle | |||
342 | struct NeighbourList *neighbours; | 342 | struct NeighbourList *neighbours; |
343 | 343 | ||
344 | /** | 344 | /** |
345 | * Peer identity as assumed by this process, or all zeros. | ||
346 | */ | ||
347 | struct GNUNET_PeerIdentity self; | ||
348 | |||
349 | /** | ||
345 | * ID of the task trying to reconnect to the service. | 350 | * ID of the task trying to reconnect to the service. |
346 | */ | 351 | */ |
347 | GNUNET_SCHEDULER_TaskIdentifier reconnect_task; | 352 | GNUNET_SCHEDULER_TaskIdentifier reconnect_task; |
@@ -363,6 +368,11 @@ struct GNUNET_TRANSPORT_Handle | |||
363 | */ | 368 | */ |
364 | int in_disconnect; | 369 | int in_disconnect; |
365 | 370 | ||
371 | /** | ||
372 | * Should we check that 'self' matches what the service thinks? | ||
373 | * (if GNUNET_NO, then 'self' is all zeros!). | ||
374 | */ | ||
375 | int check_self; | ||
366 | }; | 376 | }; |
367 | 377 | ||
368 | 378 | ||
@@ -1038,7 +1048,8 @@ GNUNET_TRANSPORT_offer_hello (struct GNUNET_TRANSPORT_Handle *handle, | |||
1038 | static size_t | 1048 | static size_t |
1039 | send_start (void *cls, size_t size, void *buf) | 1049 | send_start (void *cls, size_t size, void *buf) |
1040 | { | 1050 | { |
1041 | struct GNUNET_MessageHeader *s = buf; | 1051 | struct GNUNET_TRANSPORT_Handle *h = cls; |
1052 | struct StartMessage s; | ||
1042 | 1053 | ||
1043 | if (buf == NULL) | 1054 | if (buf == NULL) |
1044 | { | 1055 | { |
@@ -1054,10 +1065,13 @@ send_start (void *cls, size_t size, void *buf) | |||
1054 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1065 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1055 | "Transmitting `%s' request.\n", "START"); | 1066 | "Transmitting `%s' request.\n", "START"); |
1056 | #endif | 1067 | #endif |
1057 | GNUNET_assert (size >= sizeof (struct GNUNET_MessageHeader)); | 1068 | GNUNET_assert (size >= sizeof (struct StartMessage)); |
1058 | s->size = htons (sizeof (struct GNUNET_MessageHeader)); | 1069 | s.header.size = htons (sizeof (struct StartMessage)); |
1059 | s->type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START); | 1070 | s.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_START); |
1060 | return sizeof (struct GNUNET_MessageHeader); | 1071 | s.do_check = htonl (h->check_self); |
1072 | s.self = h->self; | ||
1073 | memcpy (buf, &s, sizeof (struct StartMessage)); | ||
1074 | return sizeof (struct StartMessage); | ||
1061 | } | 1075 | } |
1062 | 1076 | ||
1063 | 1077 | ||
@@ -1192,9 +1206,9 @@ reconnect (void *cls, | |||
1192 | pos = pos->next; | 1206 | pos = pos->next; |
1193 | } | 1207 | } |
1194 | schedule_control_transmit (h, | 1208 | schedule_control_transmit (h, |
1195 | sizeof (struct GNUNET_MessageHeader), | 1209 | sizeof (struct StartMessage), |
1196 | GNUNET_YES, | 1210 | GNUNET_YES, |
1197 | GNUNET_TIME_UNIT_FOREVER_REL, &send_start, NULL); | 1211 | GNUNET_TIME_UNIT_FOREVER_REL, &send_start, h); |
1198 | GNUNET_CLIENT_receive (h->client, | 1212 | GNUNET_CLIENT_receive (h->client, |
1199 | &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL); | 1213 | &demultiplexer, h, GNUNET_TIME_UNIT_FOREVER_REL); |
1200 | } | 1214 | } |
@@ -1274,6 +1288,8 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h, | |||
1274 | * | 1288 | * |
1275 | * @param sched scheduler to use | 1289 | * @param sched scheduler to use |
1276 | * @param cfg configuration to use | 1290 | * @param cfg configuration to use |
1291 | * @param self our own identity (API should check that it matches | ||
1292 | * the identity found by transport), or NULL (no check) | ||
1277 | * @param cls closure for the callbacks | 1293 | * @param cls closure for the callbacks |
1278 | * @param rec receive function to call | 1294 | * @param rec receive function to call |
1279 | * @param nc function to call on connect events | 1295 | * @param nc function to call on connect events |
@@ -1282,6 +1298,7 @@ neighbour_add (struct GNUNET_TRANSPORT_Handle *h, | |||
1282 | struct GNUNET_TRANSPORT_Handle * | 1298 | struct GNUNET_TRANSPORT_Handle * |
1283 | GNUNET_TRANSPORT_connect (struct GNUNET_SCHEDULER_Handle *sched, | 1299 | GNUNET_TRANSPORT_connect (struct GNUNET_SCHEDULER_Handle *sched, |
1284 | const struct GNUNET_CONFIGURATION_Handle *cfg, | 1300 | const struct GNUNET_CONFIGURATION_Handle *cfg, |
1301 | const struct GNUNET_PeerIdentity *self, | ||
1285 | void *cls, | 1302 | void *cls, |
1286 | GNUNET_TRANSPORT_ReceiveCallback rec, | 1303 | GNUNET_TRANSPORT_ReceiveCallback rec, |
1287 | GNUNET_TRANSPORT_NotifyConnect nc, | 1304 | GNUNET_TRANSPORT_NotifyConnect nc, |
@@ -1290,6 +1307,11 @@ GNUNET_TRANSPORT_connect (struct GNUNET_SCHEDULER_Handle *sched, | |||
1290 | struct GNUNET_TRANSPORT_Handle *ret; | 1307 | struct GNUNET_TRANSPORT_Handle *ret; |
1291 | 1308 | ||
1292 | ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Handle)); | 1309 | ret = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_Handle)); |
1310 | if (self != NULL) | ||
1311 | { | ||
1312 | ret->self = *self; | ||
1313 | ret->check_self = GNUNET_YES; | ||
1314 | } | ||
1293 | ret->sched = sched; | 1315 | ret->sched = sched; |
1294 | ret->cfg = cfg; | 1316 | ret->cfg = cfg; |
1295 | ret->cls = cls; | 1317 | ret->cls = cls; |