New way of swarm connection
This commit is contained in:
parent
91f5c50a71
commit
f9bec0ac20
14 changed files with 52 additions and 49 deletions
|
@ -6,6 +6,7 @@
|
|||
#include <pthread.h>
|
||||
#include "libp2p/os/utils.h"
|
||||
#include "libp2p/utils/logger.h"
|
||||
#include "libp2p/net/stream.h"
|
||||
#include "ipfs/core/ipfs_node.h"
|
||||
#include "ipfs/datastore/ds_helper.h"
|
||||
#include "ipfs/exchange/exchange.h"
|
||||
|
@ -15,9 +16,9 @@
|
|||
#include "ipfs/exchange/bitswap/peer_request_queue.h"
|
||||
#include "ipfs/exchange/bitswap/want_manager.h"
|
||||
|
||||
int ipfs_bitswap_can_handle(const uint8_t* incoming, size_t incoming_size) {
|
||||
char* result = strnstr((char*)incoming, "/ipfs/bitswap", incoming_size);
|
||||
if(result == NULL || result != (char*)incoming)
|
||||
int ipfs_bitswap_can_handle(const struct StreamMessage* msg) {
|
||||
char* result = strnstr((char*)msg->data, "/ipfs/bitswap", msg->data_size);
|
||||
if(result == NULL || result != (char*)msg->data)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
@ -34,9 +35,9 @@ int ipfs_bitswap_shutdown_handler(void* context) {
|
|||
* @param protocol_context the protocol-dependent context
|
||||
* @returns 0 if the caller should not continue looping, <0 on error, >0 on success
|
||||
*/
|
||||
int ipfs_bitswap_handle_message(const uint8_t* incoming, size_t incoming_size, struct SessionContext* session_context, void* protocol_context) {
|
||||
int ipfs_bitswap_handle_message(const struct StreamMessage* msg, struct SessionContext* session_context, void* protocol_context) {
|
||||
struct IpfsNode* local_node = (struct IpfsNode*)protocol_context;
|
||||
int retVal = ipfs_bitswap_network_handle_message(local_node, session_context, incoming, incoming_size);
|
||||
int retVal = ipfs_bitswap_network_handle_message(local_node, session_context, msg->data, msg->data_size);
|
||||
if (retVal == 0)
|
||||
return -1;
|
||||
return retVal;
|
||||
|
|
|
@ -108,7 +108,7 @@ void* ipfs_bitswap_engine_peer_request_processor_start(void* ctx) {
|
|||
if (current_peer_entry->sessionContext->default_stream->read(current_peer_entry->sessionContext, &buffer, 1)) {
|
||||
// handle it
|
||||
libp2p_logger_debug("bitswap_engine", "%lu bytes read, result: [%s].\n", buffer->data_size, buffer->data);
|
||||
int retVal = libp2p_protocol_marshal(buffer->data, buffer->data_size, current_peer_entry->sessionContext, context->ipfsNode->protocol_handlers);
|
||||
int retVal = libp2p_protocol_marshal(buffer, current_peer_entry->sessionContext, context->ipfsNode->protocol_handlers);
|
||||
libp2p_stream_message_free(buffer);
|
||||
did_some_processing = 1;
|
||||
if (retVal == -1) {
|
||||
|
|
|
@ -21,7 +21,7 @@ int ipfs_bitswap_network_send_message(const struct BitswapContext* context, stru
|
|||
libp2p_logger_debug("bitswap_network", "Sending bitswap message to %s.\n", libp2p_peer_id_to_string(peer));
|
||||
// get a connection to the peer
|
||||
if (peer->connection_type != CONNECTION_TYPE_CONNECTED || peer->sessionContext == NULL) {
|
||||
libp2p_peer_connect(&context->ipfsNode->identity->private_key, peer, context->ipfsNode->peerstore, context->ipfsNode->repo->config->datastore, 10);
|
||||
libp2p_peer_connect(context->ipfsNode->dialer, peer, context->ipfsNode->peerstore, context->ipfsNode->repo->config->datastore, 10);
|
||||
if(peer->connection_type != CONNECTION_TYPE_CONNECTED)
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -384,7 +384,7 @@ int ipfs_bitswap_peer_request_process_entry(const struct BitswapContext* context
|
|||
if (need_to_connect) {
|
||||
if (!connected) {
|
||||
// connect
|
||||
connected = libp2p_peer_connect(&context->ipfsNode->identity->private_key, request->peer, context->ipfsNode->peerstore, context->ipfsNode->repo->config->datastore, 0);
|
||||
connected = libp2p_peer_connect(context->ipfsNode->dialer, request->peer, context->ipfsNode->peerstore, context->ipfsNode->repo->config->datastore, 0);
|
||||
}
|
||||
if (connected) {
|
||||
// build a message
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue