Skip to content

Commit adb2bff

Browse files
committed
Make batch mode usable for global scan of nodes
Signed-off-by: Anton Litvinov <[email protected]>
1 parent cc91377 commit adb2bff

File tree

14 files changed

+268
-36
lines changed

14 files changed

+268
-36
lines changed

core/connection/interface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Connection interface {
4141

4242
// ConnectionDiag is a specialised Connection interface for provider check
4343
type ConnectionDiag interface {
44-
Diag() bool
44+
Diag() error
4545
}
4646

4747
// StateChannel is the channel we receive state change events on

core/connection/manager-diag.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/ethereum/go-ethereum/common"
3030
"github.com/rs/zerolog/log"
31+
"golang.org/x/time/rate"
3132

3233
"github.com/mysteriumnetwork/node/config"
3334
"github.com/mysteriumnetwork/node/core/connection/connectionstate"
@@ -91,6 +92,8 @@ type diagConnectionManager struct {
9192
// populated by Connect at runtime.
9293
connsMu sync.Mutex
9394
conns map[string]*conn
95+
96+
ratelimiter *rate.Limiter
9497
}
9598

9699
// NewDiagManager creates connection manager with given dependencies
@@ -120,6 +123,8 @@ func NewDiagManager(
120123
validator: validator,
121124
p2pDialer: p2pDialer,
122125
timeGetter: time.Now,
126+
127+
ratelimiter: rate.NewLimiter(rate.Every(1000*time.Millisecond), 1),
123128
}
124129

125130
m.eventBus.SubscribeAsync(connectionstate.AppTopicConnectionState, m.reconnectOnHold)
@@ -153,6 +158,13 @@ func (m *diagConnectionManager) GetReadyChan(providerID string) chan interface{}
153158
func (m *diagConnectionManager) Connect(consumerID identity.Identity, hermesID common.Address, proposalLookup ProposalLookup, params ConnectParams) (err error) {
154159
var sessionID session.ID
155160

161+
ctx := context.Background()
162+
err = m.ratelimiter.Wait(ctx) // This is a blocking call. Honors the rate limit
163+
if err != nil {
164+
log.Error().Msgf("ratelimiter.Wait: %s", err)
165+
return err
166+
}
167+
156168
proposal, err := proposalLookup()
157169
if err != nil {
158170
return fmt.Errorf("failed to lookup proposal: %w", err)
@@ -164,15 +176,19 @@ func (m *diagConnectionManager) Connect(consumerID identity.Identity, hermesID c
164176
log.Debug().Msgf("Consumer connection trace: %s", traceResult)
165177
}()
166178

167-
fmt.Println("Connect>", proposal.ProviderID)
179+
log.Error().Msgf("Connect > %v", proposal.ProviderID)
168180
uuid := proposal.ProviderID
181+
182+
m.connsMu.Lock()
169183
con, ok := m.conns[uuid]
170184
if !ok {
171185
con = new(conn)
172186
con.status.State = connectionstate.NotConnected
173187
con.uuid = uuid
174188
m.conns[uuid] = con
175189
}
190+
m.connsMu.Unlock()
191+
176192
removeConnection := func() {
177193
m.connsMu.Lock()
178194
defer m.connsMu.Unlock()
@@ -933,7 +949,9 @@ func (m *diagConnectionManager) keepAliveLoop(con *conn, channel p2p.Channel, se
933949
if config.GetBool(config.FlagKeepConnectedOnFail) {
934950
m.statusOnHold(con)
935951
} else {
936-
m.Disconnect()
952+
//m.Disconnect()
953+
log.Error().Msgf("Max p2p keepalive err count reached, disconnecting. SessionID=%s >>>>>>>>>", sessionID)
954+
m.DisconnectSingle(con)
937955
}
938956
cancel()
939957
return

core/connection/pinger.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,17 @@ import (
2525
// Diag is used to start provider check
2626
func Diag(cm *diagConnectionManager, con *conn, providerID string) {
2727
c, ok := con.activeConnection.(ConnectionDiag)
28-
res := false
28+
res := error(nil)
2929
if ok {
3030
log.Debug().Msgf("Check provider> %v", providerID)
3131

3232
res = c.Diag()
3333
cm.DisconnectSingle(con)
3434
}
35-
ev := quality.DiagEvent{ProviderID: providerID, Result: res}
35+
ev := quality.DiagEvent{ProviderID: providerID, Result: res == nil}
36+
if res != nil {
37+
ev.Error = res
38+
}
3639
con.resChannel <- ev
3740
close(con.resChannel)
3841
}

core/quality/metrics.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ type PingEvent struct {
106106
type DiagEvent struct {
107107
ProviderID string
108108
Result bool
109+
Error error
109110
}
110111

111112
const (

go.mod

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,15 @@ require (
151151
github.com/imdario/mergo v0.3.12 // indirect
152152
github.com/ipfs/go-cid v0.4.1 // indirect
153153
github.com/ipfs/go-log/v2 v2.5.1 // indirect
154+
github.com/jackc/pgpassfile v1.0.0 // indirect
155+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
156+
github.com/jackc/pgx/v5 v5.5.5 // indirect
157+
github.com/jackc/puddle/v2 v2.2.1 // indirect
154158
github.com/jackpal/go-nat-pmp v1.0.2 // indirect
155159
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
156160
github.com/jbenet/go-temp-err-catcher v0.1.0 // indirect
157161
github.com/jinzhu/gorm v1.9.2 // indirect
158-
github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a // indirect
162+
github.com/jinzhu/inflection v1.0.0 // indirect
159163
github.com/jinzhu/now v1.1.5 // indirect
160164
github.com/jmespath/go-jmespath v0.4.0 // indirect
161165
github.com/josharian/native v0.0.0-20200817173448-b6b71def0850 // indirect
@@ -181,6 +185,7 @@ require (
181185
github.com/mattn/go-colorable v0.1.13 // indirect
182186
github.com/mattn/go-isatty v0.0.20 // indirect
183187
github.com/mattn/go-pointer v0.0.1 // indirect
188+
github.com/mattn/go-sqlite3 v1.14.22 // indirect
184189
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
185190
github.com/mdlayher/genetlink v1.1.0 // indirect
186191
github.com/mdlayher/netlink v1.4.2 // indirect
@@ -263,12 +268,12 @@ require (
263268
gopkg.in/intercom/intercom-go.v2 v2.0.0-20210504094731-2bd1af0ce4b2 // indirect
264269
gopkg.in/warnings.v0 v0.1.2 // indirect
265270
gopkg.in/yaml.v3 v3.0.1 // indirect
271+
gorm.io/driver/postgres v1.5.9 // indirect
272+
gorm.io/driver/sqlite v1.5.6 // indirect
273+
gorm.io/gorm v1.25.11 // indirect
266274
honnef.co/go/tools v0.4.2 // indirect
267275
lukechampine.com/blake3 v1.2.1 // indirect
268276
rsc.io/tmplfunc v0.0.3 // indirect
269277
)
270278

271-
replace (
272-
golang.zx2c4.com/wireguard => github.com/mysteriumnetwork/wireguard-go v0.0.0-20240416113031-406b13e8996a
273-
//gvisor.dev/gvisor => github.com/mysteriumnetwork/gvisor v0.0.0-20240206094932-ff91e662b9e8
274-
)
279+
replace golang.zx2c4.com/wireguard => github.com/mysteriumnetwork/wireguard-go v0.0.0-20240416113031-406b13e8996a

go.sum

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,14 @@ github.com/ipfs/go-detect-race v0.0.1 h1:qX/xay2W3E4Q1U7d9lNs1sU9nvguX0a7319XbyQ
957957
github.com/ipfs/go-detect-race v0.0.1/go.mod h1:8BNT7shDZPo99Q74BpGMK+4D8Mn4j46UU0LZ723meps=
958958
github.com/ipfs/go-log/v2 v2.5.1 h1:1XdUzF7048prq4aBjDQQ4SL5RxftpRGdXhNRwKSAlcY=
959959
github.com/ipfs/go-log/v2 v2.5.1/go.mod h1:prSpmC1Gpllc9UYWxDiZDreBYw7zp4Iqp1kOLU9U5UI=
960+
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
961+
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
962+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk=
963+
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
964+
github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw=
965+
github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A=
966+
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
967+
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
960968
github.com/jackpal/gateway v1.0.6 h1:/MJORKvJEwNVldtGVJC2p2cwCnsSoLn3hl3zxmZT7tk=
961969
github.com/jackpal/gateway v1.0.6/go.mod h1:lTpwd4ACLXmpyiCTRtfiNyVnUmqT9RivzCDQetPfnjA=
962970
github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus=
@@ -974,6 +982,8 @@ github.com/jinzhu/gorm v1.9.2 h1:lCvgEaqe/HVE+tjAR2mt4HbbHAZsQOv3XAZiEZV37iw=
974982
github.com/jinzhu/gorm v1.9.2/go.mod h1:Vla75njaFJ8clLU1W44h34PjIkijhjHIYnZxMqCdxqo=
975983
github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a h1:eeaG9XMUvRBYXJi4pg1ZKM7nxc5AfXfojeLLW7O5J3k=
976984
github.com/jinzhu/inflection v0.0.0-20180308033659-04140366298a/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
985+
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
986+
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
977987
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
978988
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
979989
github.com/jmespath/go-jmespath v0.4.0 h1:BEgLn5cpjn8UN1mAw4NjwDrS35OdebyEtFe+9YPoQUg=
@@ -1107,6 +1117,8 @@ github.com/mattn/go-pointer v0.0.1/go.mod h1:2zXcozF6qYGgmsG+SeTZz3oAbFLdD3OWqnU
11071117
github.com/mattn/go-runewidth v0.0.13 h1:lTGmDsbAYt5DmK6OnoV7EuIF1wEIFAcxld6ypU4OSgU=
11081118
github.com/mattn/go-sqlite3 v1.10.0 h1:jbhqpg7tQe4SupckyijYiy0mJJ/pRyHvXf7JdWK860o=
11091119
github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc=
1120+
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
1121+
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
11101122
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
11111123
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
11121124
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
@@ -2352,6 +2364,14 @@ gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C
23522364
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
23532365
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
23542366
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2367+
gorm.io/driver/postgres v1.5.9 h1:DkegyItji119OlcaLjqN11kHoUgZ/j13E0jkJZgD6A8=
2368+
gorm.io/driver/postgres v1.5.9/go.mod h1:DX3GReXH+3FPWGrrgffdvCk3DQ1dwDPdmbenSkweRGI=
2369+
gorm.io/driver/sqlite v1.5.6 h1:fO/X46qn5NUEEOZtnjJRWRzZMe8nqJiQ9E+0hi+hKQE=
2370+
gorm.io/driver/sqlite v1.5.6/go.mod h1:U+J8craQU6Fzkcvu8oLeAQmi50TkwPEhHDEjQZXDah4=
2371+
gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde h1:9DShaph9qhkIYw7QF91I/ynrr4cOO2PZra2PFD7Mfeg=
2372+
gorm.io/gorm v1.25.7-0.20240204074919-46816ad31dde/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
2373+
gorm.io/gorm v1.25.11 h1:/Wfyg1B/je1hnDx3sMkX+gAlxrlZpn6X0BXRlwXlvHg=
2374+
gorm.io/gorm v1.25.11/go.mod h1:xh7N7RHfYlNc5EmcI/El95gXusucDrQnHXe0+CgWcLQ=
23552375
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
23562376
gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g=
23572377
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=

services/wireguard/connection/connection.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (c *Connection) State() <-chan connectionstate.State {
8787
}
8888

8989
// Diag is used to start provider check
90-
func (c *Connection) Diag() bool {
90+
func (c *Connection) Diag() error {
9191
return c.connectionEndpoint.Diag()
9292
}
9393

services/wireguard/connection/connection_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ func (mce *mockConnectionEndpoint) ConfigureRoutes(_ net.IP) error { retur
158158
func (mce *mockConnectionEndpoint) PeerStats() (wgcfg.Stats, error) {
159159
return wgcfg.Stats{LastHandshake: time.Now(), BytesSent: 10, BytesReceived: 11}, nil
160160
}
161-
func (mce *mockConnectionEndpoint) Diag() bool {
162-
return true
161+
func (mce *mockConnectionEndpoint) Diag() error {
162+
return nil
163163
}
164164

165165
type mockHandshakeWaiter struct {

services/wireguard/endpoint.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ type ConnectionEndpoint interface {
3434
Config() (ServiceConfig, error)
3535
InterfaceName() string
3636
Stop() error
37-
Diag() bool
37+
38+
Diag() error
3839
}

services/wireguard/endpoint/diagclient/client.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package diagclient
1919

2020
import (
2121
"bufio"
22+
"errors"
2223
"fmt"
2324
"io"
2425
"net/http"
@@ -126,25 +127,29 @@ func (c *client) Close() (err error) {
126127
return nil
127128
}
128129

129-
func (c *client) Diag() bool {
130+
func (c *client) Diag() error {
130131
client := http.Client{
131132
Transport: &http.Transport{
132133
DialContext: c.tnet.DialContext,
133134
},
135+
Timeout: 15 * time.Second,
134136
}
135-
resp, err := client.Get("http://1.1.1.1/")
137+
resp, err := client.Get("http://107.173.23.19:8080/test")
136138
if err != nil {
137139
log.Error().Err(err).Msg("Get failed")
138-
return false
140+
return err
139141
}
140142
defer resp.Body.Close()
141143

142144
body, err := io.ReadAll(resp.Body)
143145
if err != nil {
144146
log.Error().Err(err).Msg("Readall failed")
145-
return false
147+
return err
148+
}
149+
if len(body) < 6 {
150+
log.Error().Msg("Wrong length")
151+
return errors.New("Wrong body length")
146152
}
147-
_ = body
148153

149-
return true
154+
return nil
150155
}

services/wireguard/endpoint/endpoint.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ type connectionEndpoint struct {
5252
wgClient WgClient
5353
}
5454

55-
func (ce *connectionEndpoint) Diag() bool {
55+
func (ce *connectionEndpoint) Diag() error {
5656
c, ok := ce.wgClient.(WgClientDiag)
5757
if ok {
5858
return c.Diag()
5959
}
60-
return false
60+
return nil
6161
}
6262

6363
// StartConsumerMode starts and configure wireguard network interface running in consumer mode.

services/wireguard/endpoint/wg_client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ type WgClient interface {
4646

4747
// WgClientDiag is a specialised WgClient interface for provider check
4848
type WgClientDiag interface {
49-
Diag() bool
49+
Diag() error
5050
}
5151

5252
// WgClientFactory represents WireGuard client factory.

tequilapi/contract/connection.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ func NewConnectionInfoDTO(session connectionstate.Status) ConnectionInfoDTO {
5454
// ConnectionDiagInfoDTO holds provider check result
5555
// swagger:model ConnectionDiagInfoDTO
5656
type ConnectionDiagInfoDTO struct {
57-
Status bool `json:"status"`
58-
Error interface{} `json:"error"`
59-
ProviderID string `json:"provider_id"`
57+
ProviderID string `json:"provider_id"`
58+
Error string `json:"error"`
59+
DiagError string `json:"diag_err"`
6060
}
6161

6262
// ConnectionInfoDTO holds partial consumer connection details.

0 commit comments

Comments
 (0)