diff options
author | Bart Polot <bart@net.in.tum.de> | 2011-05-06 16:42:29 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2011-05-06 16:42:29 +0000 |
commit | 3812cf28795be58bce2eabccfd8b6e004e6be291 (patch) | |
tree | 02343dbe10116e136c1ddc12d1310e2cfbe6c1ff | |
parent | c2888e92dbdd4a5553f672cd7898fde80cf9215c (diff) | |
download | gnunet-3812cf28795be58bce2eabccfd8b6e004e6be291.tar.gz gnunet-3812cf28795be58bce2eabccfd8b6e004e6be291.zip |
Fixed wrong perception about how doubly linked list work
-rw-r--r-- | src/include/gnunet_container_lib.h | 1 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh.c | 89 |
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 | |||
715 | 715 | ||
716 | 716 | ||
717 | /* ******************** doubly-linked list *************** */ | 717 | /* ******************** doubly-linked list *************** */ |
718 | /* To avoid mistakes: head->prev == tail->next == NULL */ | ||
718 | 719 | ||
719 | /** | 720 | /** |
720 | * Insert an element at the head of a DLL. Assumes that head, tail and | 721 | * 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) { | |||
348 | c = clients_head; | 348 | c = clients_head; |
349 | while(NULL != c) { | 349 | while(NULL != c) { |
350 | if(c->handle == client) return c; | 350 | if(c->handle == client) return c; |
351 | if(c == clients_tail) | 351 | c = c->next; |
352 | return NULL; | ||
353 | else | ||
354 | c = c->next; | ||
355 | } | 352 | } |
356 | return NULL; | 353 | return NULL; |
357 | } | 354 | } |
@@ -445,12 +442,9 @@ send_core_create_path_for_peer (void *cls, size_t size, void *buf) { | |||
445 | if(p->peers[p->length-1] == peer_info->id) { | 442 | if(p->peers[p->length-1] == peer_info->id) { |
446 | break; | 443 | break; |
447 | } | 444 | } |
448 | if(p != peer_info->t->paths_tail) { | 445 | p = p->next; |
449 | p = p->next; | ||
450 | } else { | ||
451 | // TODO ERROR Path not found | ||
452 | } | ||
453 | } | 446 | } |
447 | if(p == NULL) return 0; // TODO Notify ERROR Path not found | ||
454 | 448 | ||
455 | size_needed = sizeof(struct GNUNET_MESH_ManipulatePath) | 449 | size_needed = sizeof(struct GNUNET_MESH_ManipulatePath) |
456 | + p->length * sizeof(struct GNUNET_PeerIdentity); | 450 | + p->length * sizeof(struct GNUNET_PeerIdentity); |
@@ -686,7 +680,6 @@ handle_client_disconnect (void *cls, struct GNUNET_SERVER_Client *client) | |||
686 | } else { | 680 | } else { |
687 | c = c->next; | 681 | c = c->next; |
688 | } | 682 | } |
689 | if(c == clients_head) return; /* Tail already processed? */ | ||
690 | } | 683 | } |
691 | return; | 684 | return; |
692 | } | 685 | } |
@@ -778,7 +771,6 @@ handle_local_tunnel_create (void *cls, | |||
778 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | 771 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); |
779 | return; | 772 | return; |
780 | } | 773 | } |
781 | if(t == c->tunnels_tail) break; | ||
782 | t = t->next; | 774 | t = t->next; |
783 | } | 775 | } |
784 | /* FIXME: calloc? Is NULL != 0 on any platform? */ | 776 | /* FIXME: calloc? Is NULL != 0 on any platform? */ |
@@ -898,22 +890,18 @@ handle_local_connect_add (void *cls, | |||
898 | 890 | ||
899 | /* Tunnel exists? */ | 891 | /* Tunnel exists? */ |
900 | tid = ntohl(peer_msg->tunnel_id); | 892 | tid = ntohl(peer_msg->tunnel_id); |
901 | if(NULL == (t = c->tunnels_head)) { | 893 | t = c->tunnels_head; |
902 | GNUNET_break(0); | ||
903 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
904 | return; | ||
905 | } | ||
906 | while(NULL != t) { | 894 | while(NULL != t) { |
907 | if(t->tid == tid) { | 895 | if(t->tid == tid) { |
908 | break; | 896 | break; |
909 | } | 897 | } |
910 | if(t == c->tunnels_tail) { | ||
911 | GNUNET_break(0); | ||
912 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
913 | return; | ||
914 | } | ||
915 | t = t->next; | 898 | t = t->next; |
916 | } | 899 | } |
900 | if(NULL == t) { | ||
901 | GNUNET_break(0); | ||
902 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
903 | return; | ||
904 | } | ||
917 | 905 | ||
918 | /* Does client own tunnel? */ | 906 | /* Does client own tunnel? */ |
919 | if(t->client->handle != client) { | 907 | if(t->client->handle != client) { |
@@ -1005,6 +993,11 @@ handle_local_connect_del (void *cls, | |||
1005 | } | 993 | } |
1006 | t = t->next; | 994 | t = t->next; |
1007 | } | 995 | } |
996 | if(NULL == t) { | ||
997 | GNUNET_break(0); | ||
998 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
999 | return; | ||
1000 | } | ||
1008 | 1001 | ||
1009 | /* Does client own tunnel? */ | 1002 | /* Does client own tunnel? */ |
1010 | if(t->client->handle != client) { | 1003 | if(t->client->handle != client) { |
@@ -1028,9 +1021,6 @@ handle_local_connect_del (void *cls, | |||
1028 | } else { | 1021 | } else { |
1029 | p = p->next; | 1022 | p = p->next; |
1030 | } | 1023 | } |
1031 | if(p == t->paths_head) { | ||
1032 | break; | ||
1033 | } | ||
1034 | } | 1024 | } |
1035 | 1025 | ||
1036 | /*Delete peer info */ | 1026 | /*Delete peer info */ |
@@ -1046,9 +1036,6 @@ handle_local_connect_del (void *cls, | |||
1046 | } else { | 1036 | } else { |
1047 | peer_info = peer_info->next; | 1037 | peer_info = peer_info->next; |
1048 | } | 1038 | } |
1049 | if(peer_info == t->peers_head) { | ||
1050 | break; | ||
1051 | } | ||
1052 | } | 1039 | } |
1053 | 1040 | ||
1054 | GNUNET_PEER_change_rc(peer_id, -1); | 1041 | GNUNET_PEER_change_rc(peer_id, -1); |
@@ -1093,22 +1080,18 @@ handle_local_connect_by_type (void *cls, | |||
1093 | 1080 | ||
1094 | /* Tunnel exists? */ | 1081 | /* Tunnel exists? */ |
1095 | tid = ntohl(connect_msg->tunnel_id); | 1082 | tid = ntohl(connect_msg->tunnel_id); |
1096 | if(NULL == (t = c->tunnels_head)) { | 1083 | t = c->tunnels_head; |
1097 | GNUNET_break(0); | ||
1098 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
1099 | return; | ||
1100 | } | ||
1101 | while(NULL != t) { | 1084 | while(NULL != t) { |
1102 | if(t->tid == tid) { | 1085 | if(t->tid == tid) { |
1103 | break; | 1086 | break; |
1104 | } | 1087 | } |
1105 | if(t == c->tunnels_tail) { | ||
1106 | GNUNET_break(0); | ||
1107 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
1108 | return; | ||
1109 | } | ||
1110 | t = t->next; | 1088 | t = t->next; |
1111 | } | 1089 | } |
1090 | if(NULL == t) { | ||
1091 | GNUNET_break(0); | ||
1092 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
1093 | return; | ||
1094 | } | ||
1112 | 1095 | ||
1113 | /* Does client own tunnel? */ | 1096 | /* Does client own tunnel? */ |
1114 | if(t->client->handle != client) { | 1097 | if(t->client->handle != client) { |
@@ -1159,22 +1142,18 @@ handle_local_network_traffic (void *cls, | |||
1159 | 1142 | ||
1160 | /* Tunnel exists? */ | 1143 | /* Tunnel exists? */ |
1161 | tid = ntohl(data_msg->tunnel_id); | 1144 | tid = ntohl(data_msg->tunnel_id); |
1162 | if(NULL == (t = c->tunnels_head)) { | 1145 | t = c->tunnels_head; |
1163 | GNUNET_break(0); | ||
1164 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
1165 | return; | ||
1166 | } | ||
1167 | while(NULL != t) { | 1146 | while(NULL != t) { |
1168 | if(t->tid == tid) { | 1147 | if(t->tid == tid) { |
1169 | break; | 1148 | break; |
1170 | } | 1149 | } |
1171 | if(t == c->tunnels_tail) { | ||
1172 | GNUNET_break(0); | ||
1173 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
1174 | return; | ||
1175 | } | ||
1176 | t = t->next; | 1150 | t = t->next; |
1177 | } | 1151 | } |
1152 | if(NULL == t) { | ||
1153 | GNUNET_break(0); | ||
1154 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
1155 | return; | ||
1156 | } | ||
1178 | 1157 | ||
1179 | /* Does client own tunnel? */ | 1158 | /* Does client own tunnel? */ |
1180 | if(t->client->handle != client) { | 1159 | if(t->client->handle != client) { |
@@ -1222,22 +1201,18 @@ handle_local_network_traffic_bcast (void *cls, | |||
1222 | 1201 | ||
1223 | /* Tunnel exists? */ | 1202 | /* Tunnel exists? */ |
1224 | tid = ntohl(data_msg->tunnel_id); | 1203 | tid = ntohl(data_msg->tunnel_id); |
1225 | if(NULL == (t = c->tunnels_head)) { | 1204 | t = c->tunnels_head; |
1226 | GNUNET_break(0); | ||
1227 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
1228 | return; | ||
1229 | } | ||
1230 | while(NULL != t) { | 1205 | while(NULL != t) { |
1231 | if(t->tid == tid) { | 1206 | if(t->tid == tid) { |
1232 | break; | 1207 | break; |
1233 | } | 1208 | } |
1234 | if(t == c->tunnels_tail) { | ||
1235 | GNUNET_break(0); | ||
1236 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
1237 | return; | ||
1238 | } | ||
1239 | t = t->next; | 1209 | t = t->next; |
1240 | } | 1210 | } |
1211 | if(NULL == t) { | ||
1212 | GNUNET_break(0); | ||
1213 | GNUNET_SERVER_receive_done(client, GNUNET_SYSERR); | ||
1214 | return; | ||
1215 | } | ||
1241 | 1216 | ||
1242 | /* Does client own tunnel? */ | 1217 | /* Does client own tunnel? */ |
1243 | if(t->client->handle != client) { | 1218 | if(t->client->handle != client) { |