From 1a197f171413d85b04b2d48853acb594b345dbc5 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sun, 12 Jun 2016 06:11:33 +0200 Subject: rename meta module --- bencode/bencode_test.go | 10 +++++----- meta/torrent.go | 29 +++++++++++++++++++++++++++++ thp/errors.go | 14 ++++++++++++++ torrent/torrent.go | 29 ----------------------------- 4 files changed, 48 insertions(+), 34 deletions(-) create mode 100644 meta/torrent.go create mode 100644 thp/errors.go delete mode 100644 torrent/torrent.go diff --git a/bencode/bencode_test.go b/bencode/bencode_test.go index 51c5bae..8f3c43f 100644 --- a/bencode/bencode_test.go +++ b/bencode/bencode_test.go @@ -6,17 +6,17 @@ import ( "testing" "time" - "dim13.org/btr/torrent" + "dim13.org/btr/meta" ) func TestMarshal(t *testing.T) { - v := torrent.Torrent{ + v := meta.Torrent{ Announce: "test", AnnounceList: []string{"test1", "test2", "test3"}, CreationDate: time.Now(), - Info: torrent.Info{ + Info: meta.Info{ Length: 1000, - Files: []torrent.File{ + Files: []meta.File{ {Path: []string{"A"}}, {Path: []string{"B"}}, }, @@ -51,7 +51,7 @@ func TestUnmarshal(t *testing.T) { t.Error(err) } for _, file := range files { - var tor torrent.Torrent + var tor meta.Torrent body, err := ioutil.ReadFile(file) if err != nil { t.Error(err) diff --git a/meta/torrent.go b/meta/torrent.go new file mode 100644 index 0000000..af71efb --- /dev/null +++ b/meta/torrent.go @@ -0,0 +1,29 @@ +package meta + +import "time" + +type File struct { + Length int `bencode:"length"` + MD5Sum []byte `bencode:"md5sum,optional"` + Path []string `bencode:"path"` +} + +type Info struct { + Length int `bencode:"length"` + MD5Sum []byte `bencode:"md5sum,optional"` + Name string `bencode:"name"` + PieceLength int `bencode:"piece length"` + Pieces []byte `bencode:"pieces"` + Files []File `bencode:"files"` +} + +type Torrent struct { + Announce string `bencode:"announce"` + AnnounceList []string `bencode:"announce-list,optional"` + Comment string `bencode:"comment,optional"` + CreatedBy string `bencode:"created by,optional"` + CreationDate time.Time `bencode:"creation date,optional"` + HTTPSeeds []string `bencode:"httpseeds,optional"` + Info Info `bencode:"info"` + URLList string `bencode:"url-list,optional"` +} diff --git a/thp/errors.go b/thp/errors.go new file mode 100644 index 0000000..33ae89f --- /dev/null +++ b/thp/errors.go @@ -0,0 +1,14 @@ +package thp + +var ErrCodes = map[int]string{ + 100: "Invalid request type: client request was not a HTTP GET", + 101: "Missing info_hash", + 102: "Missing peer_id", + 103: "Missing port", + 150: "Invalid infohash: infohash is not 20 bytes long", + 151: "Invalid peerid: peerid is not 20 bytes long", + 152: "Invalid numwant: client requested more peers than allowed by tracker", + 200: "info_hash not found in the database", + 500: "Client sent an eventless request before the specified time", + 900: "Generic error", +} diff --git a/torrent/torrent.go b/torrent/torrent.go deleted file mode 100644 index 256887f..0000000 --- a/torrent/torrent.go +++ /dev/null @@ -1,29 +0,0 @@ -package torrent - -import "time" - -type File struct { - Length int `bencode:"length"` - MD5Sum []byte `bencode:"md5sum,optional"` - Path []string `bencode:"path"` -} - -type Info struct { - Length int `bencode:"length"` - MD5Sum []byte `bencode:"md5sum,optional"` - Name string `bencode:"name"` - PieceLength int `bencode:"piece length"` - Pieces []byte `bencode:"pieces"` - Files []File `bencode:"files"` -} - -type Torrent struct { - Announce string `bencode:"announce"` - AnnounceList []string `bencode:"announce-list,optional"` - Comment string `bencode:"comment"` - CreatedBy string `bencode:"created by,optional"` - CreationDate time.Time `bencode:"creation date"` // time.Time (unix time) - HTTPSeeds []string `bencode:"httpseeds,optional"` // not in draft - Info Info `bencode:"info"` - URLList string `bencode:"url-list,optional"` // not in draft -} -- cgit v1.2.3