From 6c2ab5170d26a41bbb3f425804767518187d8c04 Mon Sep 17 00:00:00 2001 From: Leo Balduf Date: Thu, 7 Apr 2016 22:31:38 -0400 Subject: [PATCH] http: fixed bencoding, compact, added log --- server/http/request.go | 2 +- server/http/server.go | 5 ++++- server/http/writer.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/server/http/request.go b/server/http/request.go index 862e364..354c3b7 100644 --- a/server/http/request.go +++ b/server/http/request.go @@ -34,7 +34,7 @@ func announceRequest(r *http.Request, cfg *httpConfig) (*chihaya.AnnounceRequest } compactStr, _ := q.String("compact") - request.Compact = compactStr != "0" + request.Compact = compactStr != "" && compactStr != "0" infoHashes := q.InfoHashes() if len(infoHashes) < 1 { diff --git a/server/http/server.go b/server/http/server.go index 129e0b8..b5f9c6f 100644 --- a/server/http/server.go +++ b/server/http/server.go @@ -112,7 +112,10 @@ func (s *httpServer) serveAnnounce(w http.ResponseWriter, r *http.Request, p htt return } - writeAnnounceResponse(w, resp) + err = writeAnnounceResponse(w, resp) + if err != nil { + log.Println("error serializing response", err) + } } func (s *httpServer) serveScrape(w http.ResponseWriter, r *http.Request, p httprouter.Params) { diff --git a/server/http/writer.go b/server/http/writer.go index 45b4cff..5f9eda0 100644 --- a/server/http/writer.go +++ b/server/http/writer.go @@ -91,7 +91,7 @@ func compact(peer chihaya.Peer) (buf []byte) { func dict(peer chihaya.Peer) bencode.Dict { return bencode.Dict{ - "peer id": peer.ID, + "peer id": string(peer.ID), "ip": peer.IP.String(), "port": peer.Port, }