mirror of
https://github.com/sot-tech/mochi.git
synced 2026-06-12 07:43:32 -07:00
first pass with linter
This commit is contained in:
+4
-4
@@ -44,7 +44,7 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
if !whitelisted {
|
||||
fail(errors.New("Your client is not approved"), w, r)
|
||||
fail(errors.New("client is not approved"), w, r)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
if !exists {
|
||||
fail(errors.New("This torrent does not exist"), w, r)
|
||||
fail(errors.New("torrent does not exist"), w, r)
|
||||
return
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ func (s Server) validateAnnounceQuery(r *http.Request) (compact bool, numWant in
|
||||
uploadedErr != nil ||
|
||||
downloadedErr != nil ||
|
||||
leftErr != nil {
|
||||
return false, 0, "", "", "", "", 0, 0, 0, 0, errors.New("Malformed request")
|
||||
return false, 0, "", "", "", "", 0, 0, 0, 0, errors.New("malformed request")
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -306,7 +306,7 @@ func requestedIP(r *http.Request, pq *parsedQuery) (string, error) {
|
||||
if portIndex != -1 {
|
||||
return r.RemoteAddr[0:portIndex], nil
|
||||
}
|
||||
return "", errors.New("Failed to parse IP address")
|
||||
return "", errors.New("failed to parse IP address")
|
||||
}
|
||||
|
||||
func minInt(a, b int) int {
|
||||
|
||||
+10
-10
@@ -8,18 +8,18 @@ import (
|
||||
var (
|
||||
baseAddr = "https://www.subdomain.tracker.com:80/"
|
||||
testInfoHash = "01234567890123456789"
|
||||
testPeerId = "-TEST01-6wfG2wk6wWLc"
|
||||
testPeerID = "-TEST01-6wfG2wk6wWLc"
|
||||
|
||||
ValidAnnounceArguments = []url.Values{
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerId}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerId}, "ip": {"192.168.0.1"}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerId}, "ip": {"192.168.0.1"}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "numwant": {"28"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerId}, "ip": {"192.168.0.1"}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "event": {"stopped"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerId}, "ip": {"192.168.0.1"}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "event": {"started"}, "numwant": {"13"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerId}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "no_peer_id": {"1"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerId}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "compact": {"0"}, "no_peer_id": {"1"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerId}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "compact": {"0"}, "no_peer_id": {"1"}, "key": {"peerKey"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerId}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "compact": {"0"}, "no_peer_id": {"1"}, "key": {"peerKey"}, "trackerid": {"trackerId"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerID}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerID}, "ip": {"192.168.0.1"}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerID}, "ip": {"192.168.0.1"}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "numwant": {"28"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerID}, "ip": {"192.168.0.1"}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "event": {"stopped"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerID}, "ip": {"192.168.0.1"}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "event": {"started"}, "numwant": {"13"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerID}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "no_peer_id": {"1"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerID}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "compact": {"0"}, "no_peer_id": {"1"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerID}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "compact": {"0"}, "no_peer_id": {"1"}, "key": {"peerKey"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {testPeerID}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "compact": {"0"}, "no_peer_id": {"1"}, "key": {"peerKey"}, "trackerid": {"trackerId"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {"%3Ckey%3A+0x90%3E"}, "port": {"6881"}, "downloaded": {"1234"}, "left": {"4321"}, "compact": {"0"}, "no_peer_id": {"1"}, "key": {"peerKey"}, "trackerid": {"trackerId"}},
|
||||
url.Values{"info_hash": {testInfoHash}, "peer_id": {"%3Ckey%3A+0x90%3E"}, "compact": {"1"}},
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,7 +18,7 @@ func (s *Server) serveScrape(w http.ResponseWriter, r *http.Request) {
|
||||
// Parse the query
|
||||
pq, err := parseQuery(r.URL.RawQuery)
|
||||
if err != nil {
|
||||
fail(errors.New("Error parsing query"), w, r)
|
||||
fail(errors.New("error parsing query"), w, r)
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
+7
-3
@@ -24,6 +24,7 @@ import (
|
||||
"github.com/chihaya/chihaya/storage/tracker"
|
||||
)
|
||||
|
||||
// Server represents BitTorrent tracker server.
|
||||
type Server struct {
|
||||
conf *config.Config
|
||||
listener *stoppableListener.StoppableListener
|
||||
@@ -38,6 +39,7 @@ type Server struct {
|
||||
http.Server
|
||||
}
|
||||
|
||||
// New creates a new Server.
|
||||
func New(conf *config.Config) (*Server, error) {
|
||||
trackerPool, err := tracker.Open(&conf.Tracker)
|
||||
if err != nil {
|
||||
@@ -66,6 +68,7 @@ func New(conf *config.Config) (*Server, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
// ListenAndServe starts listening and handling incoming HTTP requests.
|
||||
func (s *Server) ListenAndServe() error {
|
||||
l, err := net.Listen("tcp", s.Addr)
|
||||
if err != nil {
|
||||
@@ -81,6 +84,7 @@ func (s *Server) ListenAndServe() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Stop cleanly ends the handling of incoming HTTP requests.
|
||||
func (s *Server) Stop() error {
|
||||
s.listener.Stop <- true
|
||||
err := s.trackerPool.Close()
|
||||
@@ -106,7 +110,7 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||
s.serveStats(w, r)
|
||||
return
|
||||
default:
|
||||
fail(errors.New("Unknown action"), w, r)
|
||||
fail(errors.New("unknown action"), w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -121,7 +125,7 @@ func fail(err error, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func validateUser(conn tracker.Conn, dir string) (*storage.User, error) {
|
||||
if len(dir) != 34 {
|
||||
return nil, errors.New("Passkey is invalid")
|
||||
return nil, errors.New("passkey is invalid")
|
||||
}
|
||||
passkey := dir[1:33]
|
||||
|
||||
@@ -130,7 +134,7 @@ func validateUser(conn tracker.Conn, dir string) (*storage.User, error) {
|
||||
log.Panicf("server: %s", err)
|
||||
}
|
||||
if !exists {
|
||||
return nil, errors.New("User not found")
|
||||
return nil, errors.New("user not found")
|
||||
}
|
||||
|
||||
return user, nil
|
||||
|
||||
@@ -9,8 +9,8 @@ import (
|
||||
)
|
||||
|
||||
type PeerClientPair struct {
|
||||
peerId string
|
||||
clientId string
|
||||
peerID string
|
||||
clientID string
|
||||
}
|
||||
|
||||
var TestClients = []PeerClientPair{
|
||||
@@ -59,8 +59,8 @@ var TestClients = []PeerClientPair{
|
||||
|
||||
func TestParseClientID(t *testing.T) {
|
||||
for _, pair := range TestClients {
|
||||
if parsedId := parsePeerID(pair.peerId); parsedId != pair.clientId {
|
||||
t.Error("Incorrectly parsed peer ID", pair.peerId, "as", parsedId)
|
||||
if parsedID := parsePeerID(pair.peerID); parsedID != pair.clientID {
|
||||
t.Error("Incorrectly parsed peer ID", pair.peerID, "as", parsedID)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user