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
|
||||
// in order to be able to collect information about the other services.
|
||||
if ctx.GlobalBool(utils.DashboardEnabledFlag.Name) {
|
||||
utils.RegisterDashboardService(stack, &cfg.Dashboard, cfg.Eth.SyncMode, gitCommit)
|
||||
utils.RegisterDashboardService(stack, &cfg.Dashboard, gitCommit)
|
||||
}
|
||||
return stack
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1537,7 +1537,7 @@ func RegisterEthService(stack *node.Node, cfg *eth.Config) {
|
|||
}
|
||||
|
||||
// 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) {
|
||||
var (
|
||||
ethServ *eth.Ethereum
|
||||
|
|
@ -1545,7 +1545,7 @@ func RegisterDashboardService(stack *node.Node, cfg *dashboard.Config, syncMode
|
|||
)
|
||||
_ = ctx.Service(ðServ)
|
||||
_ = 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 {
|
||||
Fatalf("Failed to register the dashboard service: %v", err)
|
||||
|
|
|
|||
|
|
@ -85,7 +85,6 @@ const defaultContent: () => Content = () => ({
|
|||
general: {
|
||||
version: null,
|
||||
commit: null,
|
||||
syncMode: '',
|
||||
},
|
||||
home: {},
|
||||
chain: {},
|
||||
|
|
@ -122,7 +121,6 @@ const updaters = {
|
|||
general: {
|
||||
version: replacer,
|
||||
commit: replacer,
|
||||
syncMode: replacer,
|
||||
},
|
||||
home: null,
|
||||
chain: null,
|
||||
|
|
@ -243,7 +241,6 @@ class Dashboard extends Component<Props, State> {
|
|||
<div className={this.props.classes.dashboard} style={styles.dashboard}>
|
||||
<Header
|
||||
switchSideBar={this.switchSideBar}
|
||||
syncMode={this.state.content.general.syncMode}
|
||||
/>
|
||||
<Body
|
||||
opened={this.state.sideBar}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,6 @@ const themeStyles = (theme: Object) => ({
|
|||
export type Props = {
|
||||
classes: Object, // injected by withStyles()
|
||||
switchSideBar: () => void,
|
||||
syncMode: string,
|
||||
};
|
||||
|
||||
// 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 {FontAwesomeIcon} from '@fortawesome/react-fontawesome';
|
||||
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 {faClipboard as farClipboard} from '@fortawesome/free-regular-svg-icons';
|
||||
import {faCircle as farCircle, faClipboard as farClipboard} from '@fortawesome/free-regular-svg-icons';
|
||||
import convert from 'color-convert';
|
||||
import {Scrollbars} from 'react-custom-scrollbars';
|
||||
|
||||
|
|
@ -139,9 +138,10 @@ const shortName = (name: string) => {
|
|||
console.error('Incorrect node name', name);
|
||||
return parts[0];
|
||||
}
|
||||
const versionRE = RegExp(/^v?\d+\.\d+\.\d+.*/);
|
||||
// Drop optional custom identifier.
|
||||
if (!RegExp(/^v?\d+\.\d+\.\d+.*/).test(parts[1])) {
|
||||
if (parts.length < 3) {
|
||||
if (!versionRE.test(parts[1])) {
|
||||
if (parts.length < 3 || !versionRE.test(parts[2])) {
|
||||
console.error('Incorrect node name', name);
|
||||
return parts[0];
|
||||
}
|
||||
|
|
@ -683,7 +683,7 @@ class Network extends Component<Props, State> {
|
|||
<Grid item style={{width: '40%'}}>
|
||||
<div className={classes.table} style={styles.table}>
|
||||
<Typography variant='subtitle1' gutterBottom className={classes.title} style={styles.title}>
|
||||
ETH peers
|
||||
Full peers
|
||||
<FontAwesomeIcon
|
||||
icon={farClipboard}
|
||||
onClick={this.copyToClipboard(JSON.stringify(this.ethList()))}
|
||||
|
|
@ -743,7 +743,7 @@ class Network extends Component<Props, State> {
|
|||
<Grid item style={{width: '40%'}}>
|
||||
<div className={classes.table} style={styles.table}>
|
||||
<Typography variant='subtitle1' gutterBottom className={classes.title} style={styles.title}>
|
||||
LES peers
|
||||
Light peers
|
||||
<FontAwesomeIcon
|
||||
icon={farClipboard}
|
||||
onClick={this.copyToClipboard(JSON.stringify(this.lesList()))}
|
||||
|
|
|
|||
|
|
@ -35,7 +35,6 @@ export type ChartEntry = {
|
|||
export type General = {
|
||||
version: ?string,
|
||||
commit: ?string,
|
||||
syncMode: string,
|
||||
};
|
||||
|
||||
export type Home = {
|
||||
|
|
|
|||
|
|
@ -34,11 +34,8 @@ import (
|
|||
"sync/atomic"
|
||||
|
||||
"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/les"
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/ethereum/go-ethereum/p2p"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
|
|
@ -75,10 +72,8 @@ type Dashboard struct {
|
|||
peerCh chan p2p.MeteredPeerEvent // Peer event channel.
|
||||
subPeer event.Subscription // Peer event subscription.
|
||||
|
||||
syncMode downloader.SyncMode
|
||||
|
||||
ethServ *eth.Ethereum
|
||||
lesServ *les.LightEthereum
|
||||
ethServ *eth.Ethereum // Ethereum object serving internals.
|
||||
lesServ *les.LightEthereum // LightEthereum object serving internals.
|
||||
}
|
||||
|
||||
// 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.
|
||||
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
|
||||
// can cause some lost peer events, therefore some peers might not appear
|
||||
// on the dashboard.
|
||||
|
|
@ -106,9 +101,8 @@ func New(config *Config, ethServ *eth.Ethereum, lesServ *les.LightEthereum, sync
|
|||
quit: make(chan chan error),
|
||||
history: &Message{
|
||||
General: &GeneralMessage{
|
||||
Commit: commit,
|
||||
Version: fmt.Sprintf("v%d.%d.%d%s", params.VersionMajor, params.VersionMinor, params.VersionPatch, versionMeta),
|
||||
SyncMode: syncMode.String(),
|
||||
Commit: commit,
|
||||
Version: fmt.Sprintf("v%d.%d.%d%s", params.VersionMajor, params.VersionMinor, params.VersionPatch, versionMeta),
|
||||
},
|
||||
System: &SystemMessage{
|
||||
ActiveMemory: emptyChartEntries(sampleLimit),
|
||||
|
|
@ -121,12 +115,11 @@ func New(config *Config, ethServ *eth.Ethereum, lesServ *les.LightEthereum, sync
|
|||
DiskWrite: emptyChartEntries(sampleLimit),
|
||||
},
|
||||
},
|
||||
logdir: logdir,
|
||||
peerCh: peerCh,
|
||||
subPeer: p2p.SubscribeMeteredPeerEvent(peerCh),
|
||||
syncMode: syncMode,
|
||||
ethServ: ethServ,
|
||||
lesServ: lesServ,
|
||||
logdir: logdir,
|
||||
peerCh: peerCh,
|
||||
subPeer: p2p.SubscribeMeteredPeerEvent(peerCh),
|
||||
ethServ: ethServ,
|
||||
lesServ: lesServ,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,7 +39,6 @@ type ChartEntry struct {
|
|||
type GeneralMessage struct {
|
||||
Version string `json:"version,omitempty"`
|
||||
Commit string `json:"commit,omitempty"`
|
||||
SyncMode string `json:"syncMode,omitempty"`
|
||||
}
|
||||
|
||||
type HomeMessage struct {
|
||||
|
|
|
|||
|
|
@ -404,12 +404,12 @@ func (db *Dashboard) collectPeerData() {
|
|||
connected := now.Add(-event.Elapsed)
|
||||
newPeerEvents = append(newPeerEvents, &peerEvent{
|
||||
Addr: event.Addr,
|
||||
Enode: event.Enode,
|
||||
Enode: event.Peer.Node().String(),
|
||||
peer: event.Peer,
|
||||
Connected: &connected,
|
||||
})
|
||||
case p2p.PeerDisconnected:
|
||||
addr, enode := event.Addr, event.Enode
|
||||
addr, enode := event.Addr, event.Peer.Node().String()
|
||||
newPeerEvents = append(newPeerEvents, &peerEvent{
|
||||
Addr: addr,
|
||||
Enode: enode,
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ type MeteredPeerEvent struct {
|
|||
Type MeteredPeerEventType // Type of peer event
|
||||
Addr string // TCP address of the peer
|
||||
Elapsed time.Duration // Time elapsed between the connection and the handshake/disconnection
|
||||
Enode string // Node URL
|
||||
Peer *Peer // Connected remote node instance
|
||||
Ingress uint64 // Ingress 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
|
||||
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.
|
||||
// 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.
|
||||
func (c *meteredConn) handshakeDone(peer *Peer) {
|
||||
enode := peer.Node().String()
|
||||
if atomic.AddInt32(&meteredPeerCount, 1) >= MeteredPeerLimit {
|
||||
// Don't register the peer in the traffic registries.
|
||||
atomic.AddInt32(&meteredPeerCount, -1)
|
||||
c.lock.Lock()
|
||||
c.enode, c.trafficMetered = enode, false
|
||||
c.peer, c.trafficMetered = peer, false
|
||||
c.lock.Unlock()
|
||||
log.Warn("Metered peer count reached the limit")
|
||||
} else {
|
||||
enode := peer.Node().String()
|
||||
c.lock.Lock()
|
||||
c.enode, c.trafficMetered = enode, true
|
||||
c.peer, c.trafficMetered = peer, true
|
||||
c.ingressMeter = metrics.NewRegisteredMeter(enode, PeerIngressRegistry)
|
||||
c.egressMeter = metrics.NewRegisteredMeter(enode, PeerEgressRegistry)
|
||||
c.lock.Unlock()
|
||||
|
|
@ -178,7 +177,6 @@ func (c *meteredConn) handshakeDone(peer *Peer) {
|
|||
meteredPeerFeed.Send(MeteredPeerEvent{
|
||||
Type: PeerHandshakeSucceeded,
|
||||
Addr: c.addr.String(),
|
||||
Enode: enode,
|
||||
Peer: peer,
|
||||
Elapsed: time.Since(c.connected),
|
||||
})
|
||||
|
|
@ -189,7 +187,7 @@ func (c *meteredConn) handshakeDone(peer *Peer) {
|
|||
func (c *meteredConn) Close() error {
|
||||
err := c.Conn.Close()
|
||||
c.lock.RLock()
|
||||
if c.enode == "" {
|
||||
if c.peer == nil {
|
||||
// If the peer disconnects before/during the handshake.
|
||||
c.lock.RUnlock()
|
||||
meteredPeerFeed.Send(MeteredPeerEvent{
|
||||
|
|
@ -200,19 +198,19 @@ func (c *meteredConn) Close() error {
|
|||
activePeerCounter.Dec(1)
|
||||
return err
|
||||
}
|
||||
enode := c.enode
|
||||
peer := c.peer
|
||||
if !c.trafficMetered {
|
||||
// If the peer isn't registered in the traffic registries.
|
||||
c.lock.RUnlock()
|
||||
meteredPeerFeed.Send(MeteredPeerEvent{
|
||||
Type: PeerDisconnected,
|
||||
Addr: c.addr.String(),
|
||||
Enode: enode,
|
||||
Type: PeerDisconnected,
|
||||
Addr: c.addr.String(),
|
||||
Peer: peer,
|
||||
})
|
||||
activePeerCounter.Dec(1)
|
||||
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()
|
||||
|
||||
// Decrement the metered peer count
|
||||
|
|
@ -225,7 +223,7 @@ func (c *meteredConn) Close() error {
|
|||
meteredPeerFeed.Send(MeteredPeerEvent{
|
||||
Type: PeerDisconnected,
|
||||
Addr: c.addr.String(),
|
||||
Enode: enode,
|
||||
Peer: peer,
|
||||
Ingress: ingress,
|
||||
Egress: egress,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -876,15 +876,13 @@ func (srv *Server) listenLoop() {
|
|||
continue
|
||||
}
|
||||
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() {
|
||||
srv.SetupConn(fd, inboundConn, nil)
|
||||
slots <- struct{}{}
|
||||
|
|
|
|||
Loading…
Reference in a new issue