mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-17 13:48:11 -07:00
Implement simple PGDC methods for storage
* sanitize code a little * move e2e build to 'e2e' tag
This commit is contained in:
committed by
Lawrence, Rendall
parent
566d99fcd7
commit
beb4736b86
@@ -29,9 +29,9 @@ type storageConfig struct {
|
||||
// Config represents the configuration used for executing Chihaya.
|
||||
type Config struct {
|
||||
middleware.ResponseConfig `yaml:",inline"`
|
||||
MetricsAddr string `yaml:"metrics_addr"`
|
||||
HTTPConfig http.Config `yaml:"http"`
|
||||
UDPConfig udp.Config `yaml:"udp"`
|
||||
MetricsAddr string `yaml:"metrics_addr"`
|
||||
HTTPConfig http.Config `yaml:"http"`
|
||||
UDPConfig udp.Config `yaml:"udp"`
|
||||
Storage storageConfig `yaml:"storage"`
|
||||
PreHooks []middleware.Config `yaml:"prehooks"`
|
||||
PostHooks []middleware.Config `yaml:"posthooks"`
|
||||
|
||||
+19
-3
@@ -1,3 +1,6 @@
|
||||
//go:build e2e
|
||||
// +build e2e
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -13,6 +16,19 @@ import (
|
||||
"github.com/chihaya/chihaya/pkg/log"
|
||||
)
|
||||
|
||||
func init() {
|
||||
e2eCmd = &cobra.Command{
|
||||
Use: "e2e",
|
||||
Short: "exec e2e tests",
|
||||
Long: "Execute the Chihaya end-to-end test suite",
|
||||
RunE: EndToEndRunCmdFunc,
|
||||
}
|
||||
|
||||
e2eCmd.Flags().String("httpaddr", "http://127.0.0.1:6969/announce", "address of the HTTP tracker")
|
||||
e2eCmd.Flags().String("udpaddr", "udp://127.0.0.1:6969", "address of the UDP tracker")
|
||||
e2eCmd.Flags().Duration("delay", time.Second, "delay between announces")
|
||||
}
|
||||
|
||||
// EndToEndRunCmdFunc implements a Cobra command that runs the end-to-end test
|
||||
// suite for a Chihaya build.
|
||||
func EndToEndRunCmdFunc(cmd *cobra.Command, args []string) error {
|
||||
@@ -55,7 +71,7 @@ func EndToEndRunCmdFunc(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
func generateInfohash() bittorrent.InfoHash {
|
||||
b := make([]byte, 20)
|
||||
b := make([]byte, bittorrent.InfoHashV1Len)
|
||||
rand.Read(b)
|
||||
ih, _ := bittorrent.NewInfoHash(b)
|
||||
return ih
|
||||
@@ -70,7 +86,7 @@ func testWithInfohash(infoHash bittorrent.InfoHash, url string, delay time.Durat
|
||||
var ih [bittorrent.InfoHashV1Len]byte
|
||||
req := tracker.AnnounceRequest{
|
||||
InfoHash: ih,
|
||||
PeerId: [20]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
||||
PeerId: [bittorrent.PeerIDLen]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20},
|
||||
Downloaded: 50,
|
||||
Left: 100,
|
||||
Uploaded: 50,
|
||||
@@ -98,7 +114,7 @@ func testWithInfohash(infoHash bittorrent.InfoHash, url string, delay time.Durat
|
||||
copy(ih[:], infoHash)
|
||||
req = tracker.AnnounceRequest{
|
||||
InfoHash: ih,
|
||||
PeerId: [20]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21},
|
||||
PeerId: [bittorrent.PeerIDLen]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21},
|
||||
Downloaded: 50,
|
||||
Left: 100,
|
||||
Uploaded: 50,
|
||||
|
||||
+8
-17
@@ -2,15 +2,13 @@ package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
"os/signal"
|
||||
"runtime"
|
||||
"strings"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
|
||||
"github.com/chihaya/chihaya/frontend/http"
|
||||
"github.com/chihaya/chihaya/frontend/udp"
|
||||
@@ -21,6 +19,8 @@ import (
|
||||
"github.com/chihaya/chihaya/storage"
|
||||
)
|
||||
|
||||
var e2eCmd *cobra.Command
|
||||
|
||||
// Run represents the state of a running instance of Chihaya.
|
||||
type Run struct {
|
||||
configFilePath string
|
||||
@@ -137,7 +137,7 @@ func (r *Run) Stop(keepPeerStore bool) (storage.Storage, error) {
|
||||
|
||||
// RootRunCmdFunc implements a Cobra command that runs an instance of Chihaya
|
||||
// and handles reloading and shutdown via process signals.
|
||||
func RootRunCmdFunc(cmd *cobra.Command, args []string) error {
|
||||
func RootRunCmdFunc(cmd *cobra.Command, _ []string) error {
|
||||
configFilePath, err := cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -177,7 +177,7 @@ func RootRunCmdFunc(cmd *cobra.Command, args []string) error {
|
||||
}
|
||||
|
||||
// RootPreRunCmdFunc handles command line flags for the Run command.
|
||||
func RootPreRunCmdFunc(cmd *cobra.Command, args []string) error {
|
||||
func RootPreRunCmdFunc(cmd *cobra.Command, _ []string) error {
|
||||
noColors, err := cmd.Flags().GetBool("nocolors")
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -233,19 +233,10 @@ func main() {
|
||||
|
||||
rootCmd.Flags().String("config", "/etc/chihaya.yaml", "location of configuration file")
|
||||
|
||||
var e2eCmd = &cobra.Command{
|
||||
Use: "e2e",
|
||||
Short: "exec e2e tests",
|
||||
Long: "Execute the Chihaya end-to-end test suite",
|
||||
RunE: EndToEndRunCmdFunc,
|
||||
if e2eCmd != nil {
|
||||
rootCmd.AddCommand(e2eCmd)
|
||||
}
|
||||
|
||||
e2eCmd.Flags().String("httpaddr", "http://127.0.0.1:6969/announce", "address of the HTTP tracker")
|
||||
e2eCmd.Flags().String("udpaddr", "udp://127.0.0.1:6969", "address of the UDP tracker")
|
||||
e2eCmd.Flags().Duration("delay", time.Second, "delay between announces")
|
||||
|
||||
rootCmd.AddCommand(e2eCmd)
|
||||
|
||||
if err := rootCmd.Execute(); err != nil {
|
||||
log.Fatal("failed when executing root cobra command: " + err.Error())
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build darwin || freebsd || linux || netbsd || openbsd || dragonfly || solaris
|
||||
// +build darwin freebsd linux netbsd openbsd dragonfly solaris
|
||||
|
||||
package main
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package main
|
||||
|
||||
Reference in New Issue
Block a user