Major changes to support large file transfer

This commit is contained in:
John Jones 2017-04-20 17:56:03 -05:00
parent a2a08156a7
commit 03696dd6e7
40 changed files with 875 additions and 427 deletions

View file

@ -59,7 +59,7 @@ int ipfs_blockstore_get_unixfs(const unsigned char* hash, size_t hash_length, st
/**
* Put a struct Node in the blockstore
*/
int ipfs_blockstore_put_node(const struct Node* node, const struct FSRepo* fs_repo, size_t* bytes_written);
int ipfs_blockstore_get_node(const unsigned char* hash, size_t hash_length, struct Node** node, const struct FSRepo* fs_repo);
int ipfs_blockstore_put_node(const struct HashtableNode* node, const struct FSRepo* fs_repo, size_t* bytes_written);
int ipfs_blockstore_get_node(const unsigned char* hash, size_t hash_length, struct HashtableNode** node, const struct FSRepo* fs_repo);
#endif

View file

@ -5,6 +5,7 @@
#include "ipfs/commands/context.h"
#include "ipfs/repo/config/config.h"
#include "ipfs/core/ipfs_node.h"
struct BuildCfg {
int online;

View file

@ -19,3 +19,17 @@ struct IpfsNode {
//struct Mount** mounts;
// TODO: Add more here
};
/***
* build an online IpfsNode
* @param repo_path where the IPFS repository directory is
* @param node the completed IpfsNode struct
* @returns true(1) on success
*/
int ipfs_node_online_new(const char* repo_path, struct IpfsNode** node);
/***
* Free resources from the creation of an IpfsNode
* @param node the node to free
* @returns true(1)
*/
int ipfs_node_free(struct IpfsNode* node);

View file

@ -1,5 +1,11 @@
#pragma once
#include "ipfs/core/ipfs_node.h"
/**
* Pull bytes from the hashtable
*/
/**
* get a file by its hash, and write the data to a file
* @param hash the base58 multihash of the cid
@ -8,6 +14,16 @@
*/
int ipfs_exporter_to_file(const unsigned char* hash, const char* file_name, const struct FSRepo* fs_repo);
/***
* Retrieve a protobuf'd Node from the router
* @param local_node the context
* @param hash the hash to retrieve
* @param hash_size the length of the hash
* @param result a place to store the Node
* @returns true(1) on success, otherwise false(0)
*/
int ipfs_exporter_get_node(struct IpfsNode* local_node, const unsigned char* hash, const size_t hash_size, struct HashtableNode** result);
int ipfs_exporter_object_get(int argc, char** argv);
/***

View file

@ -2,7 +2,7 @@
#define __IPFS_IMPORTER_IMPORTER_H__
#include "ipfs/merkledag/node.h"
#include "ipfs/repo/fsrepo/fs_repo.h"
#include "ipfs/core/ipfs_node.h"
/**
* Creates a node based on an incoming file or directory
@ -19,7 +19,7 @@
* @param recursive true if we should navigate directories
* @returns true(1) on success
*/
int ipfs_import_file(const char* root, const char* fileName, struct Node** parent_node, struct FSRepo* fs_repo, size_t* bytes_written, int recursive);
int ipfs_import_file(const char* root, const char* fileName, struct HashtableNode** parent_node, struct IpfsNode *local_node, size_t* bytes_written, int recursive);
/**
* called from the command line

View file

@ -14,7 +14,7 @@
* @param from the current node (or NULL if it is the first call)
* @returns what we are looking for, or NULL if it wasn't found
*/
struct Node* ipfs_resolver_get(const char* path, struct Node* from, const struct IpfsNode* ipfs_node);
struct HashtableNode* ipfs_resolver_get(const char* path, struct HashtableNode* from, const struct IpfsNode* ipfs_node);
/**
* Interrogate the path, looking for the peer

View file

@ -43,7 +43,7 @@ int main(int argc, char** argv)
////Nodes/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//N_Create_From_Link
struct Node * Mynode;
struct HashtableNode * Mynode;
Mynode = N_Create_From_Link(mylink);
mylink->name = "HAHA";//Testing for valid node creation
printf("Node Link[0] Name: %s\nHash: %s\n",Mynode->head_link[0]->name, Mynode->head_link[0]->Lcid->hash);
@ -72,7 +72,7 @@ int main(int argc, char** argv)
printf("Outlinkamt: %d\n", Mynode->link_ammount);
//Node Copy
struct Node * Node2;
struct HashtableNode * Node2;
Node2 = Node_Copy(Mynode);
printf("NODE COPY TEST: [0]: %s\n", Node2->head_link[0]->Lcid->hash);
Node_Delete(Node2);

View file

@ -14,7 +14,7 @@
* @param bytes_written the number of bytes written
* @returns true(1) on success
*/
int ipfs_merkledag_add(struct Node* node, struct FSRepo* fs_repo, size_t* bytes_written);
int ipfs_merkledag_add(struct HashtableNode* node, struct FSRepo* fs_repo, size_t* bytes_written);
/***
* Retrieves a node from the datastore based on the cid
@ -23,7 +23,7 @@ int ipfs_merkledag_add(struct Node* node, struct FSRepo* fs_repo, size_t* bytes_
* @param fs_repo the repository
* @returns true(1) on success
*/
int ipfs_merkledag_get(const unsigned char* hash, size_t hash_size, struct Node** node, const struct FSRepo* fs_repo);
int ipfs_merkledag_get(const unsigned char* hash, size_t hash_size, struct HashtableNode** node, const struct FSRepo* fs_repo);
/***
* Retrieves a node from the datastore based on the multihash
@ -32,6 +32,6 @@ int ipfs_merkledag_get(const unsigned char* hash, size_t hash_size, struct Node*
* @param fs_repo the repository
* @returns true(1) on success
*/
int ipfs_merkledag_get_by_multihash(const unsigned char* multihash, size_t multihash_length, struct Node** node, const struct FSRepo* fs_repo);
int ipfs_merkledag_get_by_multihash(const unsigned char* multihash, size_t multihash_length, struct HashtableNode** node, const struct FSRepo* fs_repo);
#endif

View file

@ -22,7 +22,7 @@ struct NodeLink
struct NodeLink* next;
};
struct Node
struct HashtableNode
{
// saved in protobuf
size_t data_size;
@ -103,7 +103,7 @@ int ipfs_node_link_protobuf_decode(unsigned char* buffer, size_t buffer_length,
* @param node the node to examine
* @returns the max size of an encoded stream of bytes, if it were encoded
*/
size_t ipfs_node_protobuf_encode_size(const struct Node* node);
size_t ipfs_hashtable_node_protobuf_encode_size(const struct HashtableNode* node);
/***
* Encode a node into a protobuf byte stream
@ -113,7 +113,7 @@ size_t ipfs_node_protobuf_encode_size(const struct Node* node);
* @param bytes_written how much of buffer was used
* @returns true(1) on success
*/
int ipfs_node_protobuf_encode(const struct Node* node, unsigned char* buffer, size_t max_buffer_length, size_t* bytes_written);
int ipfs_hashtable_node_protobuf_encode(const struct HashtableNode* node, unsigned char* buffer, size_t max_buffer_length, size_t* bytes_written);
/***
* Decode a stream of bytes into a Node structure
@ -122,7 +122,7 @@ int ipfs_node_protobuf_encode(const struct Node* node, unsigned char* buffer, si
* @param node pointer to the Node to be created
* @returns true(1) on success
*/
int ipfs_node_protobuf_decode(unsigned char* buffer, size_t buffer_length, struct Node** node);
int ipfs_hashtable_node_protobuf_decode(unsigned char* buffer, size_t buffer_length, struct HashtableNode** node);
/*====================================================================================
* Node Functions
@ -133,7 +133,7 @@ int ipfs_node_protobuf_decode(unsigned char* buffer, size_t buffer_length, struc
* @param node the pointer to the memory allocated
* @returns true(1) on success, otherwise false(0)
*/
int ipfs_node_new(struct Node** node);
int ipfs_hashtable_node_new(struct HashtableNode** node);
/***
* Allocates memory for a node, and sets the data section to indicate
@ -141,14 +141,14 @@ int ipfs_node_new(struct Node** node);
* @param node the node to initialize
* @returns true(1) on success, otherwise false(0)
*/
int ipfs_node_create_directory(struct Node** node);
int ipfs_hashtable_node_create_directory(struct HashtableNode** node);
/***
* Determine if this node is actually a directory
* @param node the node to examine
* @returns true(1) if this node is a directory. Otherwise, false(0)
*/
int ipfs_node_is_directory(struct Node* node);
int ipfs_hashtable_node_is_directory(struct HashtableNode* node);
/**
* sets the Cid into the struct element titled cached
@ -156,7 +156,7 @@ int ipfs_node_is_directory(struct Node* node);
* @param cid the cid
* @returns true(1) on success
*/
int ipfs_node_set_hash(struct Node* node, const unsigned char* hash, size_t hash_size);
int ipfs_hashtable_node_set_hash(struct HashtableNode* node, const unsigned char* hash, size_t hash_size);
/*ipfs_node_set_data
* Sets the data of a node
@ -165,42 +165,42 @@ int ipfs_node_set_hash(struct Node* node, const unsigned char* hash, size_t hash
* Sets pointers of encoded & cached to NULL /following go method
* returns 1 on success 0 on failure
*/
int ipfs_node_set_data(struct Node * N, unsigned char * Data, size_t data_size);
int ipfs_hashtable_node_set_data(struct HashtableNode * N, unsigned char * Data, size_t data_size);
/*ipfs_node_set_encoded
* @param NODE: the node you wish to alter (struct Node *)
* @param Data: The data you wish to set in encoded.(unsigned char *)
* returns 1 on success 0 on failure
*/
int ipfs_node_set_encoded(struct Node * N, unsigned char * Data);
int ipfs_hashtable_node_set_encoded(struct HashtableNode * N, unsigned char * Data);
/*ipfs_node_get_data
* Gets data from a node
* @param Node: = The node you want to get data from. (unsigned char *)
* Returns data of node.
*/
unsigned char * ipfs_node_get_data(struct Node * N);
unsigned char * ipfs_hashtable_node_get_data(struct HashtableNode * N);
/*ipfs_node_free
* Once you are finished using a node, always delete it using this.
* It will take care of the links inside it.
* @param N: the node you want to free. (struct Node *)
*/
int ipfs_node_free(struct Node * N);
int ipfs_hashtable_node_free(struct HashtableNode * N);
/*ipfs_node_get_link_by_name
* Returns a copy of the link with given name
* @param Name: (char * name) searches for link with this name
* Returns the link struct if it's found otherwise returns NULL
*/
struct NodeLink * ipfs_node_get_link_by_name(struct Node * N, char * Name);
struct NodeLink * ipfs_hashtable_node_get_link_by_name(struct HashtableNode * N, char * Name);
/*ipfs_node_remove_link_by_name
* Removes a link from node if found by name.
* @param name: Name of link (char * name)
* returns 1 on success, 0 on failure.
*/
int ipfs_node_remove_link_by_name(char * Name, struct Node * mynode);
int ipfs_hashtable_node_remove_link_by_name(char * Name, struct HashtableNode * mynode);
/* ipfs_node_add_link
* Adds a link to your node
@ -209,7 +209,7 @@ int ipfs_node_remove_link_by_name(char * Name, struct Node * mynode);
* @param linksz: sizeof(your cid here)
* Returns your node with the newly added link
*/
int ipfs_node_add_link(struct Node * mynode, struct NodeLink * mylink);
int ipfs_hashtable_node_add_link(struct HashtableNode * mynode, struct NodeLink * mylink);
/*ipfs_node_new_from_link
* Create a node from a link
@ -217,7 +217,7 @@ int ipfs_node_add_link(struct Node * mynode, struct NodeLink * mylink);
* @param node the pointer to the new node
* @returns true(1) on success
*/
int ipfs_node_new_from_link(struct NodeLink * mylink, struct Node** node);
int ipfs_hashtable_node_new_from_link(struct NodeLink * mylink, struct HashtableNode** node);
/*ipfs_node_new_from_data
* @param data: bytes buffer you want to create the node from
@ -225,7 +225,7 @@ int ipfs_node_new_from_link(struct NodeLink * mylink, struct Node** node);
* @param node the pointer to the new node
* @returns true(1) on success
*/
int ipfs_node_new_from_data(unsigned char * data, size_t data_size, struct Node** node);
int ipfs_hashtable_node_new_from_data(unsigned char * data, size_t data_size, struct HashtableNode** node);
/***
* create a Node struct from encoded data
@ -233,7 +233,7 @@ int ipfs_node_new_from_data(unsigned char * data, size_t data_size, struct Node*
* @param node a pointer to the node that will be created
* @returns true(1) on success
*/
int ipfs_node_new_from_encoded(unsigned char * data, struct Node** node);
int ipfs_hashtable_node_new_from_encoded(unsigned char * data, struct HashtableNode** node);
/*Node_Resolve_Max_Size
* !!!This shouldn't concern you!
@ -278,7 +278,7 @@ struct Link_Proc
* @param N: The node you want to get links from
* @param path: The "foo/bar/bin" path
*/
struct Link_Proc * Node_Resolve_Links(struct Node * N, char * path);
struct Link_Proc * Node_Resolve_Links(struct HashtableNode * N, char * path);
/*Free_link_Proc
* frees the Link_Proc struct you created.

View file

@ -33,6 +33,7 @@ struct Reprovider {
struct RepoConfig {
struct Identity* identity;
struct Datastore* datastore;
struct Filestore* filestore;
struct Addresses* addresses;
struct Mounts mounts;
struct Discovery discovery;

View file

@ -91,8 +91,8 @@ int ipfs_repo_fsrepo_unixfs_read(const unsigned char* hash, size_t hash_length,
* @param fs_repo the repo to write to
* @returns true(1) on success
*/
int ipfs_repo_fsrepo_node_write(const struct Node* unix_fs, const struct FSRepo* fs_repo, size_t* bytes_written);
int ipfs_repo_fsrepo_node_read(const unsigned char* hash, size_t hash_length, struct Node** node, const struct FSRepo* fs_repo);
int ipfs_repo_fsrepo_node_write(const struct HashtableNode* unix_fs, const struct FSRepo* fs_repo, size_t* bytes_written);
int ipfs_repo_fsrepo_node_read(const unsigned char* hash, size_t hash_length, struct HashtableNode** node, const struct FSRepo* fs_repo);
#endif /* fs_repo_h */

View file

@ -23,16 +23,16 @@ struct IpfsRouting {
* @param 5 the size of the value
* @returns 0 on success, otherwise -1
*/
int (*PutValue) (struct IpfsRouting*, char*, size_t, void*, size_t);
int (*PutValue) (struct IpfsRouting*, const unsigned char*, size_t, const void*, size_t);
/**
* Get a value from the datastore
* Get a value from the filestore
* @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 IpfsRouting*, char*, size_t, void**, size_t*);
int (*GetValue) (struct IpfsRouting*, const unsigned char*, size_t, void**, size_t*);
/**
* Find a provider
* @param routing the context
@ -41,7 +41,7 @@ struct IpfsRouting {
* @param peers a vector of peers found that can provide the value for the key
* @returns true(1) on success, otherwise false(0)
*/
int (*FindProviders) (struct IpfsRouting* routing, unsigned char* key, size_t key_size, struct Libp2pVector** peers);
int (*FindProviders) (struct IpfsRouting* routing, const unsigned char* key, size_t key_size, struct Libp2pVector** peers);
/**
* Find a peer
* @param 1 the context
@ -51,7 +51,7 @@ struct IpfsRouting {
* @param 5 the size of the results
* @returns 0 or error code
*/
int (*FindPeer) (struct IpfsRouting*, const char*, size_t, struct Libp2pPeer** result);
int (*FindPeer) (struct IpfsRouting*, const unsigned char*, size_t, struct Libp2pPeer** result);
/**
* Announce to the network that this host can provide this key
* @param 1 the context
@ -59,7 +59,7 @@ struct IpfsRouting {
* @param 3 the key size
* @returns true(1) on success, otherwise false(0)
*/
int (*Provide) (struct IpfsRouting*, char*, size_t);
int (*Provide) (struct IpfsRouting*, const unsigned char*, size_t);
/**
* Ping
* @param routing the context
@ -84,8 +84,8 @@ int ipfs_routing_online_free(ipfs_routing*);
// 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
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);
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);
// supernode
int ipfs_routing_supernode_parse_provider(const unsigned char* in, size_t in_size, struct Libp2pLinkedList** multiaddresses);