From 8da685b5cf22aed353d426708e6081e2b070a9bc Mon Sep 17 00:00:00 2001 From: Jose Marcial Vieira Bisneto Date: Thu, 6 Jul 2017 23:02:11 -0300 Subject: [PATCH] Implemented timeout to avoid hang due to connection error. --- routing/online.c | 6 +++--- test/routing/test_routing.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/routing/online.c b/routing/online.c index d070ccc..06d9966 100644 --- a/routing/online.c +++ b/routing/online.c @@ -292,7 +292,7 @@ int ipfs_routing_online_ping(struct IpfsRouting* routing, struct Libp2pPeer* pee size_t protobuf_size; if (peer->connection_type != CONNECTION_TYPE_CONNECTED) { - if (!libp2p_peer_connect(peer)) + if (!libp2p_peer_connect(peer, 5)) return 0; } if (peer->connection_type == CONNECTION_TYPE_CONNECTED) { @@ -412,7 +412,7 @@ int ipfs_routing_online_get_value (ipfs_routing* routing, const unsigned char *k if (!libp2p_peer_is_connected(current_peer)) { // attempt to connect. If unsuccessful, continue in the loop. libp2p_logger_debug("online", "Attempting to connect to peer to retrieve file\n"); - if (libp2p_peer_connect(current_peer)) { + if (libp2p_peer_connect(current_peer, 5)) { libp2p_logger_debug("online", "Peer connected\n"); if (ipfs_routing_online_get_peer_value(routing, current_peer, key, key_size, buffer, buffer_size)) { libp2p_logger_debug("online", "Retrieved a value\n"); @@ -485,7 +485,7 @@ int ipfs_routing_online_bootstrap(struct IpfsRouting* routing) { return -1; // this should never happen } if (peer->connection == NULL) { // should always be true unless we added it twice (TODO: we should prevent that earlier) - libp2p_peer_connect(peer); + libp2p_peer_connect(peer, 5); } } } diff --git a/test/routing/test_routing.h b/test/routing/test_routing.h index 0dd5b0f..e99fe0a 100644 --- a/test/routing/test_routing.h +++ b/test/routing/test_routing.h @@ -230,7 +230,7 @@ int test_routing_find_providers() { struct Libp2pPeer *remote_peer = NULL; for(int i = 0; i < result->total; i++) { remote_peer = libp2p_utils_vector_get(result, i); - if (remote_peer->connection_type == CONNECTION_TYPE_CONNECTED || libp2p_peer_connect(remote_peer)) { + if (remote_peer->connection_type == CONNECTION_TYPE_CONNECTED || libp2p_peer_connect(remote_peer, 5)) { break; } remote_peer = NULL;