[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r10148 - gnunet/src/transport
From: |
gnunet |
Subject: |
[GNUnet-SVN] r10148 - gnunet/src/transport |
Date: |
Tue, 26 Jan 2010 16:48:50 +0100 |
Author: nevans
Date: 2010-01-26 16:48:50 +0100 (Tue, 26 Jan 2010)
New Revision: 10148
Modified:
gnunet/src/transport/gnunet-service-transport.c
gnunet/src/transport/plugin_transport_udp.c
gnunet/src/transport/test_transport_api.c
Log:
still not really working... sending and receiving of messages a bit hinky
Modified: gnunet/src/transport/gnunet-service-transport.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport.c 2010-01-26 13:40:14 UTC
(rev 10147)
+++ gnunet/src/transport/gnunet-service-transport.c 2010-01-26 15:48:50 UTC
(rev 10148)
@@ -1746,11 +1746,11 @@
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 @@
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;
}
Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2010-01-26 13:40:14 UTC (rev
10147)
+++ gnunet/src/transport/plugin_transport_udp.c 2010-01-26 15:48:50 UTC (rev
10148)
@@ -235,7 +235,7 @@
#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 @@
ssize_t ret;
int offset;
int count;
+ int tsize;
+ char *msgbuf;
const struct GNUNET_MessageHeader *currhdr;
do
@@ -373,10 +375,7 @@
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 @@
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);
Modified: gnunet/src/transport/test_transport_api.c
===================================================================
--- gnunet/src/transport/test_transport_api.c 2010-01-26 13:40:14 UTC (rev
10147)
+++ gnunet/src/transport/test_transport_api.c 2010-01-26 15:48:50 UTC (rev
10148)
@@ -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_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,14 +81,37 @@
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,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
@@ -95,14 +120,14 @@
{
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 @@
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 @@
hdr->type = htons (MTYPE);
}
- return 0;
- //return sizeof (struct GNUNET_MessageHeader);
+ return sizeof (struct GNUNET_MessageHeader);
}
@@ -217,6 +241,9 @@
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 @@
#endif
GNUNET_CONFIGURATION_write(tempcfg, filename);
+
+ GNUNET_CONFIGURATION_destroy(tempcfg);
return;
}
@@ -269,23 +298,15 @@
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);
-}
-
static int
check ()
{
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r10148 - gnunet/src/transport,
gnunet <=