2017-02-23 20:15:33 +00:00
|
|
|
#pragma once
|
2017-02-03 01:15:28 +00:00
|
|
|
|
2017-04-03 22:26:33 +00:00
|
|
|
#include "libp2p/peer/peer.h"
|
2017-02-23 20:15:33 +00:00
|
|
|
#include "libp2p/crypto/rsa.h"
|
|
|
|
#include "libp2p/record/message.h"
|
2017-02-27 17:27:40 +00:00
|
|
|
#include "ipfs/core/ipfs_node.h"
|
2017-02-03 01:15:28 +00:00
|
|
|
|
2017-02-23 20:15:33 +00:00
|
|
|
// offlineRouting implements the IpfsRouting interface,
|
|
|
|
// but only provides the capability to Put and Get signed dht
|
|
|
|
// records to and from the local datastore.
|
2017-04-03 16:55:36 +00:00
|
|
|
struct IpfsRouting {
|
2017-02-27 17:27:40 +00:00
|
|
|
struct IpfsNode* local_node;
|
2017-02-23 20:15:33 +00:00
|
|
|
size_t ds_len;
|
|
|
|
struct RsaPrivateKey* sk;
|
|
|
|
struct Stream* stream;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Put a value in the datastore
|
|
|
|
* @param 1 the struct that contains connection information
|
|
|
|
* @param 2 the key
|
|
|
|
* @param 3 the size of the key
|
|
|
|
* @param 4 the value
|
|
|
|
* @param 5 the size of the value
|
|
|
|
* @returns 0 on success, otherwise -1
|
|
|
|
*/
|
2017-04-20 22:56:03 +00:00
|
|
|
int (*PutValue) (struct IpfsRouting*, const unsigned char*, size_t, const void*, size_t);
|
2017-02-23 20:15:33 +00:00
|
|
|
/**
|
2017-04-20 22:56:03 +00:00
|
|
|
* Get a value from the filestore
|
2017-02-23 20:15:33 +00:00
|
|
|
* @param 1 the struct that contains the connection information
|
|
|
|
* @param 2 the key to look for
|
|
|
|
* @param 3 the size of the key
|
|
|
|
* @param 4 a place to store the value
|
|
|
|
* @param 5 the size of the value
|
|
|
|
*/
|
2017-04-20 22:56:03 +00:00
|
|
|
int (*GetValue) (struct IpfsRouting*, const unsigned char*, size_t, void**, size_t*);
|
2017-02-23 20:15:33 +00:00
|
|
|
/**
|
|
|
|
* Find a provider
|
2017-04-17 04:47:53 +00:00
|
|
|
* @param routing the context
|
|
|
|
* @param key the information that is being looked for
|
|
|
|
* @param key_size the size of param 2
|
|
|
|
* @param peers a vector of peers found that can provide the value for the key
|
|
|
|
* @returns true(1) on success, otherwise false(0)
|
2017-02-23 20:15:33 +00:00
|
|
|
*/
|
2017-04-20 22:56:03 +00:00
|
|
|
int (*FindProviders) (struct IpfsRouting* routing, const unsigned char* key, size_t key_size, struct Libp2pVector** peers);
|
2017-02-23 20:15:33 +00:00
|
|
|
/**
|
|
|
|
* Find a peer
|
2017-03-19 12:47:19 +00:00
|
|
|
* @param 1 the context
|
|
|
|
* @param 2 the peer to look for
|
|
|
|
* @param 3 the size of the peer char array
|
|
|
|
* @param 4 the results
|
|
|
|
* @param 5 the size of the results
|
2017-04-03 16:55:36 +00:00
|
|
|
* @returns 0 or error code
|
2017-02-23 20:15:33 +00:00
|
|
|
*/
|
2017-04-20 22:56:03 +00:00
|
|
|
int (*FindPeer) (struct IpfsRouting*, const unsigned char*, size_t, struct Libp2pPeer** result);
|
2017-02-23 20:15:33 +00:00
|
|
|
/**
|
2017-03-19 12:47:19 +00:00
|
|
|
* Announce to the network that this host can provide this key
|
|
|
|
* @param 1 the context
|
|
|
|
* @param 2 the key
|
|
|
|
* @param 3 the key size
|
|
|
|
* @returns true(1) on success, otherwise false(0)
|
|
|
|
*/
|
2017-04-20 22:56:03 +00:00
|
|
|
int (*Provide) (struct IpfsRouting*, const unsigned char*, size_t);
|
2017-03-19 12:47:19 +00:00
|
|
|
/**
|
|
|
|
* Ping
|
|
|
|
* @param routing the context
|
2017-04-03 22:26:33 +00:00
|
|
|
* @param peer the peer
|
2017-03-19 12:47:19 +00:00
|
|
|
* @returns true(1) on success, otherwise false(0)
|
|
|
|
*/
|
2017-04-03 22:26:33 +00:00
|
|
|
int (*Ping) (struct IpfsRouting* routing, struct Libp2pPeer* peer);
|
2017-03-19 12:47:19 +00:00
|
|
|
/**
|
|
|
|
* Get everything going
|
|
|
|
* @param routing the context
|
|
|
|
* @returns true(1) on success, otherwise false(0)
|
2017-02-23 20:15:33 +00:00
|
|
|
*/
|
2017-04-03 16:55:36 +00:00
|
|
|
int (*Bootstrap) (struct IpfsRouting*);
|
2017-07-17 18:05:56 +00:00
|
|
|
void* (*Listen) (void*);
|
2017-07-07 02:51:53 +00:00
|
|
|
int (*Shutdown) ();
|
2017-02-23 20:15:33 +00:00
|
|
|
};
|
2017-04-03 16:55:36 +00:00
|
|
|
typedef struct IpfsRouting ipfs_routing;
|
2017-02-23 20:15:33 +00:00
|
|
|
|
|
|
|
// offline routing routines.
|
2017-02-27 17:27:40 +00:00
|
|
|
ipfs_routing* ipfs_routing_new_offline (struct IpfsNode* local_node, struct RsaPrivateKey *private_key);
|
2017-03-09 23:03:21 +00:00
|
|
|
// online using secio, should probably be deprecated
|
2017-02-27 17:27:40 +00:00
|
|
|
ipfs_routing* ipfs_routing_new_online (struct IpfsNode* local_node, struct RsaPrivateKey* private_key, struct Stream* stream);
|
2017-04-17 16:58:47 +00:00
|
|
|
int ipfs_routing_online_free(ipfs_routing*);
|
2017-03-09 23:03:21 +00:00
|
|
|
// online using DHT/kademlia, the recommended router
|
|
|
|
ipfs_routing* ipfs_routing_new_kademlia(struct IpfsNode* local_node, struct RsaPrivateKey* private_key, struct Stream* stream);
|
|
|
|
// generic routines
|
2017-04-20 22:56:03 +00:00
|
|
|
int ipfs_routing_generic_put_value (ipfs_routing* offlineRouting, const unsigned char *key, size_t key_size, const void *val, size_t vlen);
|
|
|
|
int ipfs_routing_generic_get_value (ipfs_routing* offlineRouting, const unsigned char *key, size_t key_size, void **val, size_t *vlen);
|
2017-02-03 01:15:28 +00:00
|
|
|
|
2017-03-19 12:47:19 +00:00
|
|
|
// supernode
|
2017-03-19 13:05:25 +00:00
|
|
|
int ipfs_routing_supernode_parse_provider(const unsigned char* in, size_t in_size, struct Libp2pLinkedList** multiaddresses);
|