Hashes match on large files
This commit is contained in:
parent
3004f1411a
commit
8f44c857db
3 changed files with 13 additions and 39 deletions
|
@ -43,28 +43,6 @@ int ipfs_importer_add_filesize_to_data_section(struct Node* node, size_t bytes_r
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int test_hash(unsigned char* protobuf, size_t protobuf_length) {
|
|
||||||
size_t hash_size = 32;
|
|
||||||
unsigned char hash[32];
|
|
||||||
if (hash == NULL) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if (libp2p_crypto_hashing_sha256(protobuf, protobuf_length, &hash[0]) == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// turn it into base58
|
|
||||||
size_t buffer_len = 100;
|
|
||||||
unsigned char buffer[buffer_len];
|
|
||||||
int retVal = ipfs_cid_hash_to_base58(hash, hash_size, buffer, buffer_len);
|
|
||||||
if (retVal == 0) {
|
|
||||||
printf("Unable to generate hash\n");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
printf(" hash generated from %lu: %s\n", protobuf_length, buffer);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* read the next chunk of bytes, create a node, and add a link to the node in the passed-in node
|
* read the next chunk of bytes, create a node, and add a link to the node in the passed-in node
|
||||||
* @param file the file handle
|
* @param file the file handle
|
||||||
|
@ -80,10 +58,6 @@ size_t ipfs_import_chunk(FILE* file, struct Node* parent_node, struct FSRepo* fs
|
||||||
struct Node* new_node = NULL;
|
struct Node* new_node = NULL;
|
||||||
struct NodeLink* new_link = NULL;
|
struct NodeLink* new_link = NULL;
|
||||||
|
|
||||||
//JMJ
|
|
||||||
printf("Raw from the file");
|
|
||||||
test_hash(buffer, bytes_read);
|
|
||||||
|
|
||||||
// put the file bits into a new UnixFS file
|
// put the file bits into a new UnixFS file
|
||||||
if (ipfs_unixfs_new(&new_unixfs) == 0)
|
if (ipfs_unixfs_new(&new_unixfs) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -105,9 +79,7 @@ size_t ipfs_import_chunk(FILE* file, struct Node* parent_node, struct FSRepo* fs
|
||||||
ipfs_unixfs_free(new_unixfs);
|
ipfs_unixfs_free(new_unixfs);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
//JMJ
|
|
||||||
printf("unixfs protobuf");
|
|
||||||
test_hash(protobuf, bytes_written);
|
|
||||||
// we're done with the UnixFS object
|
// we're done with the UnixFS object
|
||||||
ipfs_unixfs_free(new_unixfs);
|
ipfs_unixfs_free(new_unixfs);
|
||||||
|
|
||||||
|
@ -125,7 +97,7 @@ size_t ipfs_import_chunk(FILE* file, struct Node* parent_node, struct FSRepo* fs
|
||||||
}
|
}
|
||||||
|
|
||||||
// put link in parent node
|
// put link in parent node
|
||||||
if (ipfs_node_link_create("", new_node->hash, new_node->hash_size, &new_link) == 0) {
|
if (ipfs_node_link_create(NULL, new_node->hash, new_node->hash_size, &new_link) == 0) {
|
||||||
ipfs_node_free(new_node);
|
ipfs_node_free(new_node);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -157,7 +129,7 @@ size_t ipfs_import_chunk(FILE* file, struct Node* parent_node, struct FSRepo* fs
|
||||||
}
|
}
|
||||||
|
|
||||||
// put link in parent node
|
// put link in parent node
|
||||||
if (ipfs_node_link_create("", new_node->hash, new_node->hash_size, &new_link) == 0) {
|
if (ipfs_node_link_create(NULL, new_node->hash, new_node->hash_size, &new_link) == 0) {
|
||||||
ipfs_node_free(new_node);
|
ipfs_node_free(new_node);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include "ipfs/merkledag/merkledag.h"
|
#include "ipfs/merkledag/merkledag.h"
|
||||||
#include "ipfs/unixfs/unixfs.h"
|
#include "ipfs/unixfs/unixfs.h"
|
||||||
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Adds a node to the dagService and blockService
|
* Adds a node to the dagService and blockService
|
||||||
* @param node the node to add
|
* @param node the node to add
|
||||||
|
|
|
@ -30,7 +30,7 @@ enum WireType ipfs_node_link_message_fields[] = { WIRETYPE_LENGTH_DELIMITED, WIR
|
||||||
*/
|
*/
|
||||||
int ipfs_node_link_create(char * name, unsigned char * ahash, size_t hash_size, struct NodeLink** node_link)
|
int ipfs_node_link_create(char * name, unsigned char * ahash, size_t hash_size, struct NodeLink** node_link)
|
||||||
{
|
{
|
||||||
*node_link = malloc(sizeof(struct NodeLink));
|
ipfs_node_link_new(node_link);
|
||||||
if (*node_link == NULL)
|
if (*node_link == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -40,12 +40,14 @@ int ipfs_node_link_create(char * name, unsigned char * ahash, size_t hash_size,
|
||||||
link->hash = (unsigned char*)malloc(hash_size);
|
link->hash = (unsigned char*)malloc(hash_size);
|
||||||
memcpy(link->hash, ahash, hash_size);
|
memcpy(link->hash, ahash, hash_size);
|
||||||
// name
|
// name
|
||||||
link->name = malloc(strlen(name) + 1);
|
if (name != NULL && strlen(name) > 0) {
|
||||||
if ( link->name == NULL) {
|
link->name = malloc(strlen(name) + 1);
|
||||||
free(link);
|
if ( link->name == NULL) {
|
||||||
return 0;
|
free(link);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
strcpy(link->name, name);
|
||||||
}
|
}
|
||||||
strcpy(link->name, name);
|
|
||||||
// t_size
|
// t_size
|
||||||
link->t_size = 0;
|
link->t_size = 0;
|
||||||
// other, non-protobuffed data
|
// other, non-protobuffed data
|
||||||
|
@ -185,8 +187,7 @@ int ipfs_node_link_protobuf_decode(unsigned char* buffer, size_t buffer_length,
|
||||||
goto exit;
|
goto exit;
|
||||||
link->hash_size = hash_size - 2;
|
link->hash_size = hash_size - 2;
|
||||||
link->hash = (unsigned char*)malloc(link->hash_size);
|
link->hash = (unsigned char*)malloc(link->hash_size);
|
||||||
strncpy((char*)link->hash, (char*)hash, link->hash_size);
|
memcpy((char*)link->hash, (char*)&hash[2], link->hash_size);
|
||||||
link->hash[link->hash_size-1] = 0;
|
|
||||||
free(hash);
|
free(hash);
|
||||||
pos += bytes_read;
|
pos += bytes_read;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue