aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/transport/gnunet-service-transport_neighbours.c149
-rw-r--r--src/transport/gnunet-service-transport_neighbours.h9
2 files changed, 6 insertions, 152 deletions
diff --git a/src/transport/gnunet-service-transport_neighbours.c b/src/transport/gnunet-service-transport_neighbours.c
index 0e53f9b6f..4d3e8c0bc 100644
--- a/src/transport/gnunet-service-transport_neighbours.c
+++ b/src/transport/gnunet-service-transport_neighbours.c
@@ -1700,16 +1700,12 @@ GST_neighbours_calculate_receive_delay (const struct GNUNET_PeerIdentity *sender
1700 } 1700 }
1701 if (NULL == (n = lookup_neighbour (sender))) 1701 if (NULL == (n = lookup_neighbour (sender)))
1702 { 1702 {
1703 GST_neighbours_try_connect (sender); 1703 GNUNET_STATISTICS_update (GST_stats,
1704 if (NULL == (n = lookup_neighbour (sender))) 1704 gettext_noop ("# messages discarded due to lack of neighbour record"),
1705 { 1705 1,
1706 GNUNET_STATISTICS_update (GST_stats, 1706 GNUNET_NO);
1707 gettext_noop 1707 *do_forward = GNUNET_NO;
1708 ("# messages discarded due to lack of neighbour record"), 1708 return GNUNET_TIME_UNIT_ZERO;
1709 1, GNUNET_NO);
1710 *do_forward = GNUNET_NO;
1711 return GNUNET_TIME_UNIT_ZERO;
1712 }
1713 } 1709 }
1714 if (! test_connected (n)) 1710 if (! test_connected (n))
1715 { 1711 {
@@ -2250,139 +2246,6 @@ struct BlacklistCheckSwitchContext
2250 2246
2251 2247
2252/** 2248/**
2253 * Black list check result for try_connect call
2254 * If connection to the peer is allowed request adddress and
2255 *
2256 * @param cls blc_ctx bl context
2257 * @param peer the peer
2258 * @param address address associated with the request
2259 * @param session session associated with the request
2260 * @param result #GNUNET_OK if the connection is allowed,
2261 * #GNUNET_NO if not,
2262 * #GNUNET_SYSERR if operation was aborted
2263 */
2264static void
2265try_connect_bl_check_cont (void *cls,
2266 const struct GNUNET_PeerIdentity *peer,
2267 const struct GNUNET_HELLO_Address *address,
2268 struct GNUNET_ATS_Session *session,
2269 int result)
2270{
2271 struct BlacklistCheckSwitchContext *blc_ctx = cls;
2272 struct NeighbourMapEntry *n;
2273
2274 GNUNET_CONTAINER_DLL_remove (pending_bc_head,
2275 pending_bc_tail,
2276 blc_ctx);
2277 GNUNET_free (blc_ctx);
2278 if (GNUNET_OK != result)
2279 {
2280 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2281 _("Blacklisting disapproved to connect to peer `%s'\n"),
2282 GNUNET_i2s (peer));
2283 return;
2284 }
2285
2286 /* Setup a new neighbour */
2287 if (NULL != lookup_neighbour(peer))
2288 return; /* The neighbor was created in the meantime while waited for BL clients */
2289
2290 n = setup_neighbour (peer);
2291
2292 /* Request address suggestions for this peer */
2293 set_state_and_timeout (n,
2294 GNUNET_TRANSPORT_PS_INIT_ATS,
2295 GNUNET_TIME_relative_to_absolute (ATS_RESPONSE_TIMEOUT));
2296}
2297
2298
2299/**
2300 * Try to create a connection to the given target (eventually).
2301 *
2302 * @param target peer to try to connect to
2303 */
2304void
2305GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target)
2306{
2307 struct NeighbourMapEntry *n;
2308 struct GST_BlacklistCheck *blc;
2309 struct BlacklistCheckSwitchContext *blc_ctx;
2310
2311 if (NULL == neighbours)
2312 {
2313 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2314 "Asked to connect to peer `%s' during shutdown\n",
2315 GNUNET_i2s (target));
2316 return; /* during shutdown, do nothing */
2317 }
2318 n = lookup_neighbour (target);
2319 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2320 "Asked to connect to peer `%s' (state: %s)\n",
2321 GNUNET_i2s (target),
2322 (NULL != n) ? GNUNET_TRANSPORT_ps2s(n->state) : "NEW PEER");
2323 if (NULL != n)
2324 {
2325 switch (n->state)
2326 {
2327 case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
2328 /* this should not be possible */
2329 GNUNET_break (0);
2330 free_neighbour (n);
2331 break;
2332 case GNUNET_TRANSPORT_PS_INIT_ATS:
2333 case GNUNET_TRANSPORT_PS_SYN_SENT:
2334 case GNUNET_TRANSPORT_PS_SYN_RECV_ATS:
2335 case GNUNET_TRANSPORT_PS_SYN_RECV_ACK:
2336 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2337 "Ignoring request to try to connect to `%s', already trying!\n",
2338 GNUNET_i2s (target));
2339 return; /* already trying */
2340 case GNUNET_TRANSPORT_PS_CONNECTED:
2341 case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
2342 case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
2343 case GNUNET_TRANSPORT_PS_SWITCH_SYN_SENT:
2344 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2345 "Ignoring request to try to connect, already connected to `%s'!\n",
2346 GNUNET_i2s (target));
2347 return; /* already connected */
2348 case GNUNET_TRANSPORT_PS_DISCONNECT:
2349 /* get rid of remains, ready to re-try immediately */
2350 free_neighbour (n);
2351 break;
2352 case GNUNET_TRANSPORT_PS_DISCONNECT_FINISHED:
2353 /* should not be possible */
2354 GNUNET_assert (0);
2355 return;
2356 default:
2357 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
2358 "Unhandled state `%s'\n",
2359 GNUNET_TRANSPORT_ps2s (n->state));
2360 GNUNET_break (0);
2361 free_neighbour (n);
2362 break;
2363 }
2364 }
2365
2366 /* Do blacklist check if connecting to this peer is allowed */
2367 blc_ctx = GNUNET_new (struct BlacklistCheckSwitchContext);
2368 GNUNET_CONTAINER_DLL_insert (pending_bc_head,
2369 pending_bc_tail,
2370 blc_ctx);
2371
2372 if (NULL !=
2373 (blc = GST_blacklist_test_allowed (target,
2374 NULL,
2375 &try_connect_bl_check_cont,
2376 blc_ctx,
2377 NULL,
2378 NULL)))
2379 {
2380 blc_ctx->blc = blc;
2381 }
2382}
2383
2384
2385/**
2386 * We received a 'SYN' message from the other peer. 2249 * We received a 'SYN' message from the other peer.
2387 * Consider switching to it. 2250 * Consider switching to it.
2388 * 2251 *
diff --git a/src/transport/gnunet-service-transport_neighbours.h b/src/transport/gnunet-service-transport_neighbours.h
index b7864399d..14a6cc830 100644
--- a/src/transport/gnunet-service-transport_neighbours.h
+++ b/src/transport/gnunet-service-transport_neighbours.h
@@ -51,15 +51,6 @@ GST_neighbours_stop (void);
51 51
52 52
53/** 53/**
54 * Try to create a connection to the given target (eventually).
55 *
56 * @param target peer to try to connect to
57 */
58void
59GST_neighbours_try_connect (const struct GNUNET_PeerIdentity *target);
60
61
62/**
63 * Test if we're connected to the given peer. 54 * Test if we're connected to the given peer.
64 * 55 *
65 * @param target peer to test 56 * @param target peer to test