Skip to content

Commit 701591b

Browse files
committed
cmd, eth, p2p: fix review issues enumerated by Felix
1 parent 1528dbc commit 701591b

File tree

8 files changed

+25
-34
lines changed

8 files changed

+25
-34
lines changed

cmd/geth/admin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ func (js *jsre) adminBindings() {
2525
js.re.Set("admin", struct{}{})
2626
t, _ := js.re.Get("admin")
2727
admin := t.Object()
28-
admin.Set("trustPeer", js.trustPeer)
28+
admin.Set("addPeer", js.addPeer)
2929
admin.Set("startRPC", js.startRPC)
3030
admin.Set("stopRPC", js.stopRPC)
3131
admin.Set("nodeInfo", js.nodeInfo)
@@ -243,13 +243,13 @@ func (js *jsre) stopRPC(call otto.FunctionCall) otto.Value {
243243
return otto.FalseValue()
244244
}
245245

246-
func (js *jsre) trustPeer(call otto.FunctionCall) otto.Value {
246+
func (js *jsre) addPeer(call otto.FunctionCall) otto.Value {
247247
nodeURL, err := call.Argument(0).ToString()
248248
if err != nil {
249249
fmt.Println(err)
250250
return otto.FalseValue()
251251
}
252-
err = js.ethereum.TrustPeer(nodeURL)
252+
err = js.ethereum.AddPeer(nodeURL)
253253
if err != nil {
254254
fmt.Println(err)
255255
return otto.FalseValue()

cmd/geth/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
232232
utils.IdentityFlag,
233233
utils.UnlockedAccountFlag,
234234
utils.PasswordFileFlag,
235-
utils.BootNodesFlag,
235+
utils.BootnodesFlag,
236236
utils.DataDirFlag,
237237
utils.BlockchainVersionFlag,
238238
utils.JSpathFlag,

cmd/mist/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func init() {
6969
assetPathFlag,
7070
rpcCorsFlag,
7171

72-
utils.BootNodesFlag,
72+
utils.BootnodesFlag,
7373
utils.DataDirFlag,
7474
utils.ListenPortFlag,
7575
utils.LogFileFlag,

cmd/mist/ui_lib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (ui *UiLib) Connect(button qml.Object) {
104104
}
105105

106106
func (ui *UiLib) ConnectToPeer(nodeURL string) {
107-
if err := ui.eth.TrustPeer(nodeURL); err != nil {
107+
if err := ui.eth.AddPeer(nodeURL); err != nil {
108108
guilogger.Infoln("TrustPeer error: " + err.Error())
109109
}
110110
}

cmd/utils/flags.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ var (
202202
Usage: "Network listening port",
203203
Value: 30303,
204204
}
205-
BootNodesFlag = cli.StringFlag{
205+
BootnodesFlag = cli.StringFlag{
206206
Name: "bootnodes",
207207
Usage: "Space-separated enode URLs for p2p discovery bootstrap",
208208
Value: "",
@@ -292,7 +292,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
292292
NodeKey: GetNodeKey(ctx),
293293
Shh: ctx.GlobalBool(WhisperEnabledFlag.Name),
294294
Dial: true,
295-
BootNodes: ctx.GlobalString(BootNodesFlag.Name),
295+
BootNodes: ctx.GlobalString(BootnodesFlag.Name),
296296
}
297297
}
298298

eth/backend.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ func (cfg *Config) parseTrustedNodes() []*discover.Node {
108108
// Short circuit if no trusted node config is present
109109
path := filepath.Join(cfg.DataDir, trustedNodes)
110110
if _, err := os.Stat(path); err != nil {
111-
fmt.Println("nodes", nil)
112111
return nil
113112
}
114113
// Load the trusted nodes from the config file
@@ -122,7 +121,6 @@ func (cfg *Config) parseTrustedNodes() []*discover.Node {
122121
glog.V(logger.Error).Infof("Failed to load trusted nodes: %v", err)
123122
return nil
124123
}
125-
fmt.Println("nodes", nodelist)
126124
// Interpret the list as a discovery node array
127125
var nodes []*discover.Node
128126
for _, url := range nodelist {
@@ -486,13 +484,15 @@ func (s *Ethereum) StartForTest() {
486484
s.txPool.Start()
487485
}
488486

489-
// TrustPeer injects a new node into the list of privileged nodes.
490-
func (self *Ethereum) TrustPeer(nodeURL string) error {
487+
// AddPeer connects to the given node and maintains the connection until the
488+
// server is shut down. If the connection fails for any reason, the server will
489+
// attempt to reconnect the peer.
490+
func (self *Ethereum) AddPeer(nodeURL string) error {
491491
n, err := discover.ParseNode(nodeURL)
492492
if err != nil {
493493
return fmt.Errorf("invalid node URL: %v", err)
494494
}
495-
self.net.TrustPeer(n)
495+
self.net.AddPeer(n)
496496
return nil
497497
}
498498

p2p/server.go

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ type Server struct {
100100

101101
ourHandshake *protoHandshake
102102

103-
lock sync.RWMutex // protects running and peers
104-
running bool
105-
peers map[discover.NodeID]*Peer
106-
103+
lock sync.RWMutex // protects running, peers and the trust fields
104+
running bool
105+
peers map[discover.NodeID]*Peer
107106
trusts map[discover.NodeID]*discover.Node // Map of currently trusted remote nodes
108107
trustDial chan *discover.Node // Dial request channel reserved for the trusted nodes
109108

@@ -138,8 +137,10 @@ func (srv *Server) PeerCount() int {
138137
return n
139138
}
140139

141-
// TrustPeer inserts a node into the list of privileged nodes.
142-
func (srv *Server) TrustPeer(node *discover.Node) {
140+
// AddPeer connects to the given node and maintains the connection until the
141+
// server is shut down. If the connection fails for any reason, the server will
142+
// attempt to reconnect the peer.
143+
func (srv *Server) AddPeer(node *discover.Node) {
143144
srv.lock.Lock()
144145
defer srv.lock.Unlock()
145146

@@ -246,7 +247,7 @@ func (srv *Server) Start() (err error) {
246247
glog.V(logger.Warn).Infoln("I will be kind-of useless, neither dialing nor listening.")
247248
}
248249
// maintain the trusted peers
249-
go srv.trustLoop()
250+
go srv.trustedNodesLoop()
250251

251252
srv.running = true
252253
return nil
@@ -341,16 +342,13 @@ func (srv *Server) listenLoop() {
341342
}
342343
}
343344

344-
// trustLoop is responsible for periodically checking that trusted connections
345-
// are actually live, and requests dialing if not.
346-
func (srv *Server) trustLoop() {
347-
// Create a ticker for verifying trusted connections
345+
// trustedNodesLoop is responsible for periodically checking that trusted
346+
// connections are actually live, and requests dialing if not.
347+
func (srv *Server) trustedNodesLoop() {
348348
tick := time.Tick(trustedPeerCheckInterval)
349-
350349
for {
351350
select {
352351
case <-srv.quit:
353-
// Termination requested, simple return
354352
return
355353

356354
case <-tick:
@@ -369,10 +367,7 @@ func (srv *Server) trustLoop() {
369367
glog.V(logger.Debug).Infof("Dialing trusted peer %v", node)
370368
select {
371369
case srv.trustDial <- node:
372-
// Ok, dialing
373-
374370
case <-srv.quit:
375-
// Terminating, return
376371
return
377372
}
378373
}
@@ -547,16 +542,12 @@ func (srv *Server) checkPeer(id discover.NodeID) (bool, DiscReason) {
547542
switch {
548543
case !srv.running:
549544
return false, DiscQuitting
550-
551545
case !trusted && len(srv.peers) >= srv.MaxPeers:
552546
return false, DiscTooManyPeers
553-
554547
case srv.peers[id] != nil:
555548
return false, DiscAlreadyConnected
556-
557549
case id == srv.ntab.Self().ID:
558550
return false, DiscSelf
559-
560551
default:
561552
return true, 0
562553
}

p2p/server_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ func TestServerTrustedPeers(t *testing.T) {
260260
trusted := &discover.Node{
261261
ID: discover.PubkeyID(&key.PublicKey),
262262
}
263-
server.TrustPeer(trusted)
263+
server.AddPeer(trusted)
264264

265265
conn, err := dialer.Dial("tcp", server.ListenAddr)
266266
if err != nil {

0 commit comments

Comments
 (0)