aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2016-06-12 06:11:33 +0200
committerDimitri Sokolyuk <demon@dim13.org>2016-06-12 06:11:33 +0200
commit1a197f171413d85b04b2d48853acb594b345dbc5 (patch)
treeb510de6ff48f9f3a76e69f4c62b036a1fa9cef2b
parent1c73aa4b153812fbc64d98b609375cec617c073e (diff)
rename meta module
-rw-r--r--bencode/bencode_test.go10
-rw-r--r--meta/torrent.go (renamed from torrent/torrent.go)10
-rw-r--r--thp/errors.go14
3 files changed, 24 insertions, 10 deletions
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/torrent/torrent.go b/meta/torrent.go
index 256887f..af71efb 100644
--- a/torrent/torrent.go
+++ b/meta/torrent.go
@@ -1,4 +1,4 @@
-package torrent
+package meta
import "time"
@@ -20,10 +20,10 @@ type Info struct {
type Torrent struct {
Announce string `bencode:"announce"`
AnnounceList []string `bencode:"announce-list,optional"`
- Comment string `bencode:"comment"`
+ Comment string `bencode:"comment,optional"`
CreatedBy string `bencode:"created by,optional"`
- CreationDate time.Time `bencode:"creation date"` // time.Time (unix time)
- HTTPSeeds []string `bencode:"httpseeds,optional"` // not in draft
+ CreationDate time.Time `bencode:"creation date,optional"`
+ HTTPSeeds []string `bencode:"httpseeds,optional"`
Info Info `bencode:"info"`
- URLList string `bencode:"url-list,optional"` // not in draft
+ 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",
+}