Toychain!
A toy blockchain in C
dataio.h
Go to the documentation of this file.
1#ifndef _DATA_IO_H
2#define _DATA_IO_H
3
4#include "lib/rsa.h"
5#include "lib/sign.h"
6
12#define BLOCK_STORAGE_DIR "../data/"
13#define BLOCKCHAIN_DIR BLOCK_STORAGE_DIR "blockchain/"
14#define PENDING_BLOCK_FILE BLOCK_STORAGE_DIR "pending_block"
15#define PENDING_VOTES_FILE BLOCK_STORAGE_DIR "pending_votes.txt"
16
20typedef struct cellKey{
21 Key* data;
22 struct cellKey* next;
24
28typedef struct cellProtected {
29 Protected* data;
30 struct cellProtected* next;
32
35CellProtected* read_protected(const char* filename);
38char* list_protected_to_str(const CellProtected* list);
39CellProtected* str_to_list_protected(const char* str);
43
44void generate_random_data(int nv, int nc, const char* dir);
46CellKey* insert_cell_key(CellKey* cellkey, Key* key);
47CellKey* read_public_keys(char* file);
48void print_list_keys(CellKey* LCK);
49void free_cell_keys(CellKey* c);
50void free_list_keys(CellKey* cellkey);
51
53CellProtected* rand_list_protected_range(size_t len, char low, char hi);
54
56
57void delete_dir_files(const char* path);
58void create_dir_structure();
59
60#endif
void prepend_protected(CellProtected **list, Protected *pr)
Prepend CellProtected to a list !!! takes ownership of pr.
Definition: dataio.c:319
CellProtected * rand_list_protected(size_t len)
generate random list of protected
Definition: dataio.c:592
void free_list_protected(CellProtected *c)
frees the list of pretected
Definition: dataio.c:562
CellProtected * create_cell_protected(Protected *pr)
Create a cell protected object.
Definition: dataio.c:308
struct cellProtected CellProtected
void print_list_keys(CellKey *LCK)
print the keys from a list
Definition: dataio.c:266
void free_list_keys(CellKey *cellkey)
free a list of keys
Definition: dataio.c:537
void remove_fraudulent_declarations(CellProtected **list)
removes fraudulent block from the chain. Fraudulent blocks are the ones that don't verify the signatu...
Definition: dataio.c:575
CellProtected * str_to_list_protected(const char *str)
converts string to a list of protected
Definition: dataio.c:432
CellKey * read_public_keys(char *file)
Read the public keys of a file, return them in a CellKey structure.
Definition: dataio.c:237
void free_cell_keys(CellKey *c)
free a CellKey object(correspond to delete_cell_key in the subject).
Definition: dataio.c:526
CellProtected * fuse_protected_lists(CellProtected *A, CellProtected *B)
fusionner les liste A et B. Modifies A!
Definition: dataio.c:642
CellProtected * copy_protected_list(const CellProtected *o)
copies the list of protected values. The copies order is inverted.
Definition: dataio.c:508
struct cellKey CellKey
char * list_protected_to_str(const CellProtected *list)
converts list of protected to a string.
Definition: dataio.c:373
void free_cell_protected(CellProtected *c)
correspond au delete_cell_protected dans le sujet
Definition: dataio.c:551
CellProtected * read_protected(const char *filename)
read protected list from file. data format is lines in protected_to_str format each representing a pr...
Definition: dataio.c:334
CellProtected * rand_list_protected_range(size_t len, char low, char hi)
generate random list of protected with message characters in range [low, hi].
Definition: dataio.c:604
CellKey * insert_cell_key(CellKey *cellkey, Key *key)
Insert a new element to cellkey (head insertion).
Definition: dataio.c:220
void print_protected_list(CellProtected *list)
prints the chained list of protected
Definition: dataio.c:490
CellKey * create_cell_key(Key *key)
Allocate and initialize a CellKey object.
Definition: dataio.c:209
void generate_random_data(int nv, int nc, const char *dir)
generates nv public and private keys and prints them in ./{dir}/keys.txt. Chooses nc couple of keys a...
Definition: dataio.c:32
header of rsa.c
header of sign.c
Definition: rsa.h:16
Definition: sign.h:25
Definition: dataio.h:20
Definition: dataio.h:28