Change in secio method signature
This commit is contained in:
parent
82c8911b71
commit
fa7a6826b1
5 changed files with 36 additions and 8 deletions
|
@ -55,7 +55,7 @@ int protocol_compare(const unsigned char* incoming, size_t incoming_size, const
|
||||||
int ipfs_null_marshal(const unsigned char* incoming, size_t incoming_size, struct SessionContext* session, struct null_connection_params *connection_param) {
|
int ipfs_null_marshal(const unsigned char* incoming, size_t incoming_size, struct SessionContext* session, struct null_connection_params *connection_param) {
|
||||||
if (protocol_compare(incoming, incoming_size, "/secio")) {
|
if (protocol_compare(incoming, incoming_size, "/secio")) {
|
||||||
libp2p_logger_debug("null", "Attempting secure io connection...\n");
|
libp2p_logger_debug("null", "Attempting secure io connection...\n");
|
||||||
if (!libp2p_secio_handshake(session, &connection_param->local_node->identity->private_key, 1)) {
|
if (!libp2p_secio_handshake(session, &connection_param->local_node->identity->private_key, connection_param->local_node->peerstore, 1)) {
|
||||||
// rejecting connection
|
// rejecting connection
|
||||||
libp2p_logger_debug("null", "Secure IO connection failed\n");
|
libp2p_logger_debug("null", "Secure IO connection failed\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
int ipfs_bitswap_network_send_message(const struct BitswapContext* context, struct Libp2pPeer* peer, const struct BitswapMessage* message) {
|
int ipfs_bitswap_network_send_message(const struct BitswapContext* context, struct Libp2pPeer* peer, const struct BitswapMessage* message) {
|
||||||
// get a connection to the peer
|
// get a connection to the peer
|
||||||
if (peer->connection_type != CONNECTION_TYPE_CONNECTED) {
|
if (peer->connection_type != CONNECTION_TYPE_CONNECTED) {
|
||||||
libp2p_peer_connect(&context->ipfsNode->identity->private_key, peer, 10);
|
libp2p_peer_connect(&context->ipfsNode->identity->private_key, peer, context->ipfsNode->peerstore, 10);
|
||||||
if(peer->connection_type != CONNECTION_TYPE_CONNECTED)
|
if(peer->connection_type != CONNECTION_TYPE_CONNECTED)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -78,8 +78,36 @@ int ipfs_bitswap_network_handle_message(const struct IpfsNode* node, const struc
|
||||||
// wantlist - what they want
|
// wantlist - what they want
|
||||||
if (message->wantlist != NULL && message->wantlist->entries != NULL && message->wantlist->entries->total > 0) {
|
if (message->wantlist != NULL && message->wantlist->entries != NULL && message->wantlist->entries->total > 0) {
|
||||||
// get the peer
|
// get the peer
|
||||||
struct Libp2pPeer* peer = libp2p_peerstore_get_peer(node->peerstore, (unsigned char*)sessionContext->remote_peer_id, strlen(sessionContext->remote_peer_id));
|
if (sessionContext->remote_peer_id == NULL) {
|
||||||
|
ipfs_bitswap_message_free(message);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
struct Libp2pPeer* temp_peer = libp2p_peer_new();
|
||||||
|
temp_peer->id_size = strlen(sessionContext->remote_peer_id);
|
||||||
|
temp_peer->id = malloc(temp_peer->id_size);
|
||||||
|
if (temp_peer->id == NULL) {
|
||||||
|
libp2p_peer_free(temp_peer);
|
||||||
|
ipfs_bitswap_message_free(message);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
memcpy(temp_peer->id, sessionContext->remote_peer_id, strlen(sessionContext->remote_peer_id));
|
||||||
|
struct Libp2pPeer* peer = libp2p_peerstore_get_or_add_peer(node->peerstore, temp_peer);
|
||||||
|
libp2p_peer_free(temp_peer);
|
||||||
|
if (peer == NULL) {
|
||||||
|
ipfs_bitswap_message_free(message);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
struct PeerRequestEntry* queueEntry = ipfs_bitswap_peer_request_queue_find_entry(bitswapContext->peerRequestQueue, peer);
|
struct PeerRequestEntry* queueEntry = ipfs_bitswap_peer_request_queue_find_entry(bitswapContext->peerRequestQueue, peer);
|
||||||
|
if (queueEntry == NULL) {
|
||||||
|
struct PeerRequest* peerRequest =ipfs_bitswap_peer_request_new();
|
||||||
|
peerRequest->peer = peer;
|
||||||
|
ipfs_bitswap_peer_request_queue_add(bitswapContext->peerRequestQueue, peerRequest);
|
||||||
|
queueEntry = ipfs_bitswap_peer_request_queue_find_entry(bitswapContext->peerRequestQueue, peer);
|
||||||
|
if (queueEntry == NULL) {
|
||||||
|
ipfs_bitswap_message_free(message);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
for(int i = 0; i < message->wantlist->entries->total; i++) {
|
for(int i = 0; i < message->wantlist->entries->total; i++) {
|
||||||
struct WantlistEntry* entry = (struct WantlistEntry*) libp2p_utils_vector_get(message->wantlist->entries, i);
|
struct WantlistEntry* entry = (struct WantlistEntry*) libp2p_utils_vector_get(message->wantlist->entries, i);
|
||||||
// turn the "block" back into a cid
|
// turn the "block" back into a cid
|
||||||
|
|
|
@ -215,7 +215,7 @@ int ipfs_bitswap_peer_request_process_entry(const struct BitswapContext* context
|
||||||
if (need_to_connect) {
|
if (need_to_connect) {
|
||||||
if (!connected) {
|
if (!connected) {
|
||||||
// connect
|
// connect
|
||||||
connected = libp2p_peer_connect(&context->ipfsNode->identity->private_key, request->peer, 0);
|
connected = libp2p_peer_connect(&context->ipfsNode->identity->private_key, request->peer, context->ipfsNode->peerstore, 0);
|
||||||
}
|
}
|
||||||
if (connected) {
|
if (connected) {
|
||||||
// build a message
|
// build a message
|
||||||
|
|
|
@ -294,7 +294,7 @@ int ipfs_routing_online_ping(struct IpfsRouting* routing, struct Libp2pPeer* pee
|
||||||
size_t protobuf_size;
|
size_t protobuf_size;
|
||||||
|
|
||||||
if (peer->connection_type != CONNECTION_TYPE_CONNECTED) {
|
if (peer->connection_type != CONNECTION_TYPE_CONNECTED) {
|
||||||
if (!libp2p_peer_connect(&routing->local_node->identity->private_key, peer, 5))
|
if (!libp2p_peer_connect(&routing->local_node->identity->private_key, peer, routing->local_node->peerstore, 5))
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (peer->connection_type == CONNECTION_TYPE_CONNECTED) {
|
if (peer->connection_type == CONNECTION_TYPE_CONNECTED) {
|
||||||
|
@ -414,7 +414,7 @@ int ipfs_routing_online_get_value (ipfs_routing* routing, const unsigned char *k
|
||||||
if (!libp2p_peer_is_connected(current_peer)) {
|
if (!libp2p_peer_is_connected(current_peer)) {
|
||||||
// attempt to connect. If unsuccessful, continue in the loop.
|
// attempt to connect. If unsuccessful, continue in the loop.
|
||||||
libp2p_logger_debug("online", "Attempting to connect to peer to retrieve file\n");
|
libp2p_logger_debug("online", "Attempting to connect to peer to retrieve file\n");
|
||||||
if (libp2p_peer_connect(&routing->local_node->identity->private_key, current_peer, 5)) {
|
if (libp2p_peer_connect(&routing->local_node->identity->private_key, current_peer, routing->local_node->peerstore, 5)) {
|
||||||
libp2p_logger_debug("online", "Peer connected\n");
|
libp2p_logger_debug("online", "Peer connected\n");
|
||||||
if (ipfs_routing_online_get_peer_value(routing, current_peer, key, key_size, buffer, buffer_size)) {
|
if (ipfs_routing_online_get_peer_value(routing, current_peer, key, key_size, buffer, buffer_size)) {
|
||||||
libp2p_logger_debug("online", "Retrieved a value\n");
|
libp2p_logger_debug("online", "Retrieved a value\n");
|
||||||
|
@ -487,7 +487,7 @@ int ipfs_routing_online_bootstrap(struct IpfsRouting* routing) {
|
||||||
return -1; // this should never happen
|
return -1; // this should never happen
|
||||||
}
|
}
|
||||||
if (peer->sessionContext == NULL) { // should always be true unless we added it twice (TODO: we should prevent that earlier)
|
if (peer->sessionContext == NULL) { // should always be true unless we added it twice (TODO: we should prevent that earlier)
|
||||||
libp2p_peer_connect(&routing->local_node->identity->private_key, peer, 5);
|
libp2p_peer_connect(&routing->local_node->identity->private_key, peer, routing->local_node->peerstore, 5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,7 +233,7 @@ int test_routing_find_providers() {
|
||||||
struct Libp2pPeer *remote_peer = NULL;
|
struct Libp2pPeer *remote_peer = NULL;
|
||||||
for(int i = 0; i < result->total; i++) {
|
for(int i = 0; i < result->total; i++) {
|
||||||
remote_peer = (struct Libp2pPeer*)libp2p_utils_vector_get(result, i);
|
remote_peer = (struct Libp2pPeer*)libp2p_utils_vector_get(result, i);
|
||||||
if (remote_peer->connection_type == CONNECTION_TYPE_CONNECTED || libp2p_peer_connect(&local_node.identity->private_key, remote_peer, 5)) {
|
if (remote_peer->connection_type == CONNECTION_TYPE_CONNECTED || libp2p_peer_connect(&local_node.identity->private_key, remote_peer, local_node.peerstore, 5)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
remote_peer = NULL;
|
remote_peer = NULL;
|
||||||
|
|
Loading…
Reference in a new issue