more ping cleanup and friendly interface to streams

This commit is contained in:
John Jones 2017-02-23 15:15:33 -05:00
parent ae48e058dd
commit 7a6b138444
7 changed files with 198 additions and 83 deletions

View file

@ -1,5 +1,9 @@
#pragma once
#include "ipfs/repo/config/identity.h"
#include "ipfs/repo/fsrepo/fs_repo.h"
#include "libp2p/peer/peerstore.h"
enum NodeMode { MODE_OFFLINE, MODE_ONLINE };
struct IpfsNode {

View file

@ -1,32 +1,55 @@
#ifndef ROUTING_H
#define ROUTING_H
#pragma once
#include "libp2p/crypto/rsa.h"
#include "libp2p/crypto/rsa.h"
#include "libp2p/record/message.h"
// offlineRouting implements the IpfsRouting interface,
// but only provides the capability to Put and Get signed dht
// records to and from the local datastore.
struct s_ipfs_routing {
struct FSRepo* datastore;
size_t ds_len;
struct RsaPrivateKey* sk;
int (*PutValue) (struct s_ipfs_routing*, char*, size_t, void*, size_t);
int (*GetValue) (struct s_ipfs_routing*, char*, size_t, void*, size_t*);
int (*FindProviders) (struct s_ipfs_routing*, char*, size_t, void*, size_t*);
int (*FindPeer) (struct s_ipfs_routing*, char*, size_t, void*, size_t*);
int (*Provide) (struct s_ipfs_routing*, char*);
int (*Ping) (struct s_ipfs_routing*, char*, size_t);
int (*Bootstrap) (struct s_ipfs_routing*);
};
typedef struct s_ipfs_routing ipfs_routing;
// offlineRouting implements the IpfsRouting interface,
// but only provides the capability to Put and Get signed dht
// records to and from the local datastore.
struct s_ipfs_routing {
struct FSRepo* datastore;
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
*/
int (*PutValue) (struct s_ipfs_routing*, char*, size_t, void*, size_t);
/**
* Get a value from the datastore
* @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
*/
int (*GetValue) (struct s_ipfs_routing*, char*, size_t, void**, size_t*);
/**
* Find a provider
*/
int (*FindProviders) (struct s_ipfs_routing*, char*, size_t, void*, size_t*);
/**
* Find a peer
*/
int (*FindPeer) (struct s_ipfs_routing*, char*, size_t, void*, size_t*);
int (*Provide) (struct s_ipfs_routing*, char*);
/**
* Ping this instance
*/
int (*Ping) (struct s_ipfs_routing*, struct Libp2pMessage* message);
int (*Bootstrap) (struct s_ipfs_routing*);
};
typedef struct s_ipfs_routing ipfs_routing;
// offline routing routines.
ipfs_routing* ipfs_routing_new_offline (struct FSRepo* ds, struct RsaPrivateKey *private_key);
ipfs_routing* ipfs_routing_new_online (struct FSRepo* ds, struct RsaPrivateKey* private_key, struct Stream* stream);
int ipfs_routing_generic_put_value (ipfs_routing* offlineRouting, char *key, size_t key_size, void *val, size_t vlen);int ipfs_routing_generic_get_value (ipfs_routing* offlineRouting, char *key, size_t key_size, void **val, size_t *vlen);
// offline routing routines.
ipfs_routing* ipfs_routing_new_offline (struct FSRepo* ds, struct RsaPrivateKey *private_key);
int ipfs_routing_offline_put_value (ipfs_routing* offlineRouting, char *key, size_t key_size, void *val, size_t vlen);
int ipfs_routing_offline_get_value (ipfs_routing* offlineRouting, char *key, size_t key_size, void *val, size_t *vlen);
int ipfs_routing_offline_find_providers (ipfs_routing* offlineRouting, char *key, size_t key_size, void *ret, size_t *rlen);
int ipfs_routing_offline_find_peer (ipfs_routing* offlineRouting, char *peer_id, size_t pid_size, void *ret, size_t *rlen);
int ipfs_routing_offline_provide (ipfs_routing* offlineRouting, char *cid);
int ipfs_routing_offline_ping (ipfs_routing* offlineRouting, char *peer_id, size_t pid_size);
int ipfs_routing_offline_bootstrap (ipfs_routing* offlineRouting);
#endif // ROUTING_H