2018-05-29 23:19:40 +02:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"os/signal"
|
2018-06-15 04:30:37 +02:00
|
|
|
"strconv"
|
2018-05-29 23:19:40 +02:00
|
|
|
"syscall"
|
|
|
|
|
|
|
|
"github.com/lbryio/reflector.go/db"
|
2018-06-15 04:30:37 +02:00
|
|
|
"github.com/lbryio/reflector.go/peer"
|
|
|
|
"github.com/lbryio/reflector.go/prism"
|
2018-05-29 23:19:40 +02:00
|
|
|
"github.com/lbryio/reflector.go/reflector"
|
|
|
|
"github.com/lbryio/reflector.go/store"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
2018-06-15 04:30:37 +02:00
|
|
|
var (
|
|
|
|
startPeerPort int
|
|
|
|
startReflectorPort int
|
|
|
|
startDhtPort int
|
|
|
|
startDhtSeedPort int
|
|
|
|
startClusterPort int
|
|
|
|
startClusterSeedPort int
|
|
|
|
)
|
|
|
|
|
2018-05-29 23:19:40 +02:00
|
|
|
func init() {
|
|
|
|
var cmd = &cobra.Command{
|
|
|
|
Use: "start [cluster-address]",
|
2018-06-13 01:53:21 +02:00
|
|
|
Short: "Runs prism application with cluster, dht, peer server, and reflector server.",
|
2018-05-29 23:19:40 +02:00
|
|
|
Run: startCmd,
|
|
|
|
Args: cobra.RangeArgs(0, 1),
|
|
|
|
}
|
2018-06-15 04:30:37 +02:00
|
|
|
cmd.PersistentFlags().IntVar(&startDhtPort, "dht-port", 4570, "Port to start DHT on")
|
|
|
|
cmd.PersistentFlags().IntVar(&startDhtSeedPort, "dht-seed-port", 4567, "Port to connect to DHT bootstrap node on")
|
|
|
|
cmd.PersistentFlags().IntVar(&startClusterPort, "cluster-port", 5678, "Port to start DHT on")
|
|
|
|
cmd.PersistentFlags().IntVar(&startClusterSeedPort, "cluster-seed-port", 0, "Port to start DHT on")
|
|
|
|
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-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) {
|
|
|
|
db := new(db.SQL)
|
2018-05-30 03:38:55 +02:00
|
|
|
err := db.Connect(globalConfig.DBConn)
|
2018-05-29 23:19:40 +02:00
|
|
|
checkErr(err)
|
2018-05-30 03:38:55 +02:00
|
|
|
s3 := store.NewS3BlobStore(globalConfig.AwsID, globalConfig.AwsSecret, globalConfig.BucketRegion, globalConfig.BucketName)
|
2018-05-29 23:19:40 +02:00
|
|
|
comboStore := store.NewDBBackedS3Store(s3, db)
|
|
|
|
|
2018-06-19 19:47:13 +02:00
|
|
|
// TODO: args we need:
|
|
|
|
// clusterAddr - to connect to cluster (or start new cluster if empty)
|
|
|
|
// 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-15 04:30:37 +02:00
|
|
|
//clusterAddr := ""
|
|
|
|
//if len(args) > 0 {
|
|
|
|
// clusterAddr = args[0]
|
|
|
|
//}
|
|
|
|
|
|
|
|
conf := prism.DefaultConf()
|
|
|
|
conf.DB = db
|
|
|
|
conf.Blobs = comboStore
|
|
|
|
conf.DhtAddress = "127.0.0.1:" + strconv.Itoa(startDhtPort)
|
|
|
|
conf.DhtSeedNodes = []string{"127.0.0.1:" + strconv.Itoa(startDhtSeedPort)}
|
|
|
|
conf.ClusterPort = startClusterPort
|
|
|
|
if startClusterSeedPort > 0 {
|
|
|
|
conf.ClusterSeedAddr = "127.0.0.1:" + strconv.Itoa(startClusterSeedPort)
|
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()
|
|
|
|
}
|