* TODO: add regex to reconnect
*/
#include "platform.h"
-#include "gnunet_common.h"
-#include "gnunet_client_lib.h"
#include "gnunet_util_lib.h"
-#include "gnunet_peer_lib.h"
#include "gnunet_mesh_service.h"
#include "mesh.h"
#include "mesh_protocol.h"
* Time to the next reconnect in case one reconnect fails
*/
struct GNUNET_TIME_Relative reconnect_time;
-
+
/**
* Task for trying to reconnect.
*/
*/
struct GNUNET_MESH_Peer
{
- /**
- * ID of the peer in short form
- */
+ /**
+ * ID of the peer in short form
+ */
GNUNET_PEER_Id id;
/**
/**
* Flag indicating whether service has informed about its connection
+ * FIXME-BART: is this flag used? Seems dead right now...
*/
int connected;
*/
GNUNET_PEER_Id peer;
+ struct GNUNET_PeerIdentity pid;
+
/**
* Any data the caller wants to put in here
*/
/**
* Check whether there is any message ready in the queue and find the size.
- *
+ *
* @param h Mesh handle.
- *
+ *
* @return The size of the first ready message in the queue,
* 0 if there is none.
*/
struct GNUNET_MESH_TransmitHandle *th;
struct GNUNET_MESH_TransmitHandle *next;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "destroy_tunnel %X\n", t->tid);
-
if (NULL == t)
{
GNUNET_break (0);
return;
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "destroy_tunnel %X\n",
+ t->tid);
h = t->mesh;
GNUNET_CONTAINER_DLL_remove (h->tunnels_head, h->tunnels_tail, t);
/* clean up request */
if (GNUNET_SCHEDULER_NO_TASK != th->timeout_task)
GNUNET_SCHEDULER_cancel (th->timeout_task);
- GNUNET_free (th);
+ GNUNET_free (th);
}
/* if there are no more pending requests with mesh service, cancel active request */
/**
* Notify client that the transmission has timed out
- *
+ *
* @param cls closure
* @param tc task context
*/
struct GNUNET_MESH_TransmitHandle *th)
{
GNUNET_CONTAINER_DLL_insert_tail (h->th_head, h->th_tail, th);
- if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value == th->timeout.abs_value)
+ if (GNUNET_TIME_UNIT_FOREVER_ABS.abs_value_us == th->timeout.abs_value_us)
return;
th->timeout_task =
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining
/**
* Send an ack on the tunnel to confirm the processing of a message.
- *
+ *
* @param t Tunnel on which to send the ACK.
*/
static void
GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
GNUNET_TIME_relative_multiply
(h->reconnect_time, 2));
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Next retry in %s\n",
GNUNET_STRINGS_relative_time_to_string (h->reconnect_time,
GNUNET_NO));
tmsg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
tmsg.tunnel_id = htonl (t->tid);
tmsg.port = htonl (t->port);
+ t->pid = tmsg.peer;
GNUNET_PEER_resolve (t->peer, &tmsg.peer);
options = 0;
{
struct GNUNET_MESH_Tunnel *t;
MESH_TunnelNumber tid;
+ uint32_t port;
tid = ntohl (msg->tunnel_id);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating incoming tunnel %X\n", tid);
+ port = ntohl (msg->port);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating incoming tunnel %X:%u\n", tid, port);
if (tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
{
GNUNET_break (0);
t = create_tunnel (h, tid);
t->allow_send = GNUNET_NO;
t->peer = GNUNET_PEER_intern (&msg->peer);
+ t->pid = msg->peer;
t->mesh = h;
t->tid = tid;
- t->port = ntohl (msg->port);
+ t->port = port;
if (0 != (msg->opt & GNUNET_MESH_OPTION_NOBUFFER))
t->nobuffer = GNUNET_YES;
else
}
LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X destroyed\n", t->tid);
destroy_tunnel (t, GNUNET_YES);
- return;
}
t = retrieve_tunnel (h, ntohl (dmsg->tid));
payload = (struct GNUNET_MessageHeader *) &dmsg[1];
- LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on tunnel %s [%X]\n",
- t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV ? "fwd" : "bck",
- GNUNET_i2s (GNUNET_PEER_resolve2(t->peer)), ntohl (dmsg->tid));
if (NULL == t)
{
/* Tunnel was ignored/destroyed, probably service didn't get it yet */
LOG (GNUNET_ERROR_TYPE_DEBUG, " ignored!\n");
return;
}
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ " %s data on tunnel %s [%X]\n",
+ t->tid >= GNUNET_MESH_LOCAL_TUNNEL_ID_SERV ? "fwd" : "bck",
+ GNUNET_i2s (GNUNET_PEER_resolve2(t->peer)),
+ ntohl (dmsg->tid));
type = ntohs (payload->type);
LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %u\n", type);
for (i = 0; i < h->n_handlers; i++)
/**
* Process a local ACK message, enabling the client to send
* more data to the service.
- *
+ *
* @param h Mesh handle.
* @param message Message itself.
*/
if (msg == NULL)
{
- LOG (GNUNET_ERROR_TYPE_DEBUG,
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
"Mesh service disconnected, reconnecting\n", h);
reconnect (h);
return;
* Auxiliary function to send an already constructed packet to the service.
* Takes care of creating a new queue element, copying the message and
* calling the tmt_rdy function if necessary.
- *
+ *
* @param h mesh handle
* @param msg message to transmit
* @param tunnel tunnel this send is related to (NULL if N/A)
* @return handle to the tunnel
*/
struct GNUNET_MESH_Tunnel *
-GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
+GNUNET_MESH_tunnel_create (struct GNUNET_MESH_Handle *h,
void *tunnel_ctx,
const struct GNUNET_PeerIdentity *peer,
uint32_t port,
struct GNUNET_MESH_Tunnel *t;
struct GNUNET_MESH_TunnelMessage msg;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating new tunnel\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Creating new tunnel to %s:%u\n",
+ GNUNET_i2s (peer), port);
t = create_tunnel (h, 0);
LOG (GNUNET_ERROR_TYPE_DEBUG, " at %p\n", t);
LOG (GNUNET_ERROR_TYPE_DEBUG, " number %X\n", t->tid);
t->ctx = tunnel_ctx;
t->peer = GNUNET_PEER_intern (peer);
+ t->pid = *peer;
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_CREATE);
msg.header.size = htons (sizeof (struct GNUNET_MESH_TunnelMessage));
msg.tunnel_id = htonl (t->tid);
*
* @return Union with an answer to the query.
*/
-const union MeshTunnelInfo *
+const union GNUNET_MESH_TunnelInfo *
GNUNET_MESH_tunnel_get_info (struct GNUNET_MESH_Tunnel *tunnel,
enum MeshTunnelOption option, ...)
{
- const union MeshTunnelInfo *ret;
+ const union GNUNET_MESH_TunnelInfo *ret;
switch (option)
{
case GNUNET_MESH_OPTION_NOBUFFER:
- ret = (const union MeshTunnelInfo *) &tunnel->nobuffer;
+ ret = (const union GNUNET_MESH_TunnelInfo *) &tunnel->nobuffer;
break;
case GNUNET_MESH_OPTION_RELIABLE:
- ret = (const union MeshTunnelInfo *) &tunnel->reliable;
+ ret = (const union GNUNET_MESH_TunnelInfo *) &tunnel->reliable;
break;
case GNUNET_MESH_OPTION_OOORDER:
- ret = (const union MeshTunnelInfo *) &tunnel->ooorder;
+ ret = (const union GNUNET_MESH_TunnelInfo *) &tunnel->ooorder;
break;
case GNUNET_MESH_OPTION_PEER:
- ret = (const union MeshTunnelInfo *) &tunnel->peer;
+ ret = (const union GNUNET_MESH_TunnelInfo *) &tunnel->pid;
break;
default:
GNUNET_break (0);
mesh_mq_ntr (void *cls, size_t size,
void *buf)
{
- struct GNUNET_MQ_Handle *mq = cls;
+ struct GNUNET_MQ_Handle *mq = cls;
struct MeshMQState *state = GNUNET_MQ_impl_state (mq);
const struct GNUNET_MessageHeader *msg = GNUNET_MQ_impl_current (mq);
uint16_t msize;
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "mesh-mq",
+ "writing message (t: %u, s: %u) to buffer\n",
+ ntohs (msg->type), ntohs (msg->size));
+
state->th = NULL;
if (NULL == buf)
{
GNUNET_assert (NULL == state->th);
GNUNET_MQ_impl_send_commit (mq);
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "mesh-mq",
+ "calling ntr for message (t: %u, s: %u)\n",
+ ntohs (msg->type), ntohs (msg->size));
state->th =
GNUNET_MESH_notify_transmit_ready (state->tunnel,
/* FIXME: add option for corking */
GNUNET_NO,
- GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_TIME_UNIT_FOREVER_REL,
ntohs (msg->size),
mesh_mq_ntr, mq);
* destruction of a message queue.
* Implementations must not free 'mq', but should
* take care of 'impl_state'.
- *
+ *
* @param mq the message queue to destroy
* @param impl_state state of the implementation
*/