mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-04 13:32:52 -04:00
* add Router.Start()
* remove Router.Run()
This commit is contained in:
@ -12,6 +12,7 @@ type Router struct {
|
||||
cfg *config.RouterConfig
|
||||
ndb netdb.StdNetDB
|
||||
closeChnl chan bool
|
||||
running bool
|
||||
}
|
||||
|
||||
// create router with default configuration
|
||||
@ -29,20 +30,37 @@ func FromConfig(c *config.RouterConfig) (r *Router, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Wait blocks until router is fully stopped
|
||||
func (r *Router) Wait() {
|
||||
<-r.closeChnl
|
||||
}
|
||||
|
||||
// Stop starts stopping internal state of router
|
||||
func (r *Router) Stop() {
|
||||
r.closeChnl <- true
|
||||
r.running = false
|
||||
}
|
||||
|
||||
// Close closes any internal state and finallizes router resources so that nothing can start up again
|
||||
func (r *Router) Close() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Start starts router mainloop
|
||||
func (r *Router) Start() {
|
||||
if r.running {
|
||||
log.WithFields(log.Fields{
|
||||
"at": "(Router) Start",
|
||||
"reason": "router is already running",
|
||||
}).Error("Error Starting router")
|
||||
return
|
||||
}
|
||||
r.running = true
|
||||
go r.mainloop()
|
||||
}
|
||||
|
||||
// run i2p router mainloop
|
||||
func (r *Router) Run() {
|
||||
func (r *Router) mainloop() {
|
||||
r.ndb = netdb.StdNetDB(r.cfg.NetDb.Path)
|
||||
// make sure the netdb is ready
|
||||
err := r.ndb.Ensure()
|
||||
@ -60,5 +78,6 @@ func (r *Router) Run() {
|
||||
"at": "(Router) Run",
|
||||
"reason": err.Error(),
|
||||
}).Error("Netdb Startup failed")
|
||||
r.Stop()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user