mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-09 18:18:11 -07:00
Fix e2e execution, append 2to1 hash in approvals, update dependencies
This commit is contained in:
committed by
Lawrence, Rendall
parent
dd0a455a4a
commit
0a5ac35c4d
@@ -24,8 +24,8 @@ jobs:
|
||||
run: go build -v ./cmd/...
|
||||
- name: Vet
|
||||
run: go vet ./...
|
||||
- name: Imports
|
||||
uses: Jerome1337/goimports-action@v1.0.3
|
||||
# - name: Imports
|
||||
# uses: Jerome1337/goimports-action@v1.0.3
|
||||
- name: Format
|
||||
uses: Jerome1337/gofmt-action@v1.0.4
|
||||
- name: Lint
|
||||
|
||||
@@ -8,11 +8,10 @@ import (
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"fmt"
|
||||
"github.com/chihaya/chihaya/pkg/log"
|
||||
"github.com/pkg/errors"
|
||||
"net"
|
||||
"time"
|
||||
|
||||
"github.com/chihaya/chihaya/pkg/log"
|
||||
)
|
||||
|
||||
const PeerIDLen = 20
|
||||
|
||||
@@ -4,7 +4,7 @@ import (
|
||||
"errors"
|
||||
"os"
|
||||
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/chihaya/chihaya/frontend/http"
|
||||
"github.com/chihaya/chihaya/frontend/udp"
|
||||
|
||||
+4
-9
@@ -1,5 +1,5 @@
|
||||
//go:build e2e
|
||||
// +build e2e
|
||||
//+build e2e
|
||||
|
||||
package main
|
||||
|
||||
@@ -70,15 +70,10 @@ func EndToEndRunCmdFunc(cmd *cobra.Command, args []string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func generateInfohash() bittorrent.InfoHash {
|
||||
func test(addr string, delay time.Duration) error {
|
||||
b := make([]byte, bittorrent.InfoHashV1Len)
|
||||
rand.Read(b)
|
||||
ih, _ := bittorrent.NewInfoHash(b)
|
||||
return ih
|
||||
}
|
||||
|
||||
func test(addr string, delay time.Duration) error {
|
||||
ih := generateInfohash().TruncateV1()
|
||||
return testWithInfohash(ih, addr, delay)
|
||||
}
|
||||
|
||||
@@ -137,8 +132,8 @@ func testWithInfohash(infoHash bittorrent.InfoHash, url string, delay time.Durat
|
||||
return fmt.Errorf("expected 1 peers, got %d", len(resp.Peers))
|
||||
}
|
||||
|
||||
if resp.Peers[0].Port != 10001 {
|
||||
return fmt.Errorf("expected port 10001, got %d ", resp.Peers[0].Port)
|
||||
if resp.Peers[0].Port != int(req.Port) {
|
||||
return fmt.Errorf("expected port %d, got %d ", req.Port, resp.Peers[0].Port)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
+7
-8
@@ -2,14 +2,6 @@ package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/chihaya/chihaya/frontend/http"
|
||||
"github.com/chihaya/chihaya/frontend/udp"
|
||||
"github.com/chihaya/chihaya/middleware"
|
||||
@@ -17,6 +9,13 @@ import (
|
||||
"github.com/chihaya/chihaya/pkg/metrics"
|
||||
"github.com/chihaya/chihaya/pkg/stop"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
var e2eCmd *cobra.Command
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func makeReloadChan() <-chan os.Signal {
|
||||
reload := make(chan os.Signal)
|
||||
reload := make(chan os.Signal, 1)
|
||||
signal.Notify(reload, syscall.SIGHUP)
|
||||
return reload
|
||||
}
|
||||
|
||||
@@ -2,11 +2,10 @@ package http
|
||||
|
||||
import (
|
||||
"github.com/anacrolix/torrent/bencode"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/pkg/log"
|
||||
"net/http"
|
||||
"time"
|
||||
)
|
||||
|
||||
type strMap map[string]interface{}
|
||||
|
||||
@@ -4,19 +4,23 @@ go 1.16
|
||||
|
||||
require (
|
||||
github.com/SermoDigital/jose v0.9.2-0.20180104203859-803625baeddc
|
||||
github.com/alicebob/gopher-json v0.0.0-20180125190556-5a6b3ba71ee6 // indirect
|
||||
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
|
||||
github.com/alicebob/miniredis v2.5.0+incompatible
|
||||
github.com/anacrolix/torrent v1.28.0
|
||||
github.com/anacrolix/torrent v1.38.0
|
||||
github.com/go-redsync/redsync v1.4.2
|
||||
github.com/gomodule/redigo v2.0.0+incompatible
|
||||
github.com/hashicorp/errwrap v1.1.0 // indirect
|
||||
github.com/hashicorp/go-multierror v1.1.1 // indirect
|
||||
github.com/julienschmidt/httprouter v1.3.0
|
||||
github.com/mendsley/gojwk v0.0.0-20141217222730-4d5ec6e58103
|
||||
github.com/minio/sha256-simd v0.1.1
|
||||
github.com/minio/sha256-simd v1.0.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/prometheus/client_golang v1.11.0
|
||||
github.com/prometheus/common v0.32.1 // indirect
|
||||
github.com/prometheus/procfs v0.7.3 // indirect
|
||||
github.com/sirupsen/logrus v1.8.1
|
||||
github.com/spf13/cobra v1.1.3
|
||||
github.com/spf13/cobra v1.2.1
|
||||
github.com/stretchr/testify v1.7.0
|
||||
github.com/yuin/gopher-lua v0.0.0-20191220021717-ab39c6098bdb // indirect
|
||||
github.com/yuin/gopher-lua v0.0.0-20210529063254-f4c35e4016d9 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0
|
||||
)
|
||||
|
||||
@@ -6,11 +6,10 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/middleware"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Name is the name by which this middleware is registered with Chihaya.
|
||||
|
||||
@@ -3,11 +3,9 @@ package clientapproval
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var cases = []struct {
|
||||
|
||||
@@ -13,21 +13,19 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
jc "github.com/SermoDigital/jose/crypto"
|
||||
"github.com/SermoDigital/jose/jws"
|
||||
"github.com/SermoDigital/jose/jwt"
|
||||
"github.com/mendsley/gojwk"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/middleware"
|
||||
"github.com/chihaya/chihaya/pkg/log"
|
||||
"github.com/chihaya/chihaya/pkg/stop"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"github.com/mendsley/gojwk"
|
||||
"gopkg.in/yaml.v2"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Name is the name by which this middleware is registered with Chihaya.
|
||||
@@ -106,7 +104,7 @@ func NewHook(cfg Config) (middleware.Hook, error) {
|
||||
return
|
||||
case <-time.After(cfg.JWKUpdateInterval):
|
||||
log.Debug("performing fetch of JWKs")
|
||||
h.updateKeys()
|
||||
_ = h.updateKeys()
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
+1
-2
@@ -2,13 +2,12 @@ package middleware
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/frontend"
|
||||
"github.com/chihaya/chihaya/pkg/log"
|
||||
"github.com/chihaya/chihaya/pkg/stop"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ResponseConfig holds the configuration used for the actual response.
|
||||
|
||||
@@ -5,9 +5,8 @@ package middleware
|
||||
import (
|
||||
"errors"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"sync"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
// Package directory implements container which
|
||||
// checks if hash present in any of *.torrent file
|
||||
// checks if hash present in any of torrent file
|
||||
// placed in some directory
|
||||
package directory
|
||||
|
||||
import (
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"github.com/anacrolix/torrent/metainfo"
|
||||
"github.com/anacrolix/torrent/util/dirwatch"
|
||||
@@ -14,6 +13,7 @@ import (
|
||||
"github.com/chihaya/chihaya/pkg/log"
|
||||
"github.com/chihaya/chihaya/pkg/stop"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"github.com/minio/sha256-simd"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
@@ -53,41 +53,48 @@ func build(confBytes []byte, st storage.Storage) (container.Container, error) {
|
||||
}
|
||||
go func() {
|
||||
for event := range d.watcher.Events {
|
||||
switch event.Change {
|
||||
case dirwatch.Added:
|
||||
data := make([]storage.Pair, 1, 2)
|
||||
data[0] = storage.Pair{Left: event.InfoHash[:], Right: list.DUMMY}
|
||||
if v2ih, err := v2InfoHash(event.TorrentFilePath); err == nil {
|
||||
data = append(data, storage.Pair{Left: v2ih.RawString(), Right: list.DUMMY})
|
||||
} else {
|
||||
log.Err(err)
|
||||
var mi *metainfo.MetaInfo
|
||||
if mi, err = metainfo.LoadFromFile(event.TorrentFilePath); err == nil {
|
||||
s256 := sha256.New()
|
||||
s256.Write(mi.InfoBytes)
|
||||
v2hash, _ := bittorrent.NewInfoHash(s256.Sum(nil))
|
||||
switch event.Change {
|
||||
case dirwatch.Added:
|
||||
var name string
|
||||
if info, err := mi.UnmarshalInfo(); err == nil {
|
||||
name = info.Name
|
||||
} else {
|
||||
log.Warn(err)
|
||||
}
|
||||
if len(name) == 0 {
|
||||
name = list.DUMMY
|
||||
}
|
||||
d.Storage.BulkPut(c.StorageCtx,
|
||||
storage.Pair{
|
||||
Left: event.InfoHash.AsString(),
|
||||
Right: name,
|
||||
}, storage.Pair{
|
||||
Left: v2hash.RawString(),
|
||||
Right: name,
|
||||
}, storage.Pair{
|
||||
Left: v2hash.TruncateV1().RawString(),
|
||||
Right: name,
|
||||
})
|
||||
case dirwatch.Removed:
|
||||
d.Storage.Delete(c.StorageCtx,
|
||||
event.InfoHash.AsString(),
|
||||
v2hash.RawString(),
|
||||
v2hash.TruncateV1().RawString(),
|
||||
)
|
||||
}
|
||||
d.Storage.BulkPut(c.StorageCtx, data...)
|
||||
case dirwatch.Removed:
|
||||
data := make([]interface{}, 1, 2)
|
||||
data[0] = event.InfoHash[:]
|
||||
if v2ih, err := v2InfoHash(event.TorrentFilePath); err == nil {
|
||||
data = append(data, v2ih.RawString())
|
||||
} else {
|
||||
log.Err(err)
|
||||
}
|
||||
d.Storage.Delete(c.StorageCtx, data...)
|
||||
} else {
|
||||
log.Err(err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
return d, err
|
||||
}
|
||||
|
||||
func v2InfoHash(path string) (ih bittorrent.InfoHash, err error) {
|
||||
var mi *metainfo.MetaInfo
|
||||
if mi, err = metainfo.LoadFromFile(path); err == nil {
|
||||
hash := sha256.New()
|
||||
hash.Write(mi.InfoBytes)
|
||||
ih, err = bittorrent.NewInfoHash(hash.Sum(nil))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type directory struct {
|
||||
list.List
|
||||
watcher *dirwatch.Instance
|
||||
|
||||
@@ -23,7 +23,7 @@ type Config struct {
|
||||
StorageCtx string `yaml:"storage_ctx"`
|
||||
}
|
||||
|
||||
const DUMMY = true
|
||||
const DUMMY = "_"
|
||||
|
||||
func build(confBytes []byte, st storage.Storage) (container.Container, error) {
|
||||
c := new(Config)
|
||||
|
||||
@@ -5,15 +5,14 @@ package torrentapproval
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/middleware"
|
||||
"github.com/chihaya/chihaya/middleware/torrentapproval/container"
|
||||
_ "github.com/chihaya/chihaya/middleware/torrentapproval/container/directory"
|
||||
_ "github.com/chihaya/chihaya/middleware/torrentapproval/container/list"
|
||||
"github.com/chihaya/chihaya/pkg/stop"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/middleware"
|
||||
_ "github.com/chihaya/chihaya/middleware/torrentapproval/container/directory"
|
||||
_ "github.com/chihaya/chihaya/middleware/torrentapproval/container/list"
|
||||
)
|
||||
|
||||
// Name is the name by which this middleware is registered with Chihaya.
|
||||
|
||||
@@ -3,14 +3,12 @@ package torrentapproval
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/middleware"
|
||||
"github.com/chihaya/chihaya/storage/memory"
|
||||
"github.com/stretchr/testify/require"
|
||||
"gopkg.in/yaml.v2"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
)
|
||||
|
||||
var cases = []struct {
|
||||
|
||||
@@ -4,15 +4,13 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/middleware"
|
||||
"github.com/chihaya/chihaya/middleware/pkg/random"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"gopkg.in/yaml.v2"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Name is the name by which this middleware is registered with Chihaya.
|
||||
|
||||
@@ -3,11 +3,9 @@ package varinterval
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var configTests = []struct {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package memory
|
||||
|
||||
import (
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"github.com/chihaya/chihaya/storage/test"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
s "github.com/chihaya/chihaya/storage"
|
||||
)
|
||||
|
||||
func createNew() s.Storage {
|
||||
func createNew() storage.Storage {
|
||||
ps, err := New(Config{
|
||||
ShardCount: 1024,
|
||||
GarbageCollectionInterval: 10 * time.Minute,
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"math/rand"
|
||||
"net"
|
||||
"runtime"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
)
|
||||
|
||||
type benchData struct {
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package test
|
||||
|
||||
import (
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/chihaya/chihaya/bittorrent"
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
"github.com/stretchr/testify/require"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// PeerEqualityFunc is the boolean function to use to check two Peers for
|
||||
|
||||
Reference in New Issue
Block a user