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);
#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) {
$(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)
void qbittorrent_integration_test() {
struct addrinfo hints, *res;
struct peer *info;
+ struct hash_request req;
enum peer_message type;
ssize_t i;
assert(1==peer_keepalive(info));
- assert(1==peer_hash_request(info));
+ assert(1==peer_hash_request(info,&req));
close(info->sock);
peer_free(info);