src/util/dir.c \
src/util/file.c \
src/util/filter.c \
+ src/util/pow.c \
src/watch.c
seederd_SOURCES += \
#ifndef __BLOCK_H_
#define __BLOCK_H_
+#include<string.h>
+
#include<sodium.h>
+#include<hash.h>
+
#define BLOCK_SIZE 16384
struct block {
#include<sodium.h>
+#include<block.h>
+#include<log.h>
+
#define FILE_MESSAGE_FREAD_FAILED "failed to read file: %s\n"
struct file {
};
void file_free(struct file*);
-int file_hash(struct file*);
+int file_hash(struct file*,int);
int file_init(struct file**,const char*);
#endif
int file_filter_ignore_dotfiles(const char*);
int is_directory(const char*);
int is_file(const char*);
+size_t next_power_2(size_t);
#endif
if(NULL==p) { return NULL; }
- if(file_hash(p)<0) { return NULL; }
+ if(file_hash(p,global_options.piece_length)<0) { return NULL; }
log_info(ADD_MESSAGE_ADDED_FILE,p->path);
}
#include<block.h>
-int block_append_block(struct block *p) {
+int block_append_blank(struct block *p) {
if(NULL==p) { return -1; }
while(p->next!=NULL) {
}
int block_duplicate(struct block **p, struct block *to_dup) {
- struct block *next;
-
if(NULL==p) { return -1; }
if(NULL==to_dup) { return -1; }
free(p);
}
-int file_hash(struct file *file_p) {
+int file_hash(struct file *file_p, int piece_length) {
uint8_t data[BLOCK_SIZE];
struct block *start, *p, *next, *end;
FILE *fp;
int blocks_per_piece;
- blocks_per_piece = global_opts.piece_length / BLOCK_SIZE;
+ blocks_per_piece = piece_length / BLOCK_SIZE;
fp = fopen(file_p->path,"rb");
if(NULL==fp) { return -1; }
p = p->next;
}
- ssize_t blocks = block_length(start);
- if(blocks<=0) { goto clean; }
+ size_t blocks = block_length(start);
+ if(0==blocks) { goto clean; }
if(blocks!=blocks_per_piece) {
// if the file is smaller than one piece then the block hashes
clean:
block_free(start);
fclose(fp);
+ return -1;
}
int file_init(struct file **p, const char *path) {
--- /dev/null
+#include<util.h>
+
+size_t next_power_2(size_t i) {
+ return 0;
+}
-DNDEBUG
endif
-check_PROGRAMS = bencode.tests file.tests hash.tests hashmap.tests torrent.tests tree.tests util.filter.tests
+check_PROGRAMS = bencode.tests block.tests file.tests hash.tests hashmap.tests torrent.tests tree.tests util.filter.tests
TESTS = $(check_PROGRAMS)
if ENABLE_MEMCHECK
$(top_srcdir)/src/bencode/decode.c \
$(top_srcdir)/src/bencode/encode.c
+block_tests_SOURCES = \
+ $(common_SOURCES) \
+ block.tests.c \
+ $(top_srcdir)/src/block.c
+
file_tests_SOURCES = \
$(common_SOURCES) \
file.tests.c \
+ $(top_srcdir)/src/block.c \
$(top_srcdir)/src/file.c
hash_tests_SOURCES = \
torrent_tests_SOURCES = \
$(common_SOURCES) \
torrent.tests.c \
+ $(top_srcdir)/src/block.c \
$(top_srcdir)/src/file.c \
$(top_srcdir)/src/hashmap.c \
$(top_srcdir)/src/torrent.c \
tree_tests_SOURCES = \
$(common_SOURCES) \
tree.tests.c \
+ $(top_srcdir)/src/block.c \
$(top_srcdir)/src/file.c \
$(top_srcdir)/src/tree.c
--- /dev/null
+#include<test_utils.h>
+
+#include<block.h>
+
+int main();
+static void block_append_blank_basic_test();
+static void block_init_basic_test();
+
+int main() {
+ setup_env();
+
+// block_append_blank_basic_test();
+// block_duplicate_basic_test();
+ block_init_basic_test();
+ //block_length_basic_test();
+ //block_merkle_root_basic_test();
+
+ clean_env();
+
+ return EXIT_SUCCESS;
+}
+
+static void block_append_blank_basic_test() {
+
+}
+
+static void block_init_basic_test() {
+ struct block *p;
+
+ assert(block_init(NULL)==-1);
+ assert(block_init(&p)==1);
+
+ block_free(p);
+}