Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
57f93d25
G
go-ethereum
项目概览
whqwjb
/
go-ethereum
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
go-ethereum
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
57f93d25
编写于
4月 16, 2015
作者:
B
Bas van Kervel
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
admin.stopRPC support added which stops the RPC HTTP listener
上级
20537801
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
94 addition
and
2 deletion
+94
-2
cmd/geth/admin.go
cmd/geth/admin.go
+8
-0
rpc/http.go
rpc/http.go
+19
-2
rpc/types.go
rpc/types.go
+67
-0
未找到文件。
cmd/geth/admin.go
浏览文件 @
57f93d25
...
...
@@ -26,6 +26,7 @@ func (js *jsre) adminBindings() {
admin
:=
t
.
Object
()
admin
.
Set
(
"suggestPeer"
,
js
.
suggestPeer
)
admin
.
Set
(
"startRPC"
,
js
.
startRPC
)
admin
.
Set
(
"stopRPC"
,
js
.
stopRPC
)
admin
.
Set
(
"nodeInfo"
,
js
.
nodeInfo
)
admin
.
Set
(
"peers"
,
js
.
peers
)
admin
.
Set
(
"newAccount"
,
js
.
newAccount
)
...
...
@@ -141,6 +142,13 @@ func (js *jsre) startRPC(call otto.FunctionCall) otto.Value {
return
otto
.
TrueValue
()
}
func
(
js
*
jsre
)
stopRPC
(
call
otto
.
FunctionCall
)
otto
.
Value
{
if
rpc
.
Stop
()
==
nil
{
return
otto
.
TrueValue
()
}
return
otto
.
FalseValue
()
}
func
(
js
*
jsre
)
suggestPeer
(
call
otto
.
FunctionCall
)
otto
.
Value
{
nodeURL
,
err
:=
call
.
Argument
(
0
)
.
ToString
()
if
err
!=
nil
{
...
...
rpc/http.go
浏览文件 @
57f93d25
...
...
@@ -5,7 +5,6 @@ import (
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"github.com/ethereum/go-ethereum/logger"
...
...
@@ -15,6 +14,7 @@ import (
)
var
rpclogger
=
logger
.
NewLogger
(
"RPC"
)
var
rpclistener
*
ControllableTCPListener
const
(
jsonrpcver
=
"2.0"
...
...
@@ -22,11 +22,17 @@ const (
)
func
Start
(
pipe
*
xeth
.
XEth
,
config
RpcConfig
)
error
{
l
,
err
:=
net
.
Listen
(
"tcp"
,
fmt
.
Sprintf
(
"%s:%d"
,
config
.
ListenAddress
,
config
.
ListenPort
))
if
rpclistener
!=
nil
{
// listener already running
glog
.
Infoln
(
"RPC listener already running"
)
return
fmt
.
Errorf
(
"RPC already running on %s"
,
rpclistener
.
Addr
()
.
String
())
}
l
,
err
:=
NewControllableTCPListener
(
fmt
.
Sprintf
(
"%s:%d"
,
config
.
ListenAddress
,
config
.
ListenPort
))
if
err
!=
nil
{
rpclogger
.
Errorf
(
"Can't listen on %s:%d: %v"
,
config
.
ListenAddress
,
config
.
ListenPort
,
err
)
return
err
}
rpclistener
=
l
var
handler
http
.
Handler
if
len
(
config
.
CorsDomain
)
>
0
{
...
...
@@ -45,6 +51,17 @@ func Start(pipe *xeth.XEth, config RpcConfig) error {
return
nil
}
func
Stop
()
error
{
if
rpclistener
==
nil
{
// listener not running
glog
.
Infoln
(
"RPC listener not running"
)
return
nil
}
rpclistener
.
Stop
()
rpclistener
=
nil
return
nil
}
// JSONRPC returns a handler that implements the Ethereum JSON-RPC API.
func
JSONRPC
(
pipe
*
xeth
.
XEth
)
http
.
Handler
{
api
:=
NewEthereumApi
(
pipe
)
...
...
rpc/types.go
浏览文件 @
57f93d25
...
...
@@ -23,6 +23,10 @@ import (
"math/big"
"strings"
"errors"
"net"
"time"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
...
...
@@ -257,3 +261,66 @@ type RpcErrorObject struct {
Message
string
`json:"message"`
// Data interface{} `json:"data"`
}
type
ListenerStoppedError
struct
{
msg
string
}
func
(
self
ListenerStoppedError
)
Timout
()
bool
{
return
false
}
func
(
self
ListenerStoppedError
)
Temporary
()
bool
{
return
false
}
func
(
self
ListenerStoppedError
)
Error
()
string
{
return
self
.
msg
}
type
ControllableTCPListener
struct
{
*
net
.
TCPListener
stop
chan
struct
{}
}
var
listenerStoppedError
ListenerStoppedError
func
(
self
*
ControllableTCPListener
)
Stop
()
{
close
(
self
.
stop
)
}
func
(
self
*
ControllableTCPListener
)
Accept
()
(
net
.
Conn
,
error
)
{
for
{
self
.
SetDeadline
(
time
.
Now
()
.
Add
(
time
.
Duration
(
500
*
time
.
Millisecond
)))
c
,
err
:=
self
.
TCPListener
.
AcceptTCP
()
select
{
case
<-
self
.
stop
:
self
.
TCPListener
.
Close
()
return
nil
,
listenerStoppedError
default
:
// keep on going
}
if
err
!=
nil
{
if
netErr
,
ok
:=
err
.
(
net
.
Error
);
ok
&&
netErr
.
Timeout
()
&&
netErr
.
Temporary
()
{
continue
// regular timeout
}
}
return
c
,
err
}
}
func
NewControllableTCPListener
(
addr
string
)
(
*
ControllableTCPListener
,
error
)
{
wl
,
err
:=
net
.
Listen
(
"tcp"
,
addr
)
if
err
!=
nil
{
return
nil
,
err
}
if
tcpl
,
ok
:=
wl
.
(
*
net
.
TCPListener
);
ok
{
l
:=
&
ControllableTCPListener
{
tcpl
,
make
(
chan
struct
{})}
return
l
,
nil
}
return
nil
,
errors
.
New
(
"Unable to create TCP listener for RPC"
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录