2018-09-01 01:50:22 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2019-01-29 20:42:45 +01:00
|
|
|
"fmt"
|
2019-01-29 20:28:40 +01:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"strconv"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/lbryio/reflector.go/meta"
|
|
|
|
"github.com/lbryio/reflector.go/peer"
|
|
|
|
"github.com/lbryio/reflector.go/reflector"
|
|
|
|
"github.com/lbryio/reflector.go/store"
|
|
|
|
|
2018-09-11 13:41:29 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
2018-09-01 01:50:22 +02:00
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
var cmd = &cobra.Command{
|
|
|
|
Use: "test",
|
|
|
|
Short: "Test things",
|
|
|
|
Run: testCmd,
|
|
|
|
}
|
|
|
|
rootCmd.AddCommand(cmd)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testCmd(cmd *cobra.Command, args []string) {
|
2020-10-05 20:05:00 +02:00
|
|
|
log.Printf("reflector %s", meta.VersionString())
|
2019-01-29 20:28:40 +01:00
|
|
|
|
2020-10-22 19:49:02 +02:00
|
|
|
memStore := store.NewMemStore()
|
2019-01-29 20:28:40 +01:00
|
|
|
|
2021-01-05 05:09:55 +01:00
|
|
|
reflectorServer := reflector.NewServer(memStore, memStore)
|
2019-01-29 20:28:40 +01:00
|
|
|
reflectorServer.Timeout = 3 * time.Minute
|
|
|
|
|
|
|
|
err := reflectorServer.Start(":" + strconv.Itoa(reflector.DefaultPort))
|
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
peerServer := peer.NewServer(memStore)
|
2019-01-29 20:33:55 +01:00
|
|
|
err = peerServer.Start(":" + strconv.Itoa(reflector.DefaultPort+1))
|
2019-01-29 20:28:40 +01:00
|
|
|
if err != nil {
|
|
|
|
log.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
interruptChan := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM)
|
|
|
|
<-interruptChan
|
|
|
|
peerServer.Shutdown()
|
|
|
|
reflectorServer.Shutdown()
|
2019-01-29 20:42:45 +01:00
|
|
|
|
|
|
|
fmt.Println("Blobs in store")
|
|
|
|
for hash, blob := range memStore.Debug() {
|
|
|
|
fmt.Printf("%s: %d bytes\n", hash, len(blob))
|
|
|
|
}
|
2018-09-01 01:50:22 +02:00
|
|
|
}
|