Fix lint gosec and ifshort issues

This commit is contained in:
Lawrence, Rendall
2022-04-12 18:51:03 +03:00
parent 554ae6fcd6
commit 64eaf9d733
10 changed files with 25 additions and 22 deletions

View File

@@ -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"

View File

@@ -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.

View File

@@ -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"

View File

@@ -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 {

View File

@@ -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)
}
}

View File

@@ -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

View File

@@ -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"
)

View File

@@ -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 {

View File

@@ -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"

View File

@@ -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)