GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("try_transmission_to_peer pre-send: at this point rl->neighbor->addr is NOT NULL, addrlen is %d\n"), rl->neighbor->addr_len);
else
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, _("try_transmission_to_peer pre-send: at this point rl->neighbor->addr is NULL\n"));
+ /* FIXME: Change MessageQueue to hold message buffer and size? */
rl->plugin->api->send (rl->plugin->api->cls,
&neighbor->id,
- mq->message,
+ (char *)mq->message,
+ ntohs(mq->message->size),
mq->priority,
GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT,
rl->neighbor->addr,
GNUNET_PEERINFO_add_peer (cfg, sched, &pid, hello);
n = find_neighbor (&pid, NULL, 0);
if (NULL != n)
- try_transmission_to_peer (n);
+ {
+ try_transmission_to_peer (n);
+ }
GNUNET_free (hello);
while (NULL != (va = pos->addresses))
{
}
-static struct GNUNET_MessageHeader *
-createPingMessage (struct GNUNET_PeerIdentity * target, struct ValidationAddress *va)
-{
-
- struct TransportPingMessage *ping;
- ping = GNUNET_malloc(sizeof(struct TransportPingMessage));
-
- ping->challenge = htonl(va->challenge);
- ping->header.size = sizeof(struct TransportPingMessage);
- ping->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
- memcpy(&ping->target, target, sizeof(struct GNUNET_PeerIdentity));
-
- return &ping->header;
-}
-
/**
* Function that will be called if we receive a validation
* of an address challenge that we transmitted to another
struct TransportPlugin *tp;
struct ValidationAddress *va;
struct GNUNET_PeerIdentity id;
- struct GNUNET_MessageHeader *pingMessage;
+ char *pingMessage;
int sent;
+ struct TransportPingMessage *ping;
+ char * message_buf;
+ int hello_size;
+
tp = find_transport (tname);
if (tp == NULL)
{
(unsigned int) -1);
memcpy (&va[1], addr, addrlen);
- pingMessage = createPingMessage(&id, va);
+ hello_size = GNUNET_HELLO_size(our_hello);
+ message_buf = GNUNET_malloc(sizeof(struct TransportPingMessage) + hello_size);
+ memcpy(message_buf, &our_hello, hello_size);
+
+ 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));
+ 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, pingMessage, GNUNET_SCHEDULER_PRIORITY_DEFAULT,
+ sent = tp->api->send(tp->api->cls, &id, message_buf, sizeof(struct TransportPingMessage) + hello_size, 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);
* the address via the transport plugin. If not validated, then
* do not count this as a good peer/address...
*
+ * Currently this function is not used, ping/pongs get sent from the
+ * run_validation function. Haven't decided yet how to do this.
*/
static void
validate_address (void *cls, struct ValidationAddress *va,
*
* @param cls closure
* @param target who should receive this message (ignored by UDP)
- * @param msg the message to transmit
+ * @param msgbuf one or more GNUNET_MessageHeader(s) strung together
+ * @param msgbufsize the size of the msgbuf to send
* @param priority how important is the message (ignored by UDP)
* @param timeout when should we time out (give up) if we can not transmit?
* @param addr the addr to send the message to, needs to be a sockaddr for us
static ssize_t
udp_plugin_send (void *cls,
const struct GNUNET_PeerIdentity *target,
- const struct GNUNET_MessageHeader *msg,
+ char *msgbuf,
+ size_t msgbuf_size,
unsigned int priority,
struct GNUNET_TIME_Relative timeout,
const void *addr,
}
/* Build the message to be sent */
- message = GNUNET_malloc (sizeof (struct UDPMessage) + ntohs (msg->size));
- ssize = sizeof (struct UDPMessage) + ntohs (msg->size);
+ message = GNUNET_malloc (sizeof (struct UDPMessage) + msgbuf_size);
+ ssize = sizeof (struct UDPMessage) + msgbuf_size;
#if DEBUG_UDP
GNUNET_log_from (GNUNET_ERROR_TYPE_INFO, "udp", _
message->header.type = htons (0);
memcpy (&message->sender, plugin->env->my_identity,
sizeof (struct GNUNET_PeerIdentity));
- memcpy (&message[1], msg, ntohs (msg->size));
+ memcpy (&message[1], msgbuf, msgbuf_size);
/* Actually send the message */
sent =
socklen_t fromlen;
struct sockaddr_storage addr;
ssize_t ret;
+ int offset;
+ int count;
+ const struct GNUNET_MessageHeader *currhdr;
do
{
("msg reports message type of %d\n"),
ntohs (hdr->type));
#endif
- plugin->env->receive (plugin->env->cls,
- sender, hdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen);
+ offset = 0;
+ count = 0;
+ while (offset < (ntohs (msg->header.size) - sizeof(struct UDPMessage)))
+ {
+ currhdr = &hdr[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));
+#endif
+ plugin->env->receive (plugin->env->cls,
+ sender, currhdr, UDP_DIRECT_DISTANCE, (char *)&addr, fromlen);
+ offset += ntohs(currhdr->size);
+ }
GNUNET_free (sender);
GNUNET_free (buf);