...
authoralex <[email protected]>
Sun, 31 Jul 2022 07:35:49 +0000 (00:35 -0700)
committeralex <[email protected]>
Sun, 31 Jul 2022 07:35:49 +0000 (00:35 -0700)
inc/peer.h
src/peer/hash.c
test/integration/Makefile.am
test/integration/qbittorrent.tests.c

index c2537ca18c272981895bbb652f49b1da0474ba40..7eae50fbb561a90b8c5e975d89ee46b3e902eb4d 100644 (file)
@@ -89,7 +89,7 @@ int peer_handshake(struct peer*);
 int peer_handshake_received(struct peer*);
 int peer_hash_reject(struct peer*);
 int peer_hash_reject_received(struct peer*,ssize_t);
-int peer_hash_request(struct peer*);
+int peer_hash_request(struct peer*, const struct hash_request*);
 int peer_hash_request_received(struct peer*,ssize_t);
 int peer_hashes(struct peer*);
 int peer_hashes_received(struct peer*,ssize_t);
index efe1b43435fbcb9c01faad4e99d260938e1d4c57..ff92cba3a52964149148587c4c7c9d25cbd2aa18 100644 (file)
@@ -1,12 +1,20 @@
 #include<peer.h>
 
 #define HASH_REQUEST_LENGTH crypto_hash_sha256_BYTES+4+4+4+4
+
 int peer_hash_request(struct peer *info,const struct hash_request *request) {
        unsigned char buf[HASH_REQUEST_LENGTH];
 
-       
+       memcpy(buf,request->pieces_root,crypto_hash_sha256_BYTES);
 
-       return -1;
+       UINT32_T_TO_BYTES(request->base_layer,(&(buf[crypto_hash_sha256_BYTES])));
+       UINT32_T_TO_BYTES(request->index,(&(buf[crypto_hash_sha256_BYTES+4])));
+       UINT32_T_TO_BYTES(request->length,(&(buf[crypto_hash_sha256_BYTES+8])));
+       UINT32_T_TO_BYTES(request->proof_layers,(&(buf[crypto_hash_sha256_BYTES+12])));
+
+       if(net_send(info,buf,HASH_REQUEST_LENGTH)<0) { return -1; }
+
+       return 1;
 }
 
 int peer_hash_request_received(struct peer *info, ssize_t len) {
index 94b93aa71aa013fca8ac189233f10336287245c9..d41168f082981bd49dde5cf2a9faece9d5cfc371 100644 (file)
@@ -43,9 +43,13 @@ qbittorrent_tests_SOURCES = \
        $(top_srcdir)/src/peer/choke.c \
        $(top_srcdir)/src/peer/free.c \
        $(top_srcdir)/src/peer/handshake.c \
+       $(top_srcdir)/src/peer/hash.c \
        $(top_srcdir)/src/peer/id.c \
        $(top_srcdir)/src/peer/init.c \
-       $(top_srcdir)/src/peer/interest.c
+       $(top_srcdir)/src/peer/interest.c \
+       $(top_srcdir)/src/peer/keepalive.c \
+       $(top_srcdir)/src/peer/piece.c \
+       $(top_srcdir)/src/peer/request.c
 
 clean-local:
        -rm -rf $(TEST_DIRECTORY)
index 28543b7dee1d615e5e26f5815a83f42b3dcba0ea..cba1e42224f03b0d80c123a2f556d1f0467bb553 100644 (file)
@@ -23,6 +23,7 @@ int main() {
 void qbittorrent_integration_test() {
        struct addrinfo hints, *res;
        struct peer *info;
+       struct hash_request req;
        enum peer_message type;
        ssize_t i;
 
@@ -68,7 +69,7 @@ void qbittorrent_integration_test() {
 
        assert(1==peer_keepalive(info));
 
-       assert(1==peer_hash_request(info));
+       assert(1==peer_hash_request(info,&req));
 
        close(info->sock);
        peer_free(info);