From f206220e03ccf5cfdb8e8d51d253fed17db4d4ee Mon Sep 17 00:00:00 2001 From: "Nathan S. Evans" Date: Tue, 26 Jan 2010 15:48:50 +0000 Subject: [PATCH] still not really working... sending and receiving of messages a bit hinky --- src/transport/gnunet-service-transport.c | 19 ++++--- src/transport/plugin_transport_udp.c | 32 ++++++------ 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, struct TransportPlugin *tp; struct ValidationAddress *va; struct GNUNET_PeerIdentity id; - char *pingMessage; int sent; struct TransportPingMessage *ping; char * message_buf; int hello_size; + int tsize; tp = find_transport (tname); if (tp == NULL) @@ -1780,27 +1780,34 @@ run_validation (void *cls, memcpy (&va[1], addr, addrlen); hello_size = GNUNET_HELLO_size(our_hello); - message_buf = GNUNET_malloc(sizeof(struct TransportPingMessage) + hello_size); - memcpy(message_buf, &our_hello, hello_size); + tsize = sizeof(struct TransportPingMessage) + hello_size; + + message_buf = GNUNET_malloc(tsize); ping = GNUNET_malloc(sizeof(struct TransportPingMessage)); ping->challenge = htonl(va->challenge); ping->header.size = htons(sizeof(struct TransportPingMessage)); ping->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING); memcpy(&ping->target, &id, sizeof(struct GNUNET_PeerIdentity)); + + GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "hello size is %d, ping size is %d, total size is %d", hello_size, sizeof(struct TransportPingMessage), tsize); + + memcpy(message_buf, our_hello, hello_size); memcpy(&message_buf[hello_size], ping, sizeof(struct TransportPingMessage)); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending ping message to address `%s' via `%s' for `%4s'\n", GNUNET_a2s (addr, addrlen), tname, GNUNET_i2s (&id)); - sent = tp->api->send(tp->api->cls, &id, message_buf, sizeof(struct TransportPingMessage) + hello_size, GNUNET_SCHEDULER_PRIORITY_DEFAULT, + sent = tp->api->send(tp->api->cls, &id, message_buf, tsize, GNUNET_SCHEDULER_PRIORITY_DEFAULT, TRANSPORT_DEFAULT_TIMEOUT, addr, addrlen, GNUNET_YES, NULL, NULL); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transport returned %d from send!\n", sent); - GNUNET_free(pingMessage); - + GNUNET_free(ping); + GNUNET_free(message_buf); return GNUNET_OK; } 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, #if DEBUG_UDP GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ - ("In udp_send, ssize is %d\n"), ssize); + ("In udp_send, ssize is %d, sending message to %s\n"), ssize, GNUNET_a2s((const struct sockaddr *)addr, addrlen)); #endif message->header.size = htons (ssize); message->header.type = htons (0); @@ -357,6 +357,8 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) ssize_t ret; int offset; int count; + int tsize; + char *msgbuf; const struct GNUNET_MessageHeader *currhdr; do @@ -373,10 +375,7 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) buf = GNUNET_malloc (buflen); fromlen = sizeof (addr); -#if DEBUG_UDP - GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ - ("src_addr_len is %u\n"), fromlen); -#endif + memset (&addr, 0, fromlen); ret = GNUNET_NETWORK_socket_recvfrom (udp_sock, buf, buflen, @@ -412,31 +411,30 @@ udp_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) break; } hdr = (const struct GNUNET_MessageHeader *) &msg[1]; + msgbuf = (char *)&msg[1]; sender = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity)); memcpy (sender, &msg->sender, sizeof (struct GNUNET_PeerIdentity)); -#if DEBUG_UDP - GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ - ("msg reports message size of %d\n"), - ntohs (hdr->size)); - - GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ - ("msg reports message type of %d\n"), - ntohs (hdr->type)); -#endif offset = 0; count = 0; - while (offset < (ntohs (msg->header.size) - sizeof(struct UDPMessage))) + tsize = ntohs (msg->header.size) - sizeof(struct UDPMessage); + while (offset < tsize) { - currhdr = &hdr[offset]; + currhdr = (struct GNUNET_MessageHeader *)&msgbuf[offset]; #if DEBUG_UDP GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ ("processing msg %d: type %d, size %d at offset %d\n"), - count, offset, ntohs(currhdr->size), ntohs(currhdr->type)); + count, ntohs(currhdr->type), ntohs(currhdr->size), offset); #endif plugin->env->receive (plugin->env->cls, sender, currhdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen); offset += ntohs(currhdr->size); +#if DEBUG_UDP + GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _ + ("offset now %d, tsize %d\n"), + offset, tsize); +#endif + count++; } 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 @@ /** * How long until we give up on transmitting the message? */ -#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 50) #define MTYPE 12345 @@ -68,6 +68,8 @@ static int is_tcp; static int is_udp; +GNUNET_SCHEDULER_TaskIdentifier die_task; + #if VERBOSE #define OKPP do { ok++; fprintf (stderr, "Now at stage %u at %s:%u\n", ok, __FILE__, __LINE__); } while (0) #else @@ -79,12 +81,35 @@ static void end () { /* do work here */ - //GNUNET_assert (ok == 8); + GNUNET_assert (ok == 8); GNUNET_TRANSPORT_disconnect (p1.th); GNUNET_TRANSPORT_disconnect (p2.th); ok = 0; } +static void +stop_arm (struct PeerContext *p) +{ +#if START_ARM + if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) + GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); + GNUNET_OS_process_wait (p->arm_pid); +#endif + GNUNET_CONFIGURATION_destroy (p->cfg); +} + +static void +end_badly () +{ + /* do work here */ + fprintf(stderr, "Ending on an unhappy note.\n"); + + GNUNET_TRANSPORT_disconnect (p1.th); + GNUNET_TRANSPORT_disconnect (p2.th); + + ok = 1; + return; +} static void notify_receive (void *cls, @@ -95,14 +120,14 @@ notify_receive (void *cls, { GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ok is (%d)!\n", ok); - //GNUNET_assert (ok == 7); + GNUNET_assert (ok == 7); OKPP; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message of type %d from peer (%p)!\n", ntohs(message->type), cls); - //GNUNET_assert (MTYPE == ntohs (message->type)); - //GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == - // ntohs (message->size)); + GNUNET_assert (MTYPE == ntohs (message->type)); + GNUNET_assert (sizeof (struct GNUNET_MessageHeader) == + ntohs (message->size)); GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received message from peer (%p)!\n", cls); end (); @@ -158,8 +183,8 @@ notify_ready (void *cls, size_t size, void *buf) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting message to peer (%p) - %u!\n", cls, size); - //GNUNET_assert (size >= 256); - //GNUNET_assert ((ok >= 5) && (ok <= 6)); + GNUNET_assert (size >= 256); + GNUNET_assert ((ok >= 5) && (ok <= 6)); OKPP; if (buf != NULL) { @@ -168,8 +193,7 @@ notify_ready (void *cls, size_t size, void *buf) hdr->type = htons (MTYPE); } - return 0; - //return sizeof (struct GNUNET_MessageHeader); + return sizeof (struct GNUNET_MessageHeader); } @@ -217,6 +241,9 @@ exchange_hello (void *cls, GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) message, &me->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Received HELLO size %d\n", GNUNET_HELLO_size((const struct GNUNET_HELLO_Message *)message)); + GNUNET_TRANSPORT_offer_hello (p2.th, message); GNUNET_TRANSPORT_get_hello (p2.th, &exchange_hello_last, &p2); @@ -253,6 +280,8 @@ setTransportOptions(char * filename) #endif GNUNET_CONFIGURATION_write(tempcfg, filename); + + GNUNET_CONFIGURATION_destroy(tempcfg); return; } @@ -269,21 +298,13 @@ run (void *cls, setTransportOptions("test_transport_api_peer1.conf"); setTransportOptions("test_transport_api_peer2.conf"); + die_task = GNUNET_SCHEDULER_add_delayed (sched, + GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 1), &end_badly, NULL); + setup_peer (&p1, "test_transport_api_peer1.conf"); setup_peer (&p2, "test_transport_api_peer2.conf"); - GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); -} - -static void -stop_arm (struct PeerContext *p) -{ -#if START_ARM - if (0 != PLIBC_KILL (p->arm_pid, SIGTERM)) - GNUNET_log_strerror (GNUNET_ERROR_TYPE_WARNING, "kill"); - GNUNET_OS_process_wait (p->arm_pid); -#endif - GNUNET_CONFIGURATION_destroy (p->cfg); + GNUNET_TRANSPORT_get_hello (p1.th, &exchange_hello, &p1); } static int -- 2.25.1