Skip to content

Commit

Permalink
Merge pull request #5842 from mysteriumnetwork/fix/manage-services-st…
Browse files Browse the repository at this point in the history
…ates

Manage services states
  • Loading branch information
Zensey authored Aug 2, 2023
2 parents f8184fc + e8632ab commit 92c1f35
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 11 deletions.
17 changes: 17 additions & 0 deletions cmd/commands/service/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/mysteriumnetwork/node/config"
"github.com/mysteriumnetwork/node/config/urfavecli/clicontext"
"github.com/mysteriumnetwork/node/core/node"
"github.com/mysteriumnetwork/node/metadata"
"github.com/mysteriumnetwork/node/services"
"github.com/mysteriumnetwork/node/tequilapi/client"
"github.com/mysteriumnetwork/node/tequilapi/contract"
Expand Down Expand Up @@ -123,6 +124,22 @@ func (sc *serviceCommand) Run(ctx *cli.Context) (err error) {
)
log.Info().Msgf("Unlocked identity: %v", providerID)

if config.Current.GetString(config.FlagNodeVersion.Name) == "" {

// on first version update: enable dvpn service if wireguard service is enabled
mapServices := make(map[string]bool, 0)
for _, serviceType := range serviceTypes {
mapServices[serviceType] = true
}

if mapServices["wireguard"] && !mapServices["dvpn"] {
serviceTypes = append(serviceTypes, "dvpn")
}
}
// save the version
config.Current.SetUser(config.FlagNodeVersion.Name, metadata.BuildNumber)
config.Current.SaveUserConfig()

for _, serviceType := range serviceTypes {
serviceOpts, err := services.GetStartOptions(serviceType)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion cmd/di_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ func (di *Dependencies) bootstrapServices(nodeOptions node.Options) error {

di.dnsProxy = dns.NewProxy("", config.GetInt(config.FlagDNSListenPort), dnsHandler)

di.bootstrapServiceWireguard(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
// disable for mobile
if !nodeOptions.Mobile {
di.bootstrapServiceWireguard(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
}
di.bootstrapServiceScraping(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
di.bootstrapServiceDataTransfer(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
di.bootstrapServiceDVPN(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
Expand Down
38 changes: 38 additions & 0 deletions config/flags_version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2022 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 config

import "github.com/urfave/cli/v2"

var (
// FlagNodeVersion - stores node version to discover a fact of node update
FlagNodeVersion = cli.StringFlag{
Name: "node.version",
Usage: "",
Value: "",
Hidden: true,
}
)

// RegisterFlagNodeVersion register Node version flags to the list
func RegisterFlagNodeVersion(flags *[]cli.Flag) {
*flags = append(
*flags,
&FlagNodeVersion,
)
}
1 change: 1 addition & 0 deletions core/node/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type Options struct {
Payments OptionsPayments

Consumer bool
Mobile bool

SwarmDialerDNSHeadstart time.Duration
PilvytisAddress string
Expand Down
36 changes: 33 additions & 3 deletions docker-compose.e2e-basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,41 @@ services:
timeout: 5s
retries: 5

discovery-service:
image: mysteriumnetwork/discovery:2.18.3
expose:
- 8081
environment:
- PORT=8081
- DB_DSN=postgresql://discovery:discovery@db:5432/discovery
- QUALITY_ORACLE_URL=http://morqa:8085
- BROKER_URL=broker
- UNIVERSE_JWT_SECRET=suchsecret
- REDIS_ADDRESS=redis:6379
- BADGER_ADDRESS=http://badger:1234
- QUALITY_CACHE_TTL=20m
- LOCATION_ADDRESS="badurl"
depends_on:
- db
- redis
- http-mock

discovery:
image: mysteriumnetwork/discovery:2.8.5
image: nginx:latest
expose:
- 8080
volumes:
- ./e2e/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- discovery-service
- discovery-pricer

discovery-pricer:
image: mysteriumnetwork/discovery-pricer:2.18.3
expose:
- 8091
environment:
- PORT=8080
- PORT=8091
- DB_DSN=postgresql://discovery:discovery@db:5432/discovery
- QUALITY_ORACLE_URL=http://morqa:8085
- BROKER_URL=broker
Expand All @@ -75,6 +104,7 @@ services:
- BADGER_ADDRESS=http://badger:1234
- QUALITY_CACHE_TTL=20m
- LOCATION_ADDRESS="badurl"
- SENTINEL_URL="https://sentinel.mysterium.network"
depends_on:
- db
- redis
Expand Down Expand Up @@ -228,7 +258,7 @@ services:

pilvytis-mock:
image: wiremock/wiremock:2.32.0
expose:
expose:
- 8080
volumes:
- ./e2e/pilvytis:/home/wiremock
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.e2e-compatibility.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ services:
retries: 5

discovery:
image: mysteriumnetwork/discovery:2.8.5
image: mysteriumnetwork/discovery:2.18.3
depends_on:
- db
- http-mock
Expand Down
66 changes: 61 additions & 5 deletions docker-compose.e2e-traversal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,23 +121,67 @@ services:
public1:
ipv4_address: 172.31.0.201

discovery:
image: mysteriumnetwork/discovery:2.8.5
discovery-service:
image: mysteriumnetwork/discovery:2.18.3
expose:
- 8081
environment:
- PORT=8081
- DB_DSN=postgresql://discovery:discovery@db:5432/discovery
- QUALITY_ORACLE_URL=http://morqa:8085
- BROKER_URL=broker
- UNIVERSE_JWT_SECRET=suchsecret
- REDIS_ADDRESS=redis:6379
- BADGER_ADDRESS=http://badger:1234
- QUALITY_CACHE_TTL=20m
- LOCATION_ADDRESS="badurl"
depends_on:
- db
- redis
- http-mock
cap_add:
- NET_ADMIN
sysctls:
- net.ipv4.conf.default.rp_filter=0
- net.ipv4.conf.all.rp_filter=0
- net.ipv4.conf.eth0.rp_filter=0
- net.ipv4.conf.eth1.rp_filter=0
dns: 172.30.0.254
networks:
public0:
ipv4_address: 172.30.0.214
public1:
ipv4_address: 172.31.0.214

discovery:
image: nginx:latest
expose:
- 8080
volumes:
- ./e2e/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
depends_on:
- discovery-service
- discovery-pricer
cap_add:
- NET_ADMIN
sysctls:
- net.ipv4.conf.default.rp_filter=0
- net.ipv4.conf.all.rp_filter=0
- net.ipv4.conf.eth0.rp_filter=0
- net.ipv4.conf.eth1.rp_filter=0
dns: 172.30.0.254
networks:
public0:
ipv4_address: 172.30.0.215
public1:
ipv4_address: 172.31.0.215

discovery-pricer:
image: mysteriumnetwork/discovery-pricer:2.18.3
expose:
- 8091
environment:
- PORT=8080
- PORT=8091
- DB_DSN=postgresql://discovery:discovery@db:5432/discovery
- QUALITY_ORACLE_URL=http://morqa:8085
- BROKER_URL=broker
Expand All @@ -146,6 +190,18 @@ services:
- BADGER_ADDRESS=http://badger:1234
- QUALITY_CACHE_TTL=20m
- LOCATION_ADDRESS="badurl"
- SENTINEL_URL="https://sentinel.mysterium.network"
depends_on:
- db
- redis
- http-mock
cap_add:
- NET_ADMIN
sysctls:
- net.ipv4.conf.default.rp_filter=0
- net.ipv4.conf.all.rp_filter=0
- net.ipv4.conf.eth0.rp_filter=0
- net.ipv4.conf.eth1.rp_filter=0
dns: 172.30.0.254
networks:
public0:
Expand Down Expand Up @@ -351,10 +407,10 @@ services:
ipv4_address: 172.30.0.204
public1:
ipv4_address: 172.31.0.204

pilvytis-mock:
image: wiremock/wiremock:2.32.0
expose:
expose:
- 8080
volumes:
- ./e2e/pilvytis:/home/wiremock
Expand Down
16 changes: 16 additions & 0 deletions e2e/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
events {
worker_connections 1024;
}
http {
server {
listen 8080 default_server;

location / {
proxy_pass http://discovery-service:8081;
}

location /api/v4/prices {
proxy_pass http://discovery-pricer:8091;
}
}
}
4 changes: 4 additions & 0 deletions mobile/mysterium/entrypoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ func NewNode(appPath string, options *MobileNodeOptions) (*MobileNode, error) {
config.Current.SetDefault(config.FlagUDPListenPorts.Name, "10000:60000")
config.Current.SetDefault(config.FlagStatsReportInterval.Name, time.Second)
config.Current.SetDefault(config.FlagUIFeatures.Name, options.UIFeaturesEnabled)
config.Current.SetDefault(config.FlagActiveServices.Name, "scraping,data_transfer,dvpn")

if options.IsProvider {
config.Current.SetDefault(config.FlagUserspace.Name, "true")
Expand All @@ -235,6 +236,8 @@ func NewNode(appPath string, options *MobileNodeOptions) (*MobileNode, error) {
config.Current.SetDefault(config.FlagChain1KnownHermeses.Name, config.FlagChain1KnownHermeses.Value)
config.Current.SetDefault(config.FlagChain2KnownHermeses.Name, config.FlagChain2KnownHermeses.Value)
config.Current.SetDefault(config.FlagDNSListenPort.Name, config.FlagDNSListenPort.Value)

config.Current.SetDefault(config.FlagUIFeatures.Name, "android_mobile_node,android_sso_deeplink")
}

bcNetwork, err := config.ParseBlockchainNetwork(options.Network)
Expand Down Expand Up @@ -272,6 +275,7 @@ func NewNode(appPath string, options *MobileNodeOptions) (*MobileNode, error) {
}

nodeOptions := node.Options{
Mobile: true,
LogOptions: logOptions,
Directories: node.OptionsDirectory{
Data: dataDir,
Expand Down
7 changes: 6 additions & 1 deletion session/pingpong/pricing.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package pingpong

import (
"errors"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -101,7 +102,11 @@ func NewPricer(discoAPI discoAPI) *Pricer {
func (p *Pricer) GetCurrentPrice(nodeType string, country string, serviceType string) (market.Price, error) {
pricing := p.getPricing()

return *p.getCurrentByType(pricing, nodeType, country, serviceType), nil
price := p.getCurrentByType(pricing, nodeType, country, serviceType)
if price == nil {
return market.Price{}, errors.New("no data available")
}
return *price, nil
}

func (p *Pricer) getPriceForCountry(pricing market.LatestPrices, country string) *market.PriceHistory {
Expand Down

0 comments on commit 92c1f35

Please sign in to comment.