summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBart Polot <bart@net.in.tum.de>2011-05-06 16:42:29 +0000
committerBart Polot <bart@net.in.tum.de>2011-05-06 16:42:29 +0000
commit3812cf28795be58bce2eabccfd8b6e004e6be291 (patch)
tree02343dbe10116e136c1ddc12d1310e2cfbe6c1ff /src
parentc2888e92dbdd4a5553f672cd7898fde80cf9215c (diff)
Fixed wrong perception about how doubly linked list work
Diffstat (limited to 'src')
-rw-r--r--src/include/gnunet_container_lib.h1
-rw-r--r--src/mesh/gnunet-service-mesh.c89
2 files changed, 33 insertions, 57 deletions
diff --git a/src/include/gnunet_container_lib.h b/src/include/gnunet_container_lib.h
index 26579809d..4582c1a14 100644
--- a/src/include/gnunet_container_lib.h
+++ b/src/include/gnunet_container_lib.h
@@ -715,6 +715,7 @@ int GNUNET_CONTAINER_multihashmap_get_multiple (const struct
/* ******************** doubly-linked list *************** */
+/* To avoid mistakes: head->prev == tail->next == NULL */
/**
* Insert an element at the head of a DLL. Assumes that head, tail and
diff --git a/src/mesh/gnunet-service-mesh.c b/src/mesh/gnunet-service-mesh.c
index faed1ac01..2769793f9 100644
--- a/src/mesh/gnunet-service-mesh.c
+++ b/src/mesh/gnunet-service-mesh.c
@@ -348,10 +348,7 @@ retrieve_client (struct GNUNET_SERVER_Client *client) {
c = clients_head;
while(NULL != c) {
if(c->handle == client) return c;
- if(c == clients_tail)
- return NULL;
- else
- c = c->next;
+ c = c->next;
}
return NULL;
}
@@ -445,12 +442,9 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf) {
if(p->peers[p->length-1] == peer_info->id) {
break;
}
- if(p != peer_info->t->paths_tail) {
- p = p->next;
- } else {
- // TODO ERROR Path not found
- }
+ p = p->next;
}
+ if(p == NULL) return 0; // TODO Notify ERROR Path not found
size_needed = sizeof(struct GNUNET_MESH_ManipulatePath)
+ p->length * sizeof(struct GNUNET_PeerIdentity);
@@ -686,7 +680,6 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
} else {
c = c->next;
}
- if(c == clients_head) return; /* Tail already processed? */
}
return;
}
@@ -778,7 +771,6 @@ handle_local_tunnel_create (void *cls,
GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
return;
}
- if(t == c->tunnels_tail) break;
t = t->next;
}
/* FIXME: calloc? Is NULL != 0 on any platform? */
@@ -898,22 +890,18 @@ handle_local_connect_add (void *cls,
/* Tunnel exists? */
tid = ntohl(peer_msg->tunnel_id);
- if(NULL == (t = c->tunnels_head)) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ t = c->tunnels_head;
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;
}
+ if(NULL == t) {
+ GNUNET_break(0);
+ GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
+ return;
+ }
/* Does client own tunnel? */
if(t->client->handle != client) {
@@ -1005,6 +993,11 @@ handle_local_connect_del (void *cls,
}
t = t->next;
}
+ if(NULL == t) {
+ GNUNET_break(0);
+ GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
+ return;
+ }
/* Does client own tunnel? */
if(t->client->handle != client) {
@@ -1028,9 +1021,6 @@ handle_local_connect_del (void *cls,
} else {
p = p->next;
}
- if(p == t->paths_head) {
- break;
- }
}
/*Delete peer info */
@@ -1046,9 +1036,6 @@ handle_local_connect_del (void *cls,
} else {
peer_info = peer_info->next;
}
- if(peer_info == t->peers_head) {
- break;
- }
}
GNUNET_PEER_change_rc(peer_id, -1);
@@ -1093,22 +1080,18 @@ handle_local_connect_by_type (void *cls,
/* Tunnel exists? */
tid = ntohl(connect_msg->tunnel_id);
- if(NULL == (t = c->tunnels_head)) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ t = c->tunnels_head;
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;
}
+ if(NULL == t) {
+ GNUNET_break(0);
+ GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
+ return;
+ }
/* Does client own tunnel? */
if(t->client->handle != client) {
@@ -1159,22 +1142,18 @@ handle_local_network_traffic (void *cls,
/* Tunnel exists? */
tid = ntohl(data_msg->tunnel_id);
- if(NULL == (t = c->tunnels_head)) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ t = c->tunnels_head;
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;
}
+ if(NULL == t) {
+ GNUNET_break(0);
+ GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
+ return;
+ }
/* Does client own tunnel? */
if(t->client->handle != client) {
@@ -1222,22 +1201,18 @@ handle_local_network_traffic_bcast (void *cls,
/* Tunnel exists? */
tid = ntohl(data_msg->tunnel_id);
- if(NULL == (t = c->tunnels_head)) {
- GNUNET_break(0);
- GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
- return;
- }
+ t = c->tunnels_head;
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;
}
+ if(NULL == t) {
+ GNUNET_break(0);
+ GNUNET_SERVER_receive_done(client, GNUNET_SYSERR);
+ return;
+ }
/* Does client own tunnel? */
if(t->client->handle != client) {