* STRUCTURE:
* - DATA STRUCTURES
* - GLOBAL VARIABLES
+ * - MESH NETWORK HANDLER HELPERS
* - MESH NETWORK HANDLES
+ * - MESH LOCAL HANDLER HELPERS
* - MESH LOCAL HANDLES
* - MAIN FUNCTIONS (main & run)
*
};
-typedef uint32_t MESH_PathID;
-
-
/**
* Information regarding a path
*/
struct MeshPath *next;
struct MeshPath *prev;
- /**
- * Id of the path, in case it's needed
- */
- MESH_PathID id;
-
/**
* Whether the path is serving traffic in a tunnel or is a backup
*/
static GNUNET_PEER_Id myid;
/**
- * Tunnel ID for the next created tunnel
+ * Tunnel ID for the next created tunnel (global tunnel number)
*/
static MESH_TunnelNumber next_tid;
return NULL;
}
+
/**
* Search for a tunnel among the tunnels for a client
* @param client the client whose tunnels to search in
return GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash);
}
-#if LATER
/**
- * Search for a tunnel by global ID
+ * Search for a tunnel by global ID using PEER_ID
+ * @param pi owner of the tunnel
+ * @param tid global tunnel number
+ * @return tunnel handler, NULL if doesn't exist
*/
static struct MeshTunnel *
-retrieve_tunnel (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid)
+retrieve_tunnel_by_pi (GNUNET_PEER_Id pi, MESH_TunnelNumber tid)
{
struct MESH_TunnelID id;
GNUNET_HashCode hash;
- id.oid = GNUNET_PEER_intern(oid);
- GNUNET_PEER_change_rc(id.oid, -1);
+ id.oid = pi;
id.tid = tid;
GNUNET_CRYPTO_hash(&id, sizeof(struct MESH_TunnelID), &hash);
return GNUNET_CONTAINER_multihashmap_get(tunnels, &hash);
}
+
+
+#if LATER
+/**
+ * Search for a tunnel by global ID using full PeerIdentities
+ * @param oid owner of the tunnel
+ * @param tid global tunnel number
+ * @return tunnel handler, NULL if doesn't exist
+ */
+static struct MeshTunnel *
+retrieve_tunnel (struct GNUNET_PeerIdentity *oid, MESH_TunnelNumber tid)
+{
+ GNUNET_PEER_Id pi;
+
+ pi = GNUNET_PEER_intern(oid);
+ GNUNET_PEER_change_rc(pi, -1);
+ return retrieve_tunnel_by_pi(pi, tid);
+}
#endif
+
/**
* Destroy the path and free any allocated resources linked to it
* @param t tunnel the path belongs to
* @param pi the peer_info to destroy
* @return GNUNET_OK on success
*/
-static int
-destroy_peer_info(struct MeshTunnel *t, struct MeshPeerInfo *pi)
-{
- GNUNET_PEER_change_rc(pi->id, -1);
- /* FIXME delete from list */
- GNUNET_free(pi);
- return GNUNET_OK;
-}
+// static int
+// destroy_peer_info(struct MeshTunnel *t, struct MeshPeerInfo *pi)
+// {
+// GNUNET_PEER_change_rc(pi->id, -1);
+// /* FIXME delete from list */
+// GNUNET_free(pi);
+// return GNUNET_OK;
+// }
#endif
+
/**
* Destroy the tunnel and free any allocated resources linked to it
* @param c client the tunnel belongs to
}
/******************************************************************************/
-/******************** MESH NETWORK HANDLERS **************************/
+/**************** MESH NETWORK HANDLER HELPERS ***********************/
/******************************************************************************/
/**
peer_info = (struct MeshPeerInfo *)cls;
peer_info->dhtget = NULL;
// p = peer_info->t->paths_head;
+ p = NULL;
while (NULL != p) {
if (p->peers[p->length-1] == peer_info->id) {
break;
}
+/******************************************************************************/
+/******************** MESH NETWORK HANDLERS **************************/
+/******************************************************************************/
+
+
/**
* Core handler for path creation
* struct GNUNET_CORE_MessageHandler
/******************************************************************************/
-/********************* MESH LOCAL HANDLES **************************/
+/**************** MESH LOCAL HANDLER HELPERS ***********************/
/******************************************************************************/
static int
}
+/******************************************************************************/
+/********************* MESH LOCAL HANDLES **************************/
+/******************************************************************************/
+
+
/**
* Handler for client disconnection
*
{
struct GNUNET_MESH_ClientConnect *cc_msg;
struct MeshClient *c;
- unsigned int payload_size;
+ unsigned int size;
uint16_t types;
uint16_t apps;
- GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
- "MESH: new client connected\n");
+ GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "MESH: new client connected\n");
/* Check data sanity */
- payload_size = ntohs(message->size)
- - sizeof(struct GNUNET_MESH_ClientConnect);
+ size = ntohs(message->size) - sizeof(struct GNUNET_MESH_ClientConnect);
cc_msg = (struct GNUNET_MESH_ClientConnect *) message;
types = ntohs(cc_msg->types);
apps = ntohs(cc_msg->applications);
- if (payload_size !=
+ if (size !=
types * sizeof(uint16_t) + apps * sizeof(GNUNET_MESH_ApplicationType))
{
GNUNET_break(0);
c->type_counter,
c->app_counter);
- /* Insert new client in DLL */
- /* FIXME insert client */
- c->tunnels = GNUNET_CONTAINER_multihashmap_create(100);
+ c->next = clients;
+ clients = c;
+ c->tunnels = GNUNET_CONTAINER_multihashmap_create(32);
GNUNET_SERVER_receive_done(client, GNUNET_OK);
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
- t = GNUNET_malloc(sizeof(struct MeshTunnel ));
- // FIXME:what if all 2^32 ID are taken?
- while (NULL != retrieve_tunnel_by_local_id(c, next_tid)) next_tid++;
+
+ t = GNUNET_malloc(sizeof(struct MeshTunnel));
+ // FIXME: what if all 2^32 ID are taken?
+ while (NULL != retrieve_tunnel_by_pi(myid, next_tid)) next_tid++;
t->id.tid = next_tid++;
t->id.oid = myid;
t->local_tid = ntohl(t_msg->tunnel_id);
return;
}
- /* FIXME insert */
+ GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash);
+ if (GNUNET_OK !=
+ GNUNET_CONTAINER_multihashmap_put(tunnels, &hash, t,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ {
+ GNUNET_break(0);
+ GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
+ return;
+ }
GNUNET_SERVER_receive_done(client, GNUNET_OK);
return;
/* Retrieve tunnel */
tid = ntohl(tunnel_msg->tunnel_id);
+
+ /* Remove from local id hashmap */
GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelNumber), &hash);
t = GNUNET_CONTAINER_multihashmap_get(c->tunnels, &hash);
- GNUNET_CONTAINER_multihashmap_remove_all(c->tunnels, &hash);
+ GNUNET_CONTAINER_multihashmap_remove(c->tunnels, &hash, t);
+
+ /* Remove from global id hashmap */
+ GNUNET_CRYPTO_hash(&t->id, sizeof(struct MESH_TunnelID), &hash);
+ GNUNET_CONTAINER_multihashmap_remove(tunnels, &hash, t);
+
GNUNET_CORE_notify_transmit_ready(core_handle,
1,
1,
if (core_handle == NULL) {
GNUNET_break(0);
}
- dht_handle = GNUNET_DHT_connect(c, 100); /* FIXME ht len correct size? */
+ dht_handle = GNUNET_DHT_connect(c, 64);
if (dht_handle == NULL) {
GNUNET_break(0);
}
next_tid = 0;
+ tunnels = GNUNET_CONTAINER_multihashmap_create(64);
+
/* Scheduled the task to clean up when shutdown is called */
GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
&shutdown_task, NULL);