...
authoralex <[email protected]>
Tue, 8 Feb 2022 01:55:38 +0000 (17:55 -0800)
committeralex <[email protected]>
Tue, 8 Feb 2022 01:55:38 +0000 (17:55 -0800)
inc/peer.h
src/peer/bitfield.c [new file with mode: 0644]
src/peer/cancel.c [new file with mode: 0644]
src/peer/choke.c [new file with mode: 0644]
src/peer/handshake.c
src/peer/hash.c [new file with mode: 0644]
src/peer/have.c [new file with mode: 0644]
src/peer/interest.c [new file with mode: 0644]
src/peer/request.c [new file with mode: 0644]
test/unit/Makefile.am
test/unit/peer.tests.c [new file with mode: 0644]

index f99ac3ca97e4cb49449d5a87a1bf2746af6a9249..038e3aba8a53d3c46e2a46b11d002ebceec18274 100644 (file)
@@ -17,4 +17,6 @@ enum peer_message {
        PEER_MESSAGE_HASH_REJECT = 23
 };
 
+int peer_handshake(int,const uint8_t*,size_t,const uint8_t*,size_t);
+
 #endif
diff --git a/src/peer/bitfield.c b/src/peer/bitfield.c
new file mode 100644 (file)
index 0000000..9947ff8
--- /dev/null
@@ -0,0 +1,5 @@
+#include<peer.h>
+
+int peer_bitfield(int sock) {
+       return -1;
+}
diff --git a/src/peer/cancel.c b/src/peer/cancel.c
new file mode 100644 (file)
index 0000000..07da8b9
--- /dev/null
@@ -0,0 +1,5 @@
+#include<peer.h>
+
+int peer_cancel() {
+       return -1;
+}
diff --git a/src/peer/choke.c b/src/peer/choke.c
new file mode 100644 (file)
index 0000000..99d8423
--- /dev/null
@@ -0,0 +1,9 @@
+#include<peer.h>
+
+int peer_choke(int sock) {
+       return -1;
+}
+
+int peer_unchoke(int sock) {
+       return -1;
+}
index 42ed6a3e11ec452543575715233fc313c831e90b..24d3135b5f6e7e9c15f58b921effda340caa74ae 100644 (file)
@@ -1,11 +1,14 @@
 #include<peer.h>
 
-#define HANDSHAKE_STRING "\x13BitTorrent protocol\0\0\0\0\0\0\0\0";
+#define HANDSHAKE_STRING "\x13" "BitTorrent protocol\0\0\0\0\0\0\0\0";
 #define HANDSHAKE_INFOHASH_SIZE 20
 
-int handshake(int sock, const uint8_t *infohash, size_t infohash_size const uint8_t peer_id, size_t peer_id_size) {
+int peer_handshake(int sock, const uint8_t *infohash, size_t infohash_size const uint8_t *peer_id, size_t peer_id_size) {
        const char header[64] = HANDSHAKE_STRING;
 
+       assert(HANDSHAKE_INFOHASH_SIZE==infohash_size);
+       assert(PEER_ID_SIZE==peer_id_size);
+
        memcpy(&(header[24]),infohash,HANDSHAKE_INFOHASH_SIZE);
        memcpy(&(header[44]),peer_id,PEER_ID_SIZE);
 
diff --git a/src/peer/hash.c b/src/peer/hash.c
new file mode 100644 (file)
index 0000000..4f1e067
--- /dev/null
@@ -0,0 +1,9 @@
+#include<peer.h>
+
+int peer_hash_request() {
+       return -1;
+}
+
+int peer_hash_reject() {
+       return -1;
+}
diff --git a/src/peer/have.c b/src/peer/have.c
new file mode 100644 (file)
index 0000000..28c14b2
--- /dev/null
@@ -0,0 +1,5 @@
+#include<peer.h>
+
+int peer_have(int sock) {
+       return -1;
+}
diff --git a/src/peer/interest.c b/src/peer/interest.c
new file mode 100644 (file)
index 0000000..651704d
--- /dev/null
@@ -0,0 +1,9 @@
+#include<peer.h>
+
+int peer_interested(int sock) {
+       return -1;
+}
+
+int peer_not_interested(int sock) {
+       return -1;
+}
diff --git a/src/peer/request.c b/src/peer/request.c
new file mode 100644 (file)
index 0000000..371f988
--- /dev/null
@@ -0,0 +1,5 @@
+#include<peer.h>
+
+int peer_request() {
+       return -1;
+}
index 83cb82f2ac5211975a05097c8aeb673e01672227..0719cdd7b04887f38b7050241153b9ca6d515a4f 100644 (file)
@@ -13,7 +13,7 @@ AM_CPPFLAGS += \
        -DNDEBUG
 endif
 
-check_PROGRAMS = bencode.tests block.tests feed.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests meta.tests opt.tests rss.tests session.tests torrent.tests tree.tests
+check_PROGRAMS = bencode.tests block.tests feed.tests file.tests fs.concat.tests fs.filter.tests hash.tests hashmap.tests meta.tests opt.tests peer.tests rss.tests session.tests torrent.tests tree.tests
 TESTS = $(check_PROGRAMS)
 
 if ENABLE_MEMCHECK
@@ -138,6 +138,10 @@ opt_tests_SOURCES = \
        $(top_srcdir)/src/opt/worker.c \
        $(top_srcdir)/src/session.c
 
+peer_tests_SOURCES = \
+       $(common_SOURCES) \
+       peer.tests.c
+
 rss_tests_SOURCES = \
        $(common_SOURCES) \
        rss.tests.c \
diff --git a/test/unit/peer.tests.c b/test/unit/peer.tests.c
new file mode 100644 (file)
index 0000000..c934f73
--- /dev/null
@@ -0,0 +1,9 @@
+#include<test_utils.h>
+
+#include<peer.h>
+
+int main();
+
+int main() {
+       return EXIT_SUCCESS;
+}