#include <gnunet_constants.h>
#include <gnunet_mesh_service.h>
#include <gnunet_core_service.h>
+#include <gnunet_transport_service.h>
#include <gnunet_container_lib.h>
#include <gnunet_applications.h>
+#define LOG(kind,...) GNUNET_log_from (kind, "mesh-api",__VA_ARGS__)
+
struct tunnel_id
{
uint32_t id GNUNET_PACKED;
/* list of application-types */
struct type_list_element *type_head, *type_tail;
- struct GNUNET_TRANSPORT_ATS_Information atsi;
struct peer_list_element *next, *prev;
/* The handle that sends the hellos to this peer */
struct GNUNET_MESH_Handle
{
struct GNUNET_CORE_Handle *core;
+ struct GNUNET_TRANSPORT_Handle *transport;
struct GNUNET_MESH_MessageHandler *handlers;
struct GNUNET_PeerIdentity myself;
unsigned int connected_to_core;
struct GNUNET_MESH_Tunnel *tunnel = cls;
- tunnel->connect_handler (tunnel->handler_cls, NULL, NULL);
+ tunnel->connect_handler (tunnel->handler_cls, NULL, NULL, 0);
}
static void
struct GNUNET_MESH_Tunnel *tunnel = cls;
- tunnel->connect_handler (tunnel->handler_cls, &tunnel->handle->myself, NULL);
+ tunnel->connect_handler (tunnel->handler_cls, &tunnel->handle->myself, NULL, 0);
GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
}
struct GNUNET_MESH_Tunnel *tunnel = cls;
- tunnel->connect_handler (tunnel->handler_cls, &tunnel->peer, NULL);
+ tunnel->connect_handler (tunnel->handler_cls, &tunnel->peer, NULL, 0);
GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
}
static void
core_startup (void *cls, struct GNUNET_CORE_Handle *core
__attribute__ ((unused)),
- const struct GNUNET_PeerIdentity *my_identity,
- const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey
- __attribute__ ((unused)))
+ const struct GNUNET_PeerIdentity *my_identity)
{
struct GNUNET_MESH_Handle *handle = cls;
if (cls == NULL)
return 0;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending hello\n");
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Sending hello\n");
struct peer_list_element *element = cls;
struct GNUNET_MESH_Handle *handle = element->handle;
+
element->hello = NULL;
struct GNUNET_MessageHeader *hdr = buf;
return sent;
}
-void schedule_hello_message(void* cls, const struct GNUNET_SCHEDULER_TaskContext* tctx)
+void
+schedule_hello_message (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tctx)
{
struct peer_list_element *element = cls;
+
element->sched = GNUNET_SCHEDULER_NO_TASK;
if ((tctx->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
- return;
+ return;
if (element->hello == NULL)
- element->hello = GNUNET_CORE_notify_transmit_ready (element->handle->core, GNUNET_NO, 42,
- GNUNET_TIME_UNIT_SECONDS, &element->peer,
- sizeof (struct GNUNET_MessageHeader) +
- element->handle->hello_message_size,
- &send_hello_message, element);
-
- element->sched = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_MINUTES, schedule_hello_message, cls);
+ element->hello =
+ GNUNET_CORE_notify_transmit_ready (element->handle->core, GNUNET_NO, 42,
+ GNUNET_TIME_UNIT_SECONDS,
+ &element->peer,
+ sizeof (struct GNUNET_MessageHeader)
+ +
+ element->handle->hello_message_size,
+ &send_hello_message, element);
+
+ element->sched =
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES,
+ schedule_hello_message, cls);
}
*/
static void
core_connect (void *cls, const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
struct GNUNET_MESH_Handle *handle = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core tells us we are connected to peer %s\n", GNUNET_i2s (peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Core tells us we are connected to peer %s\n",
+ GNUNET_i2s (peer));
/* put the new peer into the list of connected peers */
struct peer_list_element *element =
element->handle = handle;
/* Send a hello to this peer */
- element->sched = GNUNET_SCHEDULER_add_now(schedule_hello_message, element);
-
- if (NULL != atsi)
- memcpy (&element->atsi, atsi,
- sizeof (struct GNUNET_TRANSPORT_ATS_Information));
-
+ element->sched = GNUNET_SCHEDULER_add_now (schedule_hello_message, element);
GNUNET_CONTAINER_DLL_insert_after (handle->connected_peers.head,
handle->connected_peers.tail,
handle->connected_peers.tail, element);
handle->established_tunnels.tail,
handle->established_tunnels.tail,
tunnel);
- tunnel->tunnel.connect_handler (tunnel->tunnel.handler_cls, peer, atsi);
+ tunnel->tunnel.connect_handler (tunnel->tunnel.handler_cls, peer, atsi, atsi_count);
GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
tunnel = next;
}
{
struct GNUNET_MESH_Handle *handle = cls;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Core tells us we are no longer connected to peer %s\n",
- GNUNET_i2s (peer));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Core tells us we are no longer connected to peer %s\n",
+ GNUNET_i2s (peer));
struct peer_list_element *element = handle->connected_peers.head;
tail);
GNUNET_free (tail);
}
- GNUNET_CORE_notify_transmit_ready_cancel(element->hello);
- GNUNET_SCHEDULER_cancel(element->sched);
+ if (element->hello != NULL)
+ GNUNET_CORE_notify_transmit_ready_cancel (element->hello);
+ GNUNET_SCHEDULER_cancel (element->sched);
GNUNET_free (element);
}
static int
receive_hello (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
struct GNUNET_MESH_Handle *handle = cls;
uint16_t *num = (uint16_t *) (message + 1);
(GNUNET_MESH_ApplicationType *) (num + 1);
unsigned int i;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The peer %s tells us he supports %d application-types.\n",
- GNUNET_i2s (other), ntohs (*num));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "The peer %s tells us he supports %d application-types.\n",
+ GNUNET_i2s (other), ntohs (*num));
struct peer_list_element *element = handle->connected_peers.head;
for (i = 0; i < ntohs (*num); i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The peer %s newly supports the application-type %d\n",
- GNUNET_i2s (other), ntohs (ports[i]));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "The peer %s newly supports the application-type %d\n",
+ GNUNET_i2s (other), ntohs (ports[i]));
if (GNUNET_APPLICATION_TYPE_END == ntohs (ports[i]))
continue;
struct type_list_element *new_type = GNUNET_malloc (sizeof *new_type);
for (type = element->type_head; type != NULL; type = type->next)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "The peer %s supports the application-type %d\n",
- GNUNET_i2s (other), type->type);
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "The peer %s supports the application-type %d\n", GNUNET_i2s (other),
+ type->type);
}
struct tunnel_list_element *tunnel = handle->pending_by_type_tunnels.head;
memcpy (&tunnel->tunnel.peer, other,
sizeof (struct GNUNET_PeerIdentity));
tunnel->tunnel.connect_handler (tunnel->tunnel.handler_cls,
- &tunnel->tunnel.peer, atsi);
+ &tunnel->tunnel.peer, atsi, atsi_count);
GNUNET_SCHEDULER_add_now (send_end_connect, tunnel);
break;
}
static int
core_receive (void *cls, const struct GNUNET_PeerIdentity *other,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_TRANSPORT_ATS_Information *atsi)
+ const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
{
struct GNUNET_MESH_Handle *handle = cls;
struct tunnel_message *tmessage = (struct tunnel_message *) message;
/* If no handler was found, drop the message but keep the channel open */
if (handler->callback == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Received message of type %d from peer %s; dropping it.\n",
- ntohs (rmessage->type), GNUNET_i2s (other));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Received message of type %d from peer %s; dropping it.\n",
+ ntohs (rmessage->type), GNUNET_i2s (other));
return GNUNET_OK;
}
/* if no tunnel was found: create a new inbound tunnel */
if (tunnel == NULL)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "New inbound tunnel from peer %s; first message has type %d.\n",
- GNUNET_i2s (other), ntohs (rmessage->type));
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "New inbound tunnel from peer %s; first message has type %d.\n",
+ GNUNET_i2s (other), ntohs (rmessage->type));
tunnel = GNUNET_malloc (sizeof (struct tunnel_list_element));
tunnel->tunnel.connect_handler = NULL;
tunnel->tunnel.disconnect_handler = NULL;
tunnel);
}
else
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Inbound message from peer %s; type %d.\n", GNUNET_i2s (other),
- ntohs (rmessage->type));
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Inbound message from peer %s; type %d.\n",
+ GNUNET_i2s (other), ntohs (rmessage->type));
return handler->callback (handle->cls, &tunnel->tunnel, &tunnel->tunnel.ctx,
- other, rmessage, atsi);
+ other, rmessage, atsi, atsi_count);
}
struct GNUNET_MESH_Tunnel *
element = element->next;
}
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect by tupe %d.\n",
- application_type);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Trying to connect by tupe %d.\n",
+ application_type);
/* Put into pending list */
struct tunnel_list_element *tunnel =
GNUNET_CONTAINER_DLL_insert_after (handle->pending_tunnels.head,
handle->pending_tunnels.tail,
handle->pending_tunnels.tail, tunnel);
- (void) GNUNET_CORE_peer_request_connect (handle->core, peers, NULL, NULL);
+ GNUNET_TRANSPORT_try_connect (handle->transport, peers);
}
return &tunnel->tunnel;
{
struct notify_cls *ncls = cls;
struct GNUNET_MESH_Tunnel *tunnel = ncls->tunnel;
-
tunnel->notify_handle = NULL;
+
+ if (NULL == buf)
+ return ncls->notify (ncls->notify_cls, 0, NULL);
+
struct tunnel_message *message = buf;
void *cbuf = (void *) &message[1];
for (t = stypes; *t != GNUNET_APPLICATION_TYPE_END; t++, num++) ;
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I can handle %d app-types.\n", num);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "I can handle %d app-types.\n", num);
handle->hello_message_size = sizeof (uint16_t) + /* For the number of types */
num * sizeof (GNUNET_MESH_ApplicationType); /* For the types */
for (i = 0; i < num; i++)
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I can handle the app-type %d\n",
- stypes[i]);
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "I can handle the app-type %d\n", stypes[i]);
types[i] = htons (stypes[i]);
}
ret->core =
GNUNET_CORE_connect (cfg, 42, ret, &core_startup, &core_connect,
- &core_disconnect, NULL, NULL, GNUNET_NO, NULL,
- GNUNET_NO, core_handlers);
+ &core_disconnect, NULL, GNUNET_NO, NULL, GNUNET_NO,
+ core_handlers);
+ ret->transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL);
return ret;
}
GNUNET_free (handle->handlers);
GNUNET_free (handle->hello_message);
GNUNET_CORE_disconnect (handle->core);
+ GNUNET_TRANSPORT_disconnect (handle->transport);
struct peer_list_element *element = handle->connected_peers.head;
tail);
GNUNET_free (tail);
}
- GNUNET_CORE_notify_transmit_ready_cancel(element->hello);
- GNUNET_SCHEDULER_cancel(element->sched);
+ GNUNET_CORE_notify_transmit_ready_cancel (element->hello);
+ GNUNET_SCHEDULER_cancel (element->sched);
GNUNET_free (element);
element = next;
}