From 97f678b9405478da31cc42eae6aefb6e99ef22b3 Mon Sep 17 00:00:00 2001 From: alex Date: Sun, 31 Jul 2022 00:35:49 -0700 Subject: [PATCH] ... --- inc/peer.h | 2 +- src/peer/hash.c | 12 ++++++++++-- test/integration/Makefile.am | 6 +++++- test/integration/qbittorrent.tests.c | 3 ++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/inc/peer.h b/inc/peer.h index c2537ca..7eae50f 100644 --- a/inc/peer.h +++ b/inc/peer.h @@ -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); diff --git a/src/peer/hash.c b/src/peer/hash.c index efe1b43..ff92cba 100644 --- a/src/peer/hash.c +++ b/src/peer/hash.c @@ -1,12 +1,20 @@ #include #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) { diff --git a/test/integration/Makefile.am b/test/integration/Makefile.am index 94b93aa..d41168f 100644 --- a/test/integration/Makefile.am +++ b/test/integration/Makefile.am @@ -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) diff --git a/test/integration/qbittorrent.tests.c b/test/integration/qbittorrent.tests.c index 28543b7..cba1e42 100644 --- a/test/integration/qbittorrent.tests.c +++ b/test/integration/qbittorrent.tests.c @@ -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); -- 2.39.5