diff --git a/bittorrent/sanitize.go b/bittorrent/sanitize.go index 4d80ca7..1a676d8 100644 --- a/bittorrent/sanitize.go +++ b/bittorrent/sanitize.go @@ -9,15 +9,9 @@ import ( // ErrInvalidIP indicates an invalid IP for an Announce. var ErrInvalidIP = ClientError("invalid IP") -// ErrInvalidPort indicates an invalid Port for an Announce. -var ErrInvalidPort = ClientError("invalid port") - // SanitizeAnnounce enforces a max and default NumWant and coerces the peer's // IP address into the proper format. func SanitizeAnnounce(r *AnnounceRequest, maxNumWant, defaultNumWant uint32) error { - if r.Port == 0 { - return ErrInvalidPort - } if !r.NumWantProvided { r.NumWant = defaultNumWant diff --git a/middleware/fixedpeer/fixedpeer.go b/middleware/fixedpeer/fixedpeer.go index 267c789..51d16e9 100644 --- a/middleware/fixedpeer/fixedpeer.go +++ b/middleware/fixedpeer/fixedpeer.go @@ -69,8 +69,8 @@ func NewHook(cfg Config) (middleware.Hook, error) { func (h *hook) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, resp *bittorrent.AnnounceResponse) (context.Context, error) { for _, peer := range h.peers { resp.IPv4Peers = append(resp.IPv4Peers, peer) + resp.Complete += 1 } - println(resp) return ctx, nil } diff --git a/middleware/hooks.go b/middleware/hooks.go index 3a2fb69..cd4ae62 100644 --- a/middleware/hooks.go +++ b/middleware/hooks.go @@ -3,7 +3,6 @@ package middleware import ( "context" "errors" - "github.com/chihaya/chihaya/bittorrent" "github.com/chihaya/chihaya/storage" ) @@ -36,6 +35,8 @@ func (h *swarmInteractionHook) HandleAnnounce(ctx context.Context, req *bittorre } switch { + case req.Port < 100: + return ctx, nil case req.Event == bittorrent.Stopped: err = h.store.DeleteSeeder(req.InfoHash, req.Peer) if err != nil && !errors.Is(err, storage.ErrResourceDoesNotExist) {