2018-08-31 19:50:22 -04:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2019-01-29 14:42:45 -05:00
|
|
|
"fmt"
|
2019-01-29 14:28:40 -05:00
|
|
|
"os"
|
|
|
|
"os/signal"
|
|
|
|
"strconv"
|
|
|
|
"syscall"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/lbryio/reflector.go/meta"
|
|
|
|
"github.com/lbryio/reflector.go/reflector"
|
2021-07-23 22:35:41 +02:00
|
|
|
"github.com/lbryio/reflector.go/server/peer"
|
2019-01-29 14:28:40 -05:00
|
|
|
"github.com/lbryio/reflector.go/store"
|
|
|
|
|
2018-09-11 07:41:29 -04:00
|
|
|
log "github.com/sirupsen/logrus"
|
2018-08-31 19:50:22 -04: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 14:05:00 -04:00
|
|
|
log.Printf("reflector %s", meta.VersionString())
|
2019-01-29 14:28:40 -05:00
|
|
|
|
2020-10-22 13:49:02 -04:00
|
|
|
memStore := store.NewMemStore()
|
2019-01-29 14:28:40 -05:00
|
|
|
|
2021-01-05 05:09:55 +01:00
|
|
|
reflectorServer := reflector.NewServer(memStore, memStore)
|
2019-01-29 14:28:40 -05: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 14:33:55 -05:00
|
|
|
err = peerServer.Start(":" + strconv.Itoa(reflector.DefaultPort+1))
|
2019-01-29 14:28:40 -05: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 14:42:45 -05:00
|
|
|
|
|
|
|
fmt.Println("Blobs in store")
|
|
|
|
for hash, blob := range memStore.Debug() {
|
|
|
|
fmt.Printf("%s: %d bytes\n", hash, len(blob))
|
|
|
|
}
|
2018-08-31 19:50:22 -04:00
|
|
|
}
|