* Time to the next reconnect in case one reconnect fails
*/
struct GNUNET_TIME_Relative reconnect_time;
+
+ /**
+ * Task for trying to reconnect.
+ */
+ GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
};
for (napps = 0; napps < h->n_applications; napps++)
{
apps[napps] = htonl (h->applications[napps]);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: app %u\n", h->applications[napps]);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " app %u\n", h->applications[napps]);
}
types = (uint16_t *) & apps[napps];
for (ntypes = 0; ntypes < h->n_handlers; ntypes++)
msg->applications = htons (napps);
msg->types = htons (ntypes);
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "mesh: Sending %lu bytes long message %d types and %d apps\n",
+ "Sending %lu bytes long message %d types and %d apps\n",
ntohs (msg->header.size), ntypes, napps);
send_packet (h, &msg->header, NULL);
}
* @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...)
*/
static int
-reconnect (struct GNUNET_MESH_Handle *h)
+do_reconnect (struct GNUNET_MESH_Handle *h)
{
struct GNUNET_MESH_Tunnel *t;
unsigned int i;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: ******* RECONNECT *******\n");
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: *****************************\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "******* RECONNECT *******\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "*****************************\n");
h->in_receive = GNUNET_NO;
/* disconnect */
h->client = GNUNET_CLIENT_connect ("mesh", h->cfg);
if (h->client == NULL)
{
- GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h);
+ h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->reconnect_time,
+ &reconnect_cbk, h);
h->reconnect_time =
GNUNET_TIME_relative_min (GNUNET_TIME_UNIT_SECONDS,
GNUNET_TIME_relative_multiply
(h->reconnect_time, 2));
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Next retry in %sms\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " Next retry in %sms\n",
GNUNET_TIME_relative_to_string (h->reconnect_time));
GNUNET_break (0);
return GNUNET_NO;
{
struct GNUNET_MESH_Handle *h = cls;
- if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
+ h->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
return;
- reconnect (h);
+ do_reconnect (h);
+}
+
+
+/**
+ * Reconnect to the service, retransmit all infomation to try to restore the
+ * original state.
+ *
+ * @param h handle to the mesh
+ *
+ * @return GNUNET_YES in case of sucess, GNUNET_NO otherwise (service down...)
+ */
+static void
+reconnect (struct GNUNET_MESH_Handle *h)
+{
+ if (GNUNET_SCHEDULER_NO_TASK != h->reconnect_task)
+ GNUNET_SCHEDULER_add_delayed (h->reconnect_time, &reconnect_cbk, h);
}
atsi.value = 0;
t->ctx = h->new_tunnel (h->cls, t, &msg->peer, &atsi);
}
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: new incoming tunnel %X\n", t->tid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "new incoming tunnel %X\n", t->tid);
return;
}
{
GNUNET_break (0);
}
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: tunnel %u destroyed\n", t->tid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %u destroyed\n", t->tid);
destroy_tunnel (t, GNUNET_YES);
return;
}
GNUNET_PEER_Id id;
uint16_t size;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: processig peer event\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "processig peer event\n");
size = ntohs (msg->header.size);
if (size != sizeof (struct GNUNET_MESH_PeerControl))
{
p = add_peer_to_tunnel (t, &msg->peer);
if (GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_ADD == ntohs (msg->header.type))
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: adding peer\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "adding peer\n");
if (NULL != t->connect_handler)
{
atsi.type = 0;
}
else
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: removing peer\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "removing peer\n");
if (NULL != t->disconnect_handler && p->connected)
{
t->disconnect_handler (t->cls, &msg->peer);
remove_peer_from_tunnel (p);
GNUNET_free (p);
}
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: processing peer event END\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "processing peer event END\n");
}
unsigned int i;
uint16_t type;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Got a data message!\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a data message!\n");
type = ntohs (message->type);
switch (type)
{
t = retrieve_tunnel (h, ntohl (ucast->tid));
payload = (struct GNUNET_MessageHeader *) &ucast[1];
peer = &ucast->oid;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: ucast on tunnel %s [%x]\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " ucast on tunnel %s [%x]\n",
GNUNET_i2s (peer), ntohl (ucast->tid));
break;
case GNUNET_MESSAGE_TYPE_MESH_MULTICAST:
t = retrieve_tunnel (h, ntohl (mcast->tid));
payload = (struct GNUNET_MessageHeader *) &mcast[1];
peer = &mcast->oid;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: mcast on tunnel %s [%x]\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " mcast on tunnel %s [%x]\n",
GNUNET_i2s (peer), ntohl (mcast->tid));
break;
case GNUNET_MESSAGE_TYPE_MESH_TO_ORIGIN:
t = retrieve_tunnel (h, ntohl (to_orig->tid));
payload = (struct GNUNET_MessageHeader *) &to_orig[1];
peer = &to_orig->sender;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: torig on tunnel %s [%x]\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " torig on tunnel %s [%x]\n",
GNUNET_i2s (peer), ntohl (to_orig->tid));
break;
default:
if (msg == NULL)
{
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NULL msg\n");
reconnect (h);
return;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: received a message type %hu from MESH\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "received a message type %hu from MESH\n",
ntohs (msg->type));
switch (ntohs (msg->type))
{
"MESH: unsolicited message form service (type %d)\n",
ntohs (msg->type));
}
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: message processed\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n");
GNUNET_CLIENT_receive (h->client, &msg_received, h,
GNUNET_TIME_UNIT_FOREVER_REL);
}
size_t tsize;
size_t psize;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() Buffer %u\n", size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Send packet() Buffer %u\n", size);
h->th = NULL;
if ((0 == size) || (NULL == buf))
{
- reconnect (h);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Received NULL callback\n");
+// reconnect (h); FIXME
return 0;
}
tsize = 0;
GNUNET_assert (size >= th->size);
mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (to)];
psize = th->notify (th->notify_cls, size - sizeof (to), mh);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: to origin, type %u\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " to origin, type %u\n",
ntohs (mh->type));
if (psize > 0)
{
GNUNET_assert (size >= th->size);
mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (mc)];
psize = th->notify (th->notify_cls, size - sizeof (mc), mh);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: multicast, type %u\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " multicast, type %u\n",
ntohs (mh->type));
if (psize > 0)
{
GNUNET_assert (size >= th->size);
mh = (struct GNUNET_MessageHeader *) &cbuf[sizeof (uc)];
psize = th->notify (th->notify_cls, size - sizeof (uc), mh);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: unicast, type %u\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " unicast, type %u\n",
ntohs (mh->type));
if (psize > 0)
{
size -= psize;
tsize += psize;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: total size: %u\n", tsize);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " total size: %u\n", tsize);
if (NULL != (th = h->th_head))
{
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: next size: %u\n", th->size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " next size: %u\n", th->size);
if (NULL == h->th)
h->th =
GNUNET_CLIENT_notify_transmit_ready (h->client, th->size,
GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_YES, &send_callback, h);
}
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Send packet() END\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Send packet() END\n");
if (GNUNET_NO == h->in_receive)
{
h->in_receive = GNUNET_YES;
{
struct GNUNET_MESH_Handle *h;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect()\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect()\n");
h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
h->cfg = cfg;
h->max_queue_size = queue_size;
for (h->n_applications = 0; stypes[h->n_applications]; h->n_applications++) ;
for (h->n_handlers = 0; handlers[h->n_handlers].type; h->n_handlers++) ;
send_connect (h);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: GNUNET_MESH_connect() END\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect() END\n");
return h;
}
if (t->tid < GNUNET_MESH_LOCAL_TUNNEL_ID_SERV)
{
GNUNET_break (0);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: tunnel %X not destroyed\n", t->tid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "tunnel %X not destroyed\n", t->tid);
}
destroy_tunnel (t, GNUNET_YES);
t = aux;
break;
default:
GNUNET_break (0);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: unexpected msg %u\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "unexpected msg %u\n",
ntohs(msg->type));
}
GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
handle->client = NULL;
}
+ if (GNUNET_SCHEDULER_NO_TASK != handle->reconnect_task)
+ {
+ GNUNET_SCHEDULER_cancel(handle->reconnect_task);
+ handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
+ }
GNUNET_free (handle);
}
struct GNUNET_MESH_Tunnel *t;
struct GNUNET_MESH_TunnelMessage msg;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Creating new tunnel\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Creating new tunnel\n");
t = create_tunnel (h, 0);
t->connect_handler = connect_handler;
t->disconnect_handler = disconnect_handler;
struct GNUNET_MESH_TunnelMessage msg;
struct GNUNET_MESH_TransmitHandle *th;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: Destroying tunnel\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying tunnel\n");
h = tunnel->mesh;
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_TUNNEL_DESTROY);
size_t overhead;
GNUNET_assert (NULL != tunnel);
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: mesh notify transmit ready called\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh notify transmit ready called\n");
if (NULL != target)
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: target %s\n", GNUNET_i2s (target));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " target %s\n", GNUNET_i2s (target));
else
- LOG (GNUNET_ERROR_TYPE_DEBUG, "mesh: target multicast\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " target multicast\n");
GNUNET_assert (NULL != notify);
if (tunnel->mesh->npackets >= tunnel->mesh->max_queue_size &&
tunnel->npackets > 0)