diff --git a/bittorrent/bittorrent.go b/bittorrent/bittorrent.go index 1dcbae5..0b8c744 100644 --- a/bittorrent/bittorrent.go +++ b/bittorrent/bittorrent.go @@ -12,6 +12,7 @@ import ( "time" "github.com/pkg/errors" + "github.com/sot-tech/mochi/pkg/log" ) diff --git a/cmd/mochi/main.go b/cmd/mochi/main.go index a8f100c..8163730 100644 --- a/cmd/mochi/main.go +++ b/cmd/mochi/main.go @@ -9,6 +9,8 @@ import ( "syscall" "github.com/sirupsen/logrus" + "github.com/spf13/cobra" + "github.com/sot-tech/mochi/frontend/http" "github.com/sot-tech/mochi/frontend/udp" "github.com/sot-tech/mochi/middleware" @@ -17,7 +19,6 @@ import ( _ "github.com/sot-tech/mochi/pkg/randseed" "github.com/sot-tech/mochi/pkg/stop" "github.com/sot-tech/mochi/storage" - "github.com/spf13/cobra" ) var e2eCmd *cobra.Command diff --git a/frontend/http/parser.go b/frontend/http/parser.go index 1351798..7c4175e 100644 --- a/frontend/http/parser.go +++ b/frontend/http/parser.go @@ -1,6 +1,7 @@ package http import ( + "errors" "net" "net/http" @@ -91,7 +92,7 @@ func ParseAnnounce(r *http.Request, opts ParseOptions) (*bittorrent.AnnounceRequ // Determine the number of peers the client wants in the response. numwant, err := qp.Uint("numwant", 32) - if err != nil && err != bittorrent.ErrKeyNotFound { + if err != nil && !errors.Is(err, bittorrent.ErrKeyNotFound) { return nil, bittorrent.ClientError("failed to parse parameter: numwant") } // If there were no errors, the user actually provided the numwant. diff --git a/frontend/http/writer.go b/frontend/http/writer.go index f5be92a..d91bfdd 100644 --- a/frontend/http/writer.go +++ b/frontend/http/writer.go @@ -6,6 +6,7 @@ import ( "time" "github.com/anacrolix/torrent/bencode" + "github.com/sot-tech/mochi/bittorrent" "github.com/sot-tech/mochi/pkg/log" ) @@ -65,7 +66,6 @@ func WriteAnnounceResponse(w http.ResponseWriter, resp *bittorrent.AnnounceRespo if len(IPv6CompactDict) > 0 { bdict["peers6"] = IPv6CompactDict } - } else { // Add the peers to the dictionary. peers := make([]map[string]any, 0, len(resp.IPv4Peers)+len(resp.IPv6Peers)) diff --git a/frontend/udp/frontend.go b/frontend/udp/frontend.go index b433e69..0e4d59a 100644 --- a/frontend/udp/frontend.go +++ b/frontend/udp/frontend.go @@ -6,6 +6,7 @@ import ( "bytes" "context" "encoding/binary" + "errors" "fmt" "math/rand" "net" @@ -186,7 +187,8 @@ func (t *Frontend) serve() error { n, addr, err := t.socket.ReadFromUDP(*buffer) if err != nil { pool.Put(buffer) - if netErr, ok := err.(net.Error); ok && netErr.Timeout() { + var netErr net.Error + if errors.As(err, &netErr) && netErr.Timeout() { // A temporary failure is not fatal; just pretend it never happened. continue } diff --git a/middleware/clientapproval/clientapproval.go b/middleware/clientapproval/clientapproval.go index 8bb9086..9c22cfb 100644 --- a/middleware/clientapproval/clientapproval.go +++ b/middleware/clientapproval/clientapproval.go @@ -7,10 +7,11 @@ import ( "errors" "fmt" + "gopkg.in/yaml.v3" + "github.com/sot-tech/mochi/bittorrent" "github.com/sot-tech/mochi/middleware" "github.com/sot-tech/mochi/storage" - "gopkg.in/yaml.v3" ) // Name is the name by which this middleware is registered with Conf. diff --git a/middleware/clientapproval/clientapproval_test.go b/middleware/clientapproval/clientapproval_test.go index b1da889..4b9fb01 100644 --- a/middleware/clientapproval/clientapproval_test.go +++ b/middleware/clientapproval/clientapproval_test.go @@ -5,8 +5,9 @@ import ( "fmt" "testing" - "github.com/sot-tech/mochi/bittorrent" "github.com/stretchr/testify/require" + + "github.com/sot-tech/mochi/bittorrent" ) var cases = []struct { diff --git a/middleware/jwt/jwt.go b/middleware/jwt/jwt.go index 4c90dde..21b9b4b 100644 --- a/middleware/jwt/jwt.go +++ b/middleware/jwt/jwt.go @@ -21,12 +21,13 @@ import ( "github.com/SermoDigital/jose/jws" "github.com/SermoDigital/jose/jwt" "github.com/mendsley/gojwk" + "gopkg.in/yaml.v3" + "github.com/sot-tech/mochi/bittorrent" "github.com/sot-tech/mochi/middleware" "github.com/sot-tech/mochi/pkg/log" "github.com/sot-tech/mochi/pkg/stop" "github.com/sot-tech/mochi/storage" - "gopkg.in/yaml.v3" ) // Name is the name by which this middleware is registered with Conf. diff --git a/middleware/middleware.go b/middleware/middleware.go index f11abb9..a0f6995 100644 --- a/middleware/middleware.go +++ b/middleware/middleware.go @@ -6,8 +6,9 @@ import ( "errors" "sync" - "github.com/sot-tech/mochi/storage" "gopkg.in/yaml.v3" + + "github.com/sot-tech/mochi/storage" ) var ( diff --git a/middleware/pkg/random/xorshift_test.go b/middleware/pkg/random/xorshift_test.go index 3a4f6e7..6df98b1 100644 --- a/middleware/pkg/random/xorshift_test.go +++ b/middleware/pkg/random/xorshift_test.go @@ -4,8 +4,9 @@ import ( "math/rand" "testing" - _ "github.com/sot-tech/mochi/pkg/randseed" "github.com/stretchr/testify/require" + + _ "github.com/sot-tech/mochi/pkg/randseed" ) func TestIntn(t *testing.T) { diff --git a/middleware/torrentapproval/container/directory/directory.go b/middleware/torrentapproval/container/directory/directory.go index ad77258..ef3cc0d 100644 --- a/middleware/torrentapproval/container/directory/directory.go +++ b/middleware/torrentapproval/container/directory/directory.go @@ -10,13 +10,14 @@ import ( "github.com/anacrolix/torrent/metainfo" "github.com/anacrolix/torrent/util/dirwatch" "github.com/minio/sha256-simd" + "gopkg.in/yaml.v3" + "github.com/sot-tech/mochi/bittorrent" "github.com/sot-tech/mochi/middleware/torrentapproval/container" "github.com/sot-tech/mochi/middleware/torrentapproval/container/list" "github.com/sot-tech/mochi/pkg/log" "github.com/sot-tech/mochi/pkg/stop" "github.com/sot-tech/mochi/storage" - "gopkg.in/yaml.v3" ) // Name of this container for registry diff --git a/middleware/torrentapproval/container/list/list.go b/middleware/torrentapproval/container/list/list.go index a5c8deb..bf31070 100644 --- a/middleware/torrentapproval/container/list/list.go +++ b/middleware/torrentapproval/container/list/list.go @@ -5,11 +5,12 @@ package list import ( "fmt" + "gopkg.in/yaml.v3" + "github.com/sot-tech/mochi/bittorrent" "github.com/sot-tech/mochi/middleware/torrentapproval/container" "github.com/sot-tech/mochi/pkg/log" "github.com/sot-tech/mochi/storage" - "gopkg.in/yaml.v3" ) // Name of this container for registry. diff --git a/middleware/torrentapproval/torrentapproval.go b/middleware/torrentapproval/torrentapproval.go index a15b83a..1f38dde 100644 --- a/middleware/torrentapproval/torrentapproval.go +++ b/middleware/torrentapproval/torrentapproval.go @@ -9,13 +9,15 @@ import ( "github.com/sot-tech/mochi/bittorrent" "github.com/sot-tech/mochi/middleware" "github.com/sot-tech/mochi/middleware/torrentapproval/container" + "gopkg.in/yaml.v3" + // import directory watcher to enable appropriate support _ "github.com/sot-tech/mochi/middleware/torrentapproval/container/directory" + // import static list to enable appropriate support _ "github.com/sot-tech/mochi/middleware/torrentapproval/container/list" "github.com/sot-tech/mochi/pkg/stop" "github.com/sot-tech/mochi/storage" - "gopkg.in/yaml.v3" ) // Name is the name by which this middleware is registered with Conf. diff --git a/middleware/torrentapproval/torrentapproval_test.go b/middleware/torrentapproval/torrentapproval_test.go index 1182c43..e37871e 100644 --- a/middleware/torrentapproval/torrentapproval_test.go +++ b/middleware/torrentapproval/torrentapproval_test.go @@ -5,10 +5,11 @@ import ( "fmt" "testing" - "github.com/sot-tech/mochi/bittorrent" - "github.com/sot-tech/mochi/storage/memory" "github.com/stretchr/testify/require" "gopkg.in/yaml.v3" + + "github.com/sot-tech/mochi/bittorrent" + "github.com/sot-tech/mochi/storage/memory" ) var cases = []struct { diff --git a/middleware/varinterval/varinterval.go b/middleware/varinterval/varinterval.go index dbbd38b..3853c70 100644 --- a/middleware/varinterval/varinterval.go +++ b/middleware/varinterval/varinterval.go @@ -7,11 +7,12 @@ import ( "sync" "time" + "gopkg.in/yaml.v3" + "github.com/sot-tech/mochi/bittorrent" "github.com/sot-tech/mochi/middleware" "github.com/sot-tech/mochi/middleware/pkg/random" "github.com/sot-tech/mochi/storage" - "gopkg.in/yaml.v3" ) // Name is the name by which this middleware is registered with Conf. diff --git a/middleware/varinterval/varinterval_test.go b/middleware/varinterval/varinterval_test.go index 74bdeb1..2c27d2d 100644 --- a/middleware/varinterval/varinterval_test.go +++ b/middleware/varinterval/varinterval_test.go @@ -5,8 +5,9 @@ import ( "fmt" "testing" - "github.com/sot-tech/mochi/bittorrent" "github.com/stretchr/testify/require" + + "github.com/sot-tech/mochi/bittorrent" ) var configTests = []struct { diff --git a/storage/redis/storage_test.go b/storage/redis/storage_test.go index 081e060..20f0c97 100644 --- a/storage/redis/storage_test.go +++ b/storage/redis/storage_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/alicebob/miniredis" + s "github.com/sot-tech/mochi/storage" "github.com/sot-tech/mochi/storage/test" ) diff --git a/storage/test/storage_test_base.go b/storage/test/storage_test_base.go index 7c0c1dd..f17d697 100644 --- a/storage/test/storage_test_base.go +++ b/storage/test/storage_test_base.go @@ -3,9 +3,10 @@ package test import ( "testing" + "github.com/stretchr/testify/require" + "github.com/sot-tech/mochi/bittorrent" "github.com/sot-tech/mochi/storage" - "github.com/stretchr/testify/require" ) // PeerEqualityFunc is the boolean function to use to check two Peers for