#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*);
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);
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; }
-DNDEBUG
endif
-check_PROGRAMS = basic.tests qbittorrent.tests
+#check_PROGRAMS = basic.tests qbittorrent.tests
+check_PROGRAMS = qbittorrent.tests
TESTS = $(check_PROGRAMS)
#if ENABLE_MEMCHECK
$(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 \
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));
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);
}
#include<time.h>
#include<unistd.h>
+#define EXIT_SKIP 77
+
void clean_env();
void reset_env();
pid_t run(char*const[]);