mirror of
https://github.com/sot-tech/mochi.git
synced 2026-06-14 08:33:36 -07:00
fix lint warnings, update wf go version
This commit is contained in:
@@ -15,7 +15,7 @@ jobs:
|
||||
- uses: "actions/checkout@v3"
|
||||
- uses: "actions/setup-go@v3"
|
||||
with:
|
||||
go-version: "^1.19"
|
||||
go-version: ">=1.19"
|
||||
- name: "Build"
|
||||
run: "go build ./cmd/..."
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ jobs:
|
||||
- uses: "actions/checkout@v3"
|
||||
- uses: "actions/setup-go@v3"
|
||||
with:
|
||||
go-version: "^1.19"
|
||||
go-version: ">=1.19"
|
||||
- uses: "authzed/actions/gofumpt@main"
|
||||
- uses: "authzed/actions/go-mod-tidy@main"
|
||||
- uses: "authzed/actions/go-generate@main"
|
||||
|
||||
@@ -3,17 +3,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"math/rand"
|
||||
"time"
|
||||
|
||||
"github.com/anacrolix/torrent/tracker"
|
||||
|
||||
"github.com/sot-tech/mochi/bittorrent"
|
||||
|
||||
_ "github.com/sot-tech/mochi/pkg/randseed"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@@ -43,7 +41,9 @@ func main() {
|
||||
|
||||
func test(addr string, delay time.Duration) error {
|
||||
b := make([]byte, bittorrent.InfoHashV1Len)
|
||||
rand.Read(b)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ih, _ := bittorrent.NewInfoHash(b)
|
||||
return testWithInfoHash(ih, addr, delay)
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/ecdsa"
|
||||
"crypto/elliptic"
|
||||
cr "crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
@@ -74,7 +75,9 @@ func init() {
|
||||
_ = log.ConfigureLogger("", "info", false, false)
|
||||
privKey, _ = jwt.ParseECPrivateKeyFromPEM([]byte(privKeyPEM))
|
||||
ihBytes := make([]byte, bittorrent.InfoHashV1Len)
|
||||
rand.Read(ihBytes)
|
||||
if _, err := cr.Read(ihBytes); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
infoHash, _ = bittorrent.NewInfoHash(ihBytes)
|
||||
s2 := sha256.New()
|
||||
s2.Write(elliptic.Marshal(privKey.PublicKey.Curve, privKey.PublicKey.X, privKey.PublicKey.Y))
|
||||
@@ -158,7 +161,9 @@ func TestHook_HandleAnnounceInvalid(t *testing.T) {
|
||||
|
||||
token.Header["kid"] = jwksData.Keys[0].KeyID
|
||||
k := make([]byte, 20)
|
||||
rand.Read(k)
|
||||
if _, err := cr.Read(k); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
tokenString, err := token.SignedString(k)
|
||||
require.Nil(t, err)
|
||||
//goland:noinspection HttpUrlsUsage
|
||||
|
||||
@@ -4,6 +4,7 @@ package test
|
||||
|
||||
import (
|
||||
"context"
|
||||
cr "crypto/rand"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/netip"
|
||||
@@ -42,7 +43,9 @@ func generatePeers() (a [peersCount]bittorrent.Peer) {
|
||||
} else {
|
||||
ip = make([]byte, net.IPv6len)
|
||||
}
|
||||
rand.Read(ip)
|
||||
if _, err := cr.Read(ip); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
addr, ok := netip.AddrFromSlice(ip)
|
||||
if !ok {
|
||||
panic("unable to create ip from random bytes")
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"crypto/rand"
|
||||
"net/netip"
|
||||
|
||||
"github.com/sot-tech/mochi/bittorrent"
|
||||
// used for seeding global math.Rand
|
||||
_ "github.com/sot-tech/mochi/pkg/randseed"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -25,14 +23,18 @@ func randIH(v2 bool) (ih bittorrent.InfoHash) {
|
||||
} else {
|
||||
b = make([]byte, bittorrent.InfoHashV1Len)
|
||||
}
|
||||
rand.Read(b)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ih, _ = bittorrent.NewInfoHash(b)
|
||||
return
|
||||
}
|
||||
|
||||
func randPeerID() (ih bittorrent.PeerID) {
|
||||
b := make([]byte, bittorrent.PeerIDLen)
|
||||
rand.Read(b)
|
||||
if _, err := rand.Read(b); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ih, _ = bittorrent.NewPeerID(b)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user