struct tunnel_id
{
- uint32_t id;
+ uint32_t id GNUNET_PACKED;
struct GNUNET_PeerIdentity initiator;
struct GNUNET_PeerIdentity target;
};
/* followed by another GNUNET_MessageHeader */
};
+struct notify_cls
+{
+ void* notify_cls;
+ GNUNET_CONNECTION_TransmitReadyNotify notify;
+ struct GNUNET_MESH_Tunnel *tunnel;
+};
+
struct GNUNET_MESH_Tunnel
{
/* The other peer this tunnel leads to; just unicast for the moment! */
struct tunnel_id id;
- void* notify_cls;
- GNUNET_CONNECTION_TransmitReadyNotify notify;
-
/* The handlers and cls for outbound tunnels. Are NULL for inbound tunnels. */
GNUNET_MESH_TunnelDisconnectHandler disconnect_handler;
GNUNET_MESH_TunnelConnectHandler connect_handler;
struct GNUNET_MESH_MessageHandler *handler;
- for (handler = handle->handlers; handler != NULL; handler++)
+ for (handler = handle->handlers; handler->callback != NULL; handler++)
{
- if (ntohs (rmessage->type) == handler->type
- && (handler->expected_size == 0
- || handler->expected_size == ntohs (rmessage->size)))
+ if ( (ntohs (rmessage->type) == handler->type)
+ && ( (handler->expected_size == 0)
+ || (handler->expected_size == ntohs (rmessage->size))) )
{
break;
}
/* handler->callback handles this message */
/* If no handler was found, drop the message but keep the channel open */
- if (handler == NULL)
+ if (handler->callback == NULL)
return GNUNET_OK;
struct tunnel_list_element *tunnel = handle->established_tunnels.head;
memcpy (&tunnel->tunnel.id.target, peers,
sizeof (struct GNUNET_PeerIdentity));
tunnel->tunnel.id.id = current_id++;
+ memcpy (&tunnel->tunnel.peer, peers, sizeof(struct GNUNET_PeerIdentity));
struct peer_list_element *element = handle->connected_peers.head;
while (element != NULL)
handle->pending_tunnels.tail,
handle->pending_tunnels.tail,
tunnel);
+ (void) GNUNET_CORE_peer_request_connect (handle->core,
+ timeout,
+ peers,
+ NULL, NULL);
}
return &tunnel->tunnel;
static size_t
core_notify(void* cls, size_t size, void* buf)
{
- struct GNUNET_MESH_Tunnel *tunnel = cls;
+ struct notify_cls *ncls = cls;
+ struct GNUNET_MESH_Tunnel *tunnel = ncls->tunnel;
struct tunnel_message* message = buf;
- void* cbuf = (void*)(message + 1);
+ void* cbuf = (void*) &message[1];
+ GNUNET_assert(NULL != ncls->notify);
- size_t sent = tunnel->notify(tunnel->notify_cls, size - sizeof(struct tunnel_message), cbuf);
+ size_t sent = ncls->notify(ncls->notify_cls, size - sizeof(struct tunnel_message), cbuf);
- tunnel->notify = NULL;
- tunnel->notify_cls = NULL;
+ GNUNET_free(ncls);
+
+ if (0 == sent) return 0;
sent += sizeof(struct tunnel_message);
GNUNET_CONNECTION_TransmitReadyNotify
notify, void *notify_cls)
{
- tunnel->notify_cls = notify_cls;
- tunnel->notify = notify;
+ struct notify_cls *cls = GNUNET_malloc(sizeof(struct notify_cls));
+ cls->notify_cls = notify_cls;
+ GNUNET_assert(NULL != notify);
+ cls->notify = notify;
+ cls->tunnel = tunnel;
GNUNET_CORE_notify_transmit_ready(tunnel->handle->core,
priority,
maxdelay,
&tunnel->peer,
notify_size + sizeof(struct tunnel_message),
- core_notify,
- (void*)tunnel);
+ &core_notify,
+ (void*)cls);
/* aborting is not implemented yet */
- return (struct GNUNET_MESH_TransmitHandle*)1;
+ return (struct GNUNET_MESH_TransmitHandle*) 1;
}
ret->connected_peers.tail = NULL;
ret->cleaner = cleaner;
ret->cls = cls;
-
+
const struct GNUNET_MESH_MessageHandler *it;
unsigned int len = 1;
for (it = handlers; it->callback != NULL; it++)
ret->handlers =
GNUNET_malloc (len * sizeof (struct GNUNET_MESH_MessageHandler));
+ memset(ret->handlers, 0, len * sizeof(struct GNUNET_MESH_MessageHandler));
memcpy (ret->handlers, handlers,
len * sizeof (struct GNUNET_MESH_MessageHandler));
const static struct GNUNET_CORE_MessageHandler core_handlers[] = {
- {core_receive, GNUNET_MESSAGE_TYPE_MESH, 0},
+ {&core_receive, GNUNET_MESSAGE_TYPE_MESH, 0},
{NULL, 0, 0}
};
ret->core = GNUNET_CORE_connect (cfg,
42,
ret,
- core_startup,
- core_connect,
- core_disconnect,
+ &core_startup,
+ &core_connect,
+ &core_disconnect,
NULL,
NULL,
GNUNET_NO, NULL, GNUNET_NO, core_handlers);
GNUNET_free (handle);
}
-/* end of core_api.c */
+/* end of mesh_api.c */