mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd, dashboard: move subscription to dashboard.New
This commit is contained in:
parent
4ffab91adf
commit
b36134a439
3 changed files with 29 additions and 32 deletions
|
|
@ -25,9 +25,6 @@ import (
|
|||
"reflect"
|
||||
"unicode"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
|
||||
cli "gopkg.in/urfave/cli.v1"
|
||||
|
||||
"github.com/ethereum/go-ethereum/cmd/utils"
|
||||
|
|
@ -163,32 +160,7 @@ func makeFullNode(ctx *cli.Context) *node.Node {
|
|||
utils.RegisterEthService(stack, &cfg.Eth)
|
||||
|
||||
if ctx.GlobalBool(utils.DashboardEnabledFlag.Name) {
|
||||
// There is a data race between the network layer and the dashboard, which
|
||||
// can cause some lost peer events, therefore some peers might not appear
|
||||
// on the dashboard.
|
||||
// In order to solve this problem, a peer event subscription is registered
|
||||
// before the network layer starts, and when the dashboard is ready, the
|
||||
// stored events are passed to it.
|
||||
peerEventBridge := make(chan p2p.MeteredPeerEvent, 1000) // The events are stored by and passed through this channel.
|
||||
closePeerEventBridge := make(chan struct{}) // This channel gets a signal from the dashboard when it is ready.
|
||||
go func() {
|
||||
peerCh := make(chan p2p.MeteredPeerEvent, 200) // Channel for the initial peer events.
|
||||
subPeer := p2p.SubscribeMeteredPeerEvent(peerCh) // Subscribe to the peer events.
|
||||
for {
|
||||
select {
|
||||
case event := <-peerCh:
|
||||
select {
|
||||
case peerEventBridge <- event:
|
||||
default:
|
||||
log.Warn("Too many peer events before the dashboard starts")
|
||||
}
|
||||
case <-closePeerEventBridge:
|
||||
subPeer.Unsubscribe()
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
utils.RegisterDashboardService(stack, &cfg.Dashboard, gitCommit, peerEventBridge, closePeerEventBridge)
|
||||
utils.RegisterDashboardService(stack, &cfg.Dashboard, gitCommit)
|
||||
}
|
||||
// Whisper must be explicitly enabled by specifying at least 1 whisper flag or in dev mode
|
||||
shhEnabled := enableWhisper(ctx)
|
||||
|
|
|
|||
|
|
@ -1461,9 +1461,9 @@ func RegisterEthService(stack *node.Node, cfg *eth.Config) {
|
|||
}
|
||||
|
||||
// RegisterDashboardService adds a dashboard to the stack.
|
||||
func RegisterDashboardService(stack *node.Node, cfg *dashboard.Config, commit string, peerEventBridge chan p2p.MeteredPeerEvent, closePeerEventBridge chan struct{}) {
|
||||
func RegisterDashboardService(stack *node.Node, cfg *dashboard.Config, commit string) {
|
||||
stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||
return dashboard.New(cfg, commit, ctx.ResolvePath("logs"), peerEventBridge, closePeerEventBridge), nil
|
||||
return dashboard.New(cfg, commit, ctx.ResolvePath("logs")), nil
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -80,7 +80,32 @@ type client struct {
|
|||
}
|
||||
|
||||
// New creates a new dashboard instance with the given configuration.
|
||||
func New(config *Config, commit string, logdir string, peerEventBridge chan p2p.MeteredPeerEvent, closePeerEventBridge chan struct{}) *Dashboard {
|
||||
func New(config *Config, commit string, logdir string) *Dashboard {
|
||||
// There is a data race between the network layer and the dashboard, which
|
||||
// can cause some lost peer events, therefore some peers might not appear
|
||||
// on the dashboard.
|
||||
// In order to solve this problem, a peer event subscription is registered
|
||||
// before the network layer starts, and when the dashboard is ready, the
|
||||
// stored events are passed to it.
|
||||
peerEventBridge := make(chan p2p.MeteredPeerEvent, 1000) // The events are stored by and passed through this channel.
|
||||
closePeerEventBridge := make(chan struct{}) // This channel gets a signal from the dashboard when it is ready.
|
||||
go func() {
|
||||
peerCh := make(chan p2p.MeteredPeerEvent, 200) // Channel for the initial peer events.
|
||||
subPeer := p2p.SubscribeMeteredPeerEvent(peerCh) // Subscribe to the peer events.
|
||||
for {
|
||||
select {
|
||||
case event := <-peerCh:
|
||||
select {
|
||||
case peerEventBridge <- event:
|
||||
default:
|
||||
log.Warn("Too many peer events before the dashboard starts")
|
||||
}
|
||||
case <-closePeerEventBridge:
|
||||
subPeer.Unsubscribe()
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
now := time.Now()
|
||||
versionMeta := ""
|
||||
if len(params.VersionMeta) > 0 {
|
||||
|
|
|
|||
Loading…
Reference in a new issue