Example #1
0
func archiveAndSaveConfig(cfg *config.Wrapper) error {
	// To prevent previous config from being cleaned up, quickly touch it too
	now := time.Now()
	_ = os.Chtimes(cfg.ConfigPath(), now, now) // May return error on Android etc; no worries

	archivePath := cfg.ConfigPath() + fmt.Sprintf(".v%d", cfg.Raw().OriginalVersion)
	l.Infoln("Archiving a copy of old config file format at:", archivePath)
	if err := osutil.Rename(cfg.ConfigPath(), archivePath); err != nil {
		return err
	}

	return cfg.Save()
}
Example #2
0
// 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
}
Example #3
0
func newUsageReportingManager(cfg *config.Wrapper, m *model.Model) *usageReportingManager {
	mgr := &usageReportingManager{
		cfg:   cfg,
		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
}
Example #4
0
func NewService(cfg *config.Wrapper, tlsCfg *tls.Config) *Service {
	conns := make(chan *tls.Conn)

	service := &Service{
		Supervisor: suture.New("Service", suture.Spec{
			Log: func(log string) {
				l.Debugln(log)
			},
			FailureBackoff:   5 * time.Minute,
			FailureDecay:     float64((10 * time.Minute) / time.Second),
			FailureThreshold: 5,
		}),
		cfg:    cfg,
		tlsCfg: tlsCfg,

		tokens:      make(map[string]suture.ServiceToken),
		clients:     make(map[string]client.RelayClient),
		mut:         sync.NewRWMutex(),
		invitations: make(chan protocol.SessionInvitation),
		conns:       conns,
	}

	rcfg := cfg.Raw()
	service.CommitConfiguration(rcfg, rcfg)
	cfg.Subscribe(service)

	receiver := &invitationReceiver{
		tlsCfg:      tlsCfg,
		conns:       conns,
		invitations: service.invitations,
		stop:        make(chan struct{}),
	}

	eventBc := &eventBroadcaster{
		Service: service,
		stop:    make(chan struct{}),
	}

	service.Add(receiver)
	service.Add(eventBc)

	return service
}