Addressed code reviews.

This commit is contained in:
Mark Beamer Jr 2018-06-12 19:53:21 -04:00 committed by Alex Grintsvayg
parent 317a7d961a
commit 2edfc28398
4 changed files with 28 additions and 17 deletions

View file

@ -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)

View file

@ -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)

View file

@ -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
}

View file

@ -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
}