Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
2edc5328
Unverified
Commit
2edc5328
authored
Jul 20, 2021
by
aloknerurkar
Committed by
GitHub
Jul 20, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: flaky ping test and log correction (#2349)
parent
f58b9d55
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
39 additions
and
15 deletions
+39
-15
go.mod
go.mod
+1
-0
hive.go
pkg/hive/hive.go
+1
-1
export_test.go
pkg/p2p/libp2p/export_test.go
+8
-0
libp2p.go
pkg/p2p/libp2p/libp2p.go
+9
-3
protocols_test.go
pkg/p2p/libp2p/protocols_test.go
+20
-11
No files found.
go.mod
View file @
2edc5328
...
...
@@ -32,6 +32,7 @@ require (
github.com/libp2p/go-libp2p-discovery v0.5.1 // indirect
github.com/libp2p/go-libp2p-peerstore v0.2.7
github.com/libp2p/go-libp2p-quic-transport v0.10.0
github.com/libp2p/go-libp2p-swarm v0.5.0 // indirect
github.com/libp2p/go-libp2p-transport-upgrader v0.4.2
github.com/libp2p/go-tcp-transport v0.2.3
github.com/libp2p/go-ws-transport v0.4.0
...
...
pkg/hive/hive.go
View file @
2edc5328
...
...
@@ -279,7 +279,7 @@ func (s *Service) checkAndAddPeers(ctx context.Context, peers pb.Peers) {
_
,
err
=
s
.
streamer
.
Ping
(
ctx
,
multiUnderlay
)
if
err
!=
nil
{
s
.
metrics
.
UnreachablePeers
.
Inc
()
s
.
logger
.
Warningf
(
"hive: multi address underlay %s not reachable err: %w"
,
multiUnderlay
,
err
)
s
.
logger
.
Debugf
(
"hive: multi address underlay %s not reachable err: %s"
,
multiUnderlay
,
err
.
Error
()
)
return
}
...
...
pkg/p2p/libp2p/export_test.go
View file @
2edc5328
...
...
@@ -8,6 +8,8 @@ import (
"context"
handshake
"github.com/ethersphere/bee/pkg/p2p/libp2p/internal/handshake"
libp2pm
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p-core/host"
"github.com/libp2p/go-libp2p-core/network"
libp2ppeer
"github.com/libp2p/go-libp2p-core/peer"
)
...
...
@@ -23,3 +25,9 @@ func (s *Service) NewStreamForPeerID(peerID libp2ppeer.ID, protocolName, protoco
type
StaticAddressResolver
=
staticAddressResolver
var
NewStaticAddressResolver
=
newStaticAddressResolver
func
WithHostFactory
(
factory
func
(
context
.
Context
,
...
libp2pm
.
Option
)
(
host
.
Host
,
error
))
Options
{
return
Options
{
hostFactory
:
factory
,
}
}
pkg/p2p/libp2p/libp2p.go
View file @
2edc5328
...
...
@@ -93,6 +93,7 @@ type Options struct {
LightNodeLimit
int
WelcomeMessage
string
Transaction
[]
byte
hostFactory
func
(
context
.
Context
,
...
libp2p
.
Option
)
(
host
.
Host
,
error
)
}
func
New
(
ctx
context
.
Context
,
signer
beecrypto
.
Signer
,
networkID
uint64
,
overlay
swarm
.
Address
,
addr
string
,
ab
addressbook
.
Putter
,
storer
storage
.
StateStorer
,
lightNodes
*
lightnode
.
Container
,
swapBackend
handshake
.
SenderMatcher
,
logger
logging
.
Logger
,
tracer
*
tracing
.
Tracer
,
o
Options
)
(
*
Service
,
error
)
{
...
...
@@ -181,14 +182,19 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
opts
=
append
(
opts
,
transports
...
)
h
,
err
:=
libp2p
.
New
(
ctx
,
opts
...
)
if
o
.
hostFactory
==
nil
{
// Use the default libp2p host creation
o
.
hostFactory
=
libp2p
.
New
}
h
,
err
:=
o
.
hostFactory
(
ctx
,
opts
...
)
if
err
!=
nil
{
return
nil
,
err
}
// Support same non default security and transport options as
// original host.
dialer
,
err
:=
libp2p
.
New
(
ctx
,
append
(
transports
,
security
)
...
)
dialer
,
err
:=
o
.
hostFactory
(
ctx
,
append
(
transports
,
security
)
...
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -224,7 +230,7 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
// the addresses used are not dialable and hence should be cleaned up. We should create
// this host with the same transports and security options to be able to dial to other
// peers.
pingDialer
,
err
:=
libp2p
.
New
(
ctx
,
append
(
transports
,
security
,
libp2p
.
NoListenAddrs
)
...
)
pingDialer
,
err
:=
o
.
hostFactory
(
ctx
,
append
(
transports
,
security
,
libp2p
.
NoListenAddrs
)
...
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
pkg/p2p/libp2p/protocols_test.go
View file @
2edc5328
...
...
@@ -14,6 +14,10 @@ import (
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p/libp2p"
libp2pm
"github.com/libp2p/go-libp2p"
"github.com/libp2p/go-libp2p-core/host"
swarmt
"github.com/libp2p/go-libp2p-swarm/testing"
bhost
"github.com/libp2p/go-libp2p/p2p/host/basic"
"github.com/multiformats/go-multistream"
)
...
...
@@ -379,21 +383,26 @@ func TestConnectDisconnectEvents(t *testing.T) {
}
func
TestPing
(
t
*
testing
.
T
)
{
t
.
Skip
(
"test flaking"
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
10
)
defer
cancel
()
s1
,
_
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2pServiceOpts
{})
s1
,
_
:=
newService
(
t
,
1
,
libp2pServiceOpts
{
libp2pOpts
:
libp2p
.
WithHostFactory
(
func
(
ctx
context
.
Context
,
_
...
libp2pm
.
Option
)
(
host
.
Host
,
error
)
{
return
bhost
.
NewHost
(
ctx
,
swarmt
.
GenSwarm
(
t
,
ctx
),
&
bhost
.
HostOpts
{
EnablePing
:
true
})
},
),
})
defer
s1
.
Close
()
// Wait for listeners to start. There are times when the test fails unexpectedly
// during CI and we suspect it is due to the listeners not starting in time. The
// sleep here ensures CPU is given up for any goroutines which are not getting
// scheduled. Ideally we should explicitly check the TCP status on the port
// where the libp2p.Host is started before assuming the host is up. This seems like
// a bit of an overkill here unless the test starts flaking.
time
.
Sleep
(
time
.
Second
)
s2
,
_
:=
newService
(
t
,
1
,
libp2pServiceOpts
{
libp2pOpts
:
libp2p
.
WithHostFactory
(
func
(
ctx
context
.
Context
,
_
...
libp2pm
.
Option
)
(
host
.
Host
,
error
)
{
return
bhost
.
NewHost
(
ctx
,
swarmt
.
GenSwarm
(
t
,
ctx
),
&
bhost
.
HostOpts
{
EnablePing
:
true
})
},
),
})
defer
s2
.
Close
()
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment