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
4c3da0f2
Commit
4c3da0f2
authored
Jun 24, 2016
by
Firescar96
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
node, p2p, internal: Add ability to remove peers via admin interface
parent
e0493457
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
48 additions
and
0 deletions
+48
-0
web3ext.go
internal/web3ext/web3ext.go
+5
-0
api.go
node/api.go
+16
-0
dial.go
p2p/dial.go
+5
-0
server.go
p2p/server.go
+20
-0
server_test.go
p2p/server_test.go
+2
-0
No files found.
internal/web3ext/web3ext.go
View file @
4c3da0f2
...
...
@@ -39,6 +39,11 @@ web3._extend({
call: 'admin_addPeer',
params: 1
}),
new web3._extend.Method({
name: 'removePeer',
call: 'admin_removePeer',
params: 1
}),
new web3._extend.Method({
name: 'exportChain',
call: 'admin_exportChain',
...
...
node/api.go
View file @
4c3da0f2
...
...
@@ -58,6 +58,22 @@ func (api *PrivateAdminAPI) AddPeer(url string) (bool, error) {
return
true
,
nil
}
// RemovePeer disconnects from a a remote node if the connection exists
func
(
api
*
PrivateAdminAPI
)
RemovePeer
(
url
string
)
(
bool
,
error
)
{
// Make sure the server is running, fail otherwise
server
:=
api
.
node
.
Server
()
if
server
==
nil
{
return
false
,
ErrNodeStopped
}
// Try to remove the url as a static peer and return
node
,
err
:=
discover
.
ParseNode
(
url
)
if
err
!=
nil
{
return
false
,
fmt
.
Errorf
(
"invalid enode: %v"
,
err
)
}
server
.
RemovePeer
(
node
)
return
true
,
nil
}
// StartRPC starts the HTTP RPC API server.
func
(
api
*
PrivateAdminAPI
)
StartRPC
(
host
*
string
,
port
*
rpc
.
HexNumber
,
cors
*
string
,
apis
*
string
)
(
bool
,
error
)
{
api
.
node
.
lock
.
Lock
()
...
...
p2p/dial.go
View file @
4c3da0f2
...
...
@@ -121,6 +121,11 @@ func (s *dialstate) addStatic(n *discover.Node) {
s
.
static
[
n
.
ID
]
=
&
dialTask
{
flags
:
staticDialedConn
,
dest
:
n
}
}
func
(
s
*
dialstate
)
removeStatic
(
n
*
discover
.
Node
)
{
// This removes a task so future attempts to connect will not be made.
delete
(
s
.
static
,
n
.
ID
)
}
func
(
s
*
dialstate
)
newTasks
(
nRunning
int
,
peers
map
[
discover
.
NodeID
]
*
Peer
,
now
time
.
Time
)
[]
task
{
var
newtasks
[]
task
isDialing
:=
func
(
id
discover
.
NodeID
)
bool
{
...
...
p2p/server.go
View file @
4c3da0f2
...
...
@@ -142,6 +142,7 @@ type Server struct {
quit
chan
struct
{}
addstatic
chan
*
discover
.
Node
removestatic
chan
*
discover
.
Node
posthandshake
chan
*
conn
addpeer
chan
*
conn
delpeer
chan
*
Peer
...
...
@@ -257,6 +258,14 @@ func (srv *Server) AddPeer(node *discover.Node) {
}
}
// RemovePeer disconnects from the given node
func
(
srv
*
Server
)
RemovePeer
(
node
*
discover
.
Node
)
{
select
{
case
srv
.
removestatic
<-
node
:
case
<-
srv
.
quit
:
}
}
// Self returns the local node's endpoint information.
func
(
srv
*
Server
)
Self
()
*
discover
.
Node
{
srv
.
lock
.
Lock
()
...
...
@@ -327,6 +336,7 @@ func (srv *Server) Start() (err error) {
srv
.
delpeer
=
make
(
chan
*
Peer
)
srv
.
posthandshake
=
make
(
chan
*
conn
)
srv
.
addstatic
=
make
(
chan
*
discover
.
Node
)
srv
.
removestatic
=
make
(
chan
*
discover
.
Node
)
srv
.
peerOp
=
make
(
chan
peerOpFunc
)
srv
.
peerOpDone
=
make
(
chan
struct
{})
...
...
@@ -395,6 +405,7 @@ type dialer interface {
newTasks
(
running
int
,
peers
map
[
discover
.
NodeID
]
*
Peer
,
now
time
.
Time
)
[]
task
taskDone
(
task
,
time
.
Time
)
addStatic
(
*
discover
.
Node
)
removeStatic
(
*
discover
.
Node
)
}
func
(
srv
*
Server
)
run
(
dialstate
dialer
)
{
...
...
@@ -458,6 +469,15 @@ running:
// it will keep the node connected.
glog
.
V
(
logger
.
Detail
)
.
Infoln
(
"<-addstatic:"
,
n
)
dialstate
.
addStatic
(
n
)
case
n
:=
<-
srv
.
removestatic
:
// This channel is used by RemovePeer to send a
// disconnect request to a peer and begin the
// stop keeping the node connected
glog
.
V
(
logger
.
Detail
)
.
Infoln
(
"<-removestatic:"
,
n
)
dialstate
.
removeStatic
(
n
)
if
p
,
ok
:=
peers
[
n
.
ID
];
ok
{
p
.
Disconnect
(
DiscRequested
)
}
case
op
:=
<-
srv
.
peerOp
:
// This channel is used by Peers and PeerCount.
op
(
peers
)
...
...
p2p/server_test.go
View file @
4c3da0f2
...
...
@@ -301,6 +301,8 @@ func (tg taskgen) taskDone(t task, now time.Time) {
}
func
(
tg
taskgen
)
addStatic
(
*
discover
.
Node
)
{
}
func
(
tg
taskgen
)
removeStatic
(
*
discover
.
Node
)
{
}
type
testTask
struct
{
index
int
...
...
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