]> infiniteadaptability.org Git - seeder/commitdiff
...
authoralex <[email protected]>
Sat, 23 Jul 2022 19:22:43 +0000 (12:22 -0700)
committeralex <[email protected]>
Sat, 23 Jul 2022 19:22:43 +0000 (12:22 -0700)
inc/peer.h
src/peer/bitfield.c
test/integration/Makefile.am
test/integration/qbittorrent.tests.c
test/integration/test_utils.h

index b2b7b8d97a93ca1326dcb138edfe1f25ae54fec1..c2537ca18c272981895bbb652f49b1da0474ba40 100644 (file)
@@ -77,6 +77,7 @@ enum peer_message {
 #include<torrent.h>
 
 int peer_bitfield(struct peer*);
+int peer_bitfield_init(struct peer*,size_t);
 int peer_bitfield_received(struct peer*,ssize_t);
 int peer_bitfield_toggle(struct peer*,size_t);
 int peer_cancel(struct peer*);
index cb79765350869790f17ee45450cd9f1c40a2e163..c7d0cf3d267e7f92b55c13dbb1b013d4f8646cdb 100644 (file)
@@ -5,8 +5,6 @@ int peer_bitfield(struct peer *info) {
        buf = malloc(info->bitfield_size);
        if(NULL==buf) { return -1; }
 
-       memset(buf,0xff,info->bitfield_size);
-
        if(net_send(info,buf,info->bitfield_size)<0) { return -1; }
 
        free(buf);
@@ -17,6 +15,10 @@ int peer_bitfield(struct peer *info) {
 int peer_bitfield_init(struct peer *info, size_t pieces) {
        info->bitfield_size = pieces/8;
 
+       if((info->bitfield_size*8)<pieces) {
+               info->bitfield_size++;
+       }
+
        info->bitfield = calloc(pieces,sizeof(uint8_t));
        if(NULL==info->bitfield) { return -1; }
 
index 470659059611d438113beb068d94b18d4e663e0a..9550eeb3b95b2822661cd3acc06646449a615766 100644 (file)
@@ -16,7 +16,8 @@ AM_CPPFLAGS += \
        -DNDEBUG
 endif
 
-check_PROGRAMS = basic.tests qbittorrent.tests
+#check_PROGRAMS = basic.tests qbittorrent.tests
+check_PROGRAMS = qbittorrent.tests
 TESTS = $(check_PROGRAMS)
 
 #if ENABLE_MEMCHECK
@@ -35,8 +36,11 @@ qbittorrent_tests_SOURCES = \
        $(common_SOURCES) \
        qbittorrent.tests.c \
        $(top_srcdir)/src/net/cache.c \
+       $(top_srcdir)/src/net/expected.c \
+       $(top_srcdir)/src/net/peek.c \
        $(top_srcdir)/src/net/send.c \
        $(top_srcdir)/src/net/wait.c \
+       $(top_srcdir)/src/peer/bitfield.c \
        $(top_srcdir)/src/peer/free.c \
        $(top_srcdir)/src/peer/handshake.c \
        $(top_srcdir)/src/peer/id.c \
index a51fe5432e6ff2011a6d6386522dc6378c891901..f1fef6f87a67cc32599d1123d63862a7dc7724fc 100644 (file)
@@ -23,7 +23,12 @@ int main() {
 void qbittorrent_integration_test() {
        struct addrinfo hints, *res;
        struct peer *info;
+       enum peer_message type;
+       ssize_t i;
+
+       // test torrent: debian-live-11.4.0-amd64-xfce.iso
        const char infohash[] = {0x25, 0x11, 0xdf, 0x9f, 0x74, 0xdc, 0x6f, 0xc1, 0x8e, 0xc9, 0x46, 0x6c, 0xdd, 0x52, 0xf5, 0xa1, 0x83, 0x27, 0xe2, 0x6e};
+       const size_t pieces = 2526;
 
        assert(1==peer_init(&info));
 
@@ -37,15 +42,24 @@ void qbittorrent_integration_test() {
        assert(info->sock>0);
 
        if(0!=connect(info->sock,res->ai_addr,res->ai_addrlen)) {
-               exit(77);
+               exit(EXIT_SKIP);
        }
 
        assert(1==session_setup());
        memcpy(info->infohash,infohash,PEER_INFOHASH_SIZE);
+       assert(1==peer_bitfield_init(info,pieces));
 
        assert(1==peer_handshake(info));
        assert(1==peer_handshake_received(info));
 
+       assert(1==peer_bitfield(info));
+
+       i = net_expected(info,&type);
+       assert(i>=0);
+       assert(PEER_MESSAGE_BITFIELD==type);
+
+       assert(1==peer_bitfield_received(info,i));
+
        close(info->sock);
        peer_free(info);
 }
index 1d9ee1b464819a85ac0273e057c41bb265ac972e..726e541a9e8b9e7670b1d417a77754a134fc9a8e 100644 (file)
@@ -15,6 +15,8 @@
 #include<time.h>
 #include<unistd.h>
 
+#define EXIT_SKIP 77
+
 void clean_env();
 void reset_env();
 pid_t run(char*const[]);