[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r15250 - gnunet/src/mesh
From: |
gnunet |
Subject: |
[GNUnet-SVN] r15250 - gnunet/src/mesh |
Date: |
Wed, 18 May 2011 15:09:54 +0200 |
Author: bartpolot
Date: 2011-05-18 15:09:54 +0200 (Wed, 18 May 2011)
New Revision: 15250
Modified:
gnunet/src/mesh/gnunet-service-mesh.c
gnunet/src/mesh/mesh_api_new.c
Log:
Added mapping of client-service tunnel numbering
Modified: gnunet/src/mesh/gnunet-service-mesh.c
===================================================================
--- gnunet/src/mesh/gnunet-service-mesh.c 2011-05-18 09:56:25 UTC (rev
15249)
+++ gnunet/src/mesh/gnunet-service-mesh.c 2011-05-18 13:09:54 UTC (rev
15250)
@@ -99,7 +99,7 @@
/**
* Tunnel this peer belongs to
*/
- struct MESH_tunnel *t;
+ struct MeshTunnel *t;
/**
* Is the peer reachable? Is the peer even connected?
@@ -197,14 +197,14 @@
* - metainfo: ready, speeds, accounting
* For an end node more fields will be needed (client-handling)
*/
-struct MESH_tunnel
+struct MeshTunnel
{
/**
* Double linked list
*/
- struct MESH_tunnel *next;
- struct MESH_tunnel *prev;
+ struct MeshTunnel *next;
+ struct MeshTunnel *prev;
/**
* Origin ID: Node that created the tunnel
@@ -286,8 +286,8 @@
/**
* Tunnels that belong to this client, for convenience on disconnect
*/
- struct MESH_tunnel *tunnels_head;
- struct MESH_tunnel *tunnels_tail;
+ struct MeshTunnel *tunnels_head;
+ struct MeshTunnel *tunnels_tail;
/**
* Handle to communicate with the client
@@ -306,6 +306,11 @@
uint16_t *types;
unsigned int type_counter;
+ /**
+ * Map tunnel IDs used by the client to owner and global tunnel ID
+ */
+ struct GNUNET_CONTAINER_MultiHashMap* tunnel_ids;
+
};
/******************************************************************************/
@@ -368,7 +373,7 @@
* @return GNUNET_OK on success
*/
static int
-destroy_path(struct MESH_tunnel *t, struct MeshPath *p)
+destroy_path(struct MeshTunnel *t, struct MeshPath *p)
{
GNUNET_PEER_decrement_rcs(p->peers, p->length);
GNUNET_free(p->peers);
@@ -384,7 +389,7 @@
* @return GNUNET_OK on success
*/
static int
-destroy_peer_info(struct MESH_tunnel *t, struct MeshPeerInfo *pi)
+destroy_peer_info(struct MeshTunnel *t, struct MeshPeerInfo *pi)
{
GNUNET_PEER_change_rc(pi->id, -1);
GNUNET_CONTAINER_DLL_remove(t->peers_head, t->peers_tail, pi);
@@ -399,11 +404,13 @@
* @return GNUNET_OK on success
*/
static int
-destroy_tunnel(struct MeshClient *c, struct MESH_tunnel *t)
+destroy_tunnel(struct MeshClient *c, struct MeshTunnel *t)
{
struct MeshPeerInfo *pi;
struct MeshPath *path;
+ if (NULL == t) return GNUNET_OK;
+
for (pi = t->peers_head; pi != NULL; pi = t->peers_head) {
destroy_peer_info(t, pi);
}
@@ -617,7 +624,7 @@
const void *data)
{
struct MeshPeerInfo *peer_info;
- struct MESH_tunnel *t;
+ struct MeshTunnel *t;
struct MeshPath *p;
int i;
@@ -679,7 +686,7 @@
handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
{
struct MeshClient *c, *next;
- struct MESH_tunnel *t;
+ struct MeshTunnel *t;
GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
"MESH: client disconnected\n");
@@ -694,6 +701,7 @@
}
if(0 != c->app_counter) GNUNET_free (c->apps);
if(0 != c->type_counter) GNUNET_free (c->types);
+ GNUNET_CONTAINER_multihashmap_destroy(c->tunnel_ids);
next = c->next;
GNUNET_free (c);
c = next;
@@ -761,6 +769,7 @@
/* Insert new client in DLL */
GNUNET_CONTAINER_DLL_insert (clients_head, clients_tail, c);
+ c->tunnel_ids = GNUNET_CONTAINER_multihashmap_create(100);
GNUNET_SERVER_receive_done(client, GNUNET_OK);
@@ -780,8 +789,9 @@
const struct GNUNET_MessageHeader *message)
{
struct GNUNET_MESH_TunnelMessage *tunnel_msg;
- struct MESH_tunnel *t;
+ struct MeshTunnel *t;
struct MeshClient *c;
+ GNUNET_HashCode hash;
/* Sanity check for client registration */
if (NULL == (c = retrieve_client(client))) {
@@ -814,12 +824,21 @@
}
t = t->next;
}
- /* FIXME: calloc? Is NULL != 0 on any platform? */
- t = GNUNET_malloc(sizeof(struct MESH_tunnel));
+ t = GNUNET_malloc(sizeof(struct MeshTunnel ));
t->tid = ntohl(tunnel_msg->tunnel_id);
t->oid = myid;
t->client = c;
+ GNUNET_CRYPTO_hash(&t->tid, sizeof(MESH_TunnelID), &hash);
+ if (GNUNET_OK !=
+ GNUNET_CONTAINER_multihashmap_put(c->tunnel_ids, &hash, t,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+ {
+ GNUNET_break(0);
+ GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
+ return;
+ }
+
GNUNET_CONTAINER_DLL_insert(c->tunnels_head, c->tunnels_tail, t);
GNUNET_SERVER_receive_done(client, GNUNET_OK);
@@ -841,9 +860,11 @@
{
struct GNUNET_MESH_TunnelMessage *tunnel_msg;
struct MeshClient *c;
- struct MESH_tunnel *t;
+ struct MeshTunnel *t;
MESH_TunnelID tid;
+ GNUNET_HashCode hash;
+
/* Sanity check for client registration */
if (NULL == (c = retrieve_client(client))) {
GNUNET_break(0);
@@ -859,25 +880,11 @@
tunnel_msg = (struct GNUNET_MESH_TunnelMessage *) message;
- /* Tunnel exists? */
+ /* Retrieve tunnel */
tid = ntohl(tunnel_msg->tunnel_id);
- if (NULL == (t = c->tunnels_head)) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
- while (NULL != t) {
- if (t->tid == tid) {
- break;
- }
- if (t == c->tunnels_tail) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
- t = t->next;
- }
-
+ GNUNET_CRYPTO_hash(&tid, sizeof(MESH_TunnelID), &hash);
+ t = GNUNET_CONTAINER_multihashmap_get(c->tunnel_ids, &hash);
+ GNUNET_CONTAINER_multihashmap_remove_all(c->tunnel_ids, &hash);
destroy_tunnel(c, t);
GNUNET_SERVER_receive_done(client, GNUNET_OK);
@@ -899,7 +906,7 @@
{
struct GNUNET_MESH_PeerControl *peer_msg;
struct MeshClient *c;
- struct MESH_tunnel *t;
+ struct MeshTunnel *t;
MESH_TunnelID tid;
struct MeshPeerInfo *peer_info;
GNUNET_HashCode key;
@@ -985,7 +992,7 @@
{
struct GNUNET_MESH_PeerControl *peer_msg;
struct MeshClient *c;
- struct MESH_tunnel *t;
+ struct MeshTunnel *t;
struct MeshPath *p;
struct MeshPath *aux_path;
MESH_TunnelID tid;
@@ -1093,7 +1100,7 @@
MESH_TunnelID tid;
GNUNET_MESH_ApplicationType application;
struct MeshClient *c;
- struct MESH_tunnel *t;
+ struct MeshTunnel *t;
/* Sanity check for client registration */
if (NULL == (c = retrieve_client(client))) {
@@ -1156,7 +1163,7 @@
const struct GNUNET_MessageHeader *message)
{
struct MeshClient *c;
- struct MESH_tunnel *t;
+ struct MeshTunnel *t;
struct GNUNET_MESH_Data *data_msg;
MESH_TunnelID tid;
@@ -1217,7 +1224,7 @@
const struct GNUNET_MessageHeader *message)
{
struct MeshClient *c;
- struct MESH_tunnel *t;
+ struct MeshTunnel *t;
struct GNUNET_MESH_DataBroadcast *data_msg;
MESH_TunnelID tid;
Modified: gnunet/src/mesh/mesh_api_new.c
===================================================================
--- gnunet/src/mesh/mesh_api_new.c 2011-05-18 09:56:25 UTC (rev 15249)
+++ gnunet/src/mesh/mesh_api_new.c 2011-05-18 13:09:54 UTC (rev 15250)
@@ -45,6 +45,7 @@
#include "gnunet_common.h"
#include "gnunet_client_lib.h"
#include "gnunet_util_lib.h"
+#include "gnunet_peer_lib.h"
#include "gnunet_mesh_service_new.h"
#include "mesh.h"
@@ -121,11 +122,6 @@
struct GNUNET_MESH_Tunnel *prev;
/**
- * Owner of the tunnel, either local or remote
- */
- GNUNET_PEER_Id owner;
-
- /**
* Local ID of the tunnel
*/
MESH_TunnelID tid;
@@ -341,6 +337,7 @@
t->disconnect_handler = NULL;
t->mesh = h;
t->tid = tid;
+
return;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r15250 - gnunet/src/mesh,
gnunet <=