IPFS protocols now implement an interface to make marshalling easier
This commit is contained in:
parent
c58134db1c
commit
ced96dcf81
6 changed files with 63 additions and 17 deletions
|
@ -8,9 +8,39 @@
|
|||
#include "ipfs/exchange/exchange.h"
|
||||
#include "ipfs/exchange/bitswap/bitswap.h"
|
||||
#include "ipfs/exchange/bitswap/message.h"
|
||||
#include "ipfs/exchange/bitswap/network.h"
|
||||
#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) {
|
||||
if (incoming_size < 8)
|
||||
return 0;
|
||||
char* result = strstr((char*)incoming, "/ipfs/bitswap");
|
||||
if(result == NULL || result != (char*)incoming)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ipfs_bitswap_shutdown_handler(void* context) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int ipfs_bitswap_handle_message(const uint8_t* incoming, size_t incoming_size, struct SessionContext* session_context, void* protocol_context) {
|
||||
struct IpfsNode* local_node = (struct IpfsNode*)protocol_context;
|
||||
return ipfs_bitswap_network_handle_message(local_node, session_context, incoming, incoming_size);
|
||||
}
|
||||
|
||||
struct Libp2pProtocolHandler* ipfs_bitswap_build_protocol_handler(const struct IpfsNode* local_node) {
|
||||
struct Libp2pProtocolHandler* handler = (struct Libp2pProtocolHandler*) malloc(sizeof(struct Libp2pProtocolHandler));
|
||||
if (handler != NULL) {
|
||||
handler->context = (void*)local_node;
|
||||
handler->CanHandle = ipfs_bitswap_can_handle;
|
||||
handler->HandleMessage = ipfs_bitswap_handle_message;
|
||||
handler->Shutdown = ipfs_bitswap_shutdown_handler;
|
||||
}
|
||||
return handler;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new bitswap exchange
|
||||
* @param sessionContext the context
|
||||
|
|
|
@ -96,7 +96,7 @@ void* ipfs_bitswap_engine_peer_request_processor_start(void* ctx) {
|
|||
size_t buffer_len = 0;
|
||||
if (current_peer_entry->sessionContext->default_stream->read(current_peer_entry->sessionContext, &buffer, &buffer_len, 1)) {
|
||||
// handle it
|
||||
int retVal = ipfs_multistream_marshal(buffer, buffer_len, current_peer_entry->sessionContext, context->ipfsNode);
|
||||
int retVal = libp2p_protocol_marshal(buffer, buffer_len, current_peer_entry->sessionContext, context->ipfsNode->protocol_handlers);
|
||||
free(buffer);
|
||||
did_some_processing = 1;
|
||||
if (retVal == -1) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue