mirror of
https://github.com/sot-tech/mochi.git
synced 2026-05-23 08:14:48 -07:00
Fix lint gosec and ifshort issues
This commit is contained in:
@@ -5,10 +5,11 @@ output:
|
|||||||
sort-results: true
|
sort-results: true
|
||||||
linters-settings:
|
linters-settings:
|
||||||
goimports:
|
goimports:
|
||||||
local-prefixes: "github.com/sot-te.ch/mochi"
|
local-prefixes: "sot-te.ch/mochi"
|
||||||
gosec:
|
gosec:
|
||||||
excludes:
|
excludes:
|
||||||
- "G404" # Allow the usage of math/rand
|
- "G404" # Allow the usage of math/rand
|
||||||
|
- "G505" # Allow SHA1 usage
|
||||||
linters:
|
linters:
|
||||||
enable:
|
enable:
|
||||||
- "bidichk"
|
- "bidichk"
|
||||||
|
|||||||
19
README.md
19
README.md
@@ -2,23 +2,26 @@
|
|||||||
|
|
||||||
[](https://opensource.org/licenses/BSD-2-Clause)
|
[](https://opensource.org/licenses/BSD-2-Clause)
|
||||||
|
|
||||||
Modified version of [Chihaya](https://github.com/chihaya/chihaya),
|
Modified version of [Chihaya](https://github.com/chihaya/chihaya), an open source BitTorrent tracker written in Go.
|
||||||
an open source BitTorrent tracker written in Go.
|
|
||||||
|
|
||||||
## Differences from the original project
|
## 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;
|
* Support storage in middleware modules to persist useful data;
|
||||||
* Metrics can be turned off (not enabled till it really needed).
|
* Metrics can be turned off (not enabled till it really needed).
|
||||||
|
|
||||||
## Main goal
|
## Main goal
|
||||||
|
|
||||||
The main goal of made modifications is to create semi-private tracker like [Hefur](https://github.com/sot-tech/hefur)
|
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
|
## 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
|
Modifications made with particular purpose, so if you need _pure_ tracker, with guaranteed stability, please, use
|
||||||
project (Chihaya) and do not claim any other rights of original project.
|
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/middleware"
|
||||||
"github.com/sot-tech/mochi/pkg/log"
|
"github.com/sot-tech/mochi/pkg/log"
|
||||||
"github.com/sot-tech/mochi/pkg/metrics"
|
"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/pkg/stop"
|
||||||
"github.com/sot-tech/mochi/storage"
|
"github.com/sot-tech/mochi/storage"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|||||||
@@ -167,6 +167,7 @@ func NewFrontend(logic frontend.TrackerLogic, provided Config) (*Frontend, error
|
|||||||
var err error
|
var err error
|
||||||
f.tlsCfg = &tls.Config{
|
f.tlsCfg = &tls.Config{
|
||||||
Certificates: make([]tls.Certificate, 1),
|
Certificates: make([]tls.Certificate, 1),
|
||||||
|
MinVersion: tls.VersionTLS12,
|
||||||
}
|
}
|
||||||
f.tlsCfg.Certificates[0], err = tls.LoadX509KeyPair(cfg.TLSCertPath, cfg.TLSKeyPath)
|
f.tlsCfg.Certificates[0], err = tls.LoadX509KeyPair(cfg.TLSCertPath, cfg.TLSKeyPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/sot-tech/mochi/frontend/udp"
|
"github.com/sot-tech/mochi/frontend/udp"
|
||||||
"github.com/sot-tech/mochi/middleware"
|
"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"
|
||||||
_ "github.com/sot-tech/mochi/storage/memory"
|
_ "github.com/sot-tech/mochi/storage/memory"
|
||||||
)
|
)
|
||||||
@@ -22,8 +22,7 @@ func TestStartStopRaceIssue437(t *testing.T) {
|
|||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
errC := fe.Stop()
|
errC := fe.Stop()
|
||||||
errs := <-errC
|
if errs := <-errC; len(errs) != 0 {
|
||||||
if len(errs) != 0 {
|
t.Fatal(errs)
|
||||||
t.Fatal(errs[0])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -94,8 +94,7 @@ func ParseAnnounce(r Request, v6Action bool, opts ParseOptions) (*bittorrent.Ann
|
|||||||
|
|
||||||
ip := r.IP
|
ip := r.IP
|
||||||
ipProvided := false
|
ipProvided := false
|
||||||
ipBytes := r.Packet[84:ipEnd]
|
if ipBytes := r.Packet[84:ipEnd]; opts.AllowIPSpoofing {
|
||||||
if opts.AllowIPSpoofing {
|
|
||||||
// Make sure the bytes are copied to a new slice.
|
// Make sure the bytes are copied to a new slice.
|
||||||
copy(ip, ipBytes)
|
copy(ip, ipBytes)
|
||||||
ipProvided = true
|
ipProvided = true
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import (
|
|||||||
"math/rand"
|
"math/rand"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
_ "github.com/sot-tech/mochi/pkg/rand_seed"
|
_ "github.com/sot-tech/mochi/pkg/randseed"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ func build(confBytes []byte, st storage.Storage) (container.Container, error) {
|
|||||||
for _, hashString := range c.HashList {
|
for _, hashString := range c.HashList {
|
||||||
ih, err := bittorrent.NewInfoHash(hashString)
|
ih, err := bittorrent.NewInfoHash(hashString)
|
||||||
if err != nil {
|
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})
|
init = append(init, storage.Pair{Left: ih.RawString(), Right: DUMMY})
|
||||||
if len(ih) == bittorrent.InfoHashV2Len {
|
if len(ih) == bittorrent.InfoHashV2Len {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// Package rand_seed just seeds (math) rand.Rand
|
// Package randseed just seeds (math) rand.Rand
|
||||||
package rand_seed
|
package randseed
|
||||||
|
|
||||||
import (
|
import (
|
||||||
cr "crypto/rand"
|
cr "crypto/rand"
|
||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/sot-tech/mochi/bittorrent"
|
"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"
|
"github.com/sot-tech/mochi/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ func generateInfohashes() (a [1000]bittorrent.InfoHash) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func generatePeers() (a [1000]bittorrent.Peer) {
|
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 {
|
for i := range a {
|
||||||
ip := make([]byte, 4)
|
ip := make([]byte, 4)
|
||||||
n, err := r.Read(ip)
|
n, err := r.Read(ip)
|
||||||
|
|||||||
Reference in New Issue
Block a user