Skip to content

Commit

Permalink
Merge pull request #1523 from mysteriumnetwork/remove-fetcher
Browse files Browse the repository at this point in the history
Remove discovery proposal fetcher
  • Loading branch information
tadaskay authored Jan 16, 2020
2 parents 5b5bfe1 + 9ad4d8c commit 25675f0
Show file tree
Hide file tree
Showing 31 changed files with 495 additions and 650 deletions.
55 changes: 20 additions & 35 deletions cmd/di.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ import (
"github.com/mysteriumnetwork/node/core/auth"
"github.com/mysteriumnetwork/node/core/connection"
"github.com/mysteriumnetwork/node/core/discovery"
discovery_api "github.com/mysteriumnetwork/node/core/discovery/api"
discovery_broker "github.com/mysteriumnetwork/node/core/discovery/broker"
discovery_composite "github.com/mysteriumnetwork/node/core/discovery/composite"
discovery_noop "github.com/mysteriumnetwork/node/core/discovery/noop"
"github.com/mysteriumnetwork/node/core/discovery/apidiscovery"
"github.com/mysteriumnetwork/node/core/discovery/brokerdiscovery"
"github.com/mysteriumnetwork/node/core/discovery/proposal"
"github.com/mysteriumnetwork/node/core/ip"
"github.com/mysteriumnetwork/node/core/location"
"github.com/mysteriumnetwork/node/core/node"
Expand Down Expand Up @@ -132,9 +131,9 @@ type Dependencies struct {
IdentityRegistry identity_registry.IdentityRegistry
IdentitySelector identity_selector.Handler

DiscoveryFactory service.DiscoveryFactory
DiscoveryStorage *discovery.ProposalStorage
DiscoveryFinder discovery.ProposalFinder
DiscoveryFactory service.DiscoveryFactory
ProposalRepository proposal.Repository
DiscoveryWorker brokerdiscovery.Worker

QualityMetricsSender *quality.Sender
QualityClient *quality.MysteriumMORQA
Expand Down Expand Up @@ -266,7 +265,7 @@ func (di *Dependencies) Bootstrap(nodeOptions node.Options) error {
if err = di.subscribeEventConsumers(); err != nil {
return err
}
if err = di.DiscoveryFinder.Start(); err != nil {
if err = di.DiscoveryWorker.Start(); err != nil {
return err
}
if err := di.Node.Start(); err != nil {
Expand Down Expand Up @@ -367,8 +366,8 @@ func (di *Dependencies) Shutdown() (err error) {
errs = append(errs, err)
}
}
if di.DiscoveryFinder != nil {
di.DiscoveryFinder.Stop()
if di.DiscoveryWorker != nil {
di.DiscoveryWorker.Stop()
}
if di.Storage != nil {
if err := di.Storage.Close(); err != nil {
Expand Down Expand Up @@ -557,10 +556,10 @@ func (di *Dependencies) bootstrapTequilapi(nodeOptions node.Options, listener ne
tequilapi_endpoints.AddRouteForStop(router, utils.SoftKiller(di.Shutdown))
tequilapi_endpoints.AddRoutesForAuthentication(router, di.Authenticator, di.JWTAuthenticator)
tequilapi_endpoints.AddRoutesForIdentities(router, di.IdentityManager, di.IdentitySelector, di.IdentityRegistry, nodeOptions.Transactor.RegistryAddress, channelImplementation, di.ConsumerBalanceTracker.GetBalance)
tequilapi_endpoints.AddRoutesForConnection(router, di.ConnectionManager, di.StatisticsTracker, di.DiscoveryStorage, di.IdentityRegistry)
tequilapi_endpoints.AddRoutesForConnection(router, di.ConnectionManager, di.StatisticsTracker, di.ProposalRepository, di.IdentityRegistry)
tequilapi_endpoints.AddRoutesForConnectionSessions(router, di.SessionStorage)
tequilapi_endpoints.AddRoutesForConnectionLocation(router, di.ConnectionManager, di.IPResolver, di.LocationResolver, di.LocationResolver)
tequilapi_endpoints.AddRoutesForProposals(router, di.DiscoveryStorage, di.QualityClient)
tequilapi_endpoints.AddRoutesForProposals(router, di.ProposalRepository, di.QualityClient)
tequilapi_endpoints.AddRoutesForService(router, di.ServicesManager, serviceTypesRequestParser, nodeOptions.AccessPolicyEndpointAddress)
tequilapi_endpoints.AddRoutesForServiceSessions(router, di.StateKeeper)
tequilapi_endpoints.AddRoutesForPayout(router, di.IdentityManager, di.SignerFactory, di.MysteriumAPI)
Expand Down Expand Up @@ -729,37 +728,23 @@ func (di *Dependencies) bootstrapIdentityComponents(options node.Options) {
}

func (di *Dependencies) bootstrapDiscoveryComponents(options node.OptionsDiscovery) error {
di.DiscoveryStorage = discovery.NewStorage()

discoveryRegistry := discovery_composite.NewRegistry()
discoveryFinder := discovery_composite.NewFinder()
proposalRepository := discovery.NewRepository()
discoveryRegistry := discovery.NewRegistry()
for _, discoveryType := range options.Types {
switch discoveryType {
case node.DiscoveryTypeAPI:
discoveryRegistry.AddRegistry(
discovery_api.NewRegistry(di.MysteriumAPI),
)

if !options.ProposalFetcherEnabled {
discoveryFinder.AddFinder(discovery_noop.NewFinder())
} else {
discoveryFinder.AddFinder(
discovery_api.NewFinder(di.DiscoveryStorage, di.MysteriumAPI.Proposals, options.FetchInterval),
)
}
discoveryRegistry.AddRegistry(apidiscovery.NewRegistry(di.MysteriumAPI))
proposalRepository.Add(apidiscovery.NewRepository(di.MysteriumAPI))
case node.DiscoveryTypeBroker:
discoveryRegistry.AddRegistry(
discovery_broker.NewRegistry(di.BrokerConnection),
)
discoveryFinder.AddFinder(
discovery_broker.NewFinder(di.DiscoveryStorage, di.BrokerConnection, options.PingInterval+time.Second, 1*time.Second),
)
discoveryRegistry.AddRegistry(brokerdiscovery.NewRegistry(di.BrokerConnection))
brokerRepository := brokerdiscovery.NewRepository(di.BrokerConnection, options.PingInterval+time.Second, 1*time.Second)
proposalRepository.Add(brokerRepository)
di.DiscoveryWorker = brokerRepository
default:
return errors.Errorf("unknown discovery adapter: %s", discoveryType)
}
}

di.DiscoveryFinder = discoveryFinder
di.ProposalRepository = proposalRepository
di.DiscoveryFactory = func() service.Discovery {
return discovery.NewService(di.IdentityRegistry, discoveryRegistry, options.PingInterval, di.SignerFactory, di.EventBus)
}
Expand Down
90 changes: 0 additions & 90 deletions core/discovery/api/finder.go

This file was deleted.

105 changes: 0 additions & 105 deletions core/discovery/api/finder_test.go

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package api
package apidiscovery

import (
"github.com/mysteriumnetwork/node/identity"
Expand Down
65 changes: 65 additions & 0 deletions core/discovery/apidiscovery/repository.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright (C) 2020 The "MysteriumNetwork/node" Authors.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package apidiscovery

import (
"fmt"

"github.com/mysteriumnetwork/node/core/discovery/proposal"
"github.com/mysteriumnetwork/node/market"
"github.com/mysteriumnetwork/node/market/mysterium"
)

type apiRepository struct {
discoveryAPI *mysterium.MysteriumAPI
}

// NewRepository constructs a new proposal repository (backed by API).
func NewRepository(api *mysterium.MysteriumAPI) *apiRepository {
return &apiRepository{discoveryAPI: api}
}

// Proposal returns proposal by ID.
func (a *apiRepository) Proposal(id market.ProposalID) (*market.ServiceProposal, error) {
proposals, err := a.discoveryAPI.QueryProposals(mysterium.ProposalsQuery{
NodeKey: id.ProviderID,
ServiceType: id.ServiceType,
})
if err != nil {
return nil, err
}
if len(proposals) != 1 {
return nil, fmt.Errorf("proposal does not exist: %+v", id)
}
return &proposals[0], nil
}

// Proposals returns proposals matching filter.
func (a *apiRepository) Proposals(filter *proposal.Filter) ([]market.ServiceProposal, error) {
proposals, err := a.discoveryAPI.Proposals()
if err != nil {
return nil, err
}
var filtered []market.ServiceProposal
for _, p := range proposals {
if filter.Matches(p) {
filtered = append(filtered, p)
}
}
return filtered, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package broker
package brokerdiscovery

import (
"github.com/mysteriumnetwork/node/communication"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package broker
package brokerdiscovery

import (
"github.com/mysteriumnetwork/node/communication"
Expand Down
Loading

0 comments on commit 25675f0

Please sign in to comment.