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
531117ed
Unverified
Commit
531117ed
authored
Aug 30, 2020
by
metacertain
Committed by
GitHub
Aug 30, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Standalone flag option for bee (#597)
* Add standalone flag
parent
6ab1b364
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
32 additions
and
12 deletions
+32
-12
cmd.go
cmd/bee/cmd/cmd.go
+2
-0
start.go
cmd/bee/cmd/start.go
+1
-0
kademlia.go
pkg/kademlia/kademlia.go
+9
-3
node.go
pkg/node/node.go
+15
-9
libp2p.go
pkg/p2p/libp2p/libp2p.go
+5
-0
No files found.
cmd/bee/cmd/cmd.go
View file @
531117ed
...
@@ -32,6 +32,7 @@ const (
...
@@ -32,6 +32,7 @@ const (
optionNameNetworkID
=
"network-id"
optionNameNetworkID
=
"network-id"
optionWelcomeMessage
=
"welcome-message"
optionWelcomeMessage
=
"welcome-message"
optionCORSAllowedOrigins
=
"cors-allowed-origins"
optionCORSAllowedOrigins
=
"cors-allowed-origins"
optionNameStandalone
=
"standalone"
optionNameTracingEnabled
=
"tracing-enable"
optionNameTracingEnabled
=
"tracing-enable"
optionNameTracingEndpoint
=
"tracing-endpoint"
optionNameTracingEndpoint
=
"tracing-endpoint"
optionNameTracingServiceName
=
"tracing-service-name"
optionNameTracingServiceName
=
"tracing-service-name"
...
@@ -172,6 +173,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
...
@@ -172,6 +173,7 @@ func (c *command) setAllFlags(cmd *cobra.Command) {
cmd
.
Flags
()
.
String
(
optionNameDebugAPIAddr
,
":6060"
,
"debug HTTP API listen address"
)
cmd
.
Flags
()
.
String
(
optionNameDebugAPIAddr
,
":6060"
,
"debug HTTP API listen address"
)
cmd
.
Flags
()
.
Uint64
(
optionNameNetworkID
,
1
,
"ID of the Swarm network"
)
cmd
.
Flags
()
.
Uint64
(
optionNameNetworkID
,
1
,
"ID of the Swarm network"
)
cmd
.
Flags
()
.
StringSlice
(
optionCORSAllowedOrigins
,
[]
string
{},
"origins with CORS headers enabled"
)
cmd
.
Flags
()
.
StringSlice
(
optionCORSAllowedOrigins
,
[]
string
{},
"origins with CORS headers enabled"
)
cmd
.
Flags
()
.
Bool
(
optionNameStandalone
,
false
,
"whether we want the node to start with no listen addresses for p2p"
)
cmd
.
Flags
()
.
Bool
(
optionNameTracingEnabled
,
false
,
"enable tracing"
)
cmd
.
Flags
()
.
Bool
(
optionNameTracingEnabled
,
false
,
"enable tracing"
)
cmd
.
Flags
()
.
String
(
optionNameTracingEndpoint
,
"127.0.0.1:6831"
,
"endpoint to send tracing data"
)
cmd
.
Flags
()
.
String
(
optionNameTracingEndpoint
,
"127.0.0.1:6831"
,
"endpoint to send tracing data"
)
cmd
.
Flags
()
.
String
(
optionNameTracingServiceName
,
"bee"
,
"service name identifier for tracing"
)
cmd
.
Flags
()
.
String
(
optionNameTracingServiceName
,
"bee"
,
"service name identifier for tracing"
)
...
...
cmd/bee/cmd/start.go
View file @
531117ed
...
@@ -139,6 +139,7 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
...
@@ -139,6 +139,7 @@ Welcome to the Swarm.... Bzzz Bzzzz Bzzzz
WelcomeMessage
:
c
.
config
.
GetString
(
optionWelcomeMessage
),
WelcomeMessage
:
c
.
config
.
GetString
(
optionWelcomeMessage
),
Bootnodes
:
c
.
config
.
GetStringSlice
(
optionNameBootnodes
),
Bootnodes
:
c
.
config
.
GetStringSlice
(
optionNameBootnodes
),
CORSAllowedOrigins
:
c
.
config
.
GetStringSlice
(
optionCORSAllowedOrigins
),
CORSAllowedOrigins
:
c
.
config
.
GetStringSlice
(
optionCORSAllowedOrigins
),
Standalone
:
c
.
config
.
GetBool
(
optionNameStandalone
),
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
),
...
...
pkg/kademlia/kademlia.go
View file @
531117ed
...
@@ -41,6 +41,7 @@ type binSaturationFunc func(bin uint8, peers, connected *pslice.PSlice) bool
...
@@ -41,6 +41,7 @@ type binSaturationFunc func(bin uint8, peers, connected *pslice.PSlice) bool
type
Options
struct
{
type
Options
struct
{
SaturationFunc
binSaturationFunc
SaturationFunc
binSaturationFunc
Bootnodes
[]
ma
.
Multiaddr
Bootnodes
[]
ma
.
Multiaddr
Standalone
bool
}
}
// Kad is the Swarm forwarding kademlia implementation.
// Kad is the Swarm forwarding kademlia implementation.
...
@@ -61,8 +62,9 @@ type Kad struct {
...
@@ -61,8 +62,9 @@ type Kad struct {
peerSig
[]
chan
struct
{}
peerSig
[]
chan
struct
{}
peerSigMtx
sync
.
Mutex
peerSigMtx
sync
.
Mutex
logger
logging
.
Logger
// logger
logger
logging
.
Logger
// logger
quit
chan
struct
{}
// quit channel
standalone
bool
done
chan
struct
{}
// signal that `manage` has quit
quit
chan
struct
{}
// quit channel
done
chan
struct
{}
// signal that `manage` has quit
wg
sync
.
WaitGroup
wg
sync
.
WaitGroup
}
}
...
@@ -89,6 +91,7 @@ func New(base swarm.Address, addressbook addressbook.Interface, discovery discov
...
@@ -89,6 +91,7 @@ func New(base swarm.Address, addressbook addressbook.Interface, discovery discov
manageC
:
make
(
chan
struct
{},
1
),
manageC
:
make
(
chan
struct
{},
1
),
waitNext
:
make
(
map
[
string
]
retryInfo
),
waitNext
:
make
(
map
[
string
]
retryInfo
),
logger
:
logger
,
logger
:
logger
,
standalone
:
o
.
Standalone
,
quit
:
make
(
chan
struct
{}),
quit
:
make
(
chan
struct
{}),
done
:
make
(
chan
struct
{}),
done
:
make
(
chan
struct
{}),
wg
:
sync
.
WaitGroup
{},
wg
:
sync
.
WaitGroup
{},
...
@@ -130,8 +133,11 @@ func (k *Kad) manage() {
...
@@ -130,8 +133,11 @@ func (k *Kad) manage() {
return
return
default
:
default
:
}
}
if
k
.
standalone
{
continue
}
err
:=
k
.
knownPeers
.
EachBinRev
(
func
(
peer
swarm
.
Address
,
po
uint8
)
(
bool
,
bool
,
error
)
{
err
:=
k
.
knownPeers
.
EachBinRev
(
func
(
peer
swarm
.
Address
,
po
uint8
)
(
bool
,
bool
,
error
)
{
if
k
.
connectedPeers
.
Exists
(
peer
)
{
if
k
.
connectedPeers
.
Exists
(
peer
)
{
return
false
,
false
,
nil
return
false
,
false
,
nil
}
}
...
...
pkg/node/node.go
View file @
531117ed
...
@@ -80,6 +80,7 @@ type Options struct {
...
@@ -80,6 +80,7 @@ type Options struct {
Bootnodes
[]
string
Bootnodes
[]
string
CORSAllowedOrigins
[]
string
CORSAllowedOrigins
[]
string
Logger
logging
.
Logger
Logger
logging
.
Logger
Standalone
bool
TracingEnabled
bool
TracingEnabled
bool
TracingEndpoint
string
TracingEndpoint
string
TracingServiceName
string
TracingServiceName
string
...
@@ -136,6 +137,7 @@ func NewBee(addr string, swarmAddress swarm.Address, keystore keystore.Service,
...
@@ -136,6 +137,7 @@ func NewBee(addr string, swarmAddress swarm.Address, keystore keystore.Service,
NATAddr
:
o
.
NATAddr
,
NATAddr
:
o
.
NATAddr
,
EnableWS
:
o
.
EnableWS
,
EnableWS
:
o
.
EnableWS
,
EnableQUIC
:
o
.
EnableQUIC
,
EnableQUIC
:
o
.
EnableQUIC
,
Standalone
:
o
.
Standalone
,
WelcomeMessage
:
o
.
WelcomeMessage
,
WelcomeMessage
:
o
.
WelcomeMessage
,
})
})
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -170,18 +172,22 @@ func NewBee(addr string, swarmAddress swarm.Address, keystore keystore.Service,
...
@@ -170,18 +172,22 @@ func NewBee(addr string, swarmAddress swarm.Address, keystore keystore.Service,
}
}
var
bootnodes
[]
ma
.
Multiaddr
var
bootnodes
[]
ma
.
Multiaddr
for
_
,
a
:=
range
o
.
Bootnodes
{
if
o
.
Standalone
{
addr
,
err
:=
ma
.
NewMultiaddr
(
a
)
logger
.
Info
(
"Starting node in standalone mode, no p2p connections will be made or accepted"
)
if
err
!=
nil
{
}
else
{
logger
.
Debugf
(
"multiaddress fail %s: %v"
,
a
,
err
)
for
_
,
a
:=
range
o
.
Bootnodes
{
logger
.
Warningf
(
"invalid bootnode address %s"
,
a
)
addr
,
err
:=
ma
.
NewMultiaddr
(
a
)
continue
if
err
!=
nil
{
}
logger
.
Debugf
(
"multiaddress fail %s: %v"
,
a
,
err
)
logger
.
Warningf
(
"invalid bootnode address %s"
,
a
)
continue
}
bootnodes
=
append
(
bootnodes
,
addr
)
bootnodes
=
append
(
bootnodes
,
addr
)
}
}
}
kad
:=
kademlia
.
New
(
swarmAddress
,
addressbook
,
hive
,
p2ps
,
logger
,
kademlia
.
Options
{
Bootnodes
:
bootnodes
})
kad
:=
kademlia
.
New
(
swarmAddress
,
addressbook
,
hive
,
p2ps
,
logger
,
kademlia
.
Options
{
Bootnodes
:
bootnodes
,
Standalone
:
o
.
Standalone
})
b
.
topologyCloser
=
kad
b
.
topologyCloser
=
kad
hive
.
SetAddPeersHandler
(
kad
.
AddPeers
)
hive
.
SetAddPeersHandler
(
kad
.
AddPeers
)
p2ps
.
AddNotifier
(
kad
)
p2ps
.
AddNotifier
(
kad
)
...
...
pkg/p2p/libp2p/libp2p.go
View file @
531117ed
...
@@ -64,6 +64,7 @@ type Options struct {
...
@@ -64,6 +64,7 @@ type Options struct {
NATAddr
string
NATAddr
string
EnableWS
bool
EnableWS
bool
EnableQUIC
bool
EnableQUIC
bool
Standalone
bool
LightNode
bool
LightNode
bool
WelcomeMessage
string
WelcomeMessage
string
}
}
...
@@ -148,6 +149,10 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
...
@@ -148,6 +149,10 @@ func New(ctx context.Context, signer beecrypto.Signer, networkID uint64, overlay
transports
=
append
(
transports
,
libp2p
.
Transport
(
libp2pquic
.
NewTransport
))
transports
=
append
(
transports
,
libp2p
.
Transport
(
libp2pquic
.
NewTransport
))
}
}
if
o
.
Standalone
{
opts
=
append
(
opts
,
libp2p
.
NoListenAddrs
)
}
opts
=
append
(
opts
,
transports
...
)
opts
=
append
(
opts
,
transports
...
)
h
,
err
:=
libp2p
.
New
(
ctx
,
opts
...
)
h
,
err
:=
libp2p
.
New
(
ctx
,
opts
...
)
...
...
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