From 250b88601a0c307a357ae830b2939d8a1411d85a Mon Sep 17 00:00:00 2001 From: jmjatlanta Date: Thu, 20 Jul 2017 07:57:20 -0500 Subject: [PATCH] Beginnings of bitswap --- bitswap/network.c | 8 +++++ include/ipfs/bitswap/network.h | 59 +++++++++++++++++++++++++++++++++ include/ipfs/bitswap/wantlist.h | 17 ++++++++++ 3 files changed, 84 insertions(+) create mode 100644 bitswap/network.c create mode 100644 include/ipfs/bitswap/network.h create mode 100644 include/ipfs/bitswap/wantlist.h diff --git a/bitswap/network.c b/bitswap/network.c new file mode 100644 index 0000000..f90a570 --- /dev/null +++ b/bitswap/network.c @@ -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" + + diff --git a/include/ipfs/bitswap/network.h b/include/ipfs/bitswap/network.h new file mode 100644 index 0000000..5eac404 --- /dev/null +++ b/include/ipfs/bitswap/network.h @@ -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); +}; diff --git a/include/ipfs/bitswap/wantlist.h b/include/ipfs/bitswap/wantlist.h new file mode 100644 index 0000000..5d1e4f8 --- /dev/null +++ b/include/ipfs/bitswap/wantlist.h @@ -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; +};