/**
* All the states a peer participating in a tunnel can be in.
*/
-enum PeerState
+enum MeshPeerState
{
/**
* Path to the peer not known yet
/**
* Struct containing all information regarding a given peer
*/
-struct PeerInfo
+struct MeshPeerInfo
{
/**
* Double linked list
*/
- struct PeerInfo *next;
- struct PeerInfo *prev;
+ struct MeshPeerInfo *next;
+ struct MeshPeerInfo *prev;
/**
* ID of the peer
/**
* Is the peer reachable? Is the peer even connected?
*/
- enum PeerState state;
+ enum MeshPeerState state;
/**
* When to try to establish contact again?
/**
* Information regarding a path
*/
-struct Path
+struct MeshPath
{
/**
* Double linked list
*/
- struct Path *next;
- struct Path *prev;
+ struct MeshPath *next;
+ struct MeshPath *prev;
/**
* Id of the path, in case it's needed
/**
* Data scheduled to transmit (to local client or remote peer)
*/
-struct MESH_queue
+struct MeshQueue
{
/**
* Double linked list
*/
- struct MESH_queue *next;
- struct MESH_queue *prev;
+ struct MeshQueue *next;
+ struct MeshQueue *prev;
/**
* Size of the message to transmit
};
-struct Client; /* FWD declaration */
+struct MeshClient; /* FWD declaration */
/**
* Struct containing all information regarding a tunnel
* For an intermediate node the improtant info used will be:
/**
* Peers in the tunnel, for future optimizations
*/
- struct PeerInfo *peers_head;
- struct PeerInfo *peers_tail;
+ struct MeshPeerInfo *peers_head;
+ struct MeshPeerInfo *peers_tail;
/**
* Number of peers that are connected and potentially ready to receive data
/**
* Paths (used and backup)
*/
- struct Path *paths_head;
- struct Path *paths_tail;
+ struct MeshPath *paths_head;
+ struct MeshPath *paths_tail;
/**
* If this tunnel was created by a local client, what's its handle?
*/
- struct Client *client;
+ struct MeshClient *client;
/**
* Messages ready to transmit
*/
- struct MESH_queue *out_head;
- struct MESH_queue *out_tail;
+ struct MeshQueue *out_head;
+ struct MeshQueue *out_tail;
/**
* Messages received and not processed
*/
- struct MESH_queue *in_head;
- struct MESH_queue *in_tail;
+ struct MeshQueue *in_head;
+ struct MeshQueue *in_tail;
};
/**
* Struct containing information about a client of the service
*/
-struct Client
+struct MeshClient
{
/**
* Double linked list
*/
- struct Client *next;
- struct Client *prev;
+ struct MeshClient *next;
+ struct MeshClient *prev;
/**
* Tunnels that belong to this client, for convenience on disconnect
/**
* All the clients
*/
-static struct Client *clients_head;
-static struct Client *clients_tail;
+static struct MeshClient *clients_head;
+static struct MeshClient *clients_tail;
/**
* Tunnels not owned by this node
* @param client the client to check
* @return non-NULL if client exists in the global DLL
*/
-static struct Client *
-retrieve_client (struct GNUNET_SERVER_Client *client) {
- struct Client *c;
+static struct MeshClient *
+retrieve_client (struct GNUNET_SERVER_Client *client)
+{
+ struct MeshClient *c;
+
c = clients_head;
- while(NULL != c) {
- if(c->handle == client) return c;
+ while (NULL != c) {
+ if (c->handle == client) return c;
c = c->next;
}
return NULL;
* @return GNUNET_OK on success
*/
static int
-destroy_path(struct MESH_tunnel *t, struct Path *p) {
+destroy_path(struct MESH_tunnel *t, struct MeshPath *p)
+{
GNUNET_PEER_decrement_rcs(p->peers, p->length);
GNUNET_free(p->peers);
GNUNET_CONTAINER_DLL_remove(t->paths_head, t->paths_tail, p);
* @return GNUNET_OK on success
*/
static int
-destroy_peer_info(struct MESH_tunnel *t, struct PeerInfo *pi) {
+destroy_peer_info(struct MESH_tunnel *t, struct MeshPeerInfo *pi)
+{
GNUNET_PEER_change_rc(pi->id, -1);
GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi);
GNUNET_free(pi);
* @return GNUNET_OK on success
*/
static int
-destroy_tunnel(struct Client *c, struct MESH_tunnel *t) {
- struct PeerInfo *pi;
- struct Path *path;
+destroy_tunnel(struct MeshClient *c, struct MESH_tunnel *t)
+{
+ struct MeshPeerInfo *pi;
+ struct MeshPath *path;
- for(pi = t->peers_head; pi != NULL; pi = t->peers_head) {
+ for (pi = t->peers_head; pi != NULL; pi = t->peers_head) {
destroy_peer_info(t, pi);
}
- for(path = t->paths_head; path != NULL; path = t->paths_head) {
+ for (path = t->paths_head; path != NULL; path = t->paths_head) {
destroy_path(t, path);
}
* @return number of bytes written to buf
*/
static size_t
-send_core_create_path_for_peer (void *cls, size_t size, void *buf) {
+send_core_create_path_for_peer (void *cls, size_t size, void *buf)
+{
size_t size_needed;
- struct PeerInfo *peer_info;
+ struct MeshPeerInfo *peer_info;
struct GNUNET_MESH_ManipulatePath *msg;
- struct Path *p;
+ struct MeshPath *p;
struct GNUNET_PeerIdentity peer_id;
struct GNUNET_PeerIdentity *peer_ptr;
int i;
- if(0 == size && NULL == buf) {
+ if (0 == size && NULL == buf) {
// TODO retry? cancel?
return 0;
}
- peer_info = (struct PeerInfo *)cls;
+ peer_info = (struct MeshPeerInfo *)cls;
peer_info->dhtget = NULL;
p = peer_info->t->paths_head;
- while(NULL != p) {
- if(p->peers[p->length-1] == peer_info->id) {
+ while (NULL != p) {
+ if (p->peers[p->length-1] == peer_info->id) {
break;
}
p = p->next;
}
- if(p == NULL) return 0; // TODO Notify ERROR Path not found
+ if (p == NULL) return 0; // TODO Notify ERROR Path not found
size_needed = sizeof(struct GNUNET_MESH_ManipulatePath)
+ p->length * sizeof(struct GNUNET_PeerIdentity);
- if(size < size_needed) {
+ if (size < size_needed) {
// TODO retry? cancel?
return 0;
}
msg->speed_min = 0;
peer_ptr = (struct GNUNET_PeerIdentity *) &msg[1];
- for(i = 0; i < p->length; i++) {
+ for (i = 0; i < p->length; i++) {
GNUNET_PEER_resolve(p->peers[i], &peer_id);
memcpy(&peer_ptr[i], &peer_id, sizeof(struct GNUNET_PeerIdentity));
}
return GNUNET_OK;
}
+
/**
* Core handler for mesh network traffic
*
const struct GNUNET_TRANSPORT_ATS_Information
*atsi)
{
- if(GNUNET_MESSAGE_TYPE_MESH_DATA_GO == ntohs(message->type)) {
+ if (GNUNET_MESSAGE_TYPE_MESH_DATA_GO == ntohs(message->type)) {
/* Retransmit to next in path of tunnel identified by message */
return GNUNET_OK;
} else { /* GNUNET_MESSAGE_TYPE_MESH_DATA_BACK */
}
}
+
/**
* Functions to handle messages from core
*/
* @return number of bytes written to buf
*/
static size_t
-notify_client_connection_failure (void *cls, size_t size, void *buf) {
+notify_client_connection_failure (void *cls, size_t size, void *buf)
+{
int size_needed;
- struct PeerInfo *peer_info;
+ struct MeshPeerInfo *peer_info;
struct GNUNET_MESH_PeerControl *msg;
struct GNUNET_PeerIdentity id;
- if(0 == size && NULL == buf) {
+ if (0 == size && NULL == buf) {
// TODO retry? cancel?
return 0;
}
size_needed = sizeof(struct GNUNET_MESH_PeerControl);
- peer_info = (struct PeerInfo *) cls;
+ peer_info = (struct MeshPeerInfo *) cls;
msg = (struct GNUNET_MESH_PeerControl *) buf;
msg->header.size = htons(sizeof(struct GNUNET_MESH_PeerControl));
msg->header.type = htons(GNUNET_MESSAGE_TYPE_MESH_LOCAL_PEER_DISCONNECTED);
size_t size,
const void *data)
{
- struct PeerInfo *peer_info;
+ struct MeshPeerInfo *peer_info;
struct MESH_tunnel *t;
- struct Path *p;
+ struct MeshPath *p;
int i;
- peer_info = (struct PeerInfo *)cls;
+ peer_info = (struct MeshPeerInfo *)cls;
t = peer_info->t;
- if(NULL == get_path || NULL == put_path) {
+ if (NULL == get_path || NULL == put_path) {
// TODO: find ourselves some alternate initial path to the destination
GNUNET_SERVER_notify_transmit_ready(
t->client->handle,
);
}
- p = GNUNET_malloc(sizeof(struct Path));
+ p = GNUNET_malloc(sizeof(struct MeshPath));
GNUNET_CONTAINER_DLL_insert(t->paths_head, t->paths_tail, p);
- for(i = 0; get_path[i] != NULL; i++);
- for(i--; i >= 0; i--) {
+ for (i = 0; get_path[i] != NULL; i++);
+ for (i--; i >= 0; i--) {
p->peers = GNUNET_realloc(p->peers,
sizeof(GNUNET_PEER_Id) * (p->length + 1));
p->peers[p->length] = GNUNET_PEER_intern(get_path[i]);
p->length++;
}
- for(i = 0; put_path[i] != NULL; i++);
- for(i--; i >= 0; i--) {
+ for (i = 0; put_path[i] != NULL; i++);
+ for (i--; i >= 0; i--) {
p->peers = GNUNET_realloc(p->peers,
sizeof(GNUNET_PEER_Id) * (p->length + 1));
p->peers[p->length] = GNUNET_PEER_intern(put_path[i]);
return;
}
+
/**
* Handler for client disconnection
*
static void
handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
{
- struct Client *c, *next;
+ struct MeshClient *c, *next;
struct MESH_tunnel *t;
c = clients_head;
- while(NULL != c) {
+ while (NULL != c) {
if (c->handle == client) {
GNUNET_CONTAINER_DLL_remove (clients_head, clients_tail, c);
while (NULL != (t = c->tunnels_head)) {
return;
}
+
/**
* Handler for new clients
*
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct Client *c;
+ struct MeshClient *c;
unsigned int payload_size;
/* Check data sanity */
}
/* Create new client structure */
- c = GNUNET_malloc(sizeof(struct Client));
+ c = GNUNET_malloc(sizeof(struct MeshClient));
c->handle = client;
- if(payload_size != 0) {
+ if (payload_size != 0) {
c->messages_subscribed = GNUNET_malloc(payload_size);
memcpy(c->messages_subscribed, &message[1], payload_size);
} else {
}
+
/**
* Handler for requests of new tunnels
*
{
struct GNUNET_MESH_TunnelMessage *tunnel_msg;
struct MESH_tunnel *t;
- struct Client *c;
+ struct MeshClient *c;
/* Sanity check for client registration */
- if(NULL == (c = retrieve_client(client))) {
+ if (NULL == (c = retrieve_client(client))) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
/* Message sanity check */
- if(sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) {
+ if (sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
/* Sanity check for tunnel numbering */
- if(0 == (ntohl(tunnel_msg->tunnel_id) & 0x80000000)) {
+ if (0 == (ntohl(tunnel_msg->tunnel_id) & 0x80000000)) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
/* Sanity check for duplicate tunnel IDs */
t = c->tunnels_head;
- while(NULL != t) {
- if(t->tid == ntohl(tunnel_msg->tunnel_id)) {
+ while (NULL != t) {
+ if (t->tid == ntohl(tunnel_msg->tunnel_id)) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
return;
}
+
/**
* Handler for requests of deleting tunnels
*
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_TunnelMessage *tunnel_msg;
- struct Client *c;
+ struct MeshClient *c;
struct MESH_tunnel *t;
MESH_TunnelID tid;
/* Sanity check for client registration */
- if(NULL == (c = retrieve_client(client))) {
+ if (NULL == (c = retrieve_client(client))) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
/* Message sanity check */
- if(sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) {
+ if (sizeof(struct GNUNET_MESH_TunnelMessage) != ntohs(message->size)) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
/* Tunnel exists? */
tid = ntohl(tunnel_msg->tunnel_id);
- if(NULL == (t = c->tunnels_head)) {
+ if (NULL == (t = c->tunnels_head)) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
- while(NULL != t) {
- if(t->tid == tid) {
+ while (NULL != t) {
+ if (t->tid == tid) {
break;
}
- if(t == c->tunnels_tail) {
+ if (t == c->tunnels_tail) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
return;
}
+
/**
* Handler for connection requests to new peers
*
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_PeerControl *peer_msg;
- struct Client *c;
+ struct MeshClient *c;
struct MESH_tunnel *t;
MESH_TunnelID tid;
- struct PeerInfo *peer_info;
-
+ struct MeshPeerInfo *peer_info;
GNUNET_HashCode key;
/* Sanity check for client registration */
- if(NULL == (c = retrieve_client(client))) {
+ if (NULL == (c = retrieve_client(client))) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
peer_msg = (struct GNUNET_MESH_PeerControl *)message;
/* Sanity check for message size */
- if(sizeof(struct GNUNET_MESH_PeerControl) != ntohs(peer_msg->header.size)) {
+ if (sizeof(struct GNUNET_MESH_PeerControl) != ntohs(peer_msg->header.size)) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
/* Tunnel exists? */
tid = ntohl(peer_msg->tunnel_id);
t = c->tunnels_head;
- while(NULL != t) {
- if(t->tid == tid) {
+ while (NULL != t) {
+ if (t->tid == tid) {
break;
}
t = t->next;
}
- if(NULL == t) {
+ if (NULL == t) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
/* Does client own tunnel? */
- if(t->client->handle != client) {
+ if (t->client->handle != client) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
/* Ok, add peer to tunnel */
- peer_info = (struct PeerInfo *) GNUNET_malloc(sizeof(struct PeerInfo));
+ peer_info = (struct MeshPeerInfo *) GNUNET_malloc(sizeof(struct MeshPeerInfo));
peer_info->id = GNUNET_PEER_intern(&peer_msg->peer);
peer_info->state = MESH_PEER_SEARCHING;
peer_info->t = t;
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_PeerControl *peer_msg;
- struct Client *c;
+ struct MeshClient *c;
struct MESH_tunnel *t;
- struct Path *p;
- struct Path *aux_path;
+ struct MeshPath *p;
+ struct MeshPath *aux_path;
MESH_TunnelID tid;
GNUNET_PEER_Id peer_id;
- struct PeerInfo *peer_info;
- struct PeerInfo *aux_peer_info;
+ struct MeshPeerInfo *peer_info;
+ struct MeshPeerInfo *aux_peer_info;
/* Sanity check for client registration */
- if(NULL == (c = retrieve_client(client))) {
+ if (NULL == (c = retrieve_client(client))) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
peer_msg = (struct GNUNET_MESH_PeerControl *)message;
/* Sanity check for message size */
- if(sizeof(struct GNUNET_MESH_PeerControl) != ntohs(peer_msg->header.size)) {
+ if (sizeof(struct GNUNET_MESH_PeerControl) != ntohs(peer_msg->header.size)) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
/* Tunnel exists? */
tid = ntohl(peer_msg->tunnel_id);
- if(NULL == (t = c->tunnels_head)) {
+ if (NULL == (t = c->tunnels_head)) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
- while(NULL != t) {
- if(t->tid == tid) {
+ while (NULL != t) {
+ if (t->tid == tid) {
break;
}
- if(t == c->tunnels_tail) {
+ if (t == c->tunnels_tail) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
t = t->next;
}
- if(NULL == t) {
+ if (NULL == t) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
/* Does client own tunnel? */
- if(t->client->handle != client) {
+ if (t->client->handle != client) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
/* Delete paths */
p = t->paths_head;
- while(p != NULL) {
- if(p->peers[p->length-1] == peer_id) { /* one path per destination */
+ while (p != NULL) {
+ if (p->peers[p->length-1] == peer_id) { /* one path per destination */
GNUNET_CONTAINER_DLL_remove(t->paths_head, t->paths_tail, p);
GNUNET_PEER_decrement_rcs(p->peers, p->length);
aux_path = p;
/*Delete peer info */
peer_info = t->peers_head;
- while(peer_info != NULL) {
- if(peer_info->id == peer_id) {
+ while (peer_info != NULL) {
+ if (peer_info->id == peer_id) {
GNUNET_CONTAINER_DLL_remove(t->peers_head,
t->peers_tail,
peer_info);
struct GNUNET_MESH_ConnectPeerByType *connect_msg;
MESH_TunnelID tid;
GNUNET_MESH_ApplicationType application;
- struct Client *c;
+ struct MeshClient *c;
struct MESH_tunnel *t;
/* Sanity check for client registration */
- if(NULL == (c = retrieve_client(client))) {
+ if (NULL == (c = retrieve_client(client))) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
connect_msg = (struct GNUNET_MESH_ConnectPeerByType *)message;
/* Sanity check for message size */
- if(sizeof(struct GNUNET_MESH_PeerControl) != ntohs(connect_msg->header.size)) {
+ if (sizeof(struct GNUNET_MESH_PeerControl) !=
+ ntohs(connect_msg->header.size))
+ {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
/* Tunnel exists? */
tid = ntohl(connect_msg->tunnel_id);
t = c->tunnels_head;
- while(NULL != t) {
- if(t->tid == tid) {
+ while (NULL != t) {
+ if (t->tid == tid) {
break;
}
t = t->next;
}
- if(NULL == t) {
+ if (NULL == t) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
/* Does client own tunnel? */
- if(t->client->handle != client) {
+ if (t->client->handle != client) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct Client *c;
+ struct MeshClient *c;
struct MESH_tunnel *t;
struct GNUNET_MESH_Data *data_msg;
MESH_TunnelID tid;
/* Sanity check for client registration */
- if(NULL == (c = retrieve_client(client))) {
+ if (NULL == (c = retrieve_client(client))) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
data_msg = (struct GNUNET_MESH_Data *)message;
/* Sanity check for message size */
- if(sizeof(struct GNUNET_MESH_PeerControl) != ntohs(data_msg->header.size)) {
+ if (sizeof(struct GNUNET_MESH_PeerControl) !=
+ ntohs(data_msg->header.size))
+ {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
/* Tunnel exists? */
tid = ntohl(data_msg->tunnel_id);
t = c->tunnels_head;
- while(NULL != t) {
- if(t->tid == tid) {
+ while (NULL != t) {
+ if (t->tid == tid) {
break;
}
t = t->next;
}
- if(NULL == t) {
+ if (NULL == t) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
/* Does client own tunnel? */
- if(t->client->handle != client) {
+ if (t->client->handle != client) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
struct GNUNET_SERVER_Client *client,
const struct GNUNET_MessageHeader *message)
{
- struct Client *c;
+ struct MeshClient *c;
struct MESH_tunnel *t;
struct GNUNET_MESH_DataBroadcast *data_msg;
MESH_TunnelID tid;
/* Sanity check for client registration */
- if(NULL == (c = retrieve_client(client))) {
+ if (NULL == (c = retrieve_client(client))) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
data_msg = (struct GNUNET_MESH_DataBroadcast *)message;
/* Sanity check for message size */
- if(sizeof(struct GNUNET_MESH_PeerControl) != ntohs(data_msg->header.size)) {
+ if (sizeof(struct GNUNET_MESH_PeerControl) != ntohs(data_msg->header.size)) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
/* Tunnel exists? */
tid = ntohl(data_msg->tunnel_id);
t = c->tunnels_head;
- while(NULL != t) {
- if(t->tid == tid) {
+ while (NULL != t) {
+ if (t->tid == tid) {
break;
}
t = t->next;
}
- if(NULL == t) {
+ if (NULL == t) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
/* Does client own tunnel? */
- if(t->client->handle != client) {
+ if (t->client->handle != client) {
GNUNET_break(0);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
const struct GNUNET_PeerIdentity *identity,
const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Core init\n");
core_handle = server;
myid = GNUNET_PEER_intern(identity);
return;
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_TRANSPORT_ATS_Information *atsi)
{
+ GNUNET_PEER_Id pid;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer connected\n");
+ pid = GNUNET_PEER_intern(peer);
+ if (myid == pid) {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ " (self)\n");
+ }
return;
}
const struct
GNUNET_PeerIdentity *peer)
{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Peer disconnected\n");
return;
}
static void
shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
{
- if (core_handle != NULL)
- {
- GNUNET_CORE_disconnect (core_handle);
- core_handle = NULL;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MESH shutting down\n");
+ if (core_handle != NULL) {
+ GNUNET_CORE_disconnect (core_handle);
+ core_handle = NULL;
}
- if (dht_handle != NULL)
- {
- GNUNET_DHT_disconnect (dht_handle);
- dht_handle = NULL;
+ if (dht_handle != NULL) {
+ GNUNET_DHT_disconnect (dht_handle);
+ dht_handle = NULL;
}
}
struct GNUNET_SERVER_Handle *server,
const struct GNUNET_CONFIGURATION_Handle *c)
{
-GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 3 ********\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "MESH starting to run\n");
GNUNET_SERVER_add_handlers (server, plugin_handlers);
GNUNET_SERVER_disconnect_notify (server, &handle_client_disconnect, NULL);
core_handle = GNUNET_CORE_connect (c, /* Main configuration */
NULL, /* Don't notify about all outbound messages */
GNUNET_NO, /* For header-only out notification */
core_handlers); /* Register these handlers */
-GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 4 ********\n");
if (core_handle == NULL) {
GNUNET_break(0);
}
GNUNET_break(0);
}
- /* Scheduled the task to clean up when shutdown is called */
+ /* Scheduled the task to clean up when shutdown is called */
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
- &shutdown_task, NULL);
+ &shutdown_task, NULL);
}
main (int argc, char *const *argv)
{
int ret;
-GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 1 ********\n");
+
ret = (GNUNET_OK ==
GNUNET_SERVICE_run (argc,
argv,
"mesh",
GNUNET_SERVICE_OPTION_NONE,
&run, NULL)) ? 0 : 1;
-GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "******* MESH DEBUG MESSAGE 2 ********\n");
return ret;
}
/**
* Handle to the server connection, to send messages later
*/
- struct GNUNET_CLIENT_Connection *mesh;
+ struct GNUNET_CLIENT_Connection *client;
/**
* Set of handlers used for processing incoming messages in the tunnels
*/
GNUNET_MESH_TunnelEndHandler *cleaner;
-
- struct GNUNET_CLIENT_TransmitHandle *th;
+ /**
+ * Handle to cancel pending transmissions in case of disconnection
+ */
+ struct GNUNET_CLIENT_TransmitHandle *th;
/**
* Closure for all the handlers given by the client
h->th = NULL;
if (0 == size || buf == NULL) {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size 0 or buffer invalid\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Send: buffer size 0 or buffer invalid\n");
// FIXME: disconnect, reconnect, retry!
return 0;
}
if (sizeof(struct GNUNET_MessageHeader) > size) {
- GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Send: buffer size too small\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+ "Send: buffer size too small\n");
// FIXME: disconnect, reconnect, retry!
return 0;
}
-
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Sending into %lu bytes buffer\n",
+ size);
msg = (struct GNUNET_MESH_ClientConnect *) buf;
msg->header.type = GNUNET_MESSAGE_TYPE_MESH_LOCAL_CONNECT;
return msg->header.size;
}
+
/**
* Type of a function to call when we receive a message
* from the service.
* @param cls closure
* @param msg message received, NULL on timeout or fatal error
*/
-void msg_received (void *cls,
- const struct
- GNUNET_MessageHeader * msg) {
+void
+msg_received (void *cls, const struct GNUNET_MessageHeader * msg)
+{
uint16_t t;
if(msg != NULL){
t = ntohs(msg->type);
return;
}
+
/**
* Connect to the mesh service.
*
h = GNUNET_malloc(sizeof(struct GNUNET_MESH_Handle));
h->cleaner = cleaner;
- h->mesh = GNUNET_CLIENT_connect("mesh", cfg);
- GNUNET_CLIENT_receive (h->mesh,
+ h->client = GNUNET_CLIENT_connect("mesh", cfg);
+ GNUNET_CLIENT_receive (h->client,
&msg_received,
h,
GNUNET_TIME_UNIT_FOREVER_REL);
- if(h->mesh == NULL) {
+ if(h->client == NULL) {
GNUNET_free(h);
return NULL;
}
size += h->n_handlers * sizeof(uint16_t);
size += h->n_applications * sizeof(GNUNET_MESH_ApplicationType);
- h->th = GNUNET_CLIENT_notify_transmit_ready(h->mesh,
+ h->th = GNUNET_CLIENT_notify_transmit_ready(h->client,
size,
GNUNET_TIME_UNIT_FOREVER_REL,
GNUNET_YES,
void
GNUNET_MESH_disconnect (struct GNUNET_MESH_Handle *handle)
{
- if (NULL != handle->th)
- GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
- if (NULL != handle->mesh)
- GNUNET_CLIENT_disconnect (handle->mesh, GNUNET_NO);
- GNUNET_free(handle);
+ if (NULL != handle->th) {
+ GNUNET_CLIENT_notify_transmit_ready_cancel (handle->th);
+ }
+ if (NULL != handle->client) {
+ GNUNET_CLIENT_disconnect (handle->client, GNUNET_NO);
+ }
+ GNUNET_free(handle);
}
connect_handler,
GNUNET_MESH_TunnelDisconnectHandler
disconnect_handler,
- void *handler_cls) {
+ void *handler_cls)
+{
struct GNUNET_MESH_Tunnel *tunnel;
tunnel = GNUNET_malloc(sizeof(struct GNUNET_MESH_Tunnel));
tunnel->connect_handler = connect_handler;
tunnel->disconnect_handler = disconnect_handler;
- tunnel->peers = NULL;
tunnel->cls = handler_cls;
return tunnel;
void
GNUNET_MESH_peer_request_connect_add (struct GNUNET_MESH_Tunnel *tunnel,
struct GNUNET_TIME_Relative timeout,
- const struct GNUNET_PeerIdentity *peer) {
+ const struct GNUNET_PeerIdentity *peer)
+{
static GNUNET_PEER_Id peer_id;
peer_id = GNUNET_PEER_intern(peer);
*/
void
GNUNET_MESH_peer_request_connect_del (struct GNUNET_MESH_Tunnel *tunnel,
- const struct GNUNET_PeerIdentity *peer) {
+ const struct GNUNET_PeerIdentity *peer)
+{
/* FIXME ACTUALLY DO STUFF */
tunnel->peers = NULL;
tunnel->disconnect_handler(tunnel->cls, peer);
GNUNET_MESH_peer_request_connect_by_type (struct GNUNET_MESH_Tunnel *tunnel,
struct GNUNET_TIME_Relative timeout,
GNUNET_MESH_ApplicationType
- app_type) {
+ app_type)
+{
return;
}
size_t notify_size,
GNUNET_CONNECTION_TransmitReadyNotify
notify,
- void *notify_cls) {
+ void *notify_cls)
+{
struct GNUNET_MESH_TransmitHandle *handle;
handle = GNUNET_malloc(sizeof(struct GNUNET_MESH_TransmitHandle));