From 407f85bc89b93076adaadb31d1df32c041f56197 Mon Sep 17 00:00:00 2001 From: John Jones Date: Thu, 31 Aug 2017 16:41:10 -0500 Subject: [PATCH] More testing and compat fixes for ipfs --- core/ipfs_node.c | 3 +++ core/null.c | 2 +- exchange/bitswap/engine.c | 4 ++-- repo/fsrepo/lmdb_datastore.c | 3 ++- repo/fsrepo/lmdb_journalstore.c | 3 ++- test/exchange/test_bitswap.h | 7 ++++++- 6 files changed, 16 insertions(+), 6 deletions(-) diff --git a/core/ipfs_node.c b/core/ipfs_node.c index dc262b1..1d9ed5b 100644 --- a/core/ipfs_node.c +++ b/core/ipfs_node.c @@ -1,5 +1,6 @@ #include +#include "libp2p/net/multistream.h" #include "libp2p/utils/vector.h" #include "libp2p/secio/secio.h" #include "libp2p/routing/dht_protocol.h" @@ -18,6 +19,8 @@ struct Libp2pVector* ipfs_node_online_build_protocol_handlers(struct IpfsNode* n libp2p_utils_vector_add(retVal, libp2p_routing_dht_build_protocol_handler(node->peerstore, node->providerstore)); // bitswap libp2p_utils_vector_add(retVal, ipfs_bitswap_build_protocol_handler(node)); + // multistream + libp2p_utils_vector_add(retVal, libp2p_net_multistream_build_protocol_handler(node)); } return retVal; } diff --git a/core/null.c b/core/null.c index c184567..2e80ded 100644 --- a/core/null.c +++ b/core/null.c @@ -159,7 +159,7 @@ int ipfs_null_do_maintenance(struct IpfsNode* local_node, struct Libp2pPeer* pee } else { if (peer->sessionContext != NULL && os_utils_gmtime() - peer->sessionContext->last_comm_epoch > 180) { // try a ping, but only if we're connected - libp2p_logger_debug("null", "Attempting ping of %s.\n", peer->id); + libp2p_logger_debug("null", "Attempting ping of %s.\n", libp2p_peer_id_to_string(peer)); if (peer->connection_type == CONNECTION_TYPE_CONNECTED && !local_node->routing->Ping(local_node->routing, peer)) { libp2p_logger_debug("null", "Attempted ping of %s failed.\n", peer->id); peer->connection_type = CONNECTION_TYPE_NOT_CONNECTED; diff --git a/exchange/bitswap/engine.c b/exchange/bitswap/engine.c index 0fd00d1..f523153 100644 --- a/exchange/bitswap/engine.c +++ b/exchange/bitswap/engine.c @@ -85,13 +85,13 @@ void* ipfs_bitswap_engine_peer_request_processor_start(void* ctx) { if (current_peer_entry->sessionContext == NULL || current_peer_entry->sessionContext->default_stream == NULL) { current_peer_entry->connection_type = CONNECTION_TYPE_NOT_CONNECTED; } else { - libp2p_logger_debug("bitswap_engine", "We're connected to %s. Lets see if there is a message waiting for us.\n", current_peer_entry->id); + libp2p_logger_debug("bitswap_engine", "We're connected to %s. Lets see if there is a message waiting for us.\n", libp2p_peer_id_to_string(current_peer_entry)); int retVal = current_peer_entry->sessionContext->default_stream->peek(current_peer_entry->sessionContext); if (retVal < 0) { libp2p_logger_debug("bitswap_engine", "We thought we were connected, but Peek reported an error.\n"); libp2p_peer_handle_connection_error(current_peer_entry); } else if (retVal > 0) { - libp2p_logger_debug("bitswap_engine", "%d bytes waiting on network for peer %s.\n", retVal, current_peer_entry->id); + libp2p_logger_debug("bitswap_engine", "%d bytes waiting on network for peer %s.\n", retVal, libp2p_peer_id_to_string(current_peer_entry)); unsigned char* buffer = NULL; size_t buffer_len = 0; if (current_peer_entry->sessionContext->default_stream->read(current_peer_entry->sessionContext, &buffer, &buffer_len, 1)) { diff --git a/repo/fsrepo/lmdb_datastore.c b/repo/fsrepo/lmdb_datastore.c index dce6db2..0015b5e 100644 --- a/repo/fsrepo/lmdb_datastore.c +++ b/repo/fsrepo/lmdb_datastore.c @@ -75,7 +75,8 @@ int repo_fsrepo_lmdb_build_record(MDB_val *key, MDB_val *value, struct Datastore *record = NULL; return 0; } - memcpy(rec->value, &value->mv_data[varint_size], rec->value_size); + uint8_t *val = (uint8_t*) value->mv_data; + memcpy(rec->value, &val[varint_size], rec->value_size); } return 1; } diff --git a/repo/fsrepo/lmdb_journalstore.c b/repo/fsrepo/lmdb_journalstore.c index c1b8cd7..ffaecf2 100644 --- a/repo/fsrepo/lmdb_journalstore.c +++ b/repo/fsrepo/lmdb_journalstore.c @@ -140,7 +140,8 @@ int repo_journalstore_cursor_get(struct Datastore* datastore, void* crsr, enum D rec->pin = ((uint8_t*)mdb_value.mv_data)[0]; rec->hash_size = mdb_value.mv_size - 1; rec->hash = malloc(rec->hash_size); - memcpy(rec->hash, &mdb_value.mv_data[1], rec->hash_size); + uint8_t *val = (uint8_t*)mdb_value.mv_data; + memcpy(rec->hash, &val[1], rec->hash_size); return 1; } return 0; diff --git a/test/exchange/test_bitswap.h b/test/exchange/test_bitswap.h index 1685827..5e6fcac 100644 --- a/test/exchange/test_bitswap.h +++ b/test/exchange/test_bitswap.h @@ -269,7 +269,7 @@ int test_bitswap_retrieve_file_known_remote() { */ int remote_port = 4001; // mac - char* remote_peer_id = "QmZVoAZGFfinB7MQQiDzB84kWaDPQ95GLuXdemJFM2r9b4"; + char* remote_peer_id = "QmPTDqsHMn3GkLBUHBofB5M6wBGzLwHAxqZpLvcda6hF6Q"; char* remote_ip = "10.211.55.2"; // linux //char* remote_peer_id = "QmRKm1d9kSCRpMFtLYpfhhCQ3DKuSSPJa3qn9wWXfwnWnY"; @@ -288,6 +288,9 @@ int test_bitswap_retrieve_file_known_remote() { libp2p_logger_add_class("online"); libp2p_logger_add_class("multistream"); libp2p_logger_add_class("secio"); + libp2p_logger_add_class("bitswap"); + libp2p_logger_add_class("bitswap_engine"); + libp2p_logger_add_class("bitswap_network"); char* ipfs_path = "/tmp/test1"; char* peer_id_1 = NULL, *peer_id_2 = NULL; @@ -314,6 +317,8 @@ int test_bitswap_retrieve_file_known_remote() { if (!ipfs_cid_decode_hash_from_base58((unsigned char*)hello_world_hash, strlen(hello_world_hash), &cid)) goto exit; + sleep(300); + // this does the heavy lifting... if (!ipfs_node2->exchange->GetBlock(ipfs_node2->exchange, cid, &result)) { libp2p_logger_error("test_bitswap", "GetBlock returned false\n");