// Creates a new progress emitter which emits DownloadProgress events every // interval. func NewProgressEmitter(cfg *config.Wrapper) *ProgressEmitter { t := &ProgressEmitter{ stop: make(chan struct{}), registry: make(map[string]*sharedPullerState), last: make(map[string]map[string]*pullerProgress), timer: time.NewTimer(time.Millisecond), } t.Changed(cfg.Raw()) cfg.Subscribe(t) return t }
func NewBlockFinder(db *leveldb.DB, cfg *config.Wrapper) *BlockFinder { if blockFinder != nil { return blockFinder } f := &BlockFinder{ db: db, } f.Changed(cfg.Raw()) cfg.Subscribe(f) return f }
// NewProgressEmitter creates a new progress emitter which emits // DownloadProgress events every interval. func NewProgressEmitter(cfg *config.Wrapper) *ProgressEmitter { t := &ProgressEmitter{ stop: make(chan struct{}), registry: make(map[string]*sharedPullerState), last: make(map[string]map[string]*pullerProgress), timer: time.NewTimer(time.Millisecond), mut: sync.NewMutex(), } t.CommitConfiguration(config.Configuration{}, cfg.Raw()) cfg.Subscribe(t) return t }
func newUsageReportingManager(m *model.Model, cfg *config.Wrapper) *usageReportingManager { mgr := &usageReportingManager{ model: m, } // Start UR if it's enabled. mgr.CommitConfiguration(config.Configuration{}, cfg.Raw()) // Listen to future config changes so that we can start and stop as // appropriate. cfg.Subscribe(mgr) return mgr }
func NewBlockFinder(db *leveldb.DB, cfg *config.Wrapper) *BlockFinder { if blockFinder != nil { return blockFinder } f := &BlockFinder{ db: db, mut: sync.NewRWMutex(), } f.CommitConfiguration(config.Configuration{}, cfg.Raw()) cfg.Subscribe(f) return f }
func setupGUI(mainSvc *suture.Supervisor, cfg *config.Wrapper, m *model.Model, apiSub *events.BufferedSubscription) { opts := cfg.Options() guiCfg := overrideGUIConfig(cfg.GUI(), guiAddress, guiAuthentication, guiAPIKey) if guiCfg.Enabled && guiCfg.Address != "" { addr, err := net.ResolveTCPAddr("tcp", guiCfg.Address) if err != nil { l.Fatalf("Cannot start GUI on %q: %v", guiCfg.Address, err) } else { var hostOpen, hostShow string switch { case addr.IP == nil: hostOpen = "localhost" hostShow = "0.0.0.0" case addr.IP.IsUnspecified(): hostOpen = "localhost" hostShow = addr.IP.String() default: hostOpen = addr.IP.String() hostShow = hostOpen } var proto = "http" if guiCfg.UseTLS { proto = "https" } urlShow := fmt.Sprintf("%s://%s/", proto, net.JoinHostPort(hostShow, strconv.Itoa(addr.Port))) l.Infoln("Starting web GUI on", urlShow) api, err := newAPISvc(myID, guiCfg, guiAssets, m, apiSub) if err != nil { l.Fatalln("Cannot start GUI:", err) } cfg.Subscribe(api) mainSvc.Add(api) if opts.StartBrowser && !noBrowser && !stRestarting { urlOpen := fmt.Sprintf("%s://%s/", proto, net.JoinHostPort(hostOpen, strconv.Itoa(addr.Port))) // Can potentially block if the utility we are invoking doesn't // fork, and just execs, hence keep it in it's own routine. go openURL(urlOpen) } } } }