First step towards removing Tracker Driver.

This feature isn't worth maintaining and if anyone needs to scale beyond
memory on a single box, we can evaluate it then.
This commit is contained in:
Jimmy Zelinskie
2014-08-13 17:45:34 -04:00
parent e3420b4013
commit 1d9b2bc322
13 changed files with 324 additions and 576 deletions
+5 -20
View File
@@ -131,10 +131,7 @@ func TestPrivateAnnounce(t *testing.T) {
t.Fatal(err)
}
err = loadPrivateTestData(tkr)
if err != nil {
t.Fatal(err)
}
loadPrivateTestData(tkr)
srv, err := createServer(tkr, &cfg)
if err != nil {
@@ -343,12 +340,7 @@ 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
}
func loadPrivateTestData(tkr *tracker.Tracker) {
users := []string{
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv1",
"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv2",
@@ -356,20 +348,13 @@ func loadPrivateTestData(tkr *tracker.Tracker) error {
}
for i, passkey := range users {
err = conn.PutUser(&models.User{
tkr.PutUser(&models.User{
ID: uint64(i + 1),
Passkey: passkey,
})
if err != nil {
return err
}
}
err = conn.PutClient("TR2820")
if err != nil {
return err
}
tkr.PutClient("TR2820")
torrent := &models.Torrent{
ID: 1,
@@ -378,5 +363,5 @@ func loadPrivateTestData(tkr *tracker.Tracker) error {
Leechers: models.NewPeerMap(false),
}
return conn.PutTorrent(torrent)
tkr.PutTorrent(torrent)
}
-1
View File
@@ -17,7 +17,6 @@ import (
"github.com/chihaya/chihaya/tracker"
_ "github.com/chihaya/chihaya/backend/noop"
_ "github.com/chihaya/chihaya/tracker/memory"
)
type params map[string]string
+15 -48
View File
@@ -71,6 +71,7 @@ func handleTorrentError(err error, w *Writer) (int, error) {
stats.RecordEvent(stats.ClientError)
return http.StatusOK, nil
}
return http.StatusInternalServerError, err
}
@@ -99,17 +100,12 @@ func (s *Server) serveScrape(w http.ResponseWriter, r *http.Request, p httproute
}
func (s *Server) getTorrent(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
conn, err := s.tracker.Pool.Get()
if err != nil {
return http.StatusInternalServerError, err
}
infohash, err := url.QueryUnescape(p.ByName("infohash"))
if err != nil {
return http.StatusNotFound, err
}
torrent, err := conn.FindTorrent(infohash)
torrent, err := s.tracker.FindTorrent(infohash)
if err != nil {
return handleError(err)
}
@@ -131,35 +127,22 @@ func (s *Server) putTorrent(w http.ResponseWriter, r *http.Request, p httprouter
return http.StatusBadRequest, err
}
conn, err := s.tracker.Pool.Get()
if err != nil {
return http.StatusInternalServerError, err
}
return handleError(conn.PutTorrent(&torrent))
s.tracker.PutTorrent(&torrent)
return http.StatusOK, nil
}
func (s *Server) delTorrent(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
conn, err := s.tracker.Pool.Get()
if err != nil {
return http.StatusInternalServerError, err
}
infohash, err := url.QueryUnescape(p.ByName("infohash"))
if err != nil {
return http.StatusNotFound, err
}
return handleError(conn.DeleteTorrent(infohash))
s.tracker.DeleteTorrent(infohash)
return http.StatusOK, nil
}
func (s *Server) getUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
conn, err := s.tracker.Pool.Get()
if err != nil {
return http.StatusInternalServerError, err
}
user, err := conn.FindUser(p.ByName("passkey"))
user, err := s.tracker.FindUser(p.ByName("passkey"))
if err == models.ErrUserDNE {
return http.StatusNotFound, err
} else if err != nil {
@@ -183,37 +166,21 @@ func (s *Server) putUser(w http.ResponseWriter, r *http.Request, p httprouter.Pa
return http.StatusBadRequest, err
}
conn, err := s.tracker.Pool.Get()
if err != nil {
return http.StatusInternalServerError, err
}
return handleError(conn.PutUser(&user))
s.tracker.PutUser(&user)
return http.StatusOK, nil
}
func (s *Server) delUser(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
conn, err := s.tracker.Pool.Get()
if err != nil {
return http.StatusInternalServerError, err
}
return handleError(conn.DeleteUser(p.ByName("passkey")))
s.tracker.DeleteUser(p.ByName("passkey"))
return http.StatusOK, nil
}
func (s *Server) putClient(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
conn, err := s.tracker.Pool.Get()
if err != nil {
return http.StatusInternalServerError, err
}
return handleError(conn.PutClient(p.ByName("clientID")))
s.tracker.PutClient(p.ByName("clientID"))
return http.StatusOK, nil
}
func (s *Server) delClient(w http.ResponseWriter, r *http.Request, p httprouter.Params) (int, error) {
conn, err := s.tracker.Pool.Get()
if err != nil {
return http.StatusInternalServerError, err
}
return handleError(conn.DeleteClient(p.ByName("clientID")))
s.tracker.DeleteClient(p.ByName("clientID"))
return http.StatusOK, nil
}