diff --git a/cmd/geth/config.go b/cmd/geth/config.go index 53c19bf1c2..f316380cee 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -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) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index f2233777a5..e00f92fa75 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -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 }) } diff --git a/dashboard/dashboard.go b/dashboard/dashboard.go index 8f0fff6281..3f12ffbd61 100644 --- a/dashboard/dashboard.go +++ b/dashboard/dashboard.go @@ -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 {