Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
701591b4
Commit
701591b4
authored
Apr 30, 2015
by
Péter Szilágyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cmd, eth, p2p: fix review issues enumerated by Felix
parent
1528dbc1
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
25 additions
and
34 deletions
+25
-34
admin.go
cmd/geth/admin.go
+3
-3
main.go
cmd/geth/main.go
+1
-1
main.go
cmd/mist/main.go
+1
-1
ui_lib.go
cmd/mist/ui_lib.go
+1
-1
flags.go
cmd/utils/flags.go
+2
-2
backend.go
eth/backend.go
+5
-5
server.go
p2p/server.go
+11
-20
server_test.go
p2p/server_test.go
+1
-1
No files found.
cmd/geth/admin.go
View file @
701591b4
...
...
@@ -25,7 +25,7 @@ func (js *jsre) adminBindings() {
js
.
re
.
Set
(
"admin"
,
struct
{}{})
t
,
_
:=
js
.
re
.
Get
(
"admin"
)
admin
:=
t
.
Object
()
admin
.
Set
(
"
trustPeer"
,
js
.
trust
Peer
)
admin
.
Set
(
"
addPeer"
,
js
.
add
Peer
)
admin
.
Set
(
"startRPC"
,
js
.
startRPC
)
admin
.
Set
(
"stopRPC"
,
js
.
stopRPC
)
admin
.
Set
(
"nodeInfo"
,
js
.
nodeInfo
)
...
...
@@ -243,13 +243,13 @@ func (js *jsre) stopRPC(call otto.FunctionCall) otto.Value {
return
otto
.
FalseValue
()
}
func
(
js
*
jsre
)
trust
Peer
(
call
otto
.
FunctionCall
)
otto
.
Value
{
func
(
js
*
jsre
)
add
Peer
(
call
otto
.
FunctionCall
)
otto
.
Value
{
nodeURL
,
err
:=
call
.
Argument
(
0
)
.
ToString
()
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
otto
.
FalseValue
()
}
err
=
js
.
ethereum
.
Trust
Peer
(
nodeURL
)
err
=
js
.
ethereum
.
Add
Peer
(
nodeURL
)
if
err
!=
nil
{
fmt
.
Println
(
err
)
return
otto
.
FalseValue
()
...
...
cmd/geth/main.go
View file @
701591b4
...
...
@@ -232,7 +232,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils
.
IdentityFlag
,
utils
.
UnlockedAccountFlag
,
utils
.
PasswordFileFlag
,
utils
.
Boot
N
odesFlag
,
utils
.
Boot
n
odesFlag
,
utils
.
DataDirFlag
,
utils
.
BlockchainVersionFlag
,
utils
.
JSpathFlag
,
...
...
cmd/mist/main.go
View file @
701591b4
...
...
@@ -69,7 +69,7 @@ func init() {
assetPathFlag
,
rpcCorsFlag
,
utils
.
Boot
N
odesFlag
,
utils
.
Boot
n
odesFlag
,
utils
.
DataDirFlag
,
utils
.
ListenPortFlag
,
utils
.
LogFileFlag
,
...
...
cmd/mist/ui_lib.go
View file @
701591b4
...
...
@@ -104,7 +104,7 @@ func (ui *UiLib) Connect(button qml.Object) {
}
func
(
ui
*
UiLib
)
ConnectToPeer
(
nodeURL
string
)
{
if
err
:=
ui
.
eth
.
Trust
Peer
(
nodeURL
);
err
!=
nil
{
if
err
:=
ui
.
eth
.
Add
Peer
(
nodeURL
);
err
!=
nil
{
guilogger
.
Infoln
(
"TrustPeer error: "
+
err
.
Error
())
}
}
...
...
cmd/utils/flags.go
View file @
701591b4
...
...
@@ -202,7 +202,7 @@ var (
Usage
:
"Network listening port"
,
Value
:
30303
,
}
Boot
N
odesFlag
=
cli
.
StringFlag
{
Boot
n
odesFlag
=
cli
.
StringFlag
{
Name
:
"bootnodes"
,
Usage
:
"Space-separated enode URLs for p2p discovery bootstrap"
,
Value
:
""
,
...
...
@@ -292,7 +292,7 @@ func MakeEthConfig(clientID, version string, ctx *cli.Context) *eth.Config {
NodeKey
:
GetNodeKey
(
ctx
),
Shh
:
ctx
.
GlobalBool
(
WhisperEnabledFlag
.
Name
),
Dial
:
true
,
BootNodes
:
ctx
.
GlobalString
(
Boot
N
odesFlag
.
Name
),
BootNodes
:
ctx
.
GlobalString
(
Boot
n
odesFlag
.
Name
),
}
}
...
...
eth/backend.go
View file @
701591b4
...
...
@@ -108,7 +108,6 @@ func (cfg *Config) parseTrustedNodes() []*discover.Node {
// Short circuit if no trusted node config is present
path
:=
filepath
.
Join
(
cfg
.
DataDir
,
trustedNodes
)
if
_
,
err
:=
os
.
Stat
(
path
);
err
!=
nil
{
fmt
.
Println
(
"nodes"
,
nil
)
return
nil
}
// Load the trusted nodes from the config file
...
...
@@ -122,7 +121,6 @@ func (cfg *Config) parseTrustedNodes() []*discover.Node {
glog
.
V
(
logger
.
Error
)
.
Infof
(
"Failed to load trusted nodes: %v"
,
err
)
return
nil
}
fmt
.
Println
(
"nodes"
,
nodelist
)
// Interpret the list as a discovery node array
var
nodes
[]
*
discover
.
Node
for
_
,
url
:=
range
nodelist
{
...
...
@@ -486,13 +484,15 @@ func (s *Ethereum) StartForTest() {
s
.
txPool
.
Start
()
}
// TrustPeer injects a new node into the list of privileged nodes.
func
(
self
*
Ethereum
)
TrustPeer
(
nodeURL
string
)
error
{
// AddPeer connects to the given node and maintains the connection until the
// server is shut down. If the connection fails for any reason, the server will
// attempt to reconnect the peer.
func
(
self
*
Ethereum
)
AddPeer
(
nodeURL
string
)
error
{
n
,
err
:=
discover
.
ParseNode
(
nodeURL
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"invalid node URL: %v"
,
err
)
}
self
.
net
.
Trust
Peer
(
n
)
self
.
net
.
Add
Peer
(
n
)
return
nil
}
...
...
p2p/server.go
View file @
701591b4
...
...
@@ -100,10 +100,9 @@ type Server struct {
ourHandshake
*
protoHandshake
lock
sync
.
RWMutex
// protects running and peers
running
bool
peers
map
[
discover
.
NodeID
]
*
Peer
lock
sync
.
RWMutex
// protects running, peers and the trust fields
running
bool
peers
map
[
discover
.
NodeID
]
*
Peer
trusts
map
[
discover
.
NodeID
]
*
discover
.
Node
// Map of currently trusted remote nodes
trustDial
chan
*
discover
.
Node
// Dial request channel reserved for the trusted nodes
...
...
@@ -138,8 +137,10 @@ func (srv *Server) PeerCount() int {
return
n
}
// TrustPeer inserts a node into the list of privileged nodes.
func
(
srv
*
Server
)
TrustPeer
(
node
*
discover
.
Node
)
{
// AddPeer connects to the given node and maintains the connection until the
// server is shut down. If the connection fails for any reason, the server will
// attempt to reconnect the peer.
func
(
srv
*
Server
)
AddPeer
(
node
*
discover
.
Node
)
{
srv
.
lock
.
Lock
()
defer
srv
.
lock
.
Unlock
()
...
...
@@ -246,7 +247,7 @@ func (srv *Server) Start() (err error) {
glog
.
V
(
logger
.
Warn
)
.
Infoln
(
"I will be kind-of useless, neither dialing nor listening."
)
}
// maintain the trusted peers
go
srv
.
trustLoop
()
go
srv
.
trust
edNodes
Loop
()
srv
.
running
=
true
return
nil
...
...
@@ -341,16 +342,13 @@ func (srv *Server) listenLoop() {
}
}
// trustLoop is responsible for periodically checking that trusted connections
// are actually live, and requests dialing if not.
func
(
srv
*
Server
)
trustLoop
()
{
// Create a ticker for verifying trusted connections
// trustedNodesLoop is responsible for periodically checking that trusted
// connections are actually live, and requests dialing if not.
func
(
srv
*
Server
)
trustedNodesLoop
()
{
tick
:=
time
.
Tick
(
trustedPeerCheckInterval
)
for
{
select
{
case
<-
srv
.
quit
:
// Termination requested, simple return
return
case
<-
tick
:
...
...
@@ -369,10 +367,7 @@ func (srv *Server) trustLoop() {
glog
.
V
(
logger
.
Debug
)
.
Infof
(
"Dialing trusted peer %v"
,
node
)
select
{
case
srv
.
trustDial
<-
node
:
// Ok, dialing
case
<-
srv
.
quit
:
// Terminating, return
return
}
}
...
...
@@ -547,16 +542,12 @@ func (srv *Server) checkPeer(id discover.NodeID) (bool, DiscReason) {
switch
{
case
!
srv
.
running
:
return
false
,
DiscQuitting
case
!
trusted
&&
len
(
srv
.
peers
)
>=
srv
.
MaxPeers
:
return
false
,
DiscTooManyPeers
case
srv
.
peers
[
id
]
!=
nil
:
return
false
,
DiscAlreadyConnected
case
id
==
srv
.
ntab
.
Self
()
.
ID
:
return
false
,
DiscSelf
default
:
return
true
,
0
}
...
...
p2p/server_test.go
View file @
701591b4
...
...
@@ -260,7 +260,7 @@ func TestServerTrustedPeers(t *testing.T) {
trusted
:=
&
discover
.
Node
{
ID
:
discover
.
PubkeyID
(
&
key
.
PublicKey
),
}
server
.
Trust
Peer
(
trusted
)
server
.
Add
Peer
(
trusted
)
conn
,
err
:=
dialer
.
Dial
(
"tcp"
,
server
.
ListenAddr
)
if
err
!=
nil
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment