diff options
author | Bart Polot <bart@net.in.tum.de> | 2013-12-17 02:27:28 +0000 |
---|---|---|
committer | Bart Polot <bart@net.in.tum.de> | 2013-12-17 02:27:28 +0000 |
commit | 10f4fb585af413a194c6ed1e138b06d1505a1f3d (patch) | |
tree | 0b3cac12a01dc606f314a5f7e66030039d3c4b2e | |
parent | 93cbfe29d41f059bc2a0ff5b7b39f782dd8d125d (diff) | |
download | gnunet-10f4fb585af413a194c6ed1e138b06d1505a1f3d.tar.gz gnunet-10f4fb585af413a194c6ed1e138b06d1505a1f3d.zip |
- refactor and improve path creation
-rw-r--r-- | src/mesh/gnunet-service-mesh_connection.c | 87 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_dht.c | 6 | ||||
-rw-r--r-- | src/mesh/gnunet-service-mesh_peer.c | 2 |
3 files changed, 71 insertions, 24 deletions
diff --git a/src/mesh/gnunet-service-mesh_connection.c b/src/mesh/gnunet-service-mesh_connection.c index fa7211c12..157f73e1a 100644 --- a/src/mesh/gnunet-service-mesh_connection.c +++ b/src/mesh/gnunet-service-mesh_connection.c | |||
@@ -448,7 +448,7 @@ send_ack (struct MeshConnection *c, unsigned int buffer, int fwd, int force) | |||
448 | { | 448 | { |
449 | LOG (GNUNET_ERROR_TYPE_DEBUG, "connection %s is origin in %s\n", | 449 | LOG (GNUNET_ERROR_TYPE_DEBUG, "connection %s is origin in %s\n", |
450 | GMC_2s (c), GM_f2s (fwd)); | 450 | GMC_2s (c), GM_f2s (fwd)); |
451 | GNUNET_assert (0); | 451 | GNUNET_assert (0); /* FIXME */ |
452 | return; | 452 | return; |
453 | } | 453 | } |
454 | 454 | ||
@@ -1221,6 +1221,67 @@ add_to_peer (struct MeshConnection *c, struct MeshPeer *peer) | |||
1221 | GMT_add_connection (c->t, c); | 1221 | GMT_add_connection (c->t, c); |
1222 | } | 1222 | } |
1223 | 1223 | ||
1224 | |||
1225 | /** | ||
1226 | * Builds a path from a PeerIdentity array. | ||
1227 | * | ||
1228 | * @param peers PeerIdentity array. | ||
1229 | * @param size Size of the @c peers array. | ||
1230 | * @param own_pos Output parameter: own position in the path. | ||
1231 | * | ||
1232 | * @return Fixed and shortened path. | ||
1233 | */ | ||
1234 | static struct MeshPeerPath * | ||
1235 | build_path_from_peer_ids (struct GNUNET_PeerIdentity *peers, | ||
1236 | unsigned int size, | ||
1237 | unsigned int *own_pos) | ||
1238 | { | ||
1239 | struct MeshPeerPath *path; | ||
1240 | GNUNET_PEER_Id shortid; | ||
1241 | unsigned int i; | ||
1242 | unsigned int j; | ||
1243 | unsigned int offset; | ||
1244 | |||
1245 | /* Create path */ | ||
1246 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n"); | ||
1247 | path = path_new (size); | ||
1248 | *own_pos = 0; | ||
1249 | offset = 0; | ||
1250 | for (i = 0; i < size; i++) | ||
1251 | { | ||
1252 | LOG (GNUNET_ERROR_TYPE_DEBUG, " - %u: taking %s\n", | ||
1253 | i, GNUNET_i2s (&peers[i])); | ||
1254 | shortid = GNUNET_PEER_intern (&peers[i]); | ||
1255 | |||
1256 | /* Check for loops / duplicates */ | ||
1257 | for (j = 0; j < i - offset; j++) | ||
1258 | { | ||
1259 | if (path->peers[j] == shortid) | ||
1260 | { | ||
1261 | LOG (GNUNET_ERROR_TYPE_DEBUG, " already exists at pos %u\n", j); | ||
1262 | offset += i - j; | ||
1263 | LOG (GNUNET_ERROR_TYPE_DEBUG, " offset now\n", offset); | ||
1264 | GNUNET_PEER_change_rc (shortid, -1); | ||
1265 | } | ||
1266 | } | ||
1267 | LOG (GNUNET_ERROR_TYPE_DEBUG, " storing at %u\n", i - offset); | ||
1268 | path->peers[i - offset] = shortid; | ||
1269 | if (path->peers[i] == myid) | ||
1270 | *own_pos = i; | ||
1271 | } | ||
1272 | path->length -= offset; | ||
1273 | |||
1274 | if (path->peers[*own_pos] != myid) | ||
1275 | { | ||
1276 | /* create path: self not found in path through self */ | ||
1277 | GNUNET_break_op (0); | ||
1278 | path_destroy (path); | ||
1279 | return NULL; | ||
1280 | } | ||
1281 | |||
1282 | return path; | ||
1283 | } | ||
1284 | |||
1224 | /******************************************************************************/ | 1285 | /******************************************************************************/ |
1225 | /******************************** API ***********************************/ | 1286 | /******************************** API ***********************************/ |
1226 | /******************************************************************************/ | 1287 | /******************************************************************************/ |
@@ -1248,7 +1309,6 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1248 | struct MeshConnection *c; | 1309 | struct MeshConnection *c; |
1249 | unsigned int own_pos; | 1310 | unsigned int own_pos; |
1250 | uint16_t size; | 1311 | uint16_t size; |
1251 | uint16_t i; | ||
1252 | 1312 | ||
1253 | LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n"); | 1313 | LOG (GNUNET_ERROR_TYPE_DEBUG, "\n\n"); |
1254 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a connection create msg\n"); | 1314 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Received a connection create msg\n"); |
@@ -1287,25 +1347,10 @@ GMC_handle_create (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1287 | c = connection_get (cid); | 1347 | c = connection_get (cid); |
1288 | if (NULL == c) | 1348 | if (NULL == c) |
1289 | { | 1349 | { |
1290 | /* Create path */ | 1350 | path = build_path_from_peer_ids ((struct GNUNET_PeerIdentity *) &msg[1], |
1291 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Creating path...\n"); | 1351 | size, &own_pos); |
1292 | path = path_new (size); | 1352 | if (NULL == path) |
1293 | own_pos = 0; | ||
1294 | for (i = 0; i < size; i++) | ||
1295 | { | ||
1296 | LOG (GNUNET_ERROR_TYPE_DEBUG, " ... adding %s\n", | ||
1297 | GNUNET_i2s (&id[i])); | ||
1298 | path->peers[i] = GNUNET_PEER_intern (&id[i]); | ||
1299 | if (path->peers[i] == myid) | ||
1300 | own_pos = i; | ||
1301 | } | ||
1302 | if (own_pos == 0 && path->peers[own_pos] != myid) | ||
1303 | { | ||
1304 | /* create path: self not found in path through self */ | ||
1305 | GNUNET_break_op (0); | ||
1306 | path_destroy (path); | ||
1307 | return GNUNET_OK; | 1353 | return GNUNET_OK; |
1308 | } | ||
1309 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); | 1354 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Own position: %u\n", own_pos); |
1310 | GMP_add_path_to_all (path, GNUNET_NO); | 1355 | GMP_add_path_to_all (path, GNUNET_NO); |
1311 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Creating connection\n"); | 1356 | LOG (GNUNET_ERROR_TYPE_DEBUG, " Creating connection\n"); |
@@ -1585,7 +1630,7 @@ GMC_handle_destroy (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
1585 | fwd = is_fwd (c, peer); | 1630 | fwd = is_fwd (c, peer); |
1586 | if (GNUNET_SYSERR == fwd) | 1631 | if (GNUNET_SYSERR == fwd) |
1587 | { | 1632 | { |
1588 | GNUNET_break_op (0); | 1633 | GNUNET_break_op (0); /* FIXME */ |
1589 | return GNUNET_OK; | 1634 | return GNUNET_OK; |
1590 | } | 1635 | } |
1591 | if (GNUNET_NO == GMC_is_terminal (c, fwd)) | 1636 | if (GNUNET_NO == GMC_is_terminal (c, fwd)) |
diff --git a/src/mesh/gnunet-service-mesh_dht.c b/src/mesh/gnunet-service-mesh_dht.c index 168706dcd..0e27eb9fa 100644 --- a/src/mesh/gnunet-service-mesh_dht.c +++ b/src/mesh/gnunet-service-mesh_dht.c | |||
@@ -110,6 +110,8 @@ static struct GNUNET_CONTAINER_MultiHashMap32 *get_requests; | |||
110 | * to obtain a local peer -> destination path and interning the peer ids. | 110 | * to obtain a local peer -> destination path and interning the peer ids. |
111 | * | 111 | * |
112 | * @return Newly allocated and created path | 112 | * @return Newly allocated and created path |
113 | * | ||
114 | * FIXME refactor and use build_path_from_peer_ids | ||
113 | */ | 115 | */ |
114 | static struct MeshPeerPath * | 116 | static struct MeshPeerPath * |
115 | path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, | 117 | path_build_from_dht (const struct GNUNET_PeerIdentity *get_path, |
@@ -269,7 +271,7 @@ announce_id (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
269 | } | 271 | } |
270 | 272 | ||
271 | /** | 273 | /** |
272 | * Iterator over hash map entries and stop GET requests before disconnecting | 274 | * Iterator over hash map entries and stop GET requests before disconnecting |
273 | * from the DHT. | 275 | * from the DHT. |
274 | * | 276 | * |
275 | * @param cls Closure (unused) | 277 | * @param cls Closure (unused) |
@@ -389,4 +391,4 @@ GMD_search_stop (struct GMD_search_handle *h) | |||
389 | h->peer_id, h)); | 391 | h->peer_id, h)); |
390 | GNUNET_DHT_get_stop (h->dhtget); | 392 | GNUNET_DHT_get_stop (h->dhtget); |
391 | GNUNET_free (h); | 393 | GNUNET_free (h); |
392 | } \ No newline at end of file | 394 | } |
diff --git a/src/mesh/gnunet-service-mesh_peer.c b/src/mesh/gnunet-service-mesh_peer.c index 23dd22222..9af0d34bf 100644 --- a/src/mesh/gnunet-service-mesh_peer.c +++ b/src/mesh/gnunet-service-mesh_peer.c | |||
@@ -783,7 +783,7 @@ queue_send (void *cls, size_t size, void *buf) | |||
783 | queue = peer_get_first_message (peer); | 783 | queue = peer_get_first_message (peer); |
784 | if (NULL == queue) | 784 | if (NULL == queue) |
785 | { | 785 | { |
786 | GNUNET_break (0); /* Core tmt_rdy should've been canceled */ | 786 | GNUNET_assert (0); /* Core tmt_rdy should've been canceled FIXME */ |
787 | return 0; | 787 | return 0; |
788 | } | 788 | } |
789 | c = queue->c; | 789 | c = queue->c; |