diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-01-26 15:48:50 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-01-26 15:48:50 +0000 |
commit | f206220e03ccf5cfdb8e8d51d253fed17db4d4ee (patch) | |
tree | 7fe48ec02fd8156465922735ea7cd16f0bec0c14 /src | |
parent | 9a072b194ac97acdf835bd917468664230d900ce (diff) | |
download | gnunet-f206220e03ccf5cfdb8e8d51d253fed17db4d4ee.tar.gz gnunet-f206220e03ccf5cfdb8e8d51d253fed17db4d4ee.zip |
still not really working... sending and receiving of messages a bit hinky
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 19 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 32 | ||||
-rw-r--r-- | src/transport/test_transport_api.c | 65 |
3 files changed, 71 insertions, 45 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index d239ce0ce..28fd38126 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -1746,11 +1746,11 @@ run_validation (void *cls, | |||
1746 | struct TransportPlugin *tp; | 1746 | struct TransportPlugin *tp; |
1747 | struct ValidationAddress *va; | 1747 | struct ValidationAddress *va; |
1748 | struct GNUNET_PeerIdentity id; | 1748 | struct GNUNET_PeerIdentity id; |
1749 | char *pingMessage; | ||
1750 | int sent; | 1749 | int sent; |
1751 | struct TransportPingMessage *ping; | 1750 | struct TransportPingMessage *ping; |
1752 | char * message_buf; | 1751 | char * message_buf; |
1753 | int hello_size; | 1752 | int hello_size; |
1753 | int tsize; | ||
1754 | 1754 | ||
1755 | tp = find_transport (tname); | 1755 | tp = find_transport (tname); |
1756 | if (tp == NULL) | 1756 | if (tp == NULL) |
@@ -1780,27 +1780,34 @@ run_validation (void *cls, | |||
1780 | memcpy (&va[1], addr, addrlen); | 1780 | memcpy (&va[1], addr, addrlen); |
1781 | 1781 | ||
1782 | hello_size = GNUNET_HELLO_size(our_hello); | 1782 | hello_size = GNUNET_HELLO_size(our_hello); |
1783 | message_buf = GNUNET_malloc(sizeof(struct TransportPingMessage) + hello_size); | 1783 | tsize = sizeof(struct TransportPingMessage) + hello_size; |
1784 | memcpy(message_buf, &our_hello, hello_size); | 1784 | |
1785 | message_buf = GNUNET_malloc(tsize); | ||
1785 | 1786 | ||
1786 | ping = GNUNET_malloc(sizeof(struct TransportPingMessage)); | 1787 | ping = GNUNET_malloc(sizeof(struct TransportPingMessage)); |
1787 | ping->challenge = htonl(va->challenge); | 1788 | ping->challenge = htonl(va->challenge); |
1788 | ping->header.size = htons(sizeof(struct TransportPingMessage)); | 1789 | ping->header.size = htons(sizeof(struct TransportPingMessage)); |
1789 | ping->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); | 1790 | ping->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); |
1790 | memcpy(&ping->target, &id, sizeof(struct GNUNET_PeerIdentity)); | 1791 | memcpy(&ping->target, &id, sizeof(struct GNUNET_PeerIdentity)); |
1792 | |||
1793 | GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "hello size is %d, ping size is %d, total size is %d", hello_size, sizeof(struct TransportPingMessage), tsize); | ||
1794 | |||
1795 | memcpy(message_buf, our_hello, hello_size); | ||
1791 | memcpy(&message_buf[hello_size], ping, sizeof(struct TransportPingMessage)); | 1796 | memcpy(&message_buf[hello_size], ping, sizeof(struct TransportPingMessage)); |
1792 | 1797 | ||
1798 | |||
1799 | |||
1793 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ping message to address `%s' via `%s' for `%4s'\n", | 1800 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ping message to address `%s' via `%s' for `%4s'\n", |
1794 | GNUNET_a2s (addr, addrlen), tname, GNUNET_i2s (&id)); | 1801 | GNUNET_a2s (addr, addrlen), tname, GNUNET_i2s (&id)); |
1795 | 1802 | ||
1796 | 1803 | ||
1797 | sent = tp->api->send(tp->api->cls, &id, message_buf, sizeof(struct TransportPingMessage) + hello_size, GNUNET_SCHEDULER_PRIORITY_DEFAULT, | 1804 | sent = tp->api->send(tp->api->cls, &id, message_buf, tsize, GNUNET_SCHEDULER_PRIORITY_DEFAULT, |
1798 | TRANSPORT_DEFAULT_TIMEOUT, addr, addrlen, GNUNET_YES, NULL, NULL); | 1805 | TRANSPORT_DEFAULT_TIMEOUT, addr, addrlen, GNUNET_YES, NULL, NULL); |
1799 | 1806 | ||
1800 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport returned %d from send!\n", sent); | 1807 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport returned %d from send!\n", sent); |
1801 | 1808 | ||
1802 | GNUNET_free(pingMessage); | 1809 | GNUNET_free(ping); |
1803 | 1810 | GNUNET_free(message_buf); | |
1804 | return GNUNET_OK; | 1811 | return GNUNET_OK; |
1805 | } | 1812 | } |
1806 | 1813 | ||
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 68e519f3e..3df492a91 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -235,7 +235,7 @@ udp_plugin_send (void *cls, | |||
235 | 235 | ||
236 | #if DEBUG_UDP | 236 | #if DEBUG_UDP |
237 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | 237 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
238 | ("In udp_send, ssize is %d\n"), ssize); | 238 | ("In udp_send, ssize is %d, sending message to %s\n"), ssize, GNUNET_a2s((const struct sockaddr *)addr, addrlen)); |
239 | #endif | 239 | #endif |
240 | message->header.size = htons (ssize); | 240 | message->header.size = htons (ssize); |
241 | message->header.type = htons (0); | 241 | message->header.type = htons (0); |
@@ -357,6 +357,8 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
357 | ssize_t ret; | 357 | ssize_t ret; |
358 | int offset; | 358 | int offset; |
359 | int count; | 359 | int count; |
360 | int tsize; | ||
361 | char *msgbuf; | ||
360 | const struct GNUNET_MessageHeader *currhdr; | 362 | const struct GNUNET_MessageHeader *currhdr; |
361 | 363 | ||
362 | do | 364 | do |
@@ -373,10 +375,7 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
373 | 375 | ||
374 | buf = GNUNET_malloc (buflen); | 376 | buf = GNUNET_malloc (buflen); |
375 | fromlen = sizeof (addr); | 377 | fromlen = sizeof (addr); |
376 | #if DEBUG_UDP | 378 | |
377 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | ||
378 | ("src_addr_len is %u\n"), fromlen); | ||
379 | #endif | ||
380 | memset (&addr, 0, fromlen); | 379 | memset (&addr, 0, fromlen); |
381 | ret = | 380 | ret = |
382 | GNUNET_NETWORK_socket_recvfrom (udp_sock, buf, buflen, | 381 | GNUNET_NETWORK_socket_recvfrom (udp_sock, buf, buflen, |
@@ -412,31 +411,30 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
412 | break; | 411 | break; |
413 | } | 412 | } |
414 | hdr = (const struct GNUNET_MessageHeader *) &msg[1]; | 413 | hdr = (const struct GNUNET_MessageHeader *) &msg[1]; |
414 | msgbuf = (char *)&msg[1]; | ||
415 | sender = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); | 415 | sender = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); |
416 | memcpy (sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity)); | 416 | memcpy (sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity)); |
417 | 417 | ||
418 | #if DEBUG_UDP | ||
419 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | ||
420 | ("msg reports message size of %d\n"), | ||
421 | ntohs (hdr->size)); | ||
422 | |||
423 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | ||
424 | ("msg reports message type of %d\n"), | ||
425 | ntohs (hdr->type)); | ||
426 | #endif | ||
427 | offset = 0; | 418 | offset = 0; |
428 | count = 0; | 419 | count = 0; |
429 | while (offset < (ntohs (msg->header.size) - sizeof(struct UDPMessage))) | 420 | tsize = ntohs (msg->header.size) - sizeof(struct UDPMessage); |
421 | while (offset < tsize) | ||
430 | { | 422 | { |
431 | currhdr = &hdr[offset]; | 423 | currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset]; |
432 | #if DEBUG_UDP | 424 | #if DEBUG_UDP |
433 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | 425 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ |
434 | ("processing msg %d: type %d, size %d at offset %d\n"), | 426 | ("processing msg %d: type %d, size %d at offset %d\n"), |
435 | count, offset, ntohs(currhdr->size), ntohs(currhdr->type)); | 427 | count, ntohs(currhdr->type), ntohs(currhdr->size), offset); |
436 | #endif | 428 | #endif |
437 | plugin->env->receive (plugin->env->cls, | 429 | plugin->env->receive (plugin->env->cls, |
438 | sender, currhdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen); | 430 | sender, currhdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen); |
439 | offset += ntohs(currhdr->size); | 431 | offset += ntohs(currhdr->size); |
432 | #if DEBUG_UDP | ||
433 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ | ||
434 | ("offset now %d, tsize %d\n"), | ||
435 | offset, tsize); | ||
436 | #endif | ||
437 | count++; | ||
440 | } | 438 | } |
441 | 439 | ||
442 | GNUNET_free (sender); | 440 | GNUNET_free (sender); |
diff --git a/src/transport/test_transport_api.c b/src/transport/test_transport_api.c index 9702d945d..536ccc29a 100644 --- a/src/transport/test_transport_api.c +++ b/src/transport/test_transport_api.c | |||
@@ -42,7 +42,7 @@ | |||
42 | /** | 42 | /** |
43 | * How long until we give up on transmitting the message? | 43 | * How long until we give up on transmitting the message? |
44 | */ | 44 | */ |
45 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) | 45 | #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 50) |
46 | 46 | ||
47 | #define MTYPE 12345 | 47 | #define MTYPE 12345 |
48 | 48 | ||
@@ -68,6 +68,8 @@ static int is_tcp; | |||
68 | 68 | ||
69 | static int is_udp; | 69 | static int is_udp; |
70 | 70 | ||
71 | GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
72 | |||
71 | #if VERBOSE | 73 | #if VERBOSE |
72 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) | 74 | #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) |
73 | #else | 75 | #else |
@@ -79,12 +81,35 @@ static void | |||
79 | end () | 81 | end () |
80 | { | 82 | { |
81 | /* do work here */ | 83 | /* do work here */ |
82 | //GNUNET_assert (ok == 8); | 84 | GNUNET_assert (ok == 8); |
83 | GNUNET_TRANSPORT_disconnect (p1.th); | 85 | GNUNET_TRANSPORT_disconnect (p1.th); |
84 | GNUNET_TRANSPORT_disconnect (p2.th); | 86 | GNUNET_TRANSPORT_disconnect (p2.th); |
85 | ok = 0; | 87 | ok = 0; |
86 | } | 88 | } |
87 | 89 | ||
90 | static void | ||
91 | stop_arm (struct PeerContext *p) | ||
92 | { | ||
93 | #if START_ARM | ||
94 | if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) | ||
95 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
96 | GNUNET_OS_process_wait (p->arm_pid); | ||
97 | #endif | ||
98 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
99 | } | ||
100 | |||
101 | static void | ||
102 | end_badly () | ||
103 | { | ||
104 | /* do work here */ | ||
105 | fprintf(stderr, "Ending on an unhappy note.\n"); | ||
106 | |||
107 | GNUNET_TRANSPORT_disconnect (p1.th); | ||
108 | GNUNET_TRANSPORT_disconnect (p2.th); | ||
109 | |||
110 | ok = 1; | ||
111 | return; | ||
112 | } | ||
88 | 113 | ||
89 | static void | 114 | static void |
90 | notify_receive (void *cls, | 115 | notify_receive (void *cls, |
@@ -95,14 +120,14 @@ notify_receive (void *cls, | |||
95 | { | 120 | { |
96 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok is (%d)!\n", | 121 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok is (%d)!\n", |
97 | ok); | 122 | ok); |
98 | //GNUNET_assert (ok == 7); | 123 | GNUNET_assert (ok == 7); |
99 | OKPP; | 124 | OKPP; |
100 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p)!\n", | 125 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p)!\n", |
101 | ntohs(message->type), cls); | 126 | ntohs(message->type), cls); |
102 | 127 | ||
103 | //GNUNET_assert (MTYPE == ntohs (message->type)); | 128 | GNUNET_assert (MTYPE == ntohs (message->type)); |
104 | //GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == | 129 | GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == |
105 | // ntohs (message->size)); | 130 | ntohs (message->size)); |
106 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer (%p)!\n", | 131 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer (%p)!\n", |
107 | cls); | 132 | cls); |
108 | end (); | 133 | end (); |
@@ -158,8 +183,8 @@ notify_ready (void *cls, size_t size, void *buf) | |||
158 | 183 | ||
159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 184 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
160 | "Transmitting message to peer (%p) - %u!\n", cls, size); | 185 | "Transmitting message to peer (%p) - %u!\n", cls, size); |
161 | //GNUNET_assert (size >= 256); | 186 | GNUNET_assert (size >= 256); |
162 | //GNUNET_assert ((ok >= 5) && (ok <= 6)); | 187 | GNUNET_assert ((ok >= 5) && (ok <= 6)); |
163 | OKPP; | 188 | OKPP; |
164 | if (buf != NULL) | 189 | if (buf != NULL) |
165 | { | 190 | { |
@@ -168,8 +193,7 @@ notify_ready (void *cls, size_t size, void *buf) | |||
168 | hdr->type = htons (MTYPE); | 193 | hdr->type = htons (MTYPE); |
169 | } | 194 | } |
170 | 195 | ||
171 | return 0; | 196 | return sizeof (struct GNUNET_MessageHeader); |
172 | //return sizeof (struct GNUNET_MessageHeader); | ||
173 | } | 197 | } |
174 | 198 | ||
175 | 199 | ||
@@ -217,6 +241,9 @@ exchange_hello (void *cls, | |||
217 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) | 241 | GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) |
218 | message, &me->id)); | 242 | message, &me->id)); |
219 | 243 | ||
244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
245 | "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message)); | ||
246 | |||
220 | GNUNET_TRANSPORT_offer_hello (p2.th, message); | 247 | GNUNET_TRANSPORT_offer_hello (p2.th, message); |
221 | 248 | ||
222 | GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); | 249 | GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); |
@@ -253,6 +280,8 @@ setTransportOptions(char * filename) | |||
253 | #endif | 280 | #endif |
254 | 281 | ||
255 | GNUNET_CONFIGURATION_write(tempcfg, filename); | 282 | GNUNET_CONFIGURATION_write(tempcfg, filename); |
283 | |||
284 | GNUNET_CONFIGURATION_destroy(tempcfg); | ||
256 | return; | 285 | return; |
257 | } | 286 | } |
258 | 287 | ||
@@ -269,21 +298,13 @@ run (void *cls, | |||
269 | setTransportOptions("test_transport_api_peer1.conf"); | 298 | setTransportOptions("test_transport_api_peer1.conf"); |
270 | setTransportOptions("test_transport_api_peer2.conf"); | 299 | setTransportOptions("test_transport_api_peer2.conf"); |
271 | 300 | ||
301 | die_task = GNUNET_SCHEDULER_add_delayed (sched, | ||
302 | GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1), &end_badly, NULL); | ||
303 | |||
272 | setup_peer (&p1, "test_transport_api_peer1.conf"); | 304 | setup_peer (&p1, "test_transport_api_peer1.conf"); |
273 | setup_peer (&p2, "test_transport_api_peer2.conf"); | 305 | setup_peer (&p2, "test_transport_api_peer2.conf"); |
274 | GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); | ||
275 | } | ||
276 | 306 | ||
277 | 307 | GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); | |
278 | static void | ||
279 | stop_arm (struct PeerContext *p) | ||
280 | { | ||
281 | #if START_ARM | ||
282 | if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) | ||
283 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); | ||
284 | GNUNET_OS_process_wait (p->arm_pid); | ||
285 | #endif | ||
286 | GNUNET_CONFIGURATION_destroy (p->cfg); | ||
287 | } | 308 | } |
288 | 309 | ||
289 | static int | 310 | static int |