char *path;
unsigned char root[crypto_hash_sha256_BYTES];
struct block *piece_layers;
- size_t size;
+ uint64_t size;
};
ssize_t file_bencode(struct file*,uint8_t*,size_t);
void torrent_free(struct torrent*);
int torrent_init(struct torrent**,const char*,const char*,unsigned long long);
char *torrent_magnet(struct torrent*);
+int torrent_bencode_piece_layers();
#endif
struct file *p;
int i;
- if((i = hashmap_insert(files,f->path,strlen(f->path),f))<0) {
+ if((i = hashmap_insert(files,f->path,strlen(f->path),f))<=0) {
if(i<0) { return -1; }
p = hashmap_find(files,f->path,strlen(f->path));
struct file *p;
int i;
- if((i = hashmap_insert(files,f->root,crypto_hash_sha256_BYTES,f))<0) {
+ if((i = hashmap_insert(files,f->root,crypto_hash_sha256_BYTES,f))<=0) {
if(i<0) { return -1; }
p = hashmap_find(files,f->root,crypto_hash_sha256_BYTES);
}
static int torrent_files_resize(struct torrent *torrent_p, size_t new_size) {
- struct file *p;
+ struct file *p, *found;
struct hash_map *new, *old;
int ret;
for(size_t i=0;i<torrent_p->files->size;i++) {
p = torrent_p->files->map[i];
if(p!=NULL) {
+ // remove reference to file
+ // check if already added this file
+ // necessary because of dual keys
+ found = hashmap_find(new,p->root,crypto_hash_sha256_BYTES);
+ if(found!=NULL) { continue; }
+
if(
((ret = torrent_add_file_by_root(new,p))<=0) ||
((ret = torrent_add_file_by_path(new,p))<=0)
--- /dev/null
+#include<torrent.h>
+
+int torrent_bencode_piece_layers() {
+ return -1;
+}
struct file *file1, *file2, *file3, *file4;
assert(file_init(&file1,TEST_FILE_1)==1);
+ memset(file1->root,1,crypto_hash_sha256_BYTES);
assert(file_init(&file2,TEST_FILE_2)==1);
+ memset(file2->root,2,crypto_hash_sha256_BYTES);
assert(file_init(&file3,TEST_FILE_3)==1);
+ memset(file3->root,3,crypto_hash_sha256_BYTES);
assert(file_init(&file4,TEST_FILE_4)==1);
+ memset(file4->root,4,crypto_hash_sha256_BYTES);
assert(torrent_init(&torrent,TEST_DIRECTORY,TEST_DIRECTORY,16384)==1);
+ memset(torrent->files->key,0,crypto_shorthash_KEYBYTES);
+
assert(torrent_add(torrent,file1)==1);
assert(torrent_add(torrent,file2)==1);
assert(torrent_add(torrent,file3)==1);
assert(torrent->tree->entries->next->next->file==file1);
assert(torrent->tree->entries->next->next->next->file==file2);
+ assert(0);
+
torrent_free(torrent);
reset_env();