]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Thu, 3 Feb 2022 01:03:57 +0000 (17:03 -0800)
committeralex <[email protected]>
Thu, 3 Feb 2022 01:03:57 +0000 (17:03 -0800)
inc/opt.h
inc/session.h
src/add.c
src/session.c
test/unit/Makefile.am
test/unit/session.tests.c [new file with mode: 0644]

index b7d968f0c7df338e97ece980965310b93b03c564..ecfa853b43b7975bab1bf4df372a86f05d465623 100644 (file)
--- a/inc/opt.h
+++ b/inc/opt.h
@@ -6,9 +6,10 @@
 
 #include<fs.h>
 #include<log.h>
-#include<session.h>
 #include<torrent.h>
 
+#include<session.h>
+
 enum file_filters {
        FILE_FILTER_IGNORE_DOTFILES,
        FILE_FILTER_ALL,
index 158e68d1584cefdbea6223e286878319e3c3edec..a3c3e690ff71ac5302cc9c652a8af8e2dc319559 100644 (file)
@@ -1,6 +1,7 @@
 #ifndef __SESSION_H_
 #define __SESSION_H_
 
+#include<hashmap.h>
 #include<log.h>
 #include<torrent.h>
 
index c1d28c5fea3985b108b22ed3a056e52e9c4eec14..ec71143f81c5376e00da02779af8b5a2e8fdd125 100644 (file)
--- a/src/add.c
+++ b/src/add.c
@@ -14,10 +14,15 @@ static struct file *get_next();
 static int ftw_helper(const char*,const struct stat*,int);
 
 int add() {
+       struct torrent *p;
+
        if(hashmap_init(&add_queue,ADD_QUEUE_INITIAL_SIZE)<0) { return -1; }
 
-       for(size_t i=0;i<session.torrent_count;i++) {
-               if(add_find_all(session.torrents[i])<0) { return -1; }
+       for(size_t i=0;i<session.torrents.infohashes->size;i++) {
+               p = session.torrents.infohashes->map[i];
+               if(p!=NULL) {
+                       if(add_find_all(p)<0) { return -1; }
+               }
        }
 
        add_queue_index = 0;
index 7b44b9774c0b7bf0418a942f372b4803b6b061da..6b3a2c64b8d7af55d8663864e0cc3a31113fc792 100644 (file)
@@ -70,5 +70,43 @@ static int session_torrent_add_by_path(struct torrent *torrent) {
 }
 
 static int session_torrent_resize(struct hash_map **map, size_t new_size) {
+       struct hash_map *new, *old;
+
+       if(hashmap_init(&new,new_size)<0) { return -1; }
+
+       flag = 0;
+       if(session.torrents.paths==(*map)) { flag = 1; }
+
+       for(size_t i=0;i<(*map)->size;i++) {
+               p = (*map)->map[i];
+               if(p!=NULL) {
+                       if(flag) {
+                               if((ret = hashmap_insert(new,p->root,strlen(p->root),p))<=0) {
+                                       if(ret<0) { goto clean; }
+                                       goto resize;
+                               }
+                       } else {
+                               if((ret = hashmap_insert(new,p->infohash,crypto_hash_sha256_BYTES,p))<=0) {
+                                       if(ret<0) { goto clean; }
+                                       goto resize;
+                               }
+                       }
+               }
+       }
+
+       hashmap_clear(*map);
+       old = *map;
+       *map = new;
+
+       hashmap_free(old);
+
+       return 1;
+resize:
+       hashmap_clear(new);
+       hashmap_free(new);
+       return session_torrent_resize(map,new_size<<1);
+clean:
+       hashmap_clear(new);
+       hashmap_free(new);
        return -1;
 }
index b0db9117c88e998acc8eaac1b00fdc190d2b397c..1af237b168643b4f081bc964d8296d30dcccc5d4 100644 (file)
@@ -13,7 +13,7 @@ AM_CPPFLAGS += \
        -DNDEBUG
 endif
 
-check_PROGRAMS = bencode.tests block.tests feed.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests meta.tests opt.tests rss.tests torrent.tests tree.tests
+check_PROGRAMS = bencode.tests block.tests feed.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests meta.tests opt.tests rss.tests session.tests torrent.tests tree.tests
 TESTS = $(check_PROGRAMS)
 
 if ENABLE_MEMCHECK
@@ -148,6 +148,11 @@ rss_tests_SOURCES = \
        $(top_srcdir)/src/rss/info.c \
        $(top_srcdir)/src/rss/init.c
 
+session_tests_SOURCES = \
+       $(common_SOURCES) \
+       $(torrent_SOURCES) \
+       session.tests.c
+
 torrent_tests_SOURCES = \
        $(common_SOURCES) \
        $(torrent_SOURCES) \
diff --git a/test/unit/session.tests.c b/test/unit/session.tests.c
new file mode 100644 (file)
index 0000000..2ead6e7
--- /dev/null
@@ -0,0 +1,13 @@
+#include<test_utils.h>
+
+#include<session.h>
+
+int main();
+
+int main() {
+       setup_env();
+
+       clean_env();
+
+       return EXIT_SUCCESS;
+}