diff --git a/cmd/root.go b/cmd/root.go index 85c1bd9..ba4a53c 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -25,8 +25,8 @@ var conf string var globalConfig Config var rootCmd = &cobra.Command{ - Use: "reflector", - Short: "Reflector accepts blobs, stores them securely, and hosts them on the network", + Use: "prism", + Short: "Prism is a single entry point application with multiple sub modules which can be leveraged individually or together", PersistentPreRun: func(cmd *cobra.Command, args []string) { if verbose { log.SetLevel(log.DebugLevel) diff --git a/cmd/start.go b/cmd/start.go index 027c19e..f587d23 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -16,7 +16,7 @@ import ( func init() { var cmd = &cobra.Command{ Use: "start [cluster-address]", - Short: "Run prism server", + Short: "Runs prism application with cluster, dht, peer server, and reflector server.", Run: startCmd, Args: cobra.RangeArgs(0, 1), } @@ -24,7 +24,6 @@ func init() { } func startCmd(cmd *cobra.Command, args []string) { - log.SetLevel(log.DebugLevel) db := new(db.SQL) err := db.Connect(globalConfig.DBConn) checkErr(err) diff --git a/dht/dht.go b/dht/dht.go index a8f068f..e954e2e 100644 --- a/dht/dht.go +++ b/dht/dht.go @@ -136,10 +136,12 @@ func (dht *DHT) join() { // now call iterativeFind on yourself nf := newContactFinder(dht.node, dht.node.id, false) // stop if dht is stopped - go func(finder *contactFinder) { + go func() { <-dht.stop.Ch() - nf.Cancel() - }(nf) + if nf != nil { + nf.Cancel() + } + }() _, err := nf.Find() if err != nil { log.Errorf("[%s] join: %s", dht.node.id.HexShort(), err.Error()) @@ -160,18 +162,21 @@ func (dht *DHT) Start() error { if err != nil { return err } + //Perform join in the background dht.stop.Add(1) go func() { defer dht.stop.Done() dht.join() - }() - dht.stop.Add(1) - go func() { - defer dht.stop.Done() - dht.startReannouncer() + log.Debugf("[%s] DHT ready on %s (%d nodes found during join)", + dht.node.id.HexShort(), dht.contact.Addr().String(), dht.node.rt.Count()) + //Reannouncer can only be launched after join is complete. + dht.stop.Add(1) + go func() { + defer dht.stop.Done() + dht.startReannouncer() + }() }() - log.Debugf("[%s] DHT ready on %s (%d nodes found during join)", dht.node.id.HexShort(), dht.contact.Addr().String(), dht.node.rt.Count()) return nil } diff --git a/reflector/prism.go b/reflector/prism.go index 40a99a7..8e50353 100644 --- a/reflector/prism.go +++ b/reflector/prism.go @@ -37,16 +37,23 @@ func NewPrism(store store.BlobStore, clusterSeedAddr string) *Prism { // Start starts the components of the application. func (p *Prism) Start() error { - if err := p.dht.Start(); err != nil { + err := p.dht.Start() + if err != nil { return err } - if err := p.cluster.Connect(); err != nil { + + err = p.cluster.Connect() + if err != nil { return err } - if err := p.peer.Start("localhost:" + strconv.Itoa(peer.DefaultPort)); err != nil { + + err = p.peer.Start("localhost:" + strconv.Itoa(peer.DefaultPort)) + if err != nil { return err } - if err := p.reflector.Start("localhost:" + strconv.Itoa(DefaultPort)); err != nil { + + err = p.reflector.Start("localhost:" + strconv.Itoa(DefaultPort)) + if err != nil { return err }