mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
cmd, dashboard, eth, p2p: cleanup after review
This commit is contained in:
parent
be5ef70bd3
commit
abc3abb4ab
11 changed files with 39 additions and 56 deletions
|
|
@ -185,7 +185,7 @@ func makeFullNode(ctx *cli.Context) *node.Node {
|
||||||
// Add dashboard daemon if requested. This should be the last registered service
|
// Add dashboard daemon if requested. This should be the last registered service
|
||||||
// in order to be able to collect information about the other services.
|
// in order to be able to collect information about the other services.
|
||||||
if ctx.GlobalBool(utils.DashboardEnabledFlag.Name) {
|
if ctx.GlobalBool(utils.DashboardEnabledFlag.Name) {
|
||||||
utils.RegisterDashboardService(stack, &cfg.Dashboard, cfg.Eth.SyncMode, gitCommit)
|
utils.RegisterDashboardService(stack, &cfg.Dashboard, gitCommit)
|
||||||
}
|
}
|
||||||
return stack
|
return stack
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1537,7 +1537,7 @@ func RegisterEthService(stack *node.Node, cfg *eth.Config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// RegisterDashboardService adds a dashboard to the stack.
|
// RegisterDashboardService adds a dashboard to the stack.
|
||||||
func RegisterDashboardService(stack *node.Node, cfg *dashboard.Config, syncMode downloader.SyncMode, commit string) {
|
func RegisterDashboardService(stack *node.Node, cfg *dashboard.Config, commit string) {
|
||||||
err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) {
|
||||||
var (
|
var (
|
||||||
ethServ *eth.Ethereum
|
ethServ *eth.Ethereum
|
||||||
|
|
@ -1545,7 +1545,7 @@ func RegisterDashboardService(stack *node.Node, cfg *dashboard.Config, syncMode
|
||||||
)
|
)
|
||||||
_ = ctx.Service(ðServ)
|
_ = ctx.Service(ðServ)
|
||||||
_ = ctx.Service(&lesServ)
|
_ = ctx.Service(&lesServ)
|
||||||
return dashboard.New(cfg, ethServ, lesServ, syncMode, commit, ctx.ResolvePath("logs")), nil
|
return dashboard.New(cfg, ethServ, lesServ, commit, ctx.ResolvePath("logs")), nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Fatalf("Failed to register the dashboard service: %v", err)
|
Fatalf("Failed to register the dashboard service: %v", err)
|
||||||
|
|
|
||||||
|
|
@ -85,7 +85,6 @@ const defaultContent: () => Content = () => ({
|
||||||
general: {
|
general: {
|
||||||
version: null,
|
version: null,
|
||||||
commit: null,
|
commit: null,
|
||||||
syncMode: '',
|
|
||||||
},
|
},
|
||||||
home: {},
|
home: {},
|
||||||
chain: {},
|
chain: {},
|
||||||
|
|
@ -122,7 +121,6 @@ const updaters = {
|
||||||
general: {
|
general: {
|
||||||
version: replacer,
|
version: replacer,
|
||||||
commit: replacer,
|
commit: replacer,
|
||||||
syncMode: replacer,
|
|
||||||
},
|
},
|
||||||
home: null,
|
home: null,
|
||||||
chain: null,
|
chain: null,
|
||||||
|
|
@ -243,7 +241,6 @@ class Dashboard extends Component<Props, State> {
|
||||||
<div className={this.props.classes.dashboard} style={styles.dashboard}>
|
<div className={this.props.classes.dashboard} style={styles.dashboard}>
|
||||||
<Header
|
<Header
|
||||||
switchSideBar={this.switchSideBar}
|
switchSideBar={this.switchSideBar}
|
||||||
syncMode={this.state.content.general.syncMode}
|
|
||||||
/>
|
/>
|
||||||
<Body
|
<Body
|
||||||
opened={this.state.sideBar}
|
opened={this.state.sideBar}
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,6 @@ const themeStyles = (theme: Object) => ({
|
||||||
export type Props = {
|
export type Props = {
|
||||||
classes: Object, // injected by withStyles()
|
classes: Object, // injected by withStyles()
|
||||||
switchSideBar: () => void,
|
switchSideBar: () => void,
|
||||||
syncMode: string,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Header renders the header of the dashboard.
|
// Header renders the header of the dashboard.
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,7 @@ import Typography from '@material-ui/core/Typography';
|
||||||
import {AreaChart, Area, Tooltip, YAxis} from 'recharts';
|
import {AreaChart, Area, Tooltip, YAxis} from 'recharts';
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
||||||
import {faCircle as fasCircle} from '@fortawesome/free-solid-svg-icons'; // More icons at fontawesome.com/icons
|
import {faCircle as fasCircle} from '@fortawesome/free-solid-svg-icons'; // More icons at fontawesome.com/icons
|
||||||
import {faCircle as farCircle} from '@fortawesome/free-regular-svg-icons';
|
import {faCircle as farCircle, faClipboard as farClipboard} from '@fortawesome/free-regular-svg-icons';
|
||||||
import {faClipboard as farClipboard} from '@fortawesome/free-regular-svg-icons';
|
|
||||||
import convert from 'color-convert';
|
import convert from 'color-convert';
|
||||||
import {Scrollbars} from 'react-custom-scrollbars';
|
import {Scrollbars} from 'react-custom-scrollbars';
|
||||||
|
|
||||||
|
|
@ -139,9 +138,10 @@ const shortName = (name: string) => {
|
||||||
console.error('Incorrect node name', name);
|
console.error('Incorrect node name', name);
|
||||||
return parts[0];
|
return parts[0];
|
||||||
}
|
}
|
||||||
|
const versionRE = RegExp(/^v?\d+\.\d+\.\d+.*/);
|
||||||
// Drop optional custom identifier.
|
// Drop optional custom identifier.
|
||||||
if (!RegExp(/^v?\d+\.\d+\.\d+.*/).test(parts[1])) {
|
if (!versionRE.test(parts[1])) {
|
||||||
if (parts.length < 3) {
|
if (parts.length < 3 || !versionRE.test(parts[2])) {
|
||||||
console.error('Incorrect node name', name);
|
console.error('Incorrect node name', name);
|
||||||
return parts[0];
|
return parts[0];
|
||||||
}
|
}
|
||||||
|
|
@ -683,7 +683,7 @@ class Network extends Component<Props, State> {
|
||||||
<Grid item style={{width: '40%'}}>
|
<Grid item style={{width: '40%'}}>
|
||||||
<div className={classes.table} style={styles.table}>
|
<div className={classes.table} style={styles.table}>
|
||||||
<Typography variant='subtitle1' gutterBottom className={classes.title} style={styles.title}>
|
<Typography variant='subtitle1' gutterBottom className={classes.title} style={styles.title}>
|
||||||
ETH peers
|
Full peers
|
||||||
<FontAwesomeIcon
|
<FontAwesomeIcon
|
||||||
icon={farClipboard}
|
icon={farClipboard}
|
||||||
onClick={this.copyToClipboard(JSON.stringify(this.ethList()))}
|
onClick={this.copyToClipboard(JSON.stringify(this.ethList()))}
|
||||||
|
|
@ -743,7 +743,7 @@ class Network extends Component<Props, State> {
|
||||||
<Grid item style={{width: '40%'}}>
|
<Grid item style={{width: '40%'}}>
|
||||||
<div className={classes.table} style={styles.table}>
|
<div className={classes.table} style={styles.table}>
|
||||||
<Typography variant='subtitle1' gutterBottom className={classes.title} style={styles.title}>
|
<Typography variant='subtitle1' gutterBottom className={classes.title} style={styles.title}>
|
||||||
LES peers
|
Light peers
|
||||||
<FontAwesomeIcon
|
<FontAwesomeIcon
|
||||||
icon={farClipboard}
|
icon={farClipboard}
|
||||||
onClick={this.copyToClipboard(JSON.stringify(this.lesList()))}
|
onClick={this.copyToClipboard(JSON.stringify(this.lesList()))}
|
||||||
|
|
|
||||||
|
|
@ -35,7 +35,6 @@ export type ChartEntry = {
|
||||||
export type General = {
|
export type General = {
|
||||||
version: ?string,
|
version: ?string,
|
||||||
commit: ?string,
|
commit: ?string,
|
||||||
syncMode: string,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Home = {
|
export type Home = {
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,8 @@ import (
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/eth"
|
"github.com/ethereum/go-ethereum/eth"
|
||||||
"github.com/ethereum/go-ethereum/les"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/eth/downloader"
|
|
||||||
"github.com/ethereum/go-ethereum/event"
|
"github.com/ethereum/go-ethereum/event"
|
||||||
|
"github.com/ethereum/go-ethereum/les"
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/p2p"
|
"github.com/ethereum/go-ethereum/p2p"
|
||||||
"github.com/ethereum/go-ethereum/params"
|
"github.com/ethereum/go-ethereum/params"
|
||||||
|
|
@ -75,10 +72,8 @@ type Dashboard struct {
|
||||||
peerCh chan p2p.MeteredPeerEvent // Peer event channel.
|
peerCh chan p2p.MeteredPeerEvent // Peer event channel.
|
||||||
subPeer event.Subscription // Peer event subscription.
|
subPeer event.Subscription // Peer event subscription.
|
||||||
|
|
||||||
syncMode downloader.SyncMode
|
ethServ *eth.Ethereum // Ethereum object serving internals.
|
||||||
|
lesServ *les.LightEthereum // LightEthereum object serving internals.
|
||||||
ethServ *eth.Ethereum
|
|
||||||
lesServ *les.LightEthereum
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// client represents active websocket connection with a remote browser.
|
// client represents active websocket connection with a remote browser.
|
||||||
|
|
@ -89,7 +84,7 @@ type client struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new dashboard instance with the given configuration.
|
// New creates a new dashboard instance with the given configuration.
|
||||||
func New(config *Config, ethServ *eth.Ethereum, lesServ *les.LightEthereum, syncMode downloader.SyncMode, commit string, logdir string) *Dashboard {
|
func New(config *Config, ethServ *eth.Ethereum, lesServ *les.LightEthereum, commit string, logdir string) *Dashboard {
|
||||||
// There is a data race between the network layer and the dashboard, which
|
// 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
|
// can cause some lost peer events, therefore some peers might not appear
|
||||||
// on the dashboard.
|
// on the dashboard.
|
||||||
|
|
@ -106,9 +101,8 @@ func New(config *Config, ethServ *eth.Ethereum, lesServ *les.LightEthereum, sync
|
||||||
quit: make(chan chan error),
|
quit: make(chan chan error),
|
||||||
history: &Message{
|
history: &Message{
|
||||||
General: &GeneralMessage{
|
General: &GeneralMessage{
|
||||||
Commit: commit,
|
Commit: commit,
|
||||||
Version: fmt.Sprintf("v%d.%d.%d%s", params.VersionMajor, params.VersionMinor, params.VersionPatch, versionMeta),
|
Version: fmt.Sprintf("v%d.%d.%d%s", params.VersionMajor, params.VersionMinor, params.VersionPatch, versionMeta),
|
||||||
SyncMode: syncMode.String(),
|
|
||||||
},
|
},
|
||||||
System: &SystemMessage{
|
System: &SystemMessage{
|
||||||
ActiveMemory: emptyChartEntries(sampleLimit),
|
ActiveMemory: emptyChartEntries(sampleLimit),
|
||||||
|
|
@ -121,12 +115,11 @@ func New(config *Config, ethServ *eth.Ethereum, lesServ *les.LightEthereum, sync
|
||||||
DiskWrite: emptyChartEntries(sampleLimit),
|
DiskWrite: emptyChartEntries(sampleLimit),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
logdir: logdir,
|
logdir: logdir,
|
||||||
peerCh: peerCh,
|
peerCh: peerCh,
|
||||||
subPeer: p2p.SubscribeMeteredPeerEvent(peerCh),
|
subPeer: p2p.SubscribeMeteredPeerEvent(peerCh),
|
||||||
syncMode: syncMode,
|
ethServ: ethServ,
|
||||||
ethServ: ethServ,
|
lesServ: lesServ,
|
||||||
lesServ: lesServ,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,6 @@ type ChartEntry struct {
|
||||||
type GeneralMessage struct {
|
type GeneralMessage struct {
|
||||||
Version string `json:"version,omitempty"`
|
Version string `json:"version,omitempty"`
|
||||||
Commit string `json:"commit,omitempty"`
|
Commit string `json:"commit,omitempty"`
|
||||||
SyncMode string `json:"syncMode,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type HomeMessage struct {
|
type HomeMessage struct {
|
||||||
|
|
|
||||||
|
|
@ -404,12 +404,12 @@ func (db *Dashboard) collectPeerData() {
|
||||||
connected := now.Add(-event.Elapsed)
|
connected := now.Add(-event.Elapsed)
|
||||||
newPeerEvents = append(newPeerEvents, &peerEvent{
|
newPeerEvents = append(newPeerEvents, &peerEvent{
|
||||||
Addr: event.Addr,
|
Addr: event.Addr,
|
||||||
Enode: event.Enode,
|
Enode: event.Peer.Node().String(),
|
||||||
peer: event.Peer,
|
peer: event.Peer,
|
||||||
Connected: &connected,
|
Connected: &connected,
|
||||||
})
|
})
|
||||||
case p2p.PeerDisconnected:
|
case p2p.PeerDisconnected:
|
||||||
addr, enode := event.Addr, event.Enode
|
addr, enode := event.Addr, event.Peer.Node().String()
|
||||||
newPeerEvents = append(newPeerEvents, &peerEvent{
|
newPeerEvents = append(newPeerEvents, &peerEvent{
|
||||||
Addr: addr,
|
Addr: addr,
|
||||||
Enode: enode,
|
Enode: enode,
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,6 @@ type MeteredPeerEvent struct {
|
||||||
Type MeteredPeerEventType // Type of peer event
|
Type MeteredPeerEventType // Type of peer event
|
||||||
Addr string // TCP address of the peer
|
Addr string // TCP address of the peer
|
||||||
Elapsed time.Duration // Time elapsed between the connection and the handshake/disconnection
|
Elapsed time.Duration // Time elapsed between the connection and the handshake/disconnection
|
||||||
Enode string // Node URL
|
|
||||||
Peer *Peer // Connected remote node instance
|
Peer *Peer // Connected remote node instance
|
||||||
Ingress uint64 // Ingress count at the moment of the event
|
Ingress uint64 // Ingress count at the moment of the event
|
||||||
Egress uint64 // Egress count at the moment of the event
|
Egress uint64 // Egress count at the moment of the event
|
||||||
|
|
@ -92,7 +91,7 @@ type meteredConn struct {
|
||||||
|
|
||||||
connected time.Time // Connection time of the peer
|
connected time.Time // Connection time of the peer
|
||||||
addr *net.TCPAddr // TCP address of the peer
|
addr *net.TCPAddr // TCP address of the peer
|
||||||
enode string // Node URL of the peer
|
peer *Peer // Peer instance
|
||||||
|
|
||||||
// trafficMetered denotes if the peer is registered in the traffic registries.
|
// trafficMetered denotes if the peer is registered in the traffic registries.
|
||||||
// Its value is true if the metered peer count doesn't reach the limit in the
|
// Its value is true if the metered peer count doesn't reach the limit in the
|
||||||
|
|
@ -160,17 +159,17 @@ func (c *meteredConn) Write(b []byte) (n int, err error) {
|
||||||
|
|
||||||
// handshakeDone is called after the connection passes the handshake.
|
// handshakeDone is called after the connection passes the handshake.
|
||||||
func (c *meteredConn) handshakeDone(peer *Peer) {
|
func (c *meteredConn) handshakeDone(peer *Peer) {
|
||||||
enode := peer.Node().String()
|
|
||||||
if atomic.AddInt32(&meteredPeerCount, 1) >= MeteredPeerLimit {
|
if atomic.AddInt32(&meteredPeerCount, 1) >= MeteredPeerLimit {
|
||||||
// Don't register the peer in the traffic registries.
|
// Don't register the peer in the traffic registries.
|
||||||
atomic.AddInt32(&meteredPeerCount, -1)
|
atomic.AddInt32(&meteredPeerCount, -1)
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
c.enode, c.trafficMetered = enode, false
|
c.peer, c.trafficMetered = peer, false
|
||||||
c.lock.Unlock()
|
c.lock.Unlock()
|
||||||
log.Warn("Metered peer count reached the limit")
|
log.Warn("Metered peer count reached the limit")
|
||||||
} else {
|
} else {
|
||||||
|
enode := peer.Node().String()
|
||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
c.enode, c.trafficMetered = enode, true
|
c.peer, c.trafficMetered = peer, true
|
||||||
c.ingressMeter = metrics.NewRegisteredMeter(enode, PeerIngressRegistry)
|
c.ingressMeter = metrics.NewRegisteredMeter(enode, PeerIngressRegistry)
|
||||||
c.egressMeter = metrics.NewRegisteredMeter(enode, PeerEgressRegistry)
|
c.egressMeter = metrics.NewRegisteredMeter(enode, PeerEgressRegistry)
|
||||||
c.lock.Unlock()
|
c.lock.Unlock()
|
||||||
|
|
@ -178,7 +177,6 @@ func (c *meteredConn) handshakeDone(peer *Peer) {
|
||||||
meteredPeerFeed.Send(MeteredPeerEvent{
|
meteredPeerFeed.Send(MeteredPeerEvent{
|
||||||
Type: PeerHandshakeSucceeded,
|
Type: PeerHandshakeSucceeded,
|
||||||
Addr: c.addr.String(),
|
Addr: c.addr.String(),
|
||||||
Enode: enode,
|
|
||||||
Peer: peer,
|
Peer: peer,
|
||||||
Elapsed: time.Since(c.connected),
|
Elapsed: time.Since(c.connected),
|
||||||
})
|
})
|
||||||
|
|
@ -189,7 +187,7 @@ func (c *meteredConn) handshakeDone(peer *Peer) {
|
||||||
func (c *meteredConn) Close() error {
|
func (c *meteredConn) Close() error {
|
||||||
err := c.Conn.Close()
|
err := c.Conn.Close()
|
||||||
c.lock.RLock()
|
c.lock.RLock()
|
||||||
if c.enode == "" {
|
if c.peer == nil {
|
||||||
// If the peer disconnects before/during the handshake.
|
// If the peer disconnects before/during the handshake.
|
||||||
c.lock.RUnlock()
|
c.lock.RUnlock()
|
||||||
meteredPeerFeed.Send(MeteredPeerEvent{
|
meteredPeerFeed.Send(MeteredPeerEvent{
|
||||||
|
|
@ -200,19 +198,19 @@ func (c *meteredConn) Close() error {
|
||||||
activePeerCounter.Dec(1)
|
activePeerCounter.Dec(1)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
enode := c.enode
|
peer := c.peer
|
||||||
if !c.trafficMetered {
|
if !c.trafficMetered {
|
||||||
// If the peer isn't registered in the traffic registries.
|
// If the peer isn't registered in the traffic registries.
|
||||||
c.lock.RUnlock()
|
c.lock.RUnlock()
|
||||||
meteredPeerFeed.Send(MeteredPeerEvent{
|
meteredPeerFeed.Send(MeteredPeerEvent{
|
||||||
Type: PeerDisconnected,
|
Type: PeerDisconnected,
|
||||||
Addr: c.addr.String(),
|
Addr: c.addr.String(),
|
||||||
Enode: enode,
|
Peer: peer,
|
||||||
})
|
})
|
||||||
activePeerCounter.Dec(1)
|
activePeerCounter.Dec(1)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ingress, egress := uint64(c.ingressMeter.Count()), uint64(c.egressMeter.Count())
|
ingress, egress, enode := uint64(c.ingressMeter.Count()), uint64(c.egressMeter.Count()), c.peer.Node().String()
|
||||||
c.lock.RUnlock()
|
c.lock.RUnlock()
|
||||||
|
|
||||||
// Decrement the metered peer count
|
// Decrement the metered peer count
|
||||||
|
|
@ -225,7 +223,7 @@ func (c *meteredConn) Close() error {
|
||||||
meteredPeerFeed.Send(MeteredPeerEvent{
|
meteredPeerFeed.Send(MeteredPeerEvent{
|
||||||
Type: PeerDisconnected,
|
Type: PeerDisconnected,
|
||||||
Addr: c.addr.String(),
|
Addr: c.addr.String(),
|
||||||
Enode: enode,
|
Peer: peer,
|
||||||
Ingress: ingress,
|
Ingress: ingress,
|
||||||
Egress: egress,
|
Egress: egress,
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -876,15 +876,13 @@ func (srv *Server) listenLoop() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if remoteIP != nil {
|
if remoteIP != nil {
|
||||||
fd = newMeteredConn(fd, true, remoteIP)
|
var addr *net.TCPAddr
|
||||||
|
if tcp, ok := fd.RemoteAddr().(*net.TCPAddr); ok {
|
||||||
|
addr = tcp
|
||||||
|
}
|
||||||
|
fd = newMeteredConn(fd, true, addr)
|
||||||
|
srv.log.Trace("Accepted connection", "addr", fd.RemoteAddr())
|
||||||
}
|
}
|
||||||
|
|
||||||
var addr *net.TCPAddr
|
|
||||||
if tcp, ok := fd.RemoteAddr().(*net.TCPAddr); ok {
|
|
||||||
addr = tcp
|
|
||||||
}
|
|
||||||
fd = newMeteredConn(fd, true, addr)
|
|
||||||
srv.log.Trace("Accepted connection", "addr", fd.RemoteAddr())
|
|
||||||
go func() {
|
go func() {
|
||||||
srv.SetupConn(fd, inboundConn, nil)
|
srv.SetupConn(fd, inboundConn, nil)
|
||||||
slots <- struct{}{}
|
slots <- struct{}{}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue