2018-05-29 23:19:40 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
2018-06-15 04:30:37 +02:00
|
|
|
"strconv"
|
2018-06-21 17:26:48 +02:00
|
|
|
"strings"
|
2018-05-29 23:19:40 +02:00
|
|
|
"syscall"
|
|
|
|
|
2018-06-21 17:26:48 +02:00
|
|
|
"github.com/lbryio/reflector.go/cluster"
|
2018-05-29 23:19:40 +02:00
|
|
|
"github.com/lbryio/reflector.go/db"
|
2018-06-15 04:30:37 +02:00
|
|
|
"github.com/lbryio/reflector.go/prism"
|
2018-05-29 23:19:40 +02:00
|
|
|
"github.com/lbryio/reflector.go/reflector"
|
2021-07-23 22:35:41 +02:00
|
|
|
"github.com/lbryio/reflector.go/server/peer"
|
2018-05-29 23:19:40 +02:00
|
|
|
"github.com/lbryio/reflector.go/store"
|
|
|
|
|
2021-07-20 02:09:14 +02:00
|
|
|
"github.com/lbryio/lbry.go/v2/dht"
|
|
|
|
"github.com/lbryio/lbry.go/v2/dht/bits"
|
|
|
|
|
2018-05-29 23:19:40 +02:00
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2018-06-21 17:26:48 +02:00
|
|
|
const (
|
|
|
|
startNewCluster = "new"
|
|
|
|
)
|
|
|
|
|
2018-06-15 04:30:37 +02:00
|
|
|
var (
|
2018-06-21 17:26:48 +02:00
|
|
|
startClusterPort int
|
|
|
|
startPeerPort int
|
|
|
|
startReflectorPort int
|
|
|
|
startDhtPort int
|
|
|
|
startDhtSeeds []string
|
|
|
|
startHashRange string
|
2018-06-15 04:30:37 +02:00
|
|
|
)
|
|
|
|
|
2018-05-29 23:19:40 +02:00
|
|
|
func init() {
|
|
|
|
var cmd = &cobra.Command{
|
2018-06-21 17:26:48 +02:00
|
|
|
Use: `start [cluster-address|"new"]`,
|
|
|
|
Short: "Runs full prism application with cluster, dht, peer server, and reflector server.",
|
2018-05-29 23:19:40 +02:00
|
|
|
Run: startCmd,
|
2018-06-21 17:26:48 +02:00
|
|
|
Args: cobra.ExactArgs(1),
|
2018-05-29 23:19:40 +02:00
|
|
|
}
|
2018-06-21 17:26:48 +02:00
|
|
|
cmd.PersistentFlags().IntVar(&startClusterPort, "cluster-port", cluster.DefaultPort, "Port that cluster listens on")
|
2018-06-15 04:30:37 +02:00
|
|
|
cmd.PersistentFlags().IntVar(&startPeerPort, "peer-port", peer.DefaultPort, "Port to start peer protocol on")
|
|
|
|
cmd.PersistentFlags().IntVar(&startReflectorPort, "reflector-port", reflector.DefaultPort, "Port to start reflector protocol on")
|
2018-06-21 17:26:48 +02:00
|
|
|
cmd.PersistentFlags().IntVar(&startDhtPort, "dht-port", dht.DefaultPort, "Port that dht will listen on")
|
|
|
|
cmd.PersistentFlags().StringSliceVar(&startDhtSeeds, "dht-seeds", []string{}, "Comma-separated list of dht seed nodes (addr:port,addr:port,...)")
|
|
|
|
|
|
|
|
cmd.PersistentFlags().StringVar(&startHashRange, "hash-range", "", "Limit on range of hashes to announce (start-end)")
|
2018-06-15 04:30:37 +02:00
|
|
|
|
2018-05-30 03:38:55 +02:00
|
|
|
rootCmd.AddCommand(cmd)
|
2018-05-29 23:19:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func startCmd(cmd *cobra.Command, args []string) {
|
2021-01-06 16:43:35 +01:00
|
|
|
db := &db.SQL{
|
|
|
|
LogQueries: log.GetLevel() == log.DebugLevel,
|
|
|
|
}
|
2018-05-30 03:38:55 +02:00
|
|
|
err := db.Connect(globalConfig.DBConn)
|
2018-05-29 23:19:40 +02:00
|
|
|
checkErr(err)
|
2020-10-22 19:12:31 +02:00
|
|
|
s3 := store.NewS3Store(globalConfig.AwsID, globalConfig.AwsSecret, globalConfig.BucketRegion, globalConfig.BucketName)
|
2020-12-22 20:53:48 +01:00
|
|
|
comboStore := store.NewDBBackedStore(s3, db, false)
|
2018-05-29 23:19:40 +02:00
|
|
|
|
2018-06-21 17:26:48 +02:00
|
|
|
conf := prism.DefaultConf()
|
|
|
|
|
2018-06-19 19:47:13 +02:00
|
|
|
// TODO: args we need:
|
|
|
|
// minNodes - minimum number of nodes before announcing starts. otherwise first node will try to announce all the blobs in the db
|
|
|
|
// or maybe we should do maxHashesPerNode?
|
|
|
|
// in either case, this should not kill the cluster, but should only limit announces (and notify when some hashes are being left unannounced)
|
|
|
|
|
2018-06-21 17:26:48 +02:00
|
|
|
if args[0] != startNewCluster {
|
|
|
|
conf.ClusterSeedAddr = args[0]
|
|
|
|
}
|
2018-06-15 04:30:37 +02:00
|
|
|
|
|
|
|
conf.DB = db
|
|
|
|
conf.Blobs = comboStore
|
2018-06-21 17:26:48 +02:00
|
|
|
conf.DhtAddress = "0.0.0.0:" + strconv.Itoa(startDhtPort)
|
|
|
|
conf.DhtSeedNodes = startDhtSeeds
|
2018-06-15 04:30:37 +02:00
|
|
|
conf.ClusterPort = startClusterPort
|
2018-06-21 17:26:48 +02:00
|
|
|
conf.PeerPort = startPeerPort
|
|
|
|
conf.ReflectorPort = startReflectorPort
|
|
|
|
|
|
|
|
if startHashRange != "" {
|
|
|
|
hashRange := strings.Split(startHashRange, "-")
|
|
|
|
if len(hashRange) != 2 {
|
|
|
|
log.Fatal("invalid hash range")
|
|
|
|
}
|
|
|
|
r := bits.Range{Start: bits.FromShortHexP(hashRange[0]), End: bits.FromShortHexP(hashRange[1])}
|
|
|
|
conf.HashRange = &r
|
2018-05-29 23:19:40 +02:00
|
|
|
}
|
|
|
|
|
2018-06-15 04:30:37 +02:00
|
|
|
p := prism.New(conf)
|
|
|
|
err = p.Start()
|
|
|
|
if err != nil {
|
2018-06-07 05:48:07 +02:00
|
|
|
log.Fatal(err)
|
2018-05-29 23:19:40 +02:00
|
|
|
}
|
2018-06-15 04:30:37 +02:00
|
|
|
|
2018-05-29 23:19:40 +02:00
|
|
|
interruptChan := make(chan os.Signal, 1)
|
|
|
|
signal.Notify(interruptChan, os.Interrupt, syscall.SIGTERM)
|
|
|
|
<-interruptChan
|
|
|
|
p.Shutdown()
|
|
|
|
}
|