From e2af935b83264383f22cf7b643e2bd6637d97b52 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Wed, 9 Jul 2014 01:34:34 -0400 Subject: [PATCH] disambiguate routing --- http/announce_test.go | 4 ++-- http/http.go | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/http/announce_test.go b/http/announce_test.go index 7fb1f4c..15c6991 100644 --- a/http/announce_test.go +++ b/http/announce_test.go @@ -131,7 +131,7 @@ func TestPrivateAnnounce(t *testing.T) { cfg := config.DefaultConfig cfg.Private = true - url := "/yby47f04riwpndba456rqxtmifenqxx2/announce?info_hash=%89%d4%bcR%11%16%ca%1dB%a2%f3%0d%1f%27M%94%e4h%1d%af&peer_id=-TR2820-l71jtqkl898b&port=51413&uploaded=0&downloaded=0&left=0&numwant=1&key=3c8e3319&compact=0" + url := "/users/yby47f04riwpndba456rqxtmifenqxx2/announce?info_hash=%89%d4%bcR%11%16%ca%1dB%a2%f3%0d%1f%27M%94%e4h%1d%af&peer_id=-TR2820-l71jtqkl898b&port=51413&uploaded=0&downloaded=0&left=0&numwant=1&key=3c8e3319&compact=0" golden1 := "d8:completei1e10:incompletei2e8:intervali1800e12:min intervali900e5:peersld2:ip9:127.0.0.17:peer id20:-TR2820-l71jtqkl8xx14:porti34000eeee" golden2 := "d8:completei1e10:incompletei2e8:intervali1800e12:min intervali900e5:peersld2:ip32:2001:0:53aa:64c:0:7f83:bc43:dec97:peer id20:-TR2820-l71jtqkl8xx34:porti34000eeee" got, err := testRoute(&cfg, url) @@ -142,7 +142,7 @@ func TestPrivateAnnounce(t *testing.T) { t.Errorf("\ngot: %s\nwanted: %s\nwanted: %s", got, golden1, golden2) } - url = "/yby47f04riwpndba456rqxtmifenqxx2/announce?info_hash=%89%d4%bcR%11%16%ca%1dB%a2%f3%0d%1f%27M%94%e4h%1d%af&peer_id=-TR2820-l71jtqkl898b&port=51413&uploaded=0&downloaded=0&left=0&numwant=2&key=3c8e3319&compact=0" + url = "/users/yby47f04riwpndba456rqxtmifenqxx2/announce?info_hash=%89%d4%bcR%11%16%ca%1dB%a2%f3%0d%1f%27M%94%e4h%1d%af&peer_id=-TR2820-l71jtqkl898b&port=51413&uploaded=0&downloaded=0&left=0&numwant=2&key=3c8e3319&compact=0" golden1 = "d8:completei1e10:incompletei2e8:intervali1800e12:min intervali900e5:peersld2:ip9:127.0.0.17:peer id20:-TR2820-l71jtqkl8xx14:porti34000eed2:ip32:2001:0:53aa:64c:0:7f83:bc43:dec97:peer id20:-TR2820-l71jtqkl8xx34:porti34000eeee" got, err = testRoute(&cfg, url) if err != nil { diff --git a/http/http.go b/http/http.go index d2676f6..01854a1 100644 --- a/http/http.go +++ b/http/http.go @@ -64,13 +64,9 @@ func makeHandler(handler ResponseHandler) httprouter.Handle { func setupRoutes(t *Tracker, cfg *config.Config) *httprouter.Router { r := httprouter.New() - r.GET("/torrents/:infohash", makeHandler(t.getTorrent)) - r.PUT("/torrents/:infohash", makeHandler(t.putTorrent)) - r.DELETE("/torrents/:infohash", makeHandler(t.delTorrent)) - if cfg.Private { - r.GET("/:passkey/announce", makeHandler(t.ServeAnnounce)) - r.GET("/:passkey/scrape", makeHandler(t.ServeScrape)) + r.GET("/users/:passkey/announce", makeHandler(t.ServeAnnounce)) + r.GET("/users/:passkey/scrape", makeHandler(t.ServeScrape)) r.PUT("/users/:passkey", makeHandler(t.putUser)) r.DELETE("/users/:passkey", makeHandler(t.delUser)) @@ -84,6 +80,10 @@ func setupRoutes(t *Tracker, cfg *config.Config) *httprouter.Router { r.DELETE("/clients/:clientID", makeHandler(t.delClient)) } + r.GET("/torrents/:infohash", makeHandler(t.getTorrent)) + r.PUT("/torrents/:infohash", makeHandler(t.putTorrent)) + r.DELETE("/torrents/:infohash", makeHandler(t.delTorrent)) + return r }