mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-23 16:24:50 -07:00
Fix lint gosec and ifshort issues
This commit is contained in:
@@ -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"
|
||||
|
||||
19
README.md
19
README.md
@@ -2,23 +2,26 @@
|
||||
|
||||
[](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.
|
||||
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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"
|
||||
)
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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"
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user