Skip to content

Commit 46f49c6

Browse files
committed
New service type - monitoring
1 parent f4617a3 commit 46f49c6

File tree

17 files changed

+149
-32
lines changed

17 files changed

+149
-32
lines changed

cmd/di_desktop.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/mysteriumnetwork/node/p2p"
3737
"github.com/mysteriumnetwork/node/services/datatransfer"
3838
"github.com/mysteriumnetwork/node/services/dvpn"
39+
"github.com/mysteriumnetwork/node/services/monitoring"
3940
service_noop "github.com/mysteriumnetwork/node/services/noop"
4041
service_openvpn "github.com/mysteriumnetwork/node/services/openvpn"
4142
openvpn_service "github.com/mysteriumnetwork/node/services/openvpn/service"
@@ -87,6 +88,7 @@ func (di *Dependencies) bootstrapServices(nodeOptions node.Options) error {
8788
di.bootstrapServiceScraping(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
8889
di.bootstrapServiceDataTransfer(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
8990
di.bootstrapServiceDVPN(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
91+
di.bootstrapServiceMonitoring(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
9092

9193
return nil
9294
}
@@ -201,6 +203,30 @@ func (di *Dependencies) bootstrapServiceDVPN(nodeOptions node.Options, resources
201203
)
202204
}
203205

206+
func (di *Dependencies) bootstrapServiceMonitoring(nodeOptions node.Options, resourcesAllocator *resources.Allocator, wgClientFactory *endpoint.WgClientFactory) {
207+
di.ServiceRegistry.Register(
208+
monitoring.ServiceType,
209+
func(serviceOptions service.Options) (service.Service, error) {
210+
loc, err := di.LocationResolver.DetectLocation()
211+
if err != nil {
212+
return nil, err
213+
}
214+
215+
svc := wireguard_service.NewManager(
216+
di.IPResolver,
217+
loc.Country,
218+
di.NATService,
219+
di.EventBus,
220+
di.ServiceFirewall,
221+
resourcesAllocator,
222+
wgClientFactory,
223+
di.dnsProxy,
224+
)
225+
return svc, nil
226+
},
227+
)
228+
}
229+
204230
func (di *Dependencies) bootstrapServiceOpenvpn(nodeOptions node.Options) {
205231
createService := func(serviceOptions service.Options) (service.Service, error) {
206232
if err := nodeOptions.Openvpn.Check(); err != nil {
@@ -373,6 +399,7 @@ func (di *Dependencies) registerConnections(nodeOptions node.Options) {
373399
di.registerQuicConnection()
374400
di.registerDataTransferConnection(nodeOptions, resourceAllocator, di.WireguardClientFactory)
375401
di.registerDVPNConnection(nodeOptions, resourceAllocator, di.WireguardClientFactory)
402+
di.registerMonitoringConnection(nodeOptions, resourceAllocator, di.WireguardClientFactory)
376403
}
377404

378405
func (di *Dependencies) registerWireguardConnection(nodeOptions node.Options, resourceAllocator *resources.Allocator, wgClientFactory *endpoint.WgClientFactory) {
@@ -447,6 +474,22 @@ func (di *Dependencies) registerDVPNConnection(nodeOptions node.Options, resourc
447474
di.ConnectionRegistry.Register(dvpn.ServiceType, connFactory)
448475
}
449476

477+
func (di *Dependencies) registerMonitoringConnection(nodeOptions node.Options, resourceAllocator *resources.Allocator, wgClientFactory *endpoint.WgClientFactory) {
478+
monitoring.Bootstrap()
479+
handshakeWaiter := wireguard_connection.NewHandshakeWaiter()
480+
endpointFactory := func() (wireguard.ConnectionEndpoint, error) {
481+
return endpoint.NewConnectionEndpoint(resourceAllocator, wgClientFactory)
482+
}
483+
connFactory := func() (connection.Connection, error) {
484+
opts := wireguard_connection.Options{
485+
DNSScriptDir: nodeOptions.Directories.Script,
486+
HandshakeTimeout: 1 * time.Minute,
487+
}
488+
return wireguard_connection.NewConnection(opts, di.IPResolver, endpointFactory, handshakeWaiter)
489+
}
490+
di.ConnectionRegistry.Register(monitoring.ServiceType, connFactory)
491+
}
492+
450493
func (di *Dependencies) bootstrapMMN() error {
451494
client := mmn.NewClient(di.HTTPClient, config.GetString(config.FlagMMNAPIAddress), di.SignerFactory)
452495

config/config_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525

2626
"github.com/mysteriumnetwork/node/services/datatransfer"
2727
"github.com/mysteriumnetwork/node/services/dvpn"
28+
"github.com/mysteriumnetwork/node/services/monitoring"
2829
"github.com/mysteriumnetwork/node/services/scraping"
2930

3031
"github.com/stretchr/testify/assert"
@@ -237,7 +238,7 @@ func TestUserConfig_GetConfig(t *testing.T) {
237238

238239
func TestHardcodedServicesNameFlagValues(t *testing.T) {
239240
// importing these constants into config package create cyclic dependency
240-
assert.Equal(t, strings.Join([]string{scraping.ServiceType, datatransfer.ServiceType, dvpn.ServiceType}, ","), FlagActiveServices.Value)
241+
assert.Equal(t, strings.Join([]string{scraping.ServiceType, datatransfer.ServiceType, dvpn.ServiceType, monitoring.ServiceType}, ","), FlagActiveServices.Value)
241242
}
242243

243244
func must(t *testing.T, err error) {

config/flags_service_start.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ var (
6767
FlagActiveServices = cli.StringFlag{
6868
Name: "active-services",
6969
Usage: "Comma separated list of active services.",
70-
Value: strings.Join([]string{"scraping", "data_transfer", "dvpn"}, ","),
70+
Value: strings.Join([]string{"scraping", "data_transfer", "dvpn", "monitoring"}, ","),
7171
}
7272

7373
// FlagStoppedServices a comma-separated list of stopped services.

core/node/node_stats_tracker.go

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,17 @@ type QualityInfo struct {
184184

185185
// EarningsPerService represents information about earnings per service
186186
type EarningsPerService struct {
187-
EarningsPublic string `json:"public"`
188-
EarningsVPN string `json:"data_transfer"`
189-
EarningsScraping string `json:"scraping"`
190-
EarningsDVPN string `json:"dvpn"`
191-
EarningsTotal string `json:"total"`
192-
TotalEarningsPublic string `json:"total_public"`
193-
TotalEarningsVPN string `json:"total_data_transfer"`
194-
TotalEarningsScraping string `json:"total_scraping"`
195-
TotalEarningsDVPN string `json:"total_dvpn"`
187+
EarningsPublic string `json:"public"`
188+
EarningsVPN string `json:"data_transfer"`
189+
EarningsScraping string `json:"scraping"`
190+
EarningsDVPN string `json:"dvpn"`
191+
EarningsMonitoring string `json:"monitoring"`
192+
EarningsTotal string `json:"total"`
193+
TotalEarningsPublic string `json:"total_public"`
194+
TotalEarningsVPN string `json:"total_data_transfer"`
195+
TotalEarningsScraping string `json:"total_scraping"`
196+
TotalEarningsDVPN string `json:"total_dvpn"`
197+
TotalEarningsMonitoring string `json:"total_monitoring"`
196198
}
197199

198200
// Sessions retrieves and resolved monitoring status from quality oracle

core/service/manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/mysteriumnetwork/node/p2p"
3535
"github.com/mysteriumnetwork/node/services/datatransfer"
3636
"github.com/mysteriumnetwork/node/services/dvpn"
37+
"github.com/mysteriumnetwork/node/services/monitoring"
3738
"github.com/mysteriumnetwork/node/services/quic"
3839
"github.com/mysteriumnetwork/node/services/scraping"
3940
"github.com/mysteriumnetwork/node/services/wireguard"
@@ -252,6 +253,7 @@ func (manager *Manager) List(includeAll bool) []*Instance {
252253
quic.ServiceType: false,
253254
datatransfer.ServiceType: false,
254255
dvpn.ServiceType: false,
256+
monitoring.ServiceType: false,
255257
}
256258

257259
result := make([]*Instance, 0, len(added))

core/state/state.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package state
1919

2020
import (
21+
"fmt"
2122
"math/big"
2223
"sync"
2324
"time"
@@ -234,6 +235,7 @@ func (k *Keeper) updateServiceState(_ interface{}) {
234235
func (k *Keeper) updateServices() {
235236
services := k.deps.ServiceLister.List(false)
236237
result := make([]contract.ServiceInfoDTO, len(services))
238+
fmt.Printf(">>>> Services %+v\n", services)
237239

238240
i := 0
239241
for _, v := range services {
@@ -246,6 +248,8 @@ func (k *Keeper) updateServices() {
246248
log.Warn().Msgf("could not load price for proposal %v(%v)", proposal.ProviderID, proposal.ServiceType)
247249
}
248250

251+
fmt.Printf(">>>> Proposal %+v\npriced: %v\n", proposal, priced)
252+
249253
prop := contract.NewProposalDTO(priced)
250254
if match.ConnectionStatistics == nil {
251255
match.ConnectionStatistics = &contract.ServiceStatisticsDTO{}

market/price.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type PriceByServiceType struct {
4949
Scraping *Price `json:"scraping"`
5050
DataTransfer *Price `json:"data_transfer"`
5151
DVPN *Price `json:"dvpn"`
52+
Monitoring *Price `json:"monitoring"`
5253
}
5354

5455
// Price represents the price.

mobile/mysterium/mobile_provider.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
"github.com/mysteriumnetwork/node/services/datatransfer"
3232
"github.com/mysteriumnetwork/node/services/dvpn"
33+
"github.com/mysteriumnetwork/node/services/monitoring"
3334
"github.com/mysteriumnetwork/node/services/scraping"
3435
"github.com/mysteriumnetwork/node/services/wireguard"
3536
)
@@ -155,7 +156,7 @@ func SetFlagLauncherVersion(val string) {
155156
}
156157

157158
func getAllServiceTypes() []string {
158-
return []string{wireguard.ServiceType, scraping.ServiceType, datatransfer.ServiceType, dvpn.ServiceType}
159+
return []string{wireguard.ServiceType, scraping.ServiceType, datatransfer.ServiceType, dvpn.ServiceType, monitoring.ServiceType}
159160
}
160161

161162
// GetServiceTypes returns all possible service types

mobile/mysterium/proposals_manager.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/mysteriumnetwork/node/nat"
3131
"github.com/mysteriumnetwork/node/services/datatransfer"
3232
"github.com/mysteriumnetwork/node/services/dvpn"
33+
"github.com/mysteriumnetwork/node/services/monitoring"
3334
"github.com/mysteriumnetwork/node/services/openvpn"
3435
"github.com/mysteriumnetwork/node/services/quic"
3536
"github.com/mysteriumnetwork/node/services/scraping"
@@ -219,6 +220,7 @@ func (m *proposalsManager) getFromRepository(req *GetProposalsRequest) ([]propos
219220
scraping.ServiceType: true,
220221
quic.ServiceType: true,
221222
dvpn.ServiceType: true,
223+
monitoring.ServiceType: true,
222224
}
223225
var res []proposal.PricedServiceProposal
224226
for _, p := range allProposals {

services/monitoring/bootstrap.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (C) 2018 The "MysteriumNetwork/node" Authors.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation, either version 3 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package monitoring
19+
20+
import "github.com/mysteriumnetwork/node/market"
21+
22+
const ServiceType = "monitoring"
23+
24+
// Bootstrap is called on program initialization time and registers various deserializers related to monitoring service
25+
func Bootstrap() {
26+
market.RegisterServiceType(ServiceType)
27+
}

0 commit comments

Comments
 (0)