aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet_peer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/gnunet-service-cadet_peer.c')
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c93
1 files changed, 60 insertions, 33 deletions
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 705165c51..4abcd1a0b 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -156,9 +156,17 @@ struct CadetPeer
156 struct CadetTunnel *tunnel; 156 struct CadetTunnel *tunnel;
157 157
158 /** 158 /**
159 * Connections that go through this peer, indexed by tid; 159 * Connections that go through this peer where we
160 * are the predecessor; indexed by tid; do NOT
161 * try to combine with @e connections_succ (#3794).
160 */ 162 */
161 struct GNUNET_CONTAINER_MultiHashMap *connections; 163 struct GNUNET_CONTAINER_MultiHashMap *connections_pred;
164
165 /**
166 * Connections that go through this peer where we are
167 * the successor; indexed by tid;
168 */
169 struct GNUNET_CONTAINER_MultiHashMap *connections_succ;
162 170
163 /** 171 /**
164 * Handle for queued transmissions 172 * Handle for queued transmissions
@@ -314,10 +322,11 @@ GCP_debug (const struct CadetPeer *p, enum GNUNET_ErrorType level)
314 322
315 LOG2 (level, "PPP core transmit handle %p\n", p->core_transmit); 323 LOG2 (level, "PPP core transmit handle %p\n", p->core_transmit);
316 LOG2 (level, "PPP DHT GET handle %p\n", p->search_h); 324 LOG2 (level, "PPP DHT GET handle %p\n", p->search_h);
317 if (NULL != p->connections) 325 conns = 0;
318 conns = GNUNET_CONTAINER_multihashmap_size (p->connections); 326 if (NULL != p->connections_pred)
319 else 327 conns = GNUNET_CONTAINER_multihashmap_size (p->connections_pred);
320 conns = 0; 328 if (NULL != p->connections_succ)
329 conns += GNUNET_CONTAINER_multihashmap_size (p->connections_succ);
321 LOG2 (level, "PPP # connections over link to peer: %u\n", conns); 330 LOG2 (level, "PPP # connections over link to peer: %u\n", conns);
322 queue_debug (p, level); 331 queue_debug (p, level);
323 LOG2 (level, "PPP DEBUG END\n"); 332 LOG2 (level, "PPP DEBUG END\n");
@@ -428,8 +437,10 @@ core_connect (void *cls,
428 "# peers", 437 "# peers",
429 1, 438 1,
430 GNUNET_NO); 439 GNUNET_NO);
431 GNUNET_assert (NULL == mp->connections); 440 GNUNET_assert (NULL == mp->connections_pred);
432 mp->connections = GNUNET_CONTAINER_multihashmap_create (32, GNUNET_YES); 441 GNUNET_assert (NULL == mp->connections_succ);
442 mp->connections_pred = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES);
443 mp->connections_succ = GNUNET_CONTAINER_multihashmap_create (16, GNUNET_YES);
433 444
434 if ( (NULL != GCP_get_tunnel (mp)) && 445 if ( (NULL != GCP_get_tunnel (mp)) &&
435 (0 > GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, peer)) ) 446 (0 > GNUNET_CRYPTO_cmp_peer_identity (&my_full_id, peer)) )
@@ -468,11 +479,16 @@ core_disconnect (void *cls,
468 "DISCONNECTED %s <= %s\n", 479 "DISCONNECTED %s <= %s\n",
469 own_id, GNUNET_i2s (peer)); 480 own_id, GNUNET_i2s (peer));
470 direct_path = pop_direct_path (p); 481 direct_path = pop_direct_path (p);
471 GNUNET_CONTAINER_multihashmap_iterate (p->connections, 482 GNUNET_CONTAINER_multihashmap_iterate (p->connections_succ,
483 &notify_broken,
484 p);
485 GNUNET_CONTAINER_multihashmap_iterate (p->connections_pred,
472 &notify_broken, 486 &notify_broken,
473 p); 487 p);
474 GNUNET_CONTAINER_multihashmap_destroy (p->connections); 488 GNUNET_CONTAINER_multihashmap_destroy (p->connections_succ);
475 p->connections = NULL; 489 p->connections_succ = NULL;
490 GNUNET_CONTAINER_multihashmap_destroy (p->connections_pred);
491 p->connections_pred = NULL;
476 if (NULL != p->core_transmit) 492 if (NULL != p->core_transmit)
477 { 493 {
478 GNUNET_CORE_notify_transmit_ready_cancel (p->core_transmit); 494 GNUNET_CORE_notify_transmit_ready_cancel (p->core_transmit);
@@ -1366,7 +1382,8 @@ GCP_queue_add (struct CadetPeer *peer, void *cls, uint16_t type,
1366 1382
1367 if (error_level == GNUNET_ERROR_TYPE_ERROR) 1383 if (error_level == GNUNET_ERROR_TYPE_ERROR)
1368 GNUNET_assert (0); 1384 GNUNET_assert (0);
1369 if (NULL == peer->connections) 1385 if ( (NULL == peer->connections_pred) ||
1386 (NULL == peer->connections_succ) )
1370 { 1387 {
1371 /* We are not connected to this peer, ignore request. */ 1388 /* We are not connected to this peer, ignore request. */
1372 LOG (GNUNET_ERROR_TYPE_WARNING, "%s not a neighbor\n", GCP_2s (peer)); 1389 LOG (GNUNET_ERROR_TYPE_WARNING, "%s not a neighbor\n", GCP_2s (peer));
@@ -1849,11 +1866,11 @@ GCP_connect (struct CadetPeer *peer)
1849 * not yet known to be connected. 1866 * not yet known to be connected.
1850 * 1867 *
1851 * This happens quite often during testing when running cadet 1868 * This happens quite often during testing when running cadet
1852 * under valgrind: core connect notifications come very late and the 1869 * under valgrind: core connect notifications come very late
1853 * DHT result has already come and created a valid path. 1870 * and the DHT result has already come and created a valid
1854 * In this case, the peer->connections hashmap will be NULL and 1871 * path. In this case, the peer->connections_{pred,succ}
1855 * tunnel_use_path will not be able to create a connection from that 1872 * hashmaps will be NULL and tunnel_use_path will not be able
1856 * path. 1873 * to create a connection from that path.
1857 * 1874 *
1858 * Re-running the DHT GET should give core time to callback. 1875 * Re-running the DHT GET should give core time to callback.
1859 * 1876 *
@@ -1902,7 +1919,8 @@ GCP_is_neighbor (const struct CadetPeer *peer)
1902{ 1919{
1903 struct CadetPeerPath *path; 1920 struct CadetPeerPath *path;
1904 1921
1905 if (NULL == peer->connections) 1922 if ( (NULL == peer->connections_pred) ||
1923 (NULL == peer->connections_succ) )
1906 return GNUNET_NO; 1924 return GNUNET_NO;
1907 1925
1908 for (path = peer->path_head; NULL != path; path = path->next) 1926 for (path = peer->path_head; NULL != path; path = path->next)
@@ -1942,10 +1960,12 @@ GCP_add_tunnel (struct CadetPeer *peer)
1942 * 1960 *
1943 * @param peer Peer to add connection to. 1961 * @param peer Peer to add connection to.
1944 * @param c Connection to add. 1962 * @param c Connection to add.
1963 * @param pred #GNUNET_YES if we are predecessor, #GNUNET_NO if we are successor
1945 */ 1964 */
1946void 1965void
1947GCP_add_connection (struct CadetPeer *peer, 1966GCP_add_connection (struct CadetPeer *peer,
1948 struct CadetConnection *c) 1967 struct CadetConnection *c,
1968 int pred)
1949{ 1969{
1950 LOG (GNUNET_ERROR_TYPE_DEBUG, 1970 LOG (GNUNET_ERROR_TYPE_DEBUG,
1951 "adding connection %s\n", 1971 "adding connection %s\n",
@@ -1953,19 +1973,20 @@ GCP_add_connection (struct CadetPeer *peer,
1953 LOG (GNUNET_ERROR_TYPE_DEBUG, 1973 LOG (GNUNET_ERROR_TYPE_DEBUG,
1954 "to peer %s\n", 1974 "to peer %s\n",
1955 GCP_2s (peer)); 1975 GCP_2s (peer));
1956 GNUNET_assert (NULL != peer->connections); 1976 GNUNET_assert (NULL != peer->connections_pred);
1957 LOG (GNUNET_ERROR_TYPE_DEBUG, 1977 GNUNET_assert (NULL != peer->connections_succ);
1958 "peer %s has %u connections.\n",
1959 GCP_2s (peer),
1960 GNUNET_CONTAINER_multihashmap_size (peer->connections));
1961 GNUNET_assert (GNUNET_OK == 1978 GNUNET_assert (GNUNET_OK ==
1962 GNUNET_CONTAINER_multihashmap_put (peer->connections, 1979 GNUNET_CONTAINER_multihashmap_put ((GNUNET_YES == pred)
1980 ? peer->connections_pred
1981 : peer->connections_succ,
1963 GCC_get_h (c), 1982 GCC_get_h (c),
1964 c, 1983 c,
1965 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); 1984 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
1966 LOG (GNUNET_ERROR_TYPE_DEBUG, 1985 LOG (GNUNET_ERROR_TYPE_DEBUG,
1967 " now has %u connections.\n", 1986 "Peer %s is now predecessor on %u connections and successor on %u connections.\n",
1968 GNUNET_CONTAINER_multihashmap_size (peer->connections)); 1987 GCP_2s (peer),
1988 GNUNET_CONTAINER_multihashmap_size (peer->connections_pred),
1989 GNUNET_CONTAINER_multihashmap_size (peer->connections_succ));
1969} 1990}
1970 1991
1971 1992
@@ -2159,10 +2180,12 @@ GCP_remove_path (struct CadetPeer *peer, struct CadetPeerPath *path)
2159 * 2180 *
2160 * @param peer Peer to remove connection from. 2181 * @param peer Peer to remove connection from.
2161 * @param c Connection to remove. 2182 * @param c Connection to remove.
2183 * @param pred #GNUNET_YES if we were predecessor, #GNUNET_NO if we were successor
2162 */ 2184 */
2163void 2185void
2164GCP_remove_connection (struct CadetPeer *peer, 2186GCP_remove_connection (struct CadetPeer *peer,
2165 const struct CadetConnection *c) 2187 const struct CadetConnection *c,
2188 int pred)
2166{ 2189{
2167 LOG (GNUNET_ERROR_TYPE_DEBUG, 2190 LOG (GNUNET_ERROR_TYPE_DEBUG,
2168 "removing connection %s\n", 2191 "removing connection %s\n",
@@ -2170,19 +2193,23 @@ GCP_remove_connection (struct CadetPeer *peer,
2170 LOG (GNUNET_ERROR_TYPE_DEBUG, 2193 LOG (GNUNET_ERROR_TYPE_DEBUG,
2171 "from peer %s\n", 2194 "from peer %s\n",
2172 GCP_2s (peer)); 2195 GCP_2s (peer));
2173
2174 if ( (NULL == peer) || 2196 if ( (NULL == peer) ||
2175 (NULL == peer->connections) ) 2197 (NULL == peer->connections_pred) ||
2198 (NULL == peer->connections_succ) )
2176 return; 2199 return;
2177 (void) GNUNET_CONTAINER_multihashmap_remove (peer->connections, 2200 (void) GNUNET_CONTAINER_multihashmap_remove ((GNUNET_YES == pred)
2201 ? peer->connections_pred
2202 : peer->connections_succ,
2178 GCC_get_h (c), 2203 GCC_get_h (c),
2179 c); 2204 c);
2180 LOG (GNUNET_ERROR_TYPE_DEBUG, 2205 LOG (GNUNET_ERROR_TYPE_DEBUG,
2181 "peer %s ok, has %u connections left.\n", 2206 "Peer %s remains predecessor for %u and successor for %u connections.\n",
2182 GCP_2s (peer), 2207 GCP_2s (peer),
2183 GNUNET_CONTAINER_multihashmap_size (peer->connections)); 2208 GNUNET_CONTAINER_multihashmap_size (peer->connections_pred),
2209 GNUNET_CONTAINER_multihashmap_size (peer->connections_succ));
2184} 2210}
2185 2211
2212
2186/** 2213/**
2187 * Start the DHT search for new paths towards the peer: we don't have 2214 * Start the DHT search for new paths towards the peer: we don't have
2188 * enough good connections. 2215 * enough good connections.