c-ipfs/include/ipfs/exchange/bitswap/bitswap.h

90 lines
2.8 KiB
C
Raw Permalink Normal View History

2017-07-24 21:03:56 +00:00
#pragma once
2017-07-24 19:56:30 +00:00
/***
* Bitswap implements the "exchange" and "Libp2pProtocolHandler" interfaces
2017-07-24 19:56:30 +00:00
* @see ../exchange.h
* @see libp2p/net/protocol.h
2017-07-24 19:56:30 +00:00
*/
#include "libp2p/net/protocol.h"
2017-07-24 19:56:30 +00:00
#include "ipfs/core/ipfs_node.h"
#include "ipfs/exchange/exchange.h"
#include "ipfs/exchange/bitswap/engine.h"
2017-08-31 11:41:54 +00:00
#include "ipfs/exchange/bitswap/wantlist_queue.h"
2017-07-24 19:56:30 +00:00
struct Libp2pProtocolHandler* ipfs_bitswap_build_protocol_handler(const struct IpfsNode* local_node);
struct BitswapContext {
2017-07-24 19:56:30 +00:00
struct IpfsNode* ipfsNode;
2017-07-24 22:58:39 +00:00
struct WantListQueue* localWantlist;
struct PeerRequestQueue* peerRequestQueue;
struct BitswapEngine* bitswap_engine;
};
2017-07-24 19:56:30 +00:00
/**
* Start up the bitswap exchange
2017-07-26 14:48:04 +00:00
* @param ipfsNode the context
2017-07-24 19:56:30 +00:00
* @returns an Exchange struct that refers to the exchange
*/
2017-07-27 17:05:41 +00:00
struct Exchange* ipfs_bitswap_new(struct IpfsNode* ipfsNode);
2017-07-24 19:56:30 +00:00
/***
* These are the implementation methods for the exchange "Interface"
*/
/***
* Checks to see if the Bitswap service is online
* @param exhcnageContext a pointer to a BitswapContext
* @reutrns true(1) if online, false(0) otherwise.
*/
2017-07-26 14:48:04 +00:00
int ipfs_bitswap_is_online(struct Exchange* exchange);
2017-07-24 19:56:30 +00:00
/***
* Closes down the Bitswap network
* @param exchangeContext a pointer to a BitswapContext
* @returns true(1)
*/
2017-07-26 14:48:04 +00:00
int ipfs_bitswap_close(struct Exchange* exchange);
2017-07-24 19:56:30 +00:00
/****
* Notify the BitswapNetwork that we have this block
* @param exchangeContext a pointer to a BitswapContext
* @block the block that we have
* @reutrns true(1) if successful, false(0) if not.
*/
2017-07-26 14:48:04 +00:00
int ipfs_bitswap_has_block(struct Exchange* exchange, struct Block* block);
2017-07-24 19:56:30 +00:00
/**
* Retrieve a block from the BitswapNetwork
* Note: This may pull the file from the local blockstore.
* Note: If false(0) is returned, block will be NULL
*
* @param exchangeContext a pointer to a BitswapContext
* @param cid the Cid of the block we're looking for
* @param block a pointer to the block when we find it.
* @returns true(1) on success, false(0) otherwise.
*/
2017-07-26 14:48:04 +00:00
int ipfs_bitswap_get_block(struct Exchange* exchange, struct Cid* cid, struct Block** block);
2017-08-31 11:41:54 +00:00
/**
* Retrieve a block from the BitswapNetwork
*
* @param exchangeContext a pointer to a BitswapContext
* @param cid the Cid of the block we're looking for
* @param queue a pointer to the queue that will change if the block arrives
* @returns true(1) on success, false(0) otherwise.
*/
int ipfs_bitswap_get_block_async(struct Exchange* exchange, struct Cid* cid, struct Block** block);
2017-07-24 19:56:30 +00:00
/***
* Retrieve a collection of blocks from the BitswapNetwork
* Note: The return of false(0) means that not all blocks were found.
*
* @param exchangeContext a pointer to a BitswapContext
* @param cids a collection of Cid structs
* @param blocks a collection that contains the results.
* @param true(1) on success, false(0) otherwise
*/
2017-07-26 14:48:04 +00:00
int ipfs_bitswap_get_blocks(struct Exchange* exchange, struct Libp2pVector* cids, struct Libp2pVector** blocks);