Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to have just on-demand proposal fetching #1598

Merged
merged 3 commits into from
Jan 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 15 additions & 17 deletions cmd/di_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,11 @@ func (di *Dependencies) bootstrapDiscoveryComponents(options node.OptionsDiscove
case node.DiscoveryTypeBroker:
discoveryRegistry.AddRegistry(brokerdiscovery.NewRegistry(di.BrokerConnection))

brokerRepository, err := di.bootstrapDiscoveryBroker(options)
if err != nil {
return errors.Wrap(err, "failed to bootstrap broker discovery")
brokerRepository := brokerdiscovery.NewRepository(di.BrokerConnection, di.EventBus, options.PingInterval+time.Second, 1*time.Second)
if options.FetchEnabled {
if err := discoverySyncStart(brokerRepository, di.EventBus); err != nil {
return errors.Wrap(err, "failed to enable broker discovery")
}
}
proposalRepository.Add(brokerRepository)
default:
Expand All @@ -59,23 +61,19 @@ func (di *Dependencies) bootstrapDiscoveryComponents(options node.OptionsDiscove
return nil
}

func (di *Dependencies) bootstrapDiscoveryBroker(options node.OptionsDiscovery) (*brokerdiscovery.Repository, error) {
repository := brokerdiscovery.NewRepository(di.BrokerConnection, di.EventBus, options.PingInterval+time.Second, 1*time.Second)

if err := discoverySyncsInConsumerMode(repository, di.EventBus); err != nil {
return repository, err
}
if err := discoveryStopsOnShutdown(repository, di.EventBus); err != nil {
return repository, err
}
return repository, discoverySyncStart(repository)
}

func discoverySyncStart(repository *brokerdiscovery.Repository) error {
func discoverySyncStart(repository *brokerdiscovery.Repository, eventBus eventbus.EventBus) error {
err := repository.Start()
if err != nil {
log.Error().Err(err).Msg("Broker discovery start failed")
}

if err := discoverySyncsInConsumerMode(repository, eventBus); err != nil {
return err
}
if err := discoveryStopsOnShutdown(repository, eventBus); err != nil {
return err
}

return err
}

Expand All @@ -85,7 +83,7 @@ func discoverySyncsInConsumerMode(repository *brokerdiscovery.Repository, eventB
case service.Running:
repository.Stop()
case service.NotRunning:
discoverySyncStart(repository)
discoverySyncStart(repository, eventBus)
}
})
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions core/node/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,10 @@ func GetDiscoveryOptions() *OptionsDiscovery {
}

return &OptionsDiscovery{
Types: types,
ProposalFetcherEnabled: true,
PingInterval: config.GetDuration(config.FlagDiscoveryPingInterval),
FetchInterval: config.GetDuration(config.FlagDiscoveryPingInterval),
Types: types,
PingInterval: config.GetDuration(config.FlagDiscoveryPingInterval),
FetchEnabled: true,
FetchInterval: config.GetDuration(config.FlagDiscoveryFetchInterval),
}
}

Expand Down
10 changes: 5 additions & 5 deletions core/node/options_discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ const (

// OptionsDiscovery describes possible parameters of discovery configuration
type OptionsDiscovery struct {
Types []DiscoveryType
Address string
ProposalFetcherEnabled bool
PingInterval time.Duration
FetchInterval time.Duration
Types []DiscoveryType
Address string
PingInterval time.Duration
FetchEnabled bool
FetchInterval time.Duration
}
6 changes: 3 additions & 3 deletions mobile/mysterium/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ func NewNode(appPath string, optionsNetwork *MobileNetworkOptions) (*MobileNode,
Address: "https://quality.mysterium.network/api/v1",
},
Discovery: node.OptionsDiscovery{
Types: []node.DiscoveryType{node.DiscoveryTypeAPI, node.DiscoveryTypeBroker},
Address: network.MysteriumAPIAddress,
ProposalFetcherEnabled: false,
Types: []node.DiscoveryType{node.DiscoveryTypeAPI, node.DiscoveryTypeBroker},
Address: network.MysteriumAPIAddress,
FetchEnabled: false,
},
Location: node.OptionsLocation{
IPDetectorURL: "https://api.ipify.org/?format=json",
Expand Down