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
a0d37e91
Unverified
Commit
a0d37e91
authored
Aug 10, 2020
by
Petar Radovic
Committed by
GitHub
Aug 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
options struct in libp2p and api (#550)
parent
db1fb013
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
99 additions
and
119 deletions
+99
-119
start.go
cmd/bee/cmd/start.go
+1
-3
io_test.go
cmd/internal/file/io_test.go
+1
-5
api.go
pkg/api/api.go
+9
-9
api_test.go
pkg/api/api_test.go
+1
-5
debugapi_test.go
pkg/debugapi/debugapi_test.go
+1
-5
node.go
pkg/node/node.go
+21
-33
connections_test.go
pkg/p2p/libp2p/connections_test.go
+31
-27
headers_test.go
pkg/p2p/libp2p/headers_test.go
+6
-7
libp2p.go
pkg/p2p/libp2p/libp2p.go
+5
-8
libp2p_test.go
pkg/p2p/libp2p/libp2p_test.go
+10
-2
protocols_test.go
pkg/p2p/libp2p/protocols_test.go
+10
-11
tracing_test.go
pkg/p2p/libp2p/tracing_test.go
+2
-3
welcome_message_test.go
pkg/p2p/libp2p/welcome_message_test.go
+1
-1
No files found.
cmd/bee/cmd/start.go
View file @
a0d37e91
...
@@ -113,13 +113,12 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
...
@@ -113,13 +113,12 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
password
=
p
password
=
p
}
}
b
,
err
:=
node
.
NewBee
(
node
.
Options
{
b
,
err
:=
node
.
NewBee
(
c
.
config
.
GetString
(
optionNameP2PAddr
),
logger
,
node
.
Options
{
DataDir
:
c
.
config
.
GetString
(
optionNameDataDir
),
DataDir
:
c
.
config
.
GetString
(
optionNameDataDir
),
DBCapacity
:
c
.
config
.
GetUint64
(
optionNameDBCapacity
),
DBCapacity
:
c
.
config
.
GetUint64
(
optionNameDBCapacity
),
Password
:
password
,
Password
:
password
,
APIAddr
:
c
.
config
.
GetString
(
optionNameAPIAddr
),
APIAddr
:
c
.
config
.
GetString
(
optionNameAPIAddr
),
DebugAPIAddr
:
debugAPIAddr
,
DebugAPIAddr
:
debugAPIAddr
,
Addr
:
c
.
config
.
GetString
(
optionNameP2PAddr
),
NATAddr
:
c
.
config
.
GetString
(
optionNameNATAddr
),
NATAddr
:
c
.
config
.
GetString
(
optionNameNATAddr
),
EnableWS
:
c
.
config
.
GetBool
(
optionNameP2PWSEnable
),
EnableWS
:
c
.
config
.
GetBool
(
optionNameP2PWSEnable
),
EnableQUIC
:
c
.
config
.
GetBool
(
optionNameP2PQUICEnable
),
EnableQUIC
:
c
.
config
.
GetBool
(
optionNameP2PQUICEnable
),
...
@@ -130,7 +129,6 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
...
@@ -130,7 +129,6 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
TracingEnabled
:
c
.
config
.
GetBool
(
optionNameTracingEnabled
),
TracingEnabled
:
c
.
config
.
GetBool
(
optionNameTracingEnabled
),
TracingEndpoint
:
c
.
config
.
GetString
(
optionNameTracingEndpoint
),
TracingEndpoint
:
c
.
config
.
GetString
(
optionNameTracingEndpoint
),
TracingServiceName
:
c
.
config
.
GetString
(
optionNameTracingServiceName
),
TracingServiceName
:
c
.
config
.
GetString
(
optionNameTracingServiceName
),
Logger
:
logger
,
PaymentThreshold
:
c
.
config
.
GetUint64
(
optionNamePaymentThreshold
),
PaymentThreshold
:
c
.
config
.
GetUint64
(
optionNamePaymentThreshold
),
PaymentTolerance
:
c
.
config
.
GetUint64
(
optionNamePaymentTolerance
),
PaymentTolerance
:
c
.
config
.
GetUint64
(
optionNamePaymentTolerance
),
})
})
...
...
cmd/internal/file/io_test.go
View file @
a0d37e91
...
@@ -153,11 +153,7 @@ func TestLimitWriter(t *testing.T) {
...
@@ -153,11 +153,7 @@ func TestLimitWriter(t *testing.T) {
// newTestServer creates an http server to serve the bee http api endpoints.
// newTestServer creates an http server to serve the bee http api endpoints.
func
newTestServer
(
t
*
testing
.
T
,
storer
storage
.
Storer
)
*
url
.
URL
{
func
newTestServer
(
t
*
testing
.
T
,
storer
storage
.
Storer
)
*
url
.
URL
{
t
.
Helper
()
t
.
Helper
()
s
:=
api
.
New
(
api
.
Options
{
s
:=
api
.
New
(
tags
.
NewTags
(),
storer
,
nil
,
logging
.
New
(
ioutil
.
Discard
,
0
),
nil
)
Storer
:
storer
,
Logger
:
logging
.
New
(
ioutil
.
Discard
,
0
),
Tags
:
tags
.
NewTags
(),
})
ts
:=
httptest
.
NewServer
(
s
)
ts
:=
httptest
.
NewServer
(
s
)
srvUrl
,
err
:=
url
.
Parse
(
ts
.
URL
)
srvUrl
,
err
:=
url
.
Parse
(
ts
.
URL
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
pkg/api/api.go
View file @
a0d37e91
...
@@ -20,17 +20,13 @@ type Service interface {
...
@@ -20,17 +20,13 @@ type Service interface {
}
}
type
server
struct
{
type
server
struct
{
Options
http
.
Handler
metrics
metrics
}
type
Options
struct
{
Tags
*
tags
.
Tags
Tags
*
tags
.
Tags
Storer
storage
.
Storer
Storer
storage
.
Storer
CORSAllowedOrigins
[]
string
CORSAllowedOrigins
[]
string
Logger
logging
.
Logger
Logger
logging
.
Logger
Tracer
*
tracing
.
Tracer
Tracer
*
tracing
.
Tracer
http
.
Handler
metrics
metrics
}
}
const
(
const
(
...
@@ -38,10 +34,14 @@ const (
...
@@ -38,10 +34,14 @@ const (
TargetsRecoveryHeader
=
"swarm-recovery-targets"
TargetsRecoveryHeader
=
"swarm-recovery-targets"
)
)
func
New
(
o
Options
)
Service
{
func
New
(
tags
*
tags
.
Tags
,
storer
storage
.
Storer
,
corsAllowedOrigins
[]
string
,
logger
logging
.
Logger
,
tracer
*
tracing
.
Tracer
)
Service
{
s
:=
&
server
{
s
:=
&
server
{
Options
:
o
,
Tags
:
tags
,
metrics
:
newMetrics
(),
Storer
:
storer
,
CORSAllowedOrigins
:
corsAllowedOrigins
,
Logger
:
logger
,
Tracer
:
tracer
,
metrics
:
newMetrics
(),
}
}
s
.
setupRouting
()
s
.
setupRouting
()
...
...
pkg/api/api_test.go
View file @
a0d37e91
...
@@ -30,11 +30,7 @@ func newTestServer(t *testing.T, o testServerOptions) *http.Client {
...
@@ -30,11 +30,7 @@ func newTestServer(t *testing.T, o testServerOptions) *http.Client {
if
o
.
Logger
==
nil
{
if
o
.
Logger
==
nil
{
o
.
Logger
=
logging
.
New
(
ioutil
.
Discard
,
0
)
o
.
Logger
=
logging
.
New
(
ioutil
.
Discard
,
0
)
}
}
s
:=
api
.
New
(
api
.
Options
{
s
:=
api
.
New
(
o
.
Tags
,
o
.
Storer
,
nil
,
o
.
Logger
,
nil
)
Tags
:
o
.
Tags
,
Storer
:
o
.
Storer
,
Logger
:
o
.
Logger
,
})
ts
:=
httptest
.
NewServer
(
s
)
ts
:=
httptest
.
NewServer
(
s
)
t
.
Cleanup
(
ts
.
Close
)
t
.
Cleanup
(
ts
.
Close
)
...
...
pkg/debugapi/debugapi_test.go
View file @
a0d37e91
...
@@ -74,11 +74,7 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer {
...
@@ -74,11 +74,7 @@ func newTestServer(t *testing.T, o testServerOptions) *testServer {
}
}
func
newBZZTestServer
(
t
*
testing
.
T
,
o
testServerOptions
)
*
http
.
Client
{
func
newBZZTestServer
(
t
*
testing
.
T
,
o
testServerOptions
)
*
http
.
Client
{
s
:=
api
.
New
(
api
.
Options
{
s
:=
api
.
New
(
o
.
Tags
,
o
.
Storer
,
nil
,
logging
.
New
(
ioutil
.
Discard
,
0
),
nil
)
Storer
:
o
.
Storer
,
Tags
:
o
.
Tags
,
Logger
:
logging
.
New
(
ioutil
.
Discard
,
0
),
})
ts
:=
httptest
.
NewServer
(
s
)
ts
:=
httptest
.
NewServer
(
s
)
t
.
Cleanup
(
ts
.
Close
)
t
.
Cleanup
(
ts
.
Close
)
...
...
pkg/node/node.go
View file @
a0d37e91
...
@@ -69,30 +69,27 @@ type Bee struct {
...
@@ -69,30 +69,27 @@ type Bee struct {
}
}
type
Options
struct
{
type
Options
struct
{
DataDir
string
DataDir
string
DBCapacity
uint64
DBCapacity
uint64
Password
string
Password
string
APIAddr
string
APIAddr
string
DebugAPIAddr
string
DebugAPIAddr
string
Addr
string
NATAddr
string
NATAddr
string
EnableWS
bool
EnableWS
bool
EnableQUIC
bool
EnableQUIC
bool
NetworkID
uint64
NetworkID
uint64
WelcomeMessage
string
WelcomeMessage
string
Bootnodes
[]
string
Bootnodes
[]
string
CORSAllowedOrigins
[]
string
CORSAllowedOrigins
[]
string
TracingEnabled
bool
Logger
logging
.
Logger
TracingEndpoint
string
TracingEnabled
bool
TracingServiceName
string
TracingEndpoint
string
DisconnectThreshold
uint64
TracingServiceName
string
PaymentThreshold
uint64
PaymentThreshold
uint64
PaymentTolerance
uint64
PaymentTolerance
uint64
}
}
func
NewBee
(
o
Options
)
(
*
Bee
,
error
)
{
func
NewBee
(
addr
string
,
logger
logging
.
Logger
,
o
Options
)
(
*
Bee
,
error
)
{
logger
:=
o
.
Logger
tracer
,
tracerCloser
,
err
:=
tracing
.
NewTracer
(
&
tracing
.
Options
{
tracer
,
tracerCloser
,
err
:=
tracing
.
NewTracer
(
&
tracing
.
Options
{
Enabled
:
o
.
TracingEnabled
,
Enabled
:
o
.
TracingEnabled
,
Endpoint
:
o
.
TracingEndpoint
,
Endpoint
:
o
.
TracingEndpoint
,
...
@@ -157,15 +154,12 @@ func NewBee(o Options) (*Bee, error) {
...
@@ -157,15 +154,12 @@ func NewBee(o Options) (*Bee, error) {
addressbook
:=
addressbook
.
New
(
stateStore
)
addressbook
:=
addressbook
.
New
(
stateStore
)
signer
:=
crypto
.
NewDefaultSigner
(
swarmPrivateKey
)
signer
:=
crypto
.
NewDefaultSigner
(
swarmPrivateKey
)
p2ps
,
err
:=
libp2p
.
New
(
p2pCtx
,
signer
,
o
.
NetworkID
,
address
,
o
.
Add
r
,
libp2p
.
Options
{
p2ps
,
err
:=
libp2p
.
New
(
p2pCtx
,
signer
,
o
.
NetworkID
,
address
,
addr
,
addressbook
,
logger
,
trace
r
,
libp2p
.
Options
{
PrivateKey
:
libp2pPrivateKey
,
PrivateKey
:
libp2pPrivateKey
,
NATAddr
:
o
.
NATAddr
,
NATAddr
:
o
.
NATAddr
,
EnableWS
:
o
.
EnableWS
,
EnableWS
:
o
.
EnableWS
,
EnableQUIC
:
o
.
EnableQUIC
,
EnableQUIC
:
o
.
EnableQUIC
,
Addressbook
:
addressbook
,
WelcomeMessage
:
o
.
WelcomeMessage
,
WelcomeMessage
:
o
.
WelcomeMessage
,
Logger
:
logger
,
Tracer
:
tracer
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"p2p service: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"p2p service: %w"
,
err
)
...
@@ -323,13 +317,7 @@ func NewBee(o Options) (*Bee, error) {
...
@@ -323,13 +317,7 @@ func NewBee(o Options) (*Bee, error) {
var
apiService
api
.
Service
var
apiService
api
.
Service
if
o
.
APIAddr
!=
""
{
if
o
.
APIAddr
!=
""
{
// API server
// API server
apiService
=
api
.
New
(
api
.
Options
{
apiService
=
api
.
New
(
tagg
,
ns
,
o
.
CORSAllowedOrigins
,
logger
,
tracer
)
Tags
:
tagg
,
Storer
:
ns
,
CORSAllowedOrigins
:
o
.
CORSAllowedOrigins
,
Logger
:
logger
,
Tracer
:
tracer
,
})
apiListener
,
err
:=
net
.
Listen
(
"tcp"
,
o
.
APIAddr
)
apiListener
,
err
:=
net
.
Listen
(
"tcp"
,
o
.
APIAddr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"api listener: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"api listener: %w"
,
err
)
...
...
pkg/p2p/libp2p/connections_test.go
View file @
a0d37e91
...
@@ -23,7 +23,7 @@ import (
...
@@ -23,7 +23,7 @@ import (
)
)
func
TestAddresses
(
t
*
testing
.
T
)
{
func
TestAddresses
(
t
*
testing
.
T
)
{
s
,
_
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s
,
_
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
addrs
,
err
:=
s
.
Addresses
()
addrs
,
err
:=
s
.
Addresses
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -38,9 +38,9 @@ func TestConnectDisconnect(t *testing.T) {
...
@@ -38,9 +38,9 @@ func TestConnectDisconnect(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -64,9 +64,9 @@ func TestDoubleConnect(t *testing.T) {
...
@@ -64,9 +64,9 @@ func TestDoubleConnect(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -89,9 +89,9 @@ func TestDoubleDisconnect(t *testing.T) {
...
@@ -89,9 +89,9 @@ func TestDoubleDisconnect(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -122,9 +122,9 @@ func TestMultipleConnectDisconnect(t *testing.T) {
...
@@ -122,9 +122,9 @@ func TestMultipleConnectDisconnect(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -163,9 +163,9 @@ func TestConnectDisconnectOnAllAddresses(t *testing.T) {
...
@@ -163,9 +163,9 @@ func TestConnectDisconnectOnAllAddresses(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
addrs
,
err
:=
s1
.
Addresses
()
addrs
,
err
:=
s1
.
Addresses
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -193,9 +193,9 @@ func TestDoubleConnectOnAllAddresses(t *testing.T) {
...
@@ -193,9 +193,9 @@ func TestDoubleConnectOnAllAddresses(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
addrs
,
err
:=
s1
.
Addresses
()
addrs
,
err
:=
s1
.
Addresses
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -229,9 +229,9 @@ func TestDifferentNetworkIDs(t *testing.T) {
...
@@ -229,9 +229,9 @@ func TestDifferentNetworkIDs(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
_
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
_
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
_
:=
newService
(
t
,
2
,
libp2p
.
Option
s
{})
s2
,
_
:=
newService
(
t
,
2
,
libp2p
ServiceOpt
s
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -247,14 +247,18 @@ func TestConnectWithEnabledQUICAndWSTransports(t *testing.T) {
...
@@ -247,14 +247,18 @@ func TestConnectWithEnabledQUICAndWSTransports(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Options
{
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2pServiceOpts
{
EnableQUIC
:
true
,
libp2pOpts
:
libp2p
.
Options
{
EnableWS
:
true
,
EnableQUIC
:
true
,
EnableWS
:
true
,
},
})
})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Options
{
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2pServiceOpts
{
EnableQUIC
:
true
,
libp2pOpts
:
libp2p
.
Options
{
EnableWS
:
true
,
EnableQUIC
:
true
,
EnableWS
:
true
,
},
})
})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -272,8 +276,8 @@ func TestConnectRepeatHandshake(t *testing.T) {
...
@@ -272,8 +276,8 @@ func TestConnectRepeatHandshake(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
_
,
err
:=
s2
.
Connect
(
ctx
,
addr
)
_
,
err
:=
s2
.
Connect
(
ctx
,
addr
)
...
@@ -341,11 +345,11 @@ func TestTopologyNotifier(t *testing.T) {
...
@@ -341,11 +345,11 @@ func TestTopologyNotifier(t *testing.T) {
}
}
)
)
notifier1
:=
mockNotifier
(
n1c
,
n1d
)
notifier1
:=
mockNotifier
(
n1c
,
n1d
)
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{
Addressbook
:
ab1
})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{
Addressbook
:
ab1
})
s1
.
SetNotifier
(
notifier1
)
s1
.
SetNotifier
(
notifier1
)
notifier2
:=
mockNotifier
(
n2c
,
n2d
)
notifier2
:=
mockNotifier
(
n2c
,
n2d
)
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{
Addressbook
:
ab2
})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{
Addressbook
:
ab2
})
s2
.
SetNotifier
(
notifier2
)
s2
.
SetNotifier
(
notifier2
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -422,10 +426,10 @@ func TestTopologyLocalNotifier(t *testing.T) {
...
@@ -422,10 +426,10 @@ func TestTopologyLocalNotifier(t *testing.T) {
}
}
)
)
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
notifier2
:=
mockNotifier
(
n2c
,
n2d
)
notifier2
:=
mockNotifier
(
n2c
,
n2d
)
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
.
SetNotifier
(
notifier2
)
s2
.
SetNotifier
(
notifier2
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
...
pkg/p2p/libp2p/headers_test.go
View file @
a0d37e91
...
@@ -11,7 +11,6 @@ import (
...
@@ -11,7 +11,6 @@ import (
"time"
"time"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p/libp2p"
)
)
func
TestHeaders
(
t
*
testing
.
T
)
{
func
TestHeaders
(
t
*
testing
.
T
)
{
...
@@ -23,9 +22,9 @@ func TestHeaders(t *testing.T) {
...
@@ -23,9 +22,9 @@ func TestHeaders(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
var
gotHeaders
p2p
.
Headers
var
gotHeaders
p2p
.
Headers
handled
:=
make
(
chan
struct
{})
handled
:=
make
(
chan
struct
{})
...
@@ -70,9 +69,9 @@ func TestHeaders_empty(t *testing.T) {
...
@@ -70,9 +69,9 @@ func TestHeaders_empty(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
var
gotHeaders
p2p
.
Headers
var
gotHeaders
p2p
.
Headers
handled
:=
make
(
chan
struct
{})
handled
:=
make
(
chan
struct
{})
...
@@ -126,9 +125,9 @@ func TestHeadler(t *testing.T) {
...
@@ -126,9 +125,9 @@ func TestHeadler(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
var
gotReceivedHeaders
p2p
.
Headers
var
gotReceivedHeaders
p2p
.
Headers
handled
:=
make
(
chan
struct
{})
handled
:=
make
(
chan
struct
{})
...
...
pkg/p2p/libp2p/libp2p.go
View file @
a0d37e91
...
@@ -66,12 +66,9 @@ type Options struct {
...
@@ -66,12 +66,9 @@ type Options struct {
EnableQUIC
bool
EnableQUIC
bool
LightNode
bool
LightNode
bool
WelcomeMessage
string
WelcomeMessage
string
Addressbook
addressbook
.
Putter
Logger
logging
.
Logger
Tracer
*
tracing
.
Tracer
}
}
func
New
(
ctx
context
.
Context
,
signer
beecrypto
.
Signer
,
networkID
uint64
,
overlay
swarm
.
Address
,
addr
string
,
o
Options
)
(
*
Service
,
error
)
{
func
New
(
ctx
context
.
Context
,
signer
beecrypto
.
Signer
,
networkID
uint64
,
overlay
swarm
.
Address
,
addr
string
,
ab
addressbook
.
Putter
,
logger
logging
.
Logger
,
tracer
*
tracing
.
Tracer
,
o
Options
)
(
*
Service
,
error
)
{
host
,
port
,
err
:=
net
.
SplitHostPort
(
addr
)
host
,
port
,
err
:=
net
.
SplitHostPort
(
addr
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"address: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"address: %w"
,
err
)
...
@@ -181,7 +178,7 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
...
@@ -181,7 +178,7 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
}
}
}
}
handshakeService
,
err
:=
handshake
.
New
(
signer
,
advertisableAddresser
,
overlay
,
networkID
,
o
.
LightNode
,
o
.
WelcomeMessage
,
o
.
L
ogger
)
handshakeService
,
err
:=
handshake
.
New
(
signer
,
advertisableAddresser
,
overlay
,
networkID
,
o
.
LightNode
,
o
.
WelcomeMessage
,
l
ogger
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"handshake service: %w"
,
err
)
return
nil
,
fmt
.
Errorf
(
"handshake service: %w"
,
err
)
}
}
...
@@ -196,9 +193,9 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
...
@@ -196,9 +193,9 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
metrics
:
newMetrics
(),
metrics
:
newMetrics
(),
networkID
:
networkID
,
networkID
:
networkID
,
peers
:
peerRegistry
,
peers
:
peerRegistry
,
addressbook
:
o
.
Addressbook
,
addressbook
:
ab
,
logger
:
o
.
L
ogger
,
logger
:
l
ogger
,
tracer
:
o
.
T
racer
,
tracer
:
t
racer
,
connectionBreaker
:
breaker
.
NewBreaker
(
breaker
.
Options
{}),
// use default options
connectionBreaker
:
breaker
.
NewBreaker
(
breaker
.
Options
{}),
// use default options
}
}
// Construct protocols.
// Construct protocols.
...
...
pkg/p2p/libp2p/libp2p_test.go
View file @
a0d37e91
...
@@ -7,6 +7,7 @@ package libp2p_test
...
@@ -7,6 +7,7 @@ package libp2p_test
import
(
import
(
"bytes"
"bytes"
"context"
"context"
"crypto/ecdsa"
"io/ioutil"
"io/ioutil"
"sort"
"sort"
"testing"
"testing"
...
@@ -22,8 +23,15 @@ import (
...
@@ -22,8 +23,15 @@ import (
"github.com/multiformats/go-multiaddr"
"github.com/multiformats/go-multiaddr"
)
)
type
libp2pServiceOpts
struct
{
Logger
logging
.
Logger
Addressbook
addressbook
.
Interface
PrivateKey
*
ecdsa
.
PrivateKey
libp2pOpts
libp2p
.
Options
}
// newService constructs a new libp2p service.
// newService constructs a new libp2p service.
func
newService
(
t
*
testing
.
T
,
networkID
uint64
,
o
libp2p
.
Option
s
)
(
s
*
libp2p
.
Service
,
overlay
swarm
.
Address
)
{
func
newService
(
t
*
testing
.
T
,
networkID
uint64
,
o
libp2p
ServiceOpt
s
)
(
s
*
libp2p
.
Service
,
overlay
swarm
.
Address
)
{
t
.
Helper
()
t
.
Helper
()
swarmKey
,
err
:=
crypto
.
GenerateSecp256k1Key
()
swarmKey
,
err
:=
crypto
.
GenerateSecp256k1Key
()
...
@@ -57,7 +65,7 @@ func newService(t *testing.T, networkID uint64, o libp2p.Options) (s *libp2p.Ser
...
@@ -57,7 +65,7 @@ func newService(t *testing.T, networkID uint64, o libp2p.Options) (s *libp2p.Ser
}
}
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
s
,
err
=
libp2p
.
New
(
ctx
,
crypto
.
NewDefaultSigner
(
swarmKey
),
networkID
,
overlay
,
addr
,
o
)
s
,
err
=
libp2p
.
New
(
ctx
,
crypto
.
NewDefaultSigner
(
swarmKey
),
networkID
,
overlay
,
addr
,
o
.
Addressbook
,
o
.
Logger
,
nil
,
o
.
libp2pOpts
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
}
}
...
...
pkg/p2p/libp2p/protocols_test.go
View file @
a0d37e91
...
@@ -11,7 +11,6 @@ import (
...
@@ -11,7 +11,6 @@ import (
"testing"
"testing"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p/libp2p"
"github.com/multiformats/go-multistream"
"github.com/multiformats/go-multistream"
)
)
...
@@ -19,9 +18,9 @@ func TestNewStream(t *testing.T) {
...
@@ -19,9 +18,9 @@ func TestNewStream(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
if
err
:=
s1
.
AddProtocol
(
newTestProtocol
(
func
(
_
context
.
Context
,
_
p2p
.
Peer
,
_
p2p
.
Stream
)
error
{
if
err
:=
s1
.
AddProtocol
(
newTestProtocol
(
func
(
_
context
.
Context
,
_
p2p
.
Peer
,
_
p2p
.
Stream
)
error
{
return
nil
return
nil
...
@@ -51,7 +50,7 @@ func TestNewStreamMulti(t *testing.T) {
...
@@ -51,7 +50,7 @@ func TestNewStreamMulti(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
var
(
var
(
h1calls
,
h2calls
int32
h1calls
,
h2calls
int32
h1
=
func
(
_
context
.
Context
,
_
p2p
.
Peer
,
s
p2p
.
Stream
)
error
{
h1
=
func
(
_
context
.
Context
,
_
p2p
.
Peer
,
s
p2p
.
Stream
)
error
{
...
@@ -65,7 +64,7 @@ func TestNewStreamMulti(t *testing.T) {
...
@@ -65,7 +64,7 @@ func TestNewStreamMulti(t *testing.T) {
return
nil
return
nil
}
}
)
)
s2
,
_
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
if
err
:=
s1
.
AddProtocol
(
newTestMultiProtocol
(
h1
,
h2
));
err
!=
nil
{
if
err
:=
s1
.
AddProtocol
(
newTestMultiProtocol
(
h1
,
h2
));
err
!=
nil
{
t
.
Fatal
(
err
)
t
.
Fatal
(
err
)
...
@@ -96,9 +95,9 @@ func TestNewStream_errNotSupported(t *testing.T) {
...
@@ -96,9 +95,9 @@ func TestNewStream_errNotSupported(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -131,9 +130,9 @@ func TestNewStream_semanticVersioning(t *testing.T) {
...
@@ -131,9 +130,9 @@ func TestNewStream_semanticVersioning(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
addr
:=
serviceUnderlayAddress
(
t
,
s1
)
...
@@ -190,9 +189,9 @@ func TestDisconnectError(t *testing.T) {
...
@@ -190,9 +189,9 @@ func TestDisconnectError(t *testing.T) {
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
ctx
,
cancel
:=
context
.
WithCancel
(
context
.
Background
())
defer
cancel
()
defer
cancel
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
overlay2
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
if
err
:=
s1
.
AddProtocol
(
newTestProtocol
(
func
(
_
context
.
Context
,
_
p2p
.
Peer
,
_
p2p
.
Stream
)
error
{
if
err
:=
s1
.
AddProtocol
(
newTestProtocol
(
func
(
_
context
.
Context
,
_
p2p
.
Peer
,
_
p2p
.
Stream
)
error
{
return
p2p
.
NewDisconnectError
(
errors
.
New
(
"test error"
))
return
p2p
.
NewDisconnectError
(
errors
.
New
(
"test error"
))
...
...
pkg/p2p/libp2p/tracing_test.go
View file @
a0d37e91
...
@@ -11,7 +11,6 @@ import (
...
@@ -11,7 +11,6 @@ import (
"time"
"time"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p"
"github.com/ethersphere/bee/pkg/p2p/libp2p"
"github.com/ethersphere/bee/pkg/tracing"
"github.com/ethersphere/bee/pkg/tracing"
)
)
...
@@ -34,9 +33,9 @@ func TestTracing(t *testing.T) {
...
@@ -34,9 +33,9 @@ func TestTracing(t *testing.T) {
}
}
defer
closer2
.
Close
()
defer
closer2
.
Close
()
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s1
,
overlay1
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2p
.
Option
s
{})
s2
,
_
:=
newService
(
t
,
1
,
libp2p
ServiceOpt
s
{})
var
handledTracingSpan
string
var
handledTracingSpan
string
handled
:=
make
(
chan
struct
{})
handled
:=
make
(
chan
struct
{})
...
...
pkg/p2p/libp2p/welcome_message_test.go
View file @
a0d37e91
...
@@ -12,7 +12,7 @@ import (
...
@@ -12,7 +12,7 @@ import (
func
TestDynamicWelcomeMessage
(
t
*
testing
.
T
)
{
func
TestDynamicWelcomeMessage
(
t
*
testing
.
T
)
{
const
TestWelcomeMessage
=
"Hello World!"
const
TestWelcomeMessage
=
"Hello World!"
svc
,
_
:=
newService
(
t
,
1
,
libp2p
.
Options
{
WelcomeMessage
:
TestWelcomeMessage
})
svc
,
_
:=
newService
(
t
,
1
,
libp2p
ServiceOpts
{
libp2pOpts
:
libp2p
.
Options
{
WelcomeMessage
:
TestWelcomeMessage
}
})
t
.
Run
(
"Get current message - OK"
,
func
(
t
*
testing
.
T
)
{
t
.
Run
(
"Get current message - OK"
,
func
(
t
*
testing
.
T
)
{
got
:=
svc
.
GetWelcomeMessage
()
got
:=
svc
.
GetWelcomeMessage
()
...
...
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