2017-07-24 21:03:56 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-07-24 19:56:30 +00:00
|
|
|
/***
|
|
|
|
* Bitswap implements the exchange "interface"
|
|
|
|
* @see ../exchange.h
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ipfs/core/ipfs_node.h"
|
|
|
|
#include "ipfs/exchange/exchange.h"
|
2017-07-27 13:38:57 +00:00
|
|
|
#include "ipfs/exchange/bitswap/engine.h"
|
2017-07-24 19:56:30 +00:00
|
|
|
|
2017-07-20 20:03:49 +00:00
|
|
|
struct BitswapContext {
|
2017-07-24 19:56:30 +00:00
|
|
|
struct IpfsNode* ipfsNode;
|
2017-07-24 22:58:39 +00:00
|
|
|
struct WantListQueue* localWantlist;
|
2017-07-27 13:38:57 +00:00
|
|
|
struct PeerRequestQueue* peerRequestQueue;
|
|
|
|
struct BitswapEngine* bitswap_engine;
|
2017-07-20 20:03:49 +00:00
|
|
|
};
|
|
|
|
|
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-20 20:03:49 +00:00
|
|
|
|
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-20 20:03:49 +00:00
|
|
|
|
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-20 20:03:49 +00:00
|
|
|
|
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-07-20 20:03:49 +00:00
|
|
|
|
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);
|