size_t size;
};
+union MeshInfoCB {
+
+ /**
+ * Channel callback.
+ */
+ GNUNET_MESH_ChannelCB channel_cb;
+
+ /**
+ * Monitor callback
+ */
+ GNUNET_MESH_PeersCB peers_cb;
+
+ /**
+ * Monitor callback
+ */
+ GNUNET_MESH_PeerCB peer_cb;
+
+ /**
+ * Monitor callback
+ */
+ GNUNET_MESH_TunnelsCB tunnels_cb;
+
+ /**
+ * Tunnel callback.
+ */
+ GNUNET_MESH_TunnelCB tunnel_cb;
+};
+
/**
* Opaque handle to the service.
GNUNET_SCHEDULER_TaskIdentifier reconnect_task;
/**
- * Monitor callback
- */
- GNUNET_MESH_ChannelsCB channels_cb;
-
- /**
- * Monitor callback closure.
- */
- void *channels_cls;
-
- /**
- * Channel callback.
+ * Callback for an info task (only one active at a time).
*/
- GNUNET_MESH_ChannelCB channel_cb;
+ union MeshInfoCB info_cb;
/**
- * Channel callback closure.
+ * Info callback closure for @c info_cb.
*/
- void *channel_cls;
+ void *info_cls;
};
* Channel this peer belongs to
*/
struct GNUNET_MESH_Channel *t;
-
- /**
- * Flag indicating whether service has informed about its connection
- * FIXME-BART: is this flag used? Seems dead right now...
- */
- int connected;
-
};
unsigned int packet_size;
/**
- * Is the channel allowed to buffer?
- */
- int nobuffer;
-
- /**
- * Is the channel realiable?
- */
- int reliable;
-
- /**
- * If reliable, is the channel out of order?
+ * Channel options: reliability, etc.
*/
- int ooorder;
+ enum GNUNET_MESH_ChannelOption options;
/**
* Are we allowed to send to the service?
{
struct GNUNET_MESH_Channel *ch;
- ch = GNUNET_malloc (sizeof (struct GNUNET_MESH_Channel));
+ ch = GNUNET_new (struct GNUNET_MESH_Channel);
GNUNET_CONTAINER_DLL_insert (h->channels_head, h->channels_tail, ch);
ch->mesh = h;
if (0 == chid)
ch->chid = chid;
}
ch->allow_send = GNUNET_NO;
- ch->nobuffer = GNUNET_NO;
return ch;
}
struct GNUNET_MESH_TransmitHandle *th;
struct GNUNET_MESH_TransmitHandle *next;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "destroy_channel %X\n", ch->chid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " destroy_channel %X\n", ch->chid);
if (NULL == ch)
{
/* signal channel destruction */
if ( (NULL != h->cleaner) && (0 != ch->peer) && (GNUNET_YES == call_cleaner) )
+ {
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " calling cleaner\n");
h->cleaner (h->cls, ch, ch->ctx);
+ }
/* check that clients did not leave messages behind in the queue */
for (th = h->th_head; NULL != th; th = next)
}
if (NULL != h->new_channel)
{
+ void *ctx;
+
ch = create_channel (h, chid);
ch->allow_send = GNUNET_NO;
ch->peer = GNUNET_PEER_intern (&msg->peer);
ch->mesh = h;
ch->chid = chid;
ch->port = port;
- if (0 != (msg->opt & GNUNET_MESH_OPTION_NOBUFFER))
- ch->nobuffer = GNUNET_YES;
- else
- ch->nobuffer = GNUNET_NO;
-
- if (0 != (msg->opt & GNUNET_MESH_OPTION_RELIABLE))
- ch->reliable = GNUNET_YES;
- else
- ch->reliable = GNUNET_NO;
-
- if (GNUNET_YES == ch->reliable &&
- 0 != (msg->opt & GNUNET_MESH_OPTION_OOORDER))
- ch->ooorder = GNUNET_YES;
- else
- ch->ooorder = GNUNET_NO;
+ ch->options = ntohl (msg->opt);
LOG (GNUNET_ERROR_TYPE_DEBUG, " created channel %p\n", ch);
- ch->ctx = h->new_channel (h->cls, ch, &msg->peer, ch->port);
+ ctx = h->new_channel (h->cls, ch, &msg->peer, ch->port, ch->options);
+ if (NULL != ctx)
+ ch->ctx = ctx;
LOG (GNUNET_ERROR_TYPE_DEBUG, "User notified\n");
}
else
struct GNUNET_MESH_Channel *ch;
MESH_ChannelNumber chid;
- LOG (GNUNET_ERROR_TYPE_DEBUG, "Destroying channel from service\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Channel Destroy received from service\n");
chid = ntohl (msg->channel_id);
ch = retrieve_channel (h, chid);
LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X unknown\n", chid);
return;
}
- LOG (GNUNET_ERROR_TYPE_DEBUG, "channel %X destroyed\n", ch->chid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " destroying channel %X\n", ch->chid);
destroy_channel (ch, GNUNET_YES);
}
const struct GNUNET_MESH_MessageHandler *handler;
struct GNUNET_MESH_LocalData *dmsg;
struct GNUNET_MESH_Channel *ch;
+ size_t size;
unsigned int i;
uint16_t type;
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Got a data message!\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Got a data message!\n");
dmsg = (struct GNUNET_MESH_LocalData *) message;
ch = retrieve_channel (h, ntohl (dmsg->id));
payload = (struct GNUNET_MessageHeader *) &dmsg[1];
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- " %s data on channel %s [%X]\n",
- ch->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV ? "fwd" : "bck",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " %s data on channel %s [%X]\n",
+ GM_f2s (ch->chid >= GNUNET_MESH_LOCAL_CHANNEL_ID_SERV),
GNUNET_i2s (GNUNET_PEER_resolve2 (ch->peer)), ntohl (dmsg->id));
+
+ size = ntohs (message->size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " %u bytes\n", size);
+
if (NULL == ch)
{
/* Channel was ignored/destroyed, probably service didn't get it yet */
return;
}
type = ntohs (payload->type);
- LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %u\n", type);
+ size = ntohs (payload->size);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " payload type %s\n", GM_m2s (type));
for (i = 0; i < h->n_handlers; i++)
{
handler = &h->message_handlers[i];
- LOG (GNUNET_ERROR_TYPE_DEBUG,
- " checking handler for type %u\n",
+ LOG (GNUNET_ERROR_TYPE_DEBUG, " checking handler for type %u\n",
handler->type);
if (handler->type == type)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, "Got an ACK!\n");
msg = (struct GNUNET_MESH_LocalAck *) message;
chid = ntohl (msg->channel_id);
- ch = retrieve_channel (h, chid);
+ ch = retrieve_channel (h, chid);
if (NULL == ch)
{
- LOG (GNUNET_ERROR_TYPE_WARNING, "ACK on unknown channel %X\n", chid);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "ACK on unknown channel %X\n", chid);
return;
}
LOG (GNUNET_ERROR_TYPE_DEBUG, " on channel %X!\n", ch->chid);
if (NULL == h->th && 0 < ch->packet_size)
{
LOG (GNUNET_ERROR_TYPE_DEBUG, " tmt rdy was NULL, requesting!\n");
- h->th =
- GNUNET_CLIENT_notify_transmit_ready (h->client, ch->packet_size,
- GNUNET_TIME_UNIT_FOREVER_REL,
- GNUNET_YES, &send_callback, h);
+ h->th = GNUNET_CLIENT_notify_transmit_ready (h->client, ch->packet_size,
+ GNUNET_TIME_UNIT_FOREVER_REL,
+ GNUNET_YES, &send_callback, h);
}
}
// process_get_channels (struct GNUNET_MESH_Handle *h,
// const struct GNUNET_MessageHeader *message)
// {
-// struct GNUNET_MESH_LocalMonitor *msg;
+// struct GNUNET_MESH_LocalInfo *msg;
//
// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Get Channels messasge received\n");
//
// return;
// }
//
-// msg = (struct GNUNET_MESH_LocalMonitor *) message;
+// msg = (struct GNUNET_MESH_LocalInfo *) message;
// if (ntohs (message->size) !=
-// (sizeof (struct GNUNET_MESH_LocalMonitor) +
+// (sizeof (struct GNUNET_MESH_LocalInfo) +
// sizeof (struct GNUNET_PeerIdentity)))
// {
// GNUNET_break_op (0);
// GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
// "Get channels message: size %hu - expected %u\n",
// ntohs (message->size),
-// sizeof (struct GNUNET_MESH_LocalMonitor));
+// sizeof (struct GNUNET_MESH_LocalInfo));
// return;
// }
// h->channels_cb (h->channels_cls,
// process_show_channel (struct GNUNET_MESH_Handle *h,
// const struct GNUNET_MessageHeader *message)
// {
-// struct GNUNET_MESH_LocalMonitor *msg;
+// struct GNUNET_MESH_LocalInfo *msg;
// size_t esize;
//
// GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Show Channel messasge received\n");
// }
//
// /* Verify message sanity */
-// msg = (struct GNUNET_MESH_LocalMonitor *) message;
-// esize = sizeof (struct GNUNET_MESH_LocalMonitor);
+// msg = (struct GNUNET_MESH_LocalInfo *) message;
+// esize = sizeof (struct GNUNET_MESH_LocalInfo);
// if (ntohs (message->size) != esize)
// {
// GNUNET_break_op (0);
// }
+
+/**
+ * Process a local reply about info on all tunnels, pass info to the user.
+ *
+ * @param h Mesh handle.
+ * @param message Message itself.
+ */
+static void
+process_get_peers (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct GNUNET_MESH_LocalInfoPeer *msg;
+ uint16_t size;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Peer messasge received\n");
+
+ if (NULL == h->info_cb.peers_cb)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n");
+ return;
+ }
+
+ size = ntohs (message->size);
+ if (sizeof (struct GNUNET_MESH_LocalInfoPeer) > size)
+ {
+ h->info_cb.peers_cb (h->info_cls, NULL, -1, 0, 0);
+ h->info_cb.peers_cb = NULL;
+ h->info_cls = NULL;
+ return;
+ }
+
+ msg = (struct GNUNET_MESH_LocalInfoPeer *) message;
+ h->info_cb.peers_cb (h->info_cls, &msg->destination,
+ (int) ntohs (msg->tunnel),
+ (unsigned int ) ntohs (msg->paths),
+ 0);
+}
+
+
+/**
+ * Process a local peer info reply, pass info to the user.
+ *
+ * @param h Mesh handle.
+ * @param message Message itself.
+ */
+static void
+process_get_peer (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct GNUNET_MESH_LocalInfoTunnel *msg;
+ size_t esize;
+ size_t msize;
+ unsigned int ch_n;
+ unsigned int c_n;
+ struct GNUNET_MeshHash *conns;
+ MESH_ChannelNumber *chns;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnel messasge received\n");
+ if (NULL == h->info_cb.tunnel_cb)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n");
+ return;
+ }
+
+ /* Verify message sanity */
+ msg = (struct GNUNET_MESH_LocalInfoTunnel *) message;
+ msize = ntohs (message->size);
+ esize = sizeof (struct GNUNET_MESH_LocalInfoTunnel);
+ if (esize > msize)
+ {
+ GNUNET_break_op (0);
+ h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0);
+ goto clean_cls;
+ }
+ ch_n = ntohl (msg->channels);
+ c_n = ntohl (msg->connections);
+ esize += ch_n * sizeof (MESH_ChannelNumber);
+ esize += c_n * sizeof (struct GNUNET_MeshHash);
+ if (msize != esize)
+ {
+ GNUNET_break_op (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "m:%u, e: %u (%u ch, %u conn)\n",
+ msize, esize, ch_n, c_n);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u (%u ch, %u conn)\n",
+ sizeof (struct GNUNET_MESH_LocalInfoTunnel),
+ sizeof (MESH_ChannelNumber), sizeof (struct GNUNET_HashCode));
+ h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0);
+ goto clean_cls;
+ }
+
+ /* Call Callback with tunnel info. */
+ conns = (struct GNUNET_MeshHash *) &msg[1];
+ chns = (MESH_ChannelNumber *) &conns[c_n];
+ h->info_cb.tunnel_cb (h->info_cls, &msg->destination,
+ ch_n, c_n, chns, conns,
+ ntohs (msg->estate), ntohs (msg->cstate));
+
+ clean_cls:
+ h->info_cb.tunnel_cb = NULL;
+ h->info_cls = NULL;
+}
+
+
+/**
+ * Process a local reply about info on all tunnels, pass info to the user.
+ *
+ * @param h Mesh handle.
+ * @param message Message itself.
+ */
+static void
+process_get_tunnels (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct GNUNET_MESH_LocalInfoTunnel *msg;
+ uint16_t size;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnels messasge received\n");
+
+ if (NULL == h->info_cb.tunnels_cb)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n");
+ return;
+ }
+
+ size = ntohs (message->size);
+ if (sizeof (struct GNUNET_MESH_LocalInfoTunnel) > size)
+ {
+ h->info_cb.tunnels_cb (h->info_cls, NULL, 0, 0, 0, 0);
+ h->info_cb.tunnels_cb = NULL;
+ h->info_cls = NULL;
+ return;
+ }
+
+ msg = (struct GNUNET_MESH_LocalInfoTunnel *) message;
+ h->info_cb.tunnels_cb (h->info_cls, &msg->destination,
+ ntohl (msg->channels), ntohl (msg->connections),
+ ntohs (msg->estate), ntohs (msg->cstate));
+
+}
+
+
+/**
+ * Process a local tunnel info reply, pass info to the user.
+ *
+ * @param h Mesh handle.
+ * @param message Message itself.
+ */
+static void
+process_get_tunnel (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_MessageHeader *message)
+{
+ struct GNUNET_MESH_LocalInfoTunnel *msg;
+ size_t esize;
+ size_t msize;
+ unsigned int ch_n;
+ unsigned int c_n;
+ struct GNUNET_MeshHash *conns;
+ MESH_ChannelNumber *chns;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Get Tunnel messasge received\n");
+ if (NULL == h->info_cb.tunnel_cb)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, " ignored\n");
+ return;
+ }
+
+ /* Verify message sanity */
+ msg = (struct GNUNET_MESH_LocalInfoTunnel *) message;
+ msize = ntohs (message->size);
+ esize = sizeof (struct GNUNET_MESH_LocalInfoTunnel);
+ if (esize > msize)
+ {
+ GNUNET_break_op (0);
+ h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0);
+ goto clean_cls;
+ }
+ ch_n = ntohl (msg->channels);
+ c_n = ntohl (msg->connections);
+ esize += ch_n * sizeof (MESH_ChannelNumber);
+ esize += c_n * sizeof (struct GNUNET_MeshHash);
+ if (msize != esize)
+ {
+ GNUNET_break_op (0);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "m:%u, e: %u (%u ch, %u conn)\n",
+ msize, esize, ch_n, c_n);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%u (%u ch, %u conn)\n",
+ sizeof (struct GNUNET_MESH_LocalInfoTunnel),
+ sizeof (MESH_ChannelNumber), sizeof (struct GNUNET_HashCode));
+ h->info_cb.tunnel_cb (h->info_cls, NULL, 0, 0, NULL, NULL, 0, 0);
+ goto clean_cls;
+ }
+
+ /* Call Callback with tunnel info. */
+ conns = (struct GNUNET_MeshHash *) &msg[1];
+ chns = (MESH_ChannelNumber *) &conns[c_n];
+ h->info_cb.tunnel_cb (h->info_cls, &msg->destination,
+ ch_n, c_n, chns, conns,
+ ntohs (msg->estate), ntohs (msg->cstate));
+
+clean_cls:
+ h->info_cb.tunnel_cb = NULL;
+ h->info_cls = NULL;
+}
+
+
/**
* Function to process all messages received from the service
*
type = ntohs (msg->type);
LOG (GNUNET_ERROR_TYPE_DEBUG, "\n");
LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a message: %s\n",
- GNUNET_MESH_DEBUG_M2S (type));
+ GM_m2s (type));
switch (type)
{
/* Notify of a new incoming channel */
process_channel_created (h, (struct GNUNET_MESH_ChannelMessage *) msg);
break;
/* Notify of a channel disconnection */
- case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
- case GNUNET_MESSAGE_TYPE_MESH_LOCAL_NACK:
+ case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY: /* TODO separate(gid problem)*/
+ case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_NACK:
process_channel_destroy (h, (struct GNUNET_MESH_ChannelMessage *) msg);
break;
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA:
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_ACK:
process_ack (h, msg);
break;
-// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS: DEPRECATED
+// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS:
// process_get_channels (h, msg);
// break;
-// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL: DEPRECATED
+// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
+// process_show_channel (h, msg);
+// break;
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS:
+ process_get_peers (h, msg);
+ break;
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER:
+ process_get_peer (h, msg);
+ break;
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS:
+ process_get_tunnels (h, msg);
+ break;
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL:
+ process_get_tunnel (h, msg);
+ break;
+// case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
// process_show_channel (h, msg);
// break;
default:
/* We shouldn't get any other packages, log and ignore */
LOG (GNUNET_ERROR_TYPE_WARNING,
"unsolicited message form service (type %s)\n",
- GNUNET_MESH_DEBUG_M2S (ntohs (msg->type)));
+ GM_m2s (ntohs (msg->type)));
}
LOG (GNUNET_ERROR_TYPE_DEBUG, "message processed\n");
if (GNUNET_YES == h->in_receive)
dmsg->id = htonl (ch->chid);
dmsg->header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_DATA);
LOG (GNUNET_ERROR_TYPE_DEBUG, "# payload type %s\n",
- GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
+ GM_m2s (ntohs (mh->type)));
ch->allow_send = GNUNET_NO;
}
else
struct GNUNET_MessageHeader *mh = (struct GNUNET_MessageHeader *) &th[1];
LOG (GNUNET_ERROR_TYPE_DEBUG, "# mesh internal traffic, type %s\n",
- GNUNET_MESH_DEBUG_M2S (ntohs (mh->type)));
+ GM_m2s (ntohs (mh->type)));
memcpy (cbuf, &th[1], th->size);
psize = th->size;
}
size_t msize;
LOG (GNUNET_ERROR_TYPE_DEBUG, " Sending message to service: %s\n",
- GNUNET_MESH_DEBUG_M2S(ntohs(msg->type)));
+ GM_m2s(ntohs(msg->type)));
msize = ntohs (msg->size);
th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle) + msize);
th->timeout = GNUNET_TIME_UNIT_FOREVER_ABS;
struct GNUNET_MESH_Handle *h;
LOG (GNUNET_ERROR_TYPE_DEBUG, "GNUNET_MESH_connect()\n");
- h = GNUNET_malloc (sizeof (struct GNUNET_MESH_Handle));
+ h = GNUNET_new (struct GNUNET_MESH_Handle);
LOG (GNUNET_ERROR_TYPE_DEBUG, " addr %p\n", h);
h->cfg = cfg;
h->new_channel = new_channel;
case GNUNET_MESSAGE_TYPE_MESH_CHANNEL_DESTROY:
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS:
case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL:
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER:
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS:
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL:
+ case GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS:
break;
default:
GNUNET_break (0);
* @param channel_ctx client's channel context to associate with the channel
* @param peer peer identity the channel should go to
* @param port Port number.
- * @param nobuffer Flag for disabling buffering on relay nodes.
- * @param reliable Flag for end-to-end reliability.
+ * @param options MeshOption flag field, with all desired option bits set to 1.
*
* @return handle to the channel
*/
struct GNUNET_MESH_Channel *
GNUNET_MESH_channel_create (struct GNUNET_MESH_Handle *h,
- void *channel_ctx,
- const struct GNUNET_PeerIdentity *peer,
- uint32_t port,
- int nobuffer,
- int reliable)
+ void *channel_ctx,
+ const struct GNUNET_PeerIdentity *peer,
+ uint32_t port,
+ enum GNUNET_MESH_ChannelOption options)
{
struct GNUNET_MESH_Channel *ch;
struct GNUNET_MESH_ChannelMessage msg;
msg.channel_id = htonl (ch->chid);
msg.port = htonl (port);
msg.peer = *peer;
- msg.opt = 0;
- if (GNUNET_YES == reliable)
- msg.opt |= GNUNET_MESH_OPTION_RELIABLE;
- if (GNUNET_YES == nobuffer)
- msg.opt |= GNUNET_MESH_OPTION_NOBUFFER;
- msg.opt = htonl (msg.opt);
+ msg.opt = htonl (options);
ch->allow_send = 0;
send_packet (h, &msg.header, ch);
return ch;
*/
const union GNUNET_MESH_ChannelInfo *
GNUNET_MESH_channel_get_info (struct GNUNET_MESH_Channel *channel,
- enum MeshOption option, ...)
+ enum GNUNET_MESH_ChannelOption option, ...)
{
+ static int bool_flag;
const union GNUNET_MESH_ChannelInfo *ret;
switch (option)
{
case GNUNET_MESH_OPTION_NOBUFFER:
- ret = (const union GNUNET_MESH_ChannelInfo *) &channel->nobuffer;
- break;
case GNUNET_MESH_OPTION_RELIABLE:
- ret = (const union GNUNET_MESH_ChannelInfo *) &channel->reliable;
- break;
case GNUNET_MESH_OPTION_OOORDER:
- ret = (const union GNUNET_MESH_ChannelInfo *) &channel->ooorder;
+ if (0 != (option & channel->options))
+ bool_flag = GNUNET_YES;
+ else
+ bool_flag = GNUNET_NO;
+ ret = (const union GNUNET_MESH_ChannelInfo *) &bool_flag;
break;
case GNUNET_MESH_OPTION_PEER:
ret = (const union GNUNET_MESH_ChannelInfo *) GNUNET_PEER_resolve2 (channel->peer);
LOG (GNUNET_ERROR_TYPE_DEBUG, " payload size %u\n", notify_size);
GNUNET_assert (NULL != notify);
GNUNET_assert (0 == channel->packet_size); // Only one data packet allowed
- th = GNUNET_malloc (sizeof (struct GNUNET_MESH_TransmitHandle));
+ th = GNUNET_new (struct GNUNET_MESH_TransmitHandle);
th->channel = channel;
th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
th->size = notify_size + sizeof (struct GNUNET_MESH_LocalData);
}
+static void
+send_info_request (struct GNUNET_MESH_Handle *h, uint16_t type)
+{
+ struct GNUNET_MessageHeader msg;
+
+ msg.size = htons (sizeof (msg));
+ msg.type = htons (type);
+ send_packet (h, &msg, NULL);
+}
+
+
/**
- * Request information about the running mesh peer.
- * The callback will be called for every channel known to the service,
- * listing all active peers that blong to the channel.
+ * Request information about peers known to the running mesh service.
+ * The callback will be called for every peer known to the service.
+ * Only one info request (of any kind) can be active at once.
*
- * If called again on the same handle, it will overwrite the previous
- * callback and cls. To retrieve the cls, monitor_cancel must be
- * called first.
*
* WARNING: unstable API, likely to change in the future!
*
* @param h Handle to the mesh peer.
* @param callback Function to call with the requested data.
* @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
*/
-void
-GNUNET_MESH_get_channels (struct GNUNET_MESH_Handle *h,
- GNUNET_MESH_ChannelsCB callback,
- void *callback_cls)
+int
+GNUNET_MESH_get_peers (struct GNUNET_MESH_Handle *h,
+ GNUNET_MESH_PeersCB callback,
+ void *callback_cls)
{
- struct GNUNET_MessageHeader msg;
+ if (NULL != h->info_cb.peers_cb)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEERS);
+ h->info_cb.peers_cb = callback;
+ h->info_cls = callback_cls;
+ return GNUNET_OK;
+}
- msg.size = htons (sizeof (msg));
- msg.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNELS);
- send_packet (h, &msg, NULL);
- h->channels_cb = callback;
- h->channels_cls = callback_cls;
+
+/**
+ * Cancel a peer info request. The callback will not be called (anymore).
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Mesh handle.
+ *
+ * @return Closure given to GNUNET_MESH_get_peers.
+ */
+void *
+GNUNET_MESH_get_peers_cancel (struct GNUNET_MESH_Handle *h)
+{
+ void *cls;
+
+ cls = h->info_cls;
+ h->info_cb.peers_cb = NULL;
+ h->info_cls = NULL;
+ return cls;
+}
+
+
+/**
+ * Request information about a peer known to the running mesh peer.
+ * The callback will be called for the tunnel once.
+ * Only one info request (of any kind) can be active at once.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Handle to the mesh peer.
+ * @param id Peer whose tunnel to examine.
+ * @param callback Function to call with the requested data.
+ * @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
+ */
+int
+GNUNET_MESH_get_peer (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_PeerIdentity *id,
+ GNUNET_MESH_PeerCB callback,
+ void *callback_cls)
+{
+ struct GNUNET_MESH_LocalInfo msg;
+
+ if (NULL != h->info_cb.peer_cb)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+
+ memset (&msg, 0, sizeof (msg));
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_PEER);
+ msg.peer = *id;
+ send_packet (h, &msg.header, NULL);
+ h->info_cb.peer_cb = callback;
+ h->info_cls = callback_cls;
+ return GNUNET_OK;
+}
+
+
+/**
+ * Request information about tunnels of the running mesh peer.
+ * The callback will be called for every tunnel of the service.
+ * Only one info request (of any kind) can be active at once.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Handle to the mesh peer.
+ * @param callback Function to call with the requested data.
+ * @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
+ */
+int
+GNUNET_MESH_get_tunnels (struct GNUNET_MESH_Handle *h,
+ GNUNET_MESH_TunnelsCB callback,
+ void *callback_cls)
+{
+ if (NULL != h->info_cb.tunnels_cb)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+ send_info_request (h, GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNELS);
+ h->info_cb.tunnels_cb = callback;
+ h->info_cls = callback_cls;
+ return GNUNET_OK;
}
*
* @param h Mesh handle.
*
- * @return Closure given to GNUNET_MESH_monitor, if any.
+ * @return Closure given to GNUNET_MESH_get_tunnels.
*/
void *
-GNUNET_MESH_get_channels_cancel (struct GNUNET_MESH_Handle *h)
+GNUNET_MESH_get_tunnels_cancel (struct GNUNET_MESH_Handle *h)
{
void *cls;
- cls = h->channels_cls;
- h->channels_cb = NULL;
- h->channels_cls = NULL;
+ h->info_cb.tunnels_cb = NULL;
+ cls = h->info_cls;
+ h->info_cls = NULL;
+
return cls;
}
+
+/**
+ * Request information about a tunnel of the running mesh peer.
+ * The callback will be called for the tunnel once.
+ * Only one info request (of any kind) can be active at once.
+ *
+ * WARNING: unstable API, likely to change in the future!
+ *
+ * @param h Handle to the mesh peer.
+ * @param id Peer whose tunnel to examine.
+ * @param callback Function to call with the requested data.
+ * @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
+ */
+int
+GNUNET_MESH_get_tunnel (struct GNUNET_MESH_Handle *h,
+ const struct GNUNET_PeerIdentity *id,
+ GNUNET_MESH_TunnelCB callback,
+ void *callback_cls)
+{
+ struct GNUNET_MESH_LocalInfo msg;
+
+ if (NULL != h->info_cb.tunnel_cb)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
+
+ memset (&msg, 0, sizeof (msg));
+ msg.header.size = htons (sizeof (msg));
+ msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_TUNNEL);
+ msg.peer = *id;
+ send_packet (h, &msg.header, NULL);
+ h->info_cb.tunnel_cb = callback;
+ h->info_cls = callback_cls;
+ return GNUNET_OK;
+}
+
+
/**
* Request information about a specific channel of the running mesh peer.
*
* @param channel_number Channel number.
* @param callback Function to call with the requested data.
* @param callback_cls Closure for @c callback.
+ *
+ * @return #GNUNET_OK / #GNUNET_SYSERR
*/
-void
+int
GNUNET_MESH_show_channel (struct GNUNET_MESH_Handle *h,
struct GNUNET_PeerIdentity *initiator,
unsigned int channel_number,
GNUNET_MESH_ChannelCB callback,
void *callback_cls)
{
- struct GNUNET_MESH_LocalMonitor msg;
+ struct GNUNET_MESH_LocalInfo msg;
+
+ if (NULL != h->info_cb.channel_cb)
+ {
+ GNUNET_break (0);
+ return GNUNET_SYSERR;
+ }
msg.header.size = htons (sizeof (msg));
msg.header.type = htons (GNUNET_MESSAGE_TYPE_MESH_LOCAL_INFO_CHANNEL);
- msg.owner = *initiator;
+ msg.peer = *initiator;
msg.channel_id = htonl (channel_number);
- msg.reserved = 0;
+// msg.reserved = 0;
send_packet (h, &msg.header, NULL);
- h->channel_cb = callback;
- h->channel_cls = callback_cls;
+ h->info_cb.channel_cb = callback;
+ h->info_cls = callback_cls;
+ return GNUNET_OK;
}