more tidying
This commit is contained in:
@@ -118,8 +118,6 @@ var commands = &cmds.Command{
|
||||
return err
|
||||
}
|
||||
|
||||
log.I.Ln("starting the server.")
|
||||
|
||||
if srv.Serve(); check(err) {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ var (
|
||||
mutex sync.Mutex
|
||||
)
|
||||
|
||||
func SetTimeout(key string, timeout time.Duration) {
|
||||
func SetInterval(timeout time.Duration) {
|
||||
hostStatusInterval = timeout
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
dht "github.com/libp2p/go-libp2p-kad-dht"
|
||||
"github.com/libp2p/go-libp2p/core/host"
|
||||
"github.com/multiformats/go-multiaddr"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -43,12 +44,6 @@ func (srv *Server) Restart() (err error) {
|
||||
|
||||
func (srv *Server) Shutdown() (err error) {
|
||||
|
||||
//log.I.Ln("shutting down the dht...")
|
||||
//
|
||||
//if srv.dht.Close(); check(err) {
|
||||
// return
|
||||
//}
|
||||
|
||||
log.I.Ln("shutting down [p2p.host]")
|
||||
|
||||
if srv.host.Close(); check(err) {
|
||||
@@ -62,6 +57,8 @@ func (srv *Server) Shutdown() (err error) {
|
||||
|
||||
func (srv *Server) Serve() (err error) {
|
||||
|
||||
log.I.Ln("starting the server")
|
||||
|
||||
// Here we create a context with cancel and add it to the interrupt handler
|
||||
var ctx context.Context
|
||||
var cancel context.CancelFunc
|
||||
@@ -74,21 +71,13 @@ func (srv *Server) Serve() (err error) {
|
||||
//metrics.Init()
|
||||
//metrics.Set('indra.host.status.reporting.interval', 30 * time.Second)
|
||||
//metrics.Enable('indra.host.status')
|
||||
metrics.SetInterval(30 * time.Second)
|
||||
|
||||
go metrics.HostStatus(ctx, srv.host)
|
||||
|
||||
// Run the bootstrapping service on the peer.
|
||||
go seed.Bootstrap(ctx, srv.host, srv.config.SeedAddresses)
|
||||
|
||||
//log.I.Ln("bootstrapping the DHT")
|
||||
|
||||
// Bootstrap the DHT. In the default configuration, this spawns a Background
|
||||
// thread that will refresh the peer table every five minutes.
|
||||
//if err = srv.dht.Bootstrap(srv.Context); check(err) {
|
||||
// return err
|
||||
//}
|
||||
|
||||
//log.I.Ln("successfully connected")
|
||||
|
||||
select {
|
||||
|
||||
case <-ctx.Done():
|
||||
@@ -128,13 +117,5 @@ func New(params *cfg.Params, config *Config) (srv *Server, err error) {
|
||||
|
||||
config.SeedAddresses = append(config.SeedAddresses, seedAddresses...)
|
||||
|
||||
// Start a DHT, for use in peer discovery. We can't just make a new DHT
|
||||
// client because we want each peer to maintain its own local copy of the
|
||||
// DHT, so that the bootstrapping node of the DHT can go down without
|
||||
// inhibiting future peer discovery.
|
||||
//if s.dht, err = dht.New(s.Context, s.host); check(err) {
|
||||
// return nil, err
|
||||
//}
|
||||
|
||||
return &s, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user