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

Add additional scraping service that works via QUIC #6104

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions cmd/commands/cli/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,7 @@ func parseStartFlags(serviceType string, args ...string) (services.StartOptions,
config.RegisterFlagsServiceStart(&flags)
config.RegisterFlagsServiceOpenvpn(&flags)
config.RegisterFlagsServiceWireguard(&flags)
config.RegisterFlagsServiceQuic(&flags)
config.RegisterFlagsServiceNoop(&flags)

set := flag.NewFlagSet("", flag.ContinueOnError)
Expand All @@ -702,6 +703,7 @@ func parseStartFlags(serviceType string, args ...string) (services.StartOptions,
config.ParseFlagsServiceStart(ctx)
config.ParseFlagsServiceOpenvpn(ctx)
config.ParseFlagsServiceWireguard(ctx)
config.ParseFlagsServiceQuic(ctx)
config.ParseFlagsServiceNoop(ctx)

return services.GetStartOptions(serviceType)
Expand Down
6 changes: 4 additions & 2 deletions cmd/commands/daemon/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
package daemon

import (
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"

"github.com/mysteriumnetwork/node/cmd"
"github.com/mysteriumnetwork/node/config"
"github.com/mysteriumnetwork/node/config/urfavecli/clicontext"
"github.com/mysteriumnetwork/node/core/node"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
)

// NewCommand function creates run command
Expand All @@ -40,6 +41,7 @@ func NewCommand() *cli.Command {
config.ParseFlagsServiceStart(ctx)
config.ParseFlagsServiceOpenvpn(ctx)
config.ParseFlagsServiceWireguard(ctx)
config.ParseFlagsServiceQuic(ctx)
config.ParseFlagsServiceNoop(ctx)
config.ParseFlagsNode(ctx)
if err := config.ValidateWireguardMTUFlag(); err != nil {
Expand Down
5 changes: 3 additions & 2 deletions cmd/commands/service/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ import (
"strings"
"time"

"github.com/mysteriumnetwork/terms/terms-go"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"
"github.com/urfave/cli/v2"
Expand All @@ -39,6 +37,7 @@ import (
"github.com/mysteriumnetwork/node/services"
"github.com/mysteriumnetwork/node/tequilapi/client"
"github.com/mysteriumnetwork/node/tequilapi/contract"
"github.com/mysteriumnetwork/terms/terms-go"
)

// NewCommand function creates service command
Expand All @@ -54,6 +53,7 @@ func NewCommand(licenseCommandName string) *cli.Command {
config.ParseFlagsServiceStart(ctx)
config.ParseFlagsServiceOpenvpn(ctx)
config.ParseFlagsServiceWireguard(ctx)
config.ParseFlagsServiceQuic(ctx)
config.ParseFlagsServiceNoop(ctx)
config.ParseFlagsNode(ctx)

Expand Down Expand Up @@ -96,6 +96,7 @@ func NewCommand(licenseCommandName string) *cli.Command {
config.RegisterFlagsServiceStart(&command.Flags)
config.RegisterFlagsServiceOpenvpn(&command.Flags)
config.RegisterFlagsServiceWireguard(&command.Flags)
config.RegisterFlagsServiceQuic(&command.Flags)
config.RegisterFlagsServiceNoop(&command.Flags)

return command
Expand Down
30 changes: 28 additions & 2 deletions cmd/di_desktop.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ package cmd
import (
"time"

"github.com/mysteriumnetwork/node/core/policy/requested"

"github.com/pkg/errors"
"github.com/rs/zerolog/log"

"github.com/mysteriumnetwork/node/config"
"github.com/mysteriumnetwork/node/core/connection"
"github.com/mysteriumnetwork/node/core/node"
"github.com/mysteriumnetwork/node/core/policy/localcopy"
"github.com/mysteriumnetwork/node/core/policy/requested"
"github.com/mysteriumnetwork/node/core/service"
"github.com/mysteriumnetwork/node/core/service/servicestate"
"github.com/mysteriumnetwork/node/dns"
Expand All @@ -40,6 +39,9 @@ import (
service_noop "github.com/mysteriumnetwork/node/services/noop"
service_openvpn "github.com/mysteriumnetwork/node/services/openvpn"
openvpn_service "github.com/mysteriumnetwork/node/services/openvpn/service"
"github.com/mysteriumnetwork/node/services/quic"
quic_connection "github.com/mysteriumnetwork/node/services/quic/connection"
quic_service "github.com/mysteriumnetwork/node/services/quic/service"
"github.com/mysteriumnetwork/node/services/scraping"
"github.com/mysteriumnetwork/node/services/wireguard"
wireguard_connection "github.com/mysteriumnetwork/node/services/wireguard/connection"
Expand Down Expand Up @@ -81,6 +83,7 @@ func (di *Dependencies) bootstrapServices(nodeOptions node.Options) error {
if !nodeOptions.Mobile {
di.bootstrapServiceWireguard(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
}
di.bootstrapServiceQuic()
di.bootstrapServiceScraping(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
di.bootstrapServiceDataTransfer(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
di.bootstrapServiceDVPN(nodeOptions, resourcesAllocator, di.WireguardClientFactory)
Expand Down Expand Up @@ -112,6 +115,20 @@ func (di *Dependencies) bootstrapServiceWireguard(nodeOptions node.Options, reso
)
}

func (di *Dependencies) bootstrapServiceQuic() {
di.ServiceRegistry.Register(
quic.ServiceType,
func(serviceOptions service.Options) (service.Service, error) {
loc, err := di.LocationResolver.DetectLocation()
if err != nil {
return nil, err
}

return quic_service.NewManager(loc.Country, di.EventBus), nil
},
)
}

func (di *Dependencies) bootstrapServiceScraping(nodeOptions node.Options, resourcesAllocator *resources.Allocator, wgClientFactory *endpoint.WgClientFactory) {
di.ServiceRegistry.Register(
scraping.ServiceType,
Expand Down Expand Up @@ -353,6 +370,7 @@ func (di *Dependencies) registerConnections(nodeOptions node.Options) {

di.registerWireguardConnection(nodeOptions, resourceAllocator, di.WireguardClientFactory)
di.registerScrapingConnection(nodeOptions, resourceAllocator, di.WireguardClientFactory)
di.registerQuicConnection()
di.registerDataTransferConnection(nodeOptions, resourceAllocator, di.WireguardClientFactory)
di.registerDVPNConnection(nodeOptions, resourceAllocator, di.WireguardClientFactory)
}
Expand All @@ -373,6 +391,14 @@ func (di *Dependencies) registerWireguardConnection(nodeOptions node.Options, re
di.ConnectionRegistry.Register(wireguard.ServiceType, connFactory)
}

func (di *Dependencies) registerQuicConnection() {
quic.Bootstrap()
connFactory := func() (connection.Connection, error) {
return quic_connection.NewConnection(quic_connection.Options{})
}
di.ConnectionRegistry.Register(quic.ServiceType, connFactory)
}

func (di *Dependencies) registerScrapingConnection(nodeOptions node.Options, resourceAllocator *resources.Allocator, wgClientFactory *endpoint.WgClientFactory) {
scraping.Bootstrap()
handshakeWaiter := wireguard_connection.NewHandshakeWaiter()
Expand Down
77 changes: 77 additions & 0 deletions config/flags_service_quic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright (C) 2025 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"
)

// FlagQUICDomain defines domain to be used by the QUIC connections.
var FlagQUICDomain = cli.StringFlag{
Name: "quic.domain",
Usage: "Domain to be used by the QUIC service",
Value: "",
}

// FlagQUICKey defines key to be used by the QUIC service.
var FlagQUICKey = cli.StringFlag{
Name: "quic.key",
Usage: "Key to be used by the QUIC service",
Value: "",
}

// FlagQUICCert defines cert to be used by the QUIC service.
var FlagQUICCert = cli.StringFlag{
Name: "quic.cert",
Usage: "Cert to be used by the QUIC service",
Value: "",
}

// FlagQUICLogin defines login to be used by the QUIC service.
var FlagQUICLogin = cli.StringFlag{
Name: "quic.login",
Usage: "Login to be used by the QUIC service",
Value: "mystuser",
}

// FlagQUICPassword defines password to be used by the QUIC service.
var FlagQUICPassword = cli.StringFlag{
Name: "quic.password",
Usage: "Password to be used by the QUIC service",
Value: "mystpass",
}

// RegisterFlagsServiceQuic function register QUIC flags to flag list.
func RegisterFlagsServiceQuic(flags *[]cli.Flag) {
*flags = append(*flags,
&FlagQUICDomain,
&FlagQUICKey,
&FlagQUICCert,
&FlagQUICLogin,
&FlagQUICPassword,
)
}

// ParseFlagsServiceQuic parses CLI flags and registers value to configuration.
func ParseFlagsServiceQuic(ctx *cli.Context) {
Current.ParseStringFlag(ctx, FlagQUICDomain)
Current.ParseStringFlag(ctx, FlagQUICKey)
Current.ParseStringFlag(ctx, FlagQUICCert)
Current.ParseStringFlag(ctx, FlagQUICLogin)
Current.ParseStringFlag(ctx, FlagQUICPassword)
}
7 changes: 3 additions & 4 deletions core/connection/connect_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@
package connection

import (
"net"

"github.com/ethereum/go-ethereum/common"

"github.com/mysteriumnetwork/node/core/discovery/proposal"
"github.com/mysteriumnetwork/node/identity"
"github.com/mysteriumnetwork/node/p2p"
"github.com/mysteriumnetwork/node/session"
)

Expand All @@ -45,7 +44,7 @@ type ConnectOptions struct {
SessionID session.ID
Params ConnectParams
SessionConfig []byte
ProviderNATConn *net.UDPConn
ChannelConn *net.UDPConn
ProviderNATConn p2p.ServiceConn
ChannelConn p2p.ServiceConn
HermesID common.Address
}
3 changes: 2 additions & 1 deletion core/connection/connection_validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ import (
"math/big"
"testing"

"github.com/stretchr/testify/assert"

"github.com/mysteriumnetwork/node/identity"
"github.com/mysteriumnetwork/node/market"
"github.com/stretchr/testify/assert"
)

func TestValidator_Validate(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions core/connection/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -631,7 +631,7 @@ type mockP2PChannel struct {
lock sync.Mutex
}

func (m *mockP2PChannel) Conn() *net.UDPConn {
func (m *mockP2PChannel) Conn() p2p.ServiceConn {
return &net.UDPConn{}
}

Expand Down Expand Up @@ -669,7 +669,7 @@ func (m *mockP2PChannel) Tracer() *trace.Tracer {
return nil
}

func (m *mockP2PChannel) ServiceConn() *net.UDPConn {
func (m *mockP2PChannel) ServiceConn() p2p.ServiceConn {
raddr, _ := net.ResolveUDPAddr("udp", "127.0.0.1:12345")
conn, _ := net.DialUDP("udp", nil, raddr)
return conn
Expand Down
2 changes: 2 additions & 0 deletions core/service/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/mysteriumnetwork/node/p2p"
"github.com/mysteriumnetwork/node/services/datatransfer"
"github.com/mysteriumnetwork/node/services/dvpn"
"github.com/mysteriumnetwork/node/services/quic"
"github.com/mysteriumnetwork/node/services/scraping"
"github.com/mysteriumnetwork/node/services/wireguard"
"github.com/mysteriumnetwork/node/session/connectivity"
Expand Down Expand Up @@ -248,6 +249,7 @@ func (manager *Manager) List(includeAll bool) []*Instance {
added := map[string]bool{
wireguard.ServiceType: false,
scraping.ServiceType: false,
quic.ServiceType: false,
datatransfer.ServiceType: false,
dvpn.ServiceType: false,
}
Expand Down
7 changes: 4 additions & 3 deletions core/service/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ package service
import (
"encoding/json"
"errors"
"net"
"sync"
"sync/atomic"
"testing"
"time"

"github.com/stretchr/testify/assert"

"github.com/mysteriumnetwork/node/market"
"github.com/mysteriumnetwork/node/mocks"
"github.com/stretchr/testify/assert"
"github.com/mysteriumnetwork/node/p2p"
)

type mockService struct {
Expand Down Expand Up @@ -56,7 +57,7 @@ func (mr *mockService) Stop() error {
return mr.killErr
}

func (mr *mockService) ProvideConfig(_ string, _ json.RawMessage, _ *net.UDPConn) (*ConfigParams, error) {
func (mr *mockService) ProvideConfig(_ string, _ json.RawMessage, _ p2p.ServiceConn) (*ConfigParams, error) {
return &ConfigParams{}, nil
}

Expand Down
3 changes: 1 addition & 2 deletions core/service/session_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"errors"
"fmt"
"math/big"
"net"
"sync"
"time"

Expand Down Expand Up @@ -94,7 +93,7 @@ func DefaultConfig() Config {

// ConfigProvider is able to handle config negotiations
type ConfigProvider interface {
ProvideConfig(sessionID string, sessionConfig json.RawMessage, conn *net.UDPConn) (*ConfigParams, error)
ProvideConfig(sessionID string, sessionConfig json.RawMessage, conn p2p.ServiceConn) (*ConfigParams, error)
}

// DestroyCallback cleanups session
Expand Down
8 changes: 3 additions & 5 deletions core/service/session_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,15 @@ import (
"errors"
"fmt"
"math/big"
"net"
"net/http"
"net/http/httptest"
"testing"
"time"

"github.com/mysteriumnetwork/node/core/policy/localcopy"

"github.com/ethereum/go-ethereum/common"
"github.com/stretchr/testify/assert"

"github.com/mysteriumnetwork/node/core/policy/localcopy"
"github.com/mysteriumnetwork/node/core/service/servicestate"
"github.com/mysteriumnetwork/node/identity"
"github.com/mysteriumnetwork/node/market"
Expand Down Expand Up @@ -97,9 +95,9 @@ func (m *mockP2PChannel) Tracer() *trace.Tracer {
return m.tracer
}

func (m *mockP2PChannel) ServiceConn() *net.UDPConn { return nil }
func (m *mockP2PChannel) ServiceConn() p2p.ServiceConn { return nil }

func (m *mockP2PChannel) Conn() *net.UDPConn { return nil }
func (m *mockP2PChannel) Conn() p2p.ServiceConn { return nil }

func (m *mockP2PChannel) Close() error { return nil }

Expand Down
4 changes: 2 additions & 2 deletions core/service/stub_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ package service

import (
"encoding/json"
"net"
"sync"

"github.com/mysteriumnetwork/node/identity"
"github.com/mysteriumnetwork/node/market"
"github.com/mysteriumnetwork/node/p2p"
)

var _ Service = &serviceFake{}
Expand Down Expand Up @@ -52,7 +52,7 @@ func (service *serviceFake) GetType() string {
return "fake"
}

func (service *serviceFake) ProvideConfig(_ string, _ json.RawMessage, _ *net.UDPConn) (*ConfigParams, error) {
func (service *serviceFake) ProvideConfig(_ string, _ json.RawMessage, _ p2p.ServiceConn) (*ConfigParams, error) {
return &ConfigParams{}, nil
}

Expand Down
Loading