src/opt/set.c \
src/opt/watch.c \
src/opt/worker.c \
+ src/server/start.c \
src/session.c \
src/setup.c \
src/shutdown.c \
src/usage.c \
src/util/dir.c \
src/util/file.c \
- src/util/filter.c
+ src/util/filter.c \
+ src/watch.c
seederd_SOURCES += \
inc/add.h \
inc/log.h \
inc/main.h \
inc/opt.h \
+ inc/server.h \
inc/session.h \
inc/setup.h \
inc/shutdown.h \
inc/torrent.h \
inc/tree.h \
inc/usage.h \
- inc/util.h
+ inc/util.h \
+ inc/watch.h
SUBDIRS = . test/unit
#include<util.h>
#define ADD_MESSAGE_ADDING_TORRENT "adding all files in %s to torrent named %s\n"
+#define ADD_MESSAGE_ADDED_FILE "added file %s\n"
#define ADD_QUEUE_INITIAL_SIZE 8
};
void file_free(struct file*);
+int file_hash(struct file*);
int file_init(struct file**,const char*);
#endif
#include<sodium.h>
-int hash(void*,size_t,unsigned char*,size_t);
+int hash(const void*,size_t,unsigned char*,size_t);
int hash_init(crypto_hash_sha256_state*);
int hash_update(crypto_hash_sha256_state*,const void*,size_t);
int hash_final(crypto_hash_sha256_state*,unsigned char*,size_t);
#include<shutdown.h>
#include<usage.h>
+extern struct option long_options[];
+
int init(int,char**);
#endif
#include<add.h>
#include<init.h>
+#include<server.h>
+#include<watch.h>
int main(int,char**);
--- /dev/null
+#ifndef __PEER_H_
+#define __PEER_H_
+
+enum peer_message {
+ PEER_MESSAGE_CHOKE = 0,
+ PEER_MESSAGE_UNCHOKE = 1,
+ PEER_MESSAGE_INTERESTED = 2,
+ PEER_MESSAGE_NOT_INTERESTED = 3,
+ PEER_MESSAGE_HAVE = 4,
+ PEER_MESSAGE_BITFIELD = 5,
+ PEER_MESSAGE_REQUEST = 6,
+ PEER_MESSAGE_PIECE = 7,
+ PEER_MESSAGE_CANCEL = 8,
+ PEER_MESSAGE_REJECT = 16,
+ PEER_MESSAGE_HASH_REQUEST = 21,
+ PEER_MESSAGE_HASHES = 22,
+ PEER_MESSAGE_HASH_REJECT = 23
+};
+
+#endif
--- /dev/null
+#ifndef __SERVER_H_
+#define __SERVER_H_
+
+int server_start();
+
+#endif
#ifndef __USAGE_H_
#define __USAGE_H_
+#include<init.h>
#include<log.h>
void usage();
--- /dev/null
+#ifndef __WATCH_H_
+#define __WATCH_H_
+
+int watch();
+
+#endif
p = get_next();
pthread_mutex_unlock(&adding_mutex);
- if(hash(
- p->path,
- strlen(p->path),
- p->root,
- crypto_hash_sha256_BYTES
- )<0) {
- log_err("hash failed\n");
- return NULL;
- }
-
if(NULL==p) { return NULL; }
- log_info("to add: %s\n",p->path);
+
+ if(file_hash(p)<0) { return NULL; }
+
+ log_info(ADD_MESSAGE_ADDED_FILE,p->path);
}
return NULL;
free(p);
}
+int file_hash(struct file *p) {
+ return 1;
+}
+
int file_init(struct file **p, const char *path) {
char *b;
#include<hash.h>
-int hash(void *data, size_t data_len, unsigned char *out, size_t out_size) {
+int hash(const void *data, size_t data_len, unsigned char *out, size_t out_size) {
if(crypto_hash_sha256(out,data,data_len)!=0) { return -1; }
return 1;
#include<init.h>
-static struct option long_options[] = {
+struct option long_options[] = {
{"config-file", required_argument, 0, 'c'},
{"daemon", no_argument, 0, 'd'},
{"file-filter", required_argument, 0, 'f'},
{"log-file", required_argument, 0, 'l'},
{"quiet", no_argument, 0, 'q'},
{"verbose", no_argument, 0, 'v'},
- {"watch", required_argument, 0, 'w'},
+ {"watch-directory", required_argument, 0, 'w'},
{"worker-threads", required_argument, 0, 1},
{0,0,0,0}
};
if(setup_logging()<0) { return EXIT_FAILURE; }
if(add()<0) { return EXIT_FAILURE; }
+ //if(feed()<0) { return EXIT_FAILURE; }
+ if(watch()<0) { return EXIT_FAILURE; }
- log_err("this is a test %d %s\n",10,"what?");
+ if(server_start()<0) { return EXIT_FAILURE; }
- return EXIT_FAILURE;
+ return EXIT_SUCCESS;
}
--- /dev/null
+#include<server.h>
+
+int server_start() {
+ return -1;
+}
#include<usage.h>
+static void usage_print_options();
+
void usage() {
- log_err("Usage:\n");
- log_err("\tseederd [options]\n");
- log_err("\n");
- log_err("Options:\n");
- log_err("\t--config-file=<path>, -c <path>\n");
- log_err("\t--daemon, -d\n");
- log_err("\t--file-filter=<filter>, -f <filter>\n");
- log_err("\t--help, -h\n");
- log_err("\t--log-file=<file>, -l <file>\n");
- log_err("\t--quiet, -q\n");
- log_err("\t--verbose, -v\n");
- log_err("\t--watch=<directory>, -w <directory>\n");
- log_err("\t--worker-threads=<number of threads>\n");
+ fprintf(stderr,"Usage:\n");
+ fprintf(stderr,"\tseederd [options]\n");
+ fprintf(stderr,"\n");
+ fprintf(stderr,"Options:\n");
+
+ usage_print_options();
+
+ fprintf(stderr,"\n");
+ fprintf(stderr,"See `man seederd` for more information\n");
+}
+
+static void usage_print_options() {
+ size_t i;
+ char *p;
+
+ i = 0;
+ while(
+ !((0==long_options[i].name) &&
+ (0==long_options[i].has_arg) &&
+ (0==long_options[i].flag) &&
+ (0==long_options[i].val))) {
+
+ fprintf(stderr,"\t%s",long_options[i].name);
+
+ p = strrchr(long_options[i].name,'-');
+ if(p!=NULL) {
+ p++;
+ if('\0'==*p) {
+ p = NULL;
+ }
+ }
+
+ if((required_argument==long_options[i].has_arg)&&(p!=NULL)) {
+ fprintf(stderr,"=<%s>",p);
+ }
+
+ if(97 <= long_options[i].val && long_options[i].val <= 122) {
+ fprintf(stderr,", -%c",long_options[i].val);
+
+ if((required_argument==long_options[i].has_arg)&&(p!=NULL)) {
+ fprintf(stderr," <%s>",p);
+ }
+ }
+
+ fprintf(stderr,"\n");
+ i++;
+ }
}
--- /dev/null
+#include<watch.h>
+
+int watch() {
+ return -1;
+}
-DNDEBUG
endif
-check_PROGRAMS = file.tests hashmap.tests torrent.tests tree.tests util.filter.tests
+check_PROGRAMS = file.tests hash.tests hashmap.tests torrent.tests tree.tests util.filter.tests
TESTS = $(check_PROGRAMS)
if ENABLE_MEMCHECK
file.tests.c \
$(top_srcdir)/src/file.c
+hash_tests_SOURCES = \
+ $(common_SOURCES) \
+ hash.tests.c \
+ $(top_srcdir)/src/hash.c
+
hashmap_tests_SOURCES = \
$(common_SOURCES) \
hashmap.tests.c \
--- /dev/null
+#include<test_utils.h>
+
+#include<hash.h>
+
+int main();
+static void hash_basic_tests();
+static void hash_multi_step_conformance_test();
+
+int main() {
+ setup_env();
+
+ hash_basic_tests();
+ hash_multi_step_conformance_test();
+
+ clean_env();
+
+ return EXIT_SUCCESS;
+}
+
+static void hash_basic_tests() {
+ unsigned char expected[crypto_hash_sha256_BYTES];
+ unsigned char out[crypto_hash_sha256_BYTES];
+ size_t i;
+
+ const char str1[] = "test\n";
+ const char expected1[] = "f2ca1bb6c7e907d06dafe4687e579fce76b37e4e93b7605022da52e6ccc26fd2";
+ assert(sodium_hex2bin(expected,crypto_hash_sha256_BYTES,expected1,strlen(expected1),NULL,&i,NULL)==0);
+ assert(i==32);
+
+ assert(hash(str1,strlen(str1),out,crypto_hash_sha256_BYTES)==1);
+ assert(memcmp(out,expected,crypto_hash_sha256_BYTES)==0);
+
+ const char expected2[] = "ae49be25bdf4ec71127aff1405e54d97bb481b4bcb20199a51f9131d7607e4e5";
+ assert(sodium_hex2bin(expected,crypto_hash_sha256_BYTES,expected2,strlen(expected2),NULL,&i,NULL)==0);
+ assert(i==32);
+
+ assert(hash(TEST_FILE_1_CONTENTS,strlen(TEST_FILE_1_CONTENTS),out,crypto_hash_sha256_BYTES)==1);
+ assert(memcmp(out,expected,crypto_hash_sha256_BYTES)==0);
+
+ const char expected3[] = "477e8d55511501d1fd3f0ac6e3872c70d38071f0f304b948058b7959299bf505";
+ assert(sodium_hex2bin(expected,crypto_hash_sha256_BYTES,expected3,strlen(expected3),NULL,&i,NULL)==0);
+ assert(i==32);
+
+ assert(hash(TEST_FILE_2_CONTENTS,strlen(TEST_FILE_2_CONTENTS),out,crypto_hash_sha256_BYTES)==1);
+ assert(memcmp(out,expected,crypto_hash_sha256_BYTES)==0);
+
+
+ const char expected4[] = "2f293857380375ececc0af34acce4469d7662f932fd5d85c0d0c75df1cb3a99d";
+ assert(sodium_hex2bin(expected,crypto_hash_sha256_BYTES,expected4,strlen(expected4),NULL,&i,NULL)==0);
+ assert(i==32);
+
+ assert(hash(TEST_FILE_3_CONTENTS,strlen(TEST_FILE_3_CONTENTS),out,crypto_hash_sha256_BYTES)==1);
+ assert(memcmp(out,expected,crypto_hash_sha256_BYTES)==0);
+
+ const char expected5[] = "0db92f82ba8d282b6c04c40c94a584b6804c532414bf1f3bda58d584e40d8b9f";
+ assert(sodium_hex2bin(expected,crypto_hash_sha256_BYTES,expected5,strlen(expected5),NULL,&i,NULL)==0);
+ assert(i==32);
+
+ assert(hash(TEST_FILE_4_CONTENTS,strlen(TEST_FILE_4_CONTENTS),out,crypto_hash_sha256_BYTES)==1);
+ assert(memcmp(out,expected,crypto_hash_sha256_BYTES)==0);
+}
+
+static void hash_multi_step_conformance_test() {
+ unsigned char expected[crypto_hash_sha256_BYTES];
+ unsigned char out[crypto_hash_sha256_BYTES];
+ crypto_hash_sha256_state state;
+ size_t i, len;
+ const char *p;
+
+ const char str[] = "alskdjflkasdfjasdfjalskdjflkasjdflkasjdlkfjaslkdfjklasdjfklajsdfkljaslkdfjlaksjdfklajsdklfjaskldfj";
+ const char expected_hash[] = "5deca19259f33b54ca65a61da595af75ac66209c4a851176a01ef201bced1cf3";
+
+ assert(sodium_hex2bin(expected,crypto_hash_sha256_BYTES,expected_hash,strlen(expected_hash),NULL,&i,NULL)==0);
+ assert(i==32);
+
+ len = strlen(str);
+ assert(hash(str,len,out,crypto_hash_sha256_BYTES)==1);
+ assert(memcmp(out,expected,crypto_hash_sha256_BYTES)==0);
+
+ assert(hash_init(&state)==1);
+ p = str;
+ while(len>0) {
+ i = rand()%len;
+ if(i==0) {
+ i = len;
+ }
+
+ if(i>0) {
+ assert(hash_update(&state,p,i)==1);
+ p += i;
+ len -= i;
+ }
+ }
+
+ memset(out,0,crypto_hash_sha256_BYTES);
+ assert(hash_final(&state,out,crypto_hash_sha256_BYTES)==1);
+ assert(memcmp(out,expected,crypto_hash_sha256_BYTES)==0);
+}
create_test_directory(TEST_DIRECTORY);
create_test_file(TEST_FILE_1,TEST_FILE_1_CONTENTS);
create_test_file(TEST_FILE_2,TEST_FILE_2_CONTENTS);
+ create_test_file(TEST_FILE_3,TEST_FILE_3_CONTENTS);
+ create_test_file(TEST_FILE_4,TEST_FILE_4_CONTENTS);
}
static void create_test_directory(const char *directory) {