The beginnings of datastore
A lot of code cleanup, plus beginning the implementation of a datastore.
This commit is contained in:
parent
0b765481da
commit
c64a700223
28 changed files with 1169 additions and 132 deletions
40
blocks/block.c
Normal file
40
blocks/block.c
Normal file
|
@ -0,0 +1,40 @@
|
|||
/**
|
||||
* The implementation of methods around IPFS blocks
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "ipfs/blocks/block.h"
|
||||
#include "ipfs/cid/cid.h"
|
||||
|
||||
/***
|
||||
* Create a new block based on the incoming data
|
||||
* @param data the data to base the block on
|
||||
* @param data_size the length of the data array
|
||||
* @param block a pointer to the struct Block that will be created
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blocks_block_new(unsigned char* data, size_t data_size, struct Block* block) {
|
||||
char hash[32];
|
||||
ipfs_crypto_hashing_sha256(data, hash, 32);
|
||||
ipfs_cid_new(0, hash, 32, CID_PROTOBUF, block->cid);
|
||||
|
||||
block->data = malloc(sizeof(unsigned char) * data_size);
|
||||
if (block->data == NULL)
|
||||
return 0;
|
||||
|
||||
memcpy(block->data, data, data_size);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/***
|
||||
* Free resources used by the creation of a block
|
||||
* @param block the block to free
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blocks_block_free(struct Block* block) {
|
||||
ipfs_cid_free(block->cid);
|
||||
if (block->data != NULL)
|
||||
free(block->data);
|
||||
return 1;
|
||||
}
|
41
blocks/blockstore.c
Normal file
41
blocks/blockstore.c
Normal file
|
@ -0,0 +1,41 @@
|
|||
/***
|
||||
* a thin wrapper over a datastore for getting and putting block objects
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
* Delete a block based on its Cid
|
||||
* @param cid the Cid to look for
|
||||
* @param returns true(1) on success
|
||||
*/
|
||||
int ipfs_blockstore_delete(struct Cid* cid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
* Determine if the Cid can be found
|
||||
* @param cid the Cid to look for
|
||||
* @returns true(1) if found
|
||||
*/
|
||||
int ipfs_blockstore_has(struct Cid* cid) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
* Find a block based on its Cid
|
||||
* @param cid the Cid to look for
|
||||
* @param block where to put the data to be returned
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blockstore_get(struct Cid* cid, struct Block* block) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/***
|
||||
* Put a block in the blockstore
|
||||
* @param block the block to store
|
||||
* @returns true(1) on success
|
||||
*/
|
||||
int ipfs_blockstore_put(struct Block* block) {
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue