]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Begin on UDP trackers
authorMatt Joiner <anacrolix@gmail.com>
Mon, 4 Nov 2013 13:04:14 +0000 (00:04 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 4 Nov 2013 13:04:14 +0000 (00:04 +1100)
tracker/udp.go [new file with mode: 0644]
tracker/udp_test.go [new file with mode: 0644]

diff --git a/tracker/udp.go b/tracker/udp.go
new file mode 100644 (file)
index 0000000..55e9ad3
--- /dev/null
@@ -0,0 +1,27 @@
+package tracker
+
+type UDPConnectionRequest struct {
+       ConnectionId int64
+       Action       int32
+       TransctionId int32
+}
+
+type UDPAnnounceResponseHeader struct {
+       Action        int32
+       TransactionId int32
+       Interval      int32
+       Leechers      int32
+       Seeders       int32
+}
+
+type UDPAnnounceResponse struct {
+       UDPAnnounceResponseHeader
+       PeerAddrSlice
+}
+
+type PeerAddr struct {
+       IP   int32
+       Port int16
+}
+
+type PeerAddrSlice []PeerAddr
diff --git a/tracker/udp_test.go b/tracker/udp_test.go
new file mode 100644 (file)
index 0000000..cf4c0e0
--- /dev/null
@@ -0,0 +1,20 @@
+package tracker
+
+import (
+       "bytes"
+       "encoding/binary"
+       "testing"
+)
+
+func TestMarshalUDPAnnounceResponse(t *testing.T) {
+       w := bytes.NewBuffer(nil)
+       if err := binary.Write(w, binary.BigEndian, &PeerAddrSlice{{1, 2}, {3, 4}}); err != nil {
+               t.Fatalf("error writing udp announce response addrs: %s", err)
+       }
+       if w.String() != "\x00\x00\x00\x01\x00\x02\x00\x00\x00\x03\x00\x04" {
+               t.FailNow()
+       }
+       if binary.Size(UDPAnnounceResponseHeader{}) != 20 {
+               t.FailNow()
+       }
+}