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)
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;
}
#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);
ssize_t ret;
int offset;
int count;
+ int tsize;
+ char *msgbuf;
const struct GNUNET_MessageHeader *currhdr;
do
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,
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);
/**
* 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
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
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,
{
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 ();
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)
{
hdr->type = htons (MTYPE);
}
- return 0;
- //return sizeof (struct GNUNET_MessageHeader);
+ return sizeof (struct GNUNET_MessageHeader);
}
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);
#endif
GNUNET_CONFIGURATION_write(tempcfg, filename);
+
+ GNUNET_CONFIGURATION_destroy(tempcfg);
return;
}
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