diff --git a/drivers/backend/backend.go b/backend/backend.go similarity index 100% rename from drivers/backend/backend.go rename to backend/backend.go diff --git a/drivers/backend/noop/driver.go b/backend/noop/driver.go similarity index 96% rename from drivers/backend/noop/driver.go rename to backend/noop/driver.go index 4c072ae..04750e8 100644 --- a/drivers/backend/noop/driver.go +++ b/backend/noop/driver.go @@ -8,7 +8,7 @@ package noop import ( "github.com/chihaya/chihaya/config" - "github.com/chihaya/chihaya/drivers/backend" + "github.com/chihaya/chihaya/backend" "github.com/chihaya/chihaya/tracker/models" ) diff --git a/chihaya.go b/chihaya.go index 7bb5a34..30ab48a 100644 --- a/chihaya.go +++ b/chihaya.go @@ -17,7 +17,7 @@ import ( "github.com/chihaya/chihaya/tracker" // See the README for how to import custom drivers. - _ "github.com/chihaya/chihaya/drivers/backend/noop" + _ "github.com/chihaya/chihaya/backend/noop" _ "github.com/chihaya/chihaya/tracker/memory" ) diff --git a/http/announce_private_test.go b/http/announce_private_test.go deleted file mode 100644 index a1129d0..0000000 --- a/http/announce_private_test.go +++ /dev/null @@ -1,103 +0,0 @@ -// Copyright 2014 The Chihaya Authors. All rights reserved. -// Use of this source code is governed by the BSD 2-Clause license, -// which can be found in the LICENSE file. - -package http - -import ( - "testing" - - "github.com/chihaya/bencode" - "github.com/chihaya/chihaya/config" - "github.com/chihaya/chihaya/tracker" - "github.com/chihaya/chihaya/tracker/models" -) - -func TestPrivateAnnounce(t *testing.T) { - cfg := config.DefaultConfig - cfg.Private = true - - tkr, err := tracker.New(&cfg) - if err != nil { - t.Fatal(err) - } - - err = loadTestData(tkr) - if err != nil { - t.Fatal(err) - } - - srv, err := createServer(tkr, &cfg) - if err != nil { - t.Fatal(err) - } - - defer srv.Close() - baseURL := srv.URL - - peer := makePeerParams("-TR2820-peer1", false) - expected := makeResponse(0, 1, bencode.List{}) - srv.URL = baseURL + "/users/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv1" - checkAnnounce(peer, expected, srv, t) - - peer = makePeerParams("-TR2820-peer2", false) - expected = makeResponse(0, 2, bencode.List{ - makePeerResponse("-TR2820-peer1"), - }) - srv.URL = baseURL + "/users/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv2" - checkAnnounce(peer, expected, srv, t) - - peer = makePeerParams("-TR2820-peer3", true) - expected = makeResponse(1, 2, bencode.List{ - makePeerResponse("-TR2820-peer1"), - makePeerResponse("-TR2820-peer2"), - }) - srv.URL = baseURL + "/users/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv3" - checkAnnounce(peer, expected, srv, t) - - peer = makePeerParams("-TR2820-peer1", false) - expected = makeResponse(1, 2, bencode.List{ - makePeerResponse("-TR2820-peer2"), - makePeerResponse("-TR2820-peer3"), - }) - srv.URL = baseURL + "/users/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv1" - checkAnnounce(peer, expected, srv, t) -} - -func loadTestData(tkr *tracker.Tracker) error { - conn, err := tkr.Pool.Get() - if err != nil { - return err - } - - users := []string{ - "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv1", - "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv2", - "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv3", - } - - for i, passkey := range users { - err = conn.PutUser(&models.User{ - ID: uint64(i + 1), - Passkey: passkey, - }) - - if err != nil { - return err - } - } - - err = conn.PutClient("TR2820") - if err != nil { - return err - } - - torrent := &models.Torrent{ - ID: 1, - Infohash: infoHash, - Seeders: models.PeerMap{}, - Leechers: models.PeerMap{}, - } - - return conn.PutTorrent(torrent) -} diff --git a/http/announce_test.go b/http/announce_test.go index abc2f03..696d562 100644 --- a/http/announce_test.go +++ b/http/announce_test.go @@ -14,6 +14,8 @@ import ( "github.com/chihaya/bencode" "github.com/chihaya/chihaya/config" + "github.com/chihaya/chihaya/tracker" + "github.com/chihaya/chihaya/tracker/models" ) func TestPublicAnnounce(t *testing.T) { @@ -131,6 +133,57 @@ func TestStalePeerPurging(t *testing.T) { } } +func TestPrivateAnnounce(t *testing.T) { + cfg := config.DefaultConfig + cfg.Private = true + + tkr, err := tracker.New(&cfg) + if err != nil { + t.Fatal(err) + } + + err = loadPrivateTestData(tkr) + if err != nil { + t.Fatal(err) + } + + srv, err := createServer(tkr, &cfg) + if err != nil { + t.Fatal(err) + } + + defer srv.Close() + baseURL := srv.URL + + peer := makePeerParams("-TR2820-peer1", false) + expected := makeResponse(0, 1, bencode.List{}) + srv.URL = baseURL + "/users/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv1" + checkAnnounce(peer, expected, srv, t) + + peer = makePeerParams("-TR2820-peer2", false) + expected = makeResponse(0, 2, bencode.List{ + makePeerResponse("-TR2820-peer1"), + }) + srv.URL = baseURL + "/users/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv2" + checkAnnounce(peer, expected, srv, t) + + peer = makePeerParams("-TR2820-peer3", true) + expected = makeResponse(1, 2, bencode.List{ + makePeerResponse("-TR2820-peer1"), + makePeerResponse("-TR2820-peer2"), + }) + srv.URL = baseURL + "/users/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv3" + checkAnnounce(peer, expected, srv, t) + + peer = makePeerParams("-TR2820-peer1", false) + expected = makeResponse(1, 2, bencode.List{ + makePeerResponse("-TR2820-peer2"), + makePeerResponse("-TR2820-peer3"), + }) + srv.URL = baseURL + "/users/vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv1" + checkAnnounce(peer, expected, srv, t) +} + func makePeerParams(id string, seed bool) params { left := "1" if seed { @@ -193,3 +246,41 @@ func checkAnnounce(p params, expected interface{}, srv *httptest.Server, t *test } return true } + +func loadPrivateTestData(tkr *tracker.Tracker) error { + conn, err := tkr.Pool.Get() + if err != nil { + return err + } + + users := []string{ + "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv1", + "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv2", + "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv3", + } + + for i, passkey := range users { + err = conn.PutUser(&models.User{ + ID: uint64(i + 1), + Passkey: passkey, + }) + + if err != nil { + return err + } + } + + err = conn.PutClient("TR2820") + if err != nil { + return err + } + + torrent := &models.Torrent{ + ID: 1, + Infohash: infoHash, + Seeders: models.PeerMap{}, + Leechers: models.PeerMap{}, + } + + return conn.PutTorrent(torrent) +} diff --git a/http/http_test.go b/http/http_test.go index 4f25b91..8fe5eb7 100644 --- a/http/http_test.go +++ b/http/http_test.go @@ -15,7 +15,7 @@ import ( "github.com/chihaya/chihaya/config" "github.com/chihaya/chihaya/tracker" - _ "github.com/chihaya/chihaya/drivers/backend/noop" + _ "github.com/chihaya/chihaya/backend/noop" _ "github.com/chihaya/chihaya/tracker/memory" ) diff --git a/http/api.go b/http/routes.go similarity index 100% rename from http/api.go rename to http/routes.go diff --git a/tracker/tracker.go b/tracker/tracker.go index 6509854..5a715a4 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -8,7 +8,7 @@ package tracker import ( "github.com/chihaya/chihaya/config" - "github.com/chihaya/chihaya/drivers/backend" + "github.com/chihaya/chihaya/backend" "github.com/chihaya/chihaya/tracker/models" )