diff --git a/.golangci.yaml b/.golangci.yaml index b2d9873..b644552 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -5,10 +5,11 @@ output: sort-results: true linters-settings: goimports: - local-prefixes: "github.com/sot-te.ch/mochi" + local-prefixes: "sot-te.ch/mochi" gosec: excludes: - "G404" # Allow the usage of math/rand + - "G505" # Allow SHA1 usage linters: enable: - "bidichk" diff --git a/README.md b/README.md index 9c05326..ec161c0 100644 --- a/README.md +++ b/README.md @@ -2,23 +2,26 @@ [![License](https://img.shields.io/badge/license-BSD-blue.svg)](https://opensource.org/licenses/BSD-2-Clause) -Modified version of [Chihaya](https://github.com/chihaya/chihaya), -an open source BitTorrent tracker written in Go. +Modified version of [Chihaya](https://github.com/chihaya/chihaya), an open source BitTorrent tracker written in Go. ## Differences from the original project -* Support BittorrentV2 hashes (SHA-256 and _hybrid_ SHA-256-to-160 [BEP52](https://www.bittorrent.org/beps/bep_0052.html), tested with qBittorrent); +* Support BittorrentV2 hashes (SHA-256 and _hybrid_ + SHA-256-to-160 [BEP52](https://www.bittorrent.org/beps/bep_0052.html), tested with qBittorrent); * Support storage in middleware modules to persist useful data; * Metrics can be turned off (not enabled till it really needed). ## Main goal + The main goal of made modifications is to create semi-private tracker like [Hefur](https://github.com/sot-tech/hefur) -but with cluster support (allowed torrents limited by pre-existent `list` middleware and another `directory` middleware to limit registered torrents). +but with cluster support (allowed torrents limited by pre-existent `list` middleware and another `directory` middleware +to limit registered torrents). ## Notice -Modifications made with particular purpose, so if you need _pure_ tracker, -with guaranteed stability, please, use the [original project](https://github.com/chihaya/chihaya). -Developer(s) of this project (MoChi) do not declare themselves as authors of original -project (Chihaya) and do not claim any other rights of original project. +Modifications made with particular purpose, so if you need _pure_ tracker, with guaranteed stability, please, use +the [original project](https://github.com/chihaya/chihaya). + +Developer(s) of this project (MoChi) do not declare themselves as authors of original project (Chihaya) and do not claim +any other rights of original project. diff --git a/cmd/mochi/main.go b/cmd/mochi/main.go index 053053d..a8f100c 100644 --- a/cmd/mochi/main.go +++ b/cmd/mochi/main.go @@ -14,7 +14,7 @@ import ( "github.com/sot-tech/mochi/middleware" "github.com/sot-tech/mochi/pkg/log" "github.com/sot-tech/mochi/pkg/metrics" - _ "github.com/sot-tech/mochi/pkg/rand_seed" + _ "github.com/sot-tech/mochi/pkg/randseed" "github.com/sot-tech/mochi/pkg/stop" "github.com/sot-tech/mochi/storage" "github.com/spf13/cobra" diff --git a/frontend/http/frontend.go b/frontend/http/frontend.go index 7010229..5968e63 100644 --- a/frontend/http/frontend.go +++ b/frontend/http/frontend.go @@ -167,6 +167,7 @@ func NewFrontend(logic frontend.TrackerLogic, provided Config) (*Frontend, error var err error f.tlsCfg = &tls.Config{ Certificates: make([]tls.Certificate, 1), + MinVersion: tls.VersionTLS12, } f.tlsCfg.Certificates[0], err = tls.LoadX509KeyPair(cfg.TLSCertPath, cfg.TLSKeyPath) if err != nil { diff --git a/frontend/udp/frontend_test.go b/frontend/udp/frontend_test.go index c2a4202..32227d0 100644 --- a/frontend/udp/frontend_test.go +++ b/frontend/udp/frontend_test.go @@ -5,7 +5,7 @@ import ( "github.com/sot-tech/mochi/frontend/udp" "github.com/sot-tech/mochi/middleware" - _ "github.com/sot-tech/mochi/pkg/rand_seed" + _ "github.com/sot-tech/mochi/pkg/randseed" "github.com/sot-tech/mochi/storage" _ "github.com/sot-tech/mochi/storage/memory" ) @@ -22,8 +22,7 @@ func TestStartStopRaceIssue437(t *testing.T) { t.Fatal(err) } errC := fe.Stop() - errs := <-errC - if len(errs) != 0 { - t.Fatal(errs[0]) + if errs := <-errC; len(errs) != 0 { + t.Fatal(errs) } } diff --git a/frontend/udp/parser.go b/frontend/udp/parser.go index 1e91a3d..e778403 100644 --- a/frontend/udp/parser.go +++ b/frontend/udp/parser.go @@ -94,8 +94,7 @@ func ParseAnnounce(r Request, v6Action bool, opts ParseOptions) (*bittorrent.Ann ip := r.IP ipProvided := false - ipBytes := r.Packet[84:ipEnd] - if opts.AllowIPSpoofing { + if ipBytes := r.Packet[84:ipEnd]; opts.AllowIPSpoofing { // Make sure the bytes are copied to a new slice. copy(ip, ipBytes) ipProvided = true diff --git a/middleware/pkg/random/xorshift_test.go b/middleware/pkg/random/xorshift_test.go index d763bb7..3a4f6e7 100644 --- a/middleware/pkg/random/xorshift_test.go +++ b/middleware/pkg/random/xorshift_test.go @@ -4,7 +4,7 @@ import ( "math/rand" "testing" - _ "github.com/sot-tech/mochi/pkg/rand_seed" + _ "github.com/sot-tech/mochi/pkg/randseed" "github.com/stretchr/testify/require" ) diff --git a/middleware/torrentapproval/container/list/list.go b/middleware/torrentapproval/container/list/list.go index 58a8ba3..a5c8deb 100644 --- a/middleware/torrentapproval/container/list/list.go +++ b/middleware/torrentapproval/container/list/list.go @@ -54,7 +54,7 @@ func build(confBytes []byte, st storage.Storage) (container.Container, error) { for _, hashString := range c.HashList { ih, err := bittorrent.NewInfoHash(hashString) if err != nil { - return nil, fmt.Errorf("whitelist : %s : %v", hashString, err) + return nil, fmt.Errorf("whitelist : %s : %w", hashString, err) } init = append(init, storage.Pair{Left: ih.RawString(), Right: DUMMY}) if len(ih) == bittorrent.InfoHashV2Len { diff --git a/pkg/rand_seed/rand_seed.go b/pkg/randseed/rand_seed.go similarity index 88% rename from pkg/rand_seed/rand_seed.go rename to pkg/randseed/rand_seed.go index 1206caf..4fe72b4 100644 --- a/pkg/rand_seed/rand_seed.go +++ b/pkg/randseed/rand_seed.go @@ -1,5 +1,5 @@ -// Package rand_seed just seeds (math) rand.Rand -package rand_seed +// Package randseed just seeds (math) rand.Rand +package randseed import ( cr "crypto/rand" diff --git a/storage/test/storage_bench.go b/storage/test/storage_bench.go index 6328335..253d92e 100644 --- a/storage/test/storage_bench.go +++ b/storage/test/storage_bench.go @@ -8,7 +8,7 @@ import ( "testing" "github.com/sot-tech/mochi/bittorrent" - "github.com/sot-tech/mochi/pkg/rand_seed" + "github.com/sot-tech/mochi/pkg/randseed" "github.com/sot-tech/mochi/storage" ) @@ -28,7 +28,7 @@ func generateInfohashes() (a [1000]bittorrent.InfoHash) { } func generatePeers() (a [1000]bittorrent.Peer) { - r := rand.New(rand.NewSource(rand_seed.GenSeed())) + r := rand.New(rand.NewSource(randseed.GenSeed())) for i := range a { ip := make([]byte, 4) n, err := r.Read(ip)