Beginnings of bitswap
This commit is contained in:
parent
cb05b249ba
commit
250b88601a
3 changed files with 84 additions and 0 deletions
8
bitswap/network.c
Normal file
8
bitswap/network.c
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
/***
|
||||||
|
* This implements the BitswapNetwork. Members of this network can fill requests and
|
||||||
|
* smartly handle queues of local and remote requests.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ipfs/bitswap/network.h"
|
||||||
|
|
||||||
|
|
59
include/ipfs/bitswap/network.h
Normal file
59
include/ipfs/bitswap/network.h
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
/***
|
||||||
|
* This implements the BitswapNetwork. Members of this network can fill requests and
|
||||||
|
* smartly handle queues of local and remote requests.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct BitswapRouting {
|
||||||
|
/**
|
||||||
|
* Find the provider of a key asyncronously
|
||||||
|
* @param context the session context
|
||||||
|
* @param hash the key we're looking for
|
||||||
|
* @param forWhat I have yet to research this
|
||||||
|
* @param responseMethod a function pointer to call when results are found
|
||||||
|
* @returns true(1) on success, otherwise false(0)
|
||||||
|
*/
|
||||||
|
int (*FindProviderAsync)(struct SessionContext* context, unsigned char* hash, int forWhat, void (*responseMethod)(void*));
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides the key to the network. Is this an announcement or a fill?
|
||||||
|
* I think it is an announcement
|
||||||
|
* @param context the session context
|
||||||
|
* @param hash the hash to announce
|
||||||
|
* @returns true(1) on success, false(0) on error
|
||||||
|
*/
|
||||||
|
int (*Provide)(struct SessionContext* context, unsigned char* hash);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct BitswapNetwork {
|
||||||
|
/***
|
||||||
|
* Send a message to a particular peer
|
||||||
|
* @param context the context
|
||||||
|
* @param peerId the peer ID of who to send to
|
||||||
|
* @param message the message to send
|
||||||
|
* @returns true(1) on success, false(0) otherwise
|
||||||
|
*/
|
||||||
|
int (*SendMessage)(struct SessionContext* context, unsigned char* peerId, struct BitswapMessage* message);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The BitswapReceiver is who receives messages from the network
|
||||||
|
* @param receiver the struct that contains function pointers for receiving messages
|
||||||
|
* @returns true(1) on success, otherwise false(0)
|
||||||
|
*/
|
||||||
|
int (*SetDelegate)(struct BitswapReceiver* receiver);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt a connection to a particular peer
|
||||||
|
* @param context the session context
|
||||||
|
* @param peerId the id of the peer
|
||||||
|
* @returns true(1) on success, otherwise false(0)
|
||||||
|
*/
|
||||||
|
int (*ConnectTo)(struct SessionContext* context, unsigned char* peerId);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A pointer to the method that creates a new BitswapMessageSender
|
||||||
|
* @param context the session context
|
||||||
|
* @param peerId the peer id of whom we should send the message to.
|
||||||
|
* @reutrns a pointer to the allocated struct that contains the initialized BitswapMessageSender or NULL if there was a problem
|
||||||
|
*/
|
||||||
|
struct BitswapMessageSender* (*NewMessageSender)(struct SessionContext* context, unsigned char* peerId);
|
||||||
|
};
|
17
include/ipfs/bitswap/wantlist.h
Normal file
17
include/ipfs/bitswap/wantlist.h
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/**
|
||||||
|
* This is a list of requests from a peer.
|
||||||
|
* NOTE: This tracks who wants what. If 2 peers want the same file,
|
||||||
|
* there will be 1 WantListEntry in the WantList. There will be 2 entries in
|
||||||
|
* WantListEntry.sessionsRequesting.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct WantListEntry {
|
||||||
|
unsigned char* cid;
|
||||||
|
size_t cid_length;
|
||||||
|
int priority;
|
||||||
|
struct Libp2pVector* sessionsRequesting;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct WantList {
|
||||||
|
struct Libp2pVector* set;
|
||||||
|
};
|
Loading…
Reference in a new issue