mirror of
https://github.com/LBRYFoundation/reflector.go.git
synced 2025-08-23 17:27:25 +00:00
Addressed code reviews.
This commit is contained in:
parent
317a7d961a
commit
2edfc28398
4 changed files with 28 additions and 17 deletions
|
@ -25,8 +25,8 @@ var conf string
|
||||||
var globalConfig Config
|
var globalConfig Config
|
||||||
|
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "reflector",
|
Use: "prism",
|
||||||
Short: "Reflector accepts blobs, stores them securely, and hosts them on the network",
|
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) {
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||||
if verbose {
|
if verbose {
|
||||||
log.SetLevel(log.DebugLevel)
|
log.SetLevel(log.DebugLevel)
|
||||||
|
|
|
@ -16,7 +16,7 @@ import (
|
||||||
func init() {
|
func init() {
|
||||||
var cmd = &cobra.Command{
|
var cmd = &cobra.Command{
|
||||||
Use: "start [cluster-address]",
|
Use: "start [cluster-address]",
|
||||||
Short: "Run prism server",
|
Short: "Runs prism application with cluster, dht, peer server, and reflector server.",
|
||||||
Run: startCmd,
|
Run: startCmd,
|
||||||
Args: cobra.RangeArgs(0, 1),
|
Args: cobra.RangeArgs(0, 1),
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,6 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func startCmd(cmd *cobra.Command, args []string) {
|
func startCmd(cmd *cobra.Command, args []string) {
|
||||||
log.SetLevel(log.DebugLevel)
|
|
||||||
db := new(db.SQL)
|
db := new(db.SQL)
|
||||||
err := db.Connect(globalConfig.DBConn)
|
err := db.Connect(globalConfig.DBConn)
|
||||||
checkErr(err)
|
checkErr(err)
|
||||||
|
|
23
dht/dht.go
23
dht/dht.go
|
@ -136,10 +136,12 @@ func (dht *DHT) join() {
|
||||||
// now call iterativeFind on yourself
|
// now call iterativeFind on yourself
|
||||||
nf := newContactFinder(dht.node, dht.node.id, false)
|
nf := newContactFinder(dht.node, dht.node.id, false)
|
||||||
// stop if dht is stopped
|
// stop if dht is stopped
|
||||||
go func(finder *contactFinder) {
|
go func() {
|
||||||
<-dht.stop.Ch()
|
<-dht.stop.Ch()
|
||||||
nf.Cancel()
|
if nf != nil {
|
||||||
}(nf)
|
nf.Cancel()
|
||||||
|
}
|
||||||
|
}()
|
||||||
_, err := nf.Find()
|
_, err := nf.Find()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("[%s] join: %s", dht.node.id.HexShort(), err.Error())
|
log.Errorf("[%s] join: %s", dht.node.id.HexShort(), err.Error())
|
||||||
|
@ -160,18 +162,21 @@ func (dht *DHT) Start() error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
//Perform join in the background
|
||||||
dht.stop.Add(1)
|
dht.stop.Add(1)
|
||||||
go func() {
|
go func() {
|
||||||
defer dht.stop.Done()
|
defer dht.stop.Done()
|
||||||
dht.join()
|
dht.join()
|
||||||
}()
|
log.Debugf("[%s] DHT ready on %s (%d nodes found during join)",
|
||||||
dht.stop.Add(1)
|
dht.node.id.HexShort(), dht.contact.Addr().String(), dht.node.rt.Count())
|
||||||
go func() {
|
//Reannouncer can only be launched after join is complete.
|
||||||
defer dht.stop.Done()
|
dht.stop.Add(1)
|
||||||
dht.startReannouncer()
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,16 +37,23 @@ func NewPrism(store store.BlobStore, clusterSeedAddr string) *Prism {
|
||||||
|
|
||||||
// Start starts the components of the application.
|
// Start starts the components of the application.
|
||||||
func (p *Prism) Start() error {
|
func (p *Prism) Start() error {
|
||||||
if err := p.dht.Start(); err != nil {
|
err := p.dht.Start()
|
||||||
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := p.cluster.Connect(); err != nil {
|
|
||||||
|
err = p.cluster.Connect()
|
||||||
|
if err != nil {
|
||||||
return err
|
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
|
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue