--- /dev/null
+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
--- /dev/null
+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()
+ }
+}