2017-03-19 19:39:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
2017-07-31 17:49:41 +00:00
|
|
|
#include "libp2p/db/datastore.h"
|
|
|
|
#include "libp2p/peer/peer.h"
|
|
|
|
|
2017-03-30 18:58:53 +00:00
|
|
|
/**
|
|
|
|
* Contains a hash and the peer id of
|
|
|
|
* who can provide it
|
|
|
|
*/
|
2017-03-19 19:39:48 +00:00
|
|
|
struct ProviderEntry {
|
|
|
|
unsigned char* hash;
|
|
|
|
int hash_size;
|
|
|
|
unsigned char* peer_id;
|
|
|
|
int peer_id_size;
|
|
|
|
};
|
|
|
|
|
2017-03-30 18:58:53 +00:00
|
|
|
/***
|
|
|
|
* A structure to store providers. The implementation
|
|
|
|
* is a vector of ProviderEntry structures, which contain
|
|
|
|
* the hash and peer id.
|
|
|
|
*/
|
2017-03-19 19:39:48 +00:00
|
|
|
struct ProviderStore {
|
|
|
|
struct Libp2pVector* provider_entries;
|
2017-07-31 17:49:41 +00:00
|
|
|
// this is requred so we can look locally for requests
|
|
|
|
const struct Datastore* datastore;
|
|
|
|
const struct Libp2pPeer* local_peer;
|
2017-03-19 19:39:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new ProviderStore
|
|
|
|
* @returns a ProviderStore struct
|
|
|
|
*/
|
2017-07-31 17:49:41 +00:00
|
|
|
struct ProviderStore* libp2p_providerstore_new(const struct Datastore* datastore, const struct Libp2pPeer* local_peer);
|
2017-03-19 19:39:48 +00:00
|
|
|
|
|
|
|
/***
|
|
|
|
* Clean resources used by a ProviderStore
|
|
|
|
* @param in the ProviderStore to clean up
|
|
|
|
*/
|
|
|
|
void libp2p_providerstore_free(struct ProviderStore* in);
|
|
|
|
|
2017-05-11 12:04:28 +00:00
|
|
|
int libp2p_providerstore_add(struct ProviderStore* store, const unsigned char* hash, int hash_size, const unsigned char* peer_id, int peer_id_size);
|
2017-03-19 19:39:48 +00:00
|
|
|
|
2017-04-20 22:55:18 +00:00
|
|
|
int libp2p_providerstore_get(struct ProviderStore* store, const unsigned char* hash, int hash_size, unsigned char** peer_id, int *peer_id_size);
|