// this always returns hex, unnecessary to return
sodium_bin2hex(hex,(crypto_hash_sha256_BYTES<<1)+1,infohash,crypto_hash_sha256_BYTES);
- p = concat(PREFIX TORRENT_FILE_DIRECTORY,hex);
+ p = concat(TORRENT_FILE_DIRECTORY,hex);
if(NULL==p) { return NULL; }
path = malloc(strlen(p)+strlen(".torrent")+1);
return NULL;
}
- if(sprintf("%s" TORRENT_FILE_EXTENSION,p)<0) {
+ if(sprintf(path,"%s" TORRENT_FILE_EXTENSION,p)<0) {
free(p);
free(path);
return NULL;
static void torrent_file_info_basic_test() {
struct torrent *torrent;
+ uint8_t *buf;
torrent_setup_example(&torrent);
+ assert(-1==torrent_file_info(NULL,NULL));
+ assert(-1==torrent_file_info(torrent,NULL));
+
+ assert(212==torrent_file_info(torrent,&buf));
+
+ uint8_t expected[] = "d9:file treed4:testd0:d6:lengthi0e11:pieces root32:" "\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01" "ee5:test2d0:d6:lengthi0e11:pieces root32:" "\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02\x02" "eee12:meta versioni2e4:name5:.test12:piece lengthi16384e";
+ assert(memcmp(buf,expected,212)==0);
+
+ free(buf);
+
torrent_free(torrent);
}
static void torrent_file_path_basic_test() {
- struct torrent *torrent;
+ unsigned char infohash[crypto_hash_sha256_BYTES];
+ char *p;
- torrent_setup_example(&torrent);
+ memset(infohash,0,crypto_hash_sha256_BYTES);
- torrent_free(torrent);
+
+ p = torrent_file_path(NULL,0);
+ assert(NULL==p);
+
+ p = torrent_file_path(infohash,0);
+ assert(NULL==p);
+
+ p = torrent_file_path(infohash,23);
+ assert(NULL==p);
+
+ p = torrent_file_path(infohash,crypto_hash_sha256_BYTES);
+ assert(strcmp(p,"/torrents/0000000000000000000000000000000000000000000000000000000000000000.torrent")==0);
+
+ free(p);
}
static void torrent_init_basic_test() {