]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Mon, 6 Sep 2021 03:54:30 +0000 (20:54 -0700)
committeralex <[email protected]>
Mon, 6 Sep 2021 03:54:30 +0000 (20:54 -0700)
14 files changed:
Makefile.am
inc/default.h
inc/opt.h
inc/torrent.h
inc/util.h
src/default.c
src/main.c
src/opt/env.c
src/opt/piecel.c
src/opt/set.c
src/opt/worker.c [new file with mode: 0644]
src/torrent.c
src/usage.c
src/util/find.c [new file with mode: 0644]

index 2fb2ad54f0dd0c2f02be64229c4d0220f4a80e7d..dd4c753b5d802f3975472dab62174a8117f8e284 100644 (file)
@@ -21,6 +21,7 @@ seederd_SOURCES = \
        src/opt/piecel.c \
        src/opt/set.c \
        src/opt/watch.c \
+       src/opt/worker.c \
        src/setup.c \
        src/torrent.c \
        src/usage.c \
index 4b43a4c1658110662bce8e99a0972d6c3ca907e4..3a91225ef976c676c913a9dbf0c1db70bb315aab 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __DEFAULT_H_
 #define __DEFAULT_H_
 
+#include<unistd.h>
+
 #include<log.h>
 #include<opt.h>
 
index b3506d2a8de45255ee421ed407321e6d8df0b985..b1f54077cc8b09b8c5fa61d74f029ddfa8b7c255 100644 (file)
--- a/inc/opt.h
+++ b/inc/opt.h
@@ -7,8 +7,16 @@
 #include<torrent.h>
 #include<util.h>
 
+struct options {
+       unsigned int worker_threads;
+       unsigned long long piece_length;
+};
+
+extern struct options global_options;
+
 #define OPT_MESSAGE_CONFIG_FILE_FORMAT_ERROR "invalid format in config file %s:%d\n"
 #define OPT_MESSAGE_ENV_LOADING "loading settings from environment\n"
+#define OPT_MESSAGE_ENV_LOADING_END "finished loading settings from environment\n"
 #define OPT_MESSAGE_LOADING_CONFIG_FILE "loading config file %s\n"
 #define OPT_MESSAGE_PIECE_LENGTH_INVALID "invalid piece length of %llu\npiece length must be >16384 and a power of 2\n"
 #define OPT_MESSAGE_PIECE_LENGTH_SET "piece length set to %llu\n"
@@ -16,6 +24,8 @@
 #define OPT_MESSAGE_UNKNOWN_OPTION "unknown option %s\n"
 #define OPT_MESSAGE_WATCH_ADD_SUCCESS "watching %s\n"
 #define OPT_MESSAGE_WATCH_INVALID_DIRECTORY "watching directory %s failed\n"
+#define OPT_MESSAGE_WORKER_THREADS_INVALID "invalid value to option worker_threads: %u\n"
+#define OPT_MESSAGE_WORKER_THREADS_SET "number of worker threads set to %u\n"
 
 int opt_add_watch(char*);
 int opt_load_config_file(char*);
@@ -23,5 +33,6 @@ int opt_load_from_env();
 int opt_set(char*,char*);
 void opt_set_log_level(enum log_level);
 int opt_set_piece_length(char*);
+int opt_set_worker_threads(char*);
 
 #endif
index 21ab3276dcb2b8eb6b58770fb720504b73bb012b..0e53ec1218c0fce65d48767eefe93bab2d2564e1 100644 (file)
@@ -9,6 +9,8 @@ struct torrent {
        char *root;
 };
 
+extern struct torrent **torrents;
+
 void torrent_free(struct torrent*);
 int torrent_init(struct torrent**,char*);
 
index 4d5febbeac87c3d9fce94fa1b5ccf98442b8e51f..55244cfb8fb8a47925a79c6873b8cf839bc1c0ae 100644 (file)
@@ -1,9 +1,12 @@
 #ifndef __UTIL_H_
 #define __UTIL_H_
 
+#include<dirent.h>
 #include<stdio.h>
 #include<sys/stat.h>
 
+int file_filter(char*);
+void find(char*);
 int is_directory(char*);
 int is_file(char*);
 
index cbc4a2dedc26fb27361823a95df56a472f814c22..c55fff931734634d67caac815425483a9d0163a4 100644 (file)
@@ -1,5 +1,7 @@
 #include<default.h>
 
+struct options global_options;
+
 int defaults() {
        // logging needs to be setup first
        logging_thread = pthread_self();
@@ -13,7 +15,13 @@ int defaults() {
 
        log_info(DEFAULT_MESSAGE_SETTING_DEFAULTS);
 
-       opt_set_piece_length("16384");
+       if(opt_set_piece_length("16384")<0) { return -1; }
+       
+       {
+               char buf[10];
+               snprintf(buf,10,"%lu",sysconf(_SC_NPROCESSORS_ONLN));
+               if(opt_set_worker_threads(buf)<0) { return -1; }
+       }
        
        return 1;
 }
index c8e4b219374f45f77cf4c5585145190ee2429e56..54c6c5d0be7b841178b48c84c76a9bdcfdd06227 100644 (file)
@@ -7,6 +7,7 @@ static struct option long_options[] = {
        {"quiet", no_argument, &verbose_flag, LOG_LEVEL_SILENT},
        {"verbose", no_argument, &verbose_flag, LOG_LEVEL_VERBOSE},
        {"watch", required_argument, 0, 'w'},
+       {"worker-threads", required_argument, 0, 1},
        {0,0,0,0}
 };
 
@@ -22,6 +23,9 @@ int main(int argc, char **argv) {
                if((c = getopt_long(argc,argv,"c:dhqvw:",long_options,&option_index))==-1) { break; }
 
                switch(c) {
+                       case 1:
+                               if(opt_set_worker_threads(optarg)<0) { return EXIT_FAILURE; }
+                               break;
                        case 'c':
                                if(opt_load_config_file(optarg)<0) { return EXIT_FAILURE; }
                                break;
index 4ec76dbaeb8149db8b48d0967d3876af6db87748..31f2005468048835edcbba0655bd9bc07f591fa0 100644 (file)
@@ -16,6 +16,9 @@ int opt_load_from_env() {
 
        CHECK_ENV("CONFIG",opt_load_config_file);
        CHECK_ENV("PIECE_LENGTH",opt_set_piece_length);
+       CHECK_ENV("WORKER_THREADS",opt_set_worker_threads);
+
+       log_info(OPT_MESSAGE_ENV_LOADING_END);
 
        return 1;
 }
index 1b5ba7dc7336388bc66583a68a7d47eab2d277d8..c9fd8c7da1d1cda917ea0fe38cae76865dca225c 100644 (file)
@@ -11,6 +11,8 @@ int opt_set_piece_length(char *length) {
                return -1;
        }
 
+       global_options.piece_length = i;
        log_info(OPT_MESSAGE_PIECE_LENGTH_SET,i);
-       return -1;
+
+       return 1;
 }
index 18b7e87879c9f6e822aa4678656c1fb20aed6929..14b1ef5279193233e19321b450e24a11301505ec 100644 (file)
@@ -8,6 +8,7 @@ struct option_lookup_table_entry {
 struct option_lookup_table_entry option_lookup_table[] = {
        {"piece_length",&opt_set_piece_length},
        {"watch",&opt_add_watch},
+       {"worker_threads",&opt_set_worker_threads},
        {NULL,NULL}
 };
 
diff --git a/src/opt/worker.c b/src/opt/worker.c
new file mode 100644 (file)
index 0000000..4e3def8
--- /dev/null
@@ -0,0 +1,14 @@
+#include<opt.h>
+
+int opt_set_worker_threads(char *str) {
+       char *end;
+
+       global_options.worker_threads = strtoul(str,&end,10);
+       if(0==global_options.worker_threads) {
+               log_err(OPT_MESSAGE_WORKER_THREADS_INVALID,str);
+               return -1;
+       }
+
+       log_info(OPT_MESSAGE_WORKER_THREADS_SET,global_options.worker_threads);
+       return 1;
+}
index 7f78130febffbcd7055c919353cd119b1d9e273d..a64227224f1208b31edd7a0e259f019060e1d961 100644 (file)
@@ -1,5 +1,7 @@
 #include<torrent.h>
 
+struct torrent **torrents;
+
 void torrent_free(struct torrent *p) {
        free(p->root);
        free(p);
index e189a94eb125b9b466483fbae14b5a1ef1224f85..5a194edbd58afceef8bc03dff8450bde11c83de2 100644 (file)
@@ -11,4 +11,5 @@ void usage() {
        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");
 }
diff --git a/src/util/find.c b/src/util/find.c
new file mode 100644 (file)
index 0000000..85f7860
--- /dev/null
@@ -0,0 +1,24 @@
+#include<util.h>
+
+int file_filter(char *path) {
+       /* scandir requires non-zero return values to include */
+       char *p;
+       if(NULL==path) { return false; }
+
+       p = strrchr(path, '/');
+
+       if(NULL==p) {
+               p = path;
+       } else {
+               p++;
+       }
+
+       if(p[0]=='.') { return 0; }
+       
+       return 1;
+}
+
+void find(char *path) {
+       if(is_file(path)<0) {
+               
+}