Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
whqwjb
go-ethereum
提交
d00e2731
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,发现更多精彩内容 >>
提交
d00e2731
编写于
2月 05, 2015
作者:
O
obscuren
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' of
https://github.com/tgerring/go-ethereum
into tgerring-develop
Conflicts: rpc/http/server.go
上级
db7c34a9
429077a5
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
39 addition
and
40 deletion
+39
-40
cmd/ethereum/flags.go
cmd/ethereum/flags.go
+1
-1
cmd/mist/flags.go
cmd/mist/flags.go
+1
-1
cmd/utils/cmd.go
cmd/utils/cmd.go
+1
-1
rpc/http/server.go
rpc/http/server.go
+8
-5
rpc/message.go
rpc/message.go
+12
-13
rpc/ws/server.go
rpc/ws/server.go
+16
-19
未找到文件。
cmd/ethereum/flags.go
浏览文件 @
d00e2731
...
@@ -96,7 +96,7 @@ func Init() {
...
@@ -96,7 +96,7 @@ func Init() {
flag
.
StringVar
(
&
NatType
,
"nat"
,
""
,
"NAT support (UPNP|PMP) (none)"
)
flag
.
StringVar
(
&
NatType
,
"nat"
,
""
,
"NAT support (UPNP|PMP) (none)"
)
flag
.
StringVar
(
&
PMPGateway
,
"pmp"
,
""
,
"Gateway IP for PMP"
)
flag
.
StringVar
(
&
PMPGateway
,
"pmp"
,
""
,
"Gateway IP for PMP"
)
flag
.
IntVar
(
&
MaxPeer
,
"maxpeer"
,
30
,
"maximum desired peers"
)
flag
.
IntVar
(
&
MaxPeer
,
"maxpeer"
,
30
,
"maximum desired peers"
)
flag
.
IntVar
(
&
RpcPort
,
"rpcport"
,
8
080
,
"port to start json-rpc server on"
)
flag
.
IntVar
(
&
RpcPort
,
"rpcport"
,
8
545
,
"port to start json-rpc server on"
)
flag
.
IntVar
(
&
WsPort
,
"wsport"
,
40404
,
"port to start websocket rpc server on"
)
flag
.
IntVar
(
&
WsPort
,
"wsport"
,
40404
,
"port to start websocket rpc server on"
)
flag
.
BoolVar
(
&
StartRpc
,
"rpc"
,
false
,
"start rpc server"
)
flag
.
BoolVar
(
&
StartRpc
,
"rpc"
,
false
,
"start rpc server"
)
flag
.
BoolVar
(
&
StartWebSockets
,
"ws"
,
false
,
"start websocket server"
)
flag
.
BoolVar
(
&
StartWebSockets
,
"ws"
,
false
,
"start websocket server"
)
...
...
cmd/mist/flags.go
浏览文件 @
d00e2731
...
@@ -111,7 +111,7 @@ func Init() {
...
@@ -111,7 +111,7 @@ func Init() {
flag
.
StringVar
(
&
OutboundPort
,
"port"
,
"30303"
,
"listening port"
)
flag
.
StringVar
(
&
OutboundPort
,
"port"
,
"30303"
,
"listening port"
)
flag
.
BoolVar
(
&
UseUPnP
,
"upnp"
,
true
,
"enable UPnP support"
)
flag
.
BoolVar
(
&
UseUPnP
,
"upnp"
,
true
,
"enable UPnP support"
)
flag
.
IntVar
(
&
MaxPeer
,
"maxpeer"
,
30
,
"maximum desired peers"
)
flag
.
IntVar
(
&
MaxPeer
,
"maxpeer"
,
30
,
"maximum desired peers"
)
flag
.
IntVar
(
&
RpcPort
,
"rpcport"
,
8
080
,
"port to start json-rpc server on"
)
flag
.
IntVar
(
&
RpcPort
,
"rpcport"
,
8
545
,
"port to start json-rpc server on"
)
flag
.
IntVar
(
&
WsPort
,
"wsport"
,
40404
,
"port to start websocket rpc server on"
)
flag
.
IntVar
(
&
WsPort
,
"wsport"
,
40404
,
"port to start websocket rpc server on"
)
flag
.
BoolVar
(
&
StartRpc
,
"rpc"
,
true
,
"start rpc server"
)
flag
.
BoolVar
(
&
StartRpc
,
"rpc"
,
true
,
"start rpc server"
)
flag
.
BoolVar
(
&
StartWebSockets
,
"ws"
,
false
,
"start websocket server"
)
flag
.
BoolVar
(
&
StartWebSockets
,
"ws"
,
false
,
"start websocket server"
)
...
...
cmd/utils/cmd.go
浏览文件 @
d00e2731
...
@@ -205,7 +205,7 @@ func StartWebSockets(eth *eth.Ethereum, wsPort int) {
...
@@ -205,7 +205,7 @@ func StartWebSockets(eth *eth.Ethereum, wsPort int) {
clilogger
.
Infoln
(
"Starting WebSockets"
)
clilogger
.
Infoln
(
"Starting WebSockets"
)
var
err
error
var
err
error
eth
.
WsServer
,
err
=
rpcws
.
NewWebSocketServer
(
eth
,
wsPort
)
eth
.
WsServer
,
err
=
rpcws
.
NewWebSocketServer
(
xeth
.
New
(
eth
)
,
wsPort
)
if
err
!=
nil
{
if
err
!=
nil
{
clilogger
.
Errorf
(
"Could not start RPC interface (port %v): %v"
,
wsPort
,
err
)
clilogger
.
Errorf
(
"Could not start RPC interface (port %v): %v"
,
wsPort
,
err
)
}
else
{
}
else
{
...
...
rpc/http/server.go
浏览文件 @
d00e2731
...
@@ -84,6 +84,7 @@ func (s *RpcHttpServer) Start() {
...
@@ -84,6 +84,7 @@ func (s *RpcHttpServer) Start() {
}
}
func
(
s
*
RpcHttpServer
)
apiHandler
(
api
*
rpc
.
EthereumApi
)
http
.
Handler
{
func
(
s
*
RpcHttpServer
)
apiHandler
(
api
*
rpc
.
EthereumApi
)
http
.
Handler
{
var
jsonrpcver
string
=
"2.0"
fn
:=
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
fn
:=
func
(
w
http
.
ResponseWriter
,
req
*
http
.
Request
)
{
w
.
Header
()
.
Set
(
"Access-Control-Allow-Origin"
,
"*"
)
w
.
Header
()
.
Set
(
"Access-Control-Allow-Origin"
,
"*"
)
...
@@ -91,20 +92,22 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
...
@@ -91,20 +92,22 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler {
reqParsed
,
reqerr
:=
JSON
.
ParseRequestBody
(
req
)
reqParsed
,
reqerr
:=
JSON
.
ParseRequestBody
(
req
)
if
reqerr
!=
nil
{
if
reqerr
!=
nil
{
JSON
.
Send
(
w
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
true
,
ErrorText
:
rpc
.
ErrorParseRequest
})
jsonerr
:=
&
rpc
.
RpcErrorObject
{
-
32700
,
rpc
.
ErrorParseRequest
}
JSON
.
Send
(
w
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
nil
,
Error
:
jsonerr
})
return
return
}
}
var
response
interface
{}
var
response
interface
{}
reserr
:=
api
.
GetRequestReply
(
&
reqParsed
,
&
response
)
reserr
:=
api
.
GetRequestReply
(
&
reqParsed
,
&
response
)
if
reserr
!=
nil
{
if
reserr
!=
nil
{
rpchttplogger
.
Errorln
(
reserr
)
rpchttplogger
.
Warnln
(
reserr
)
JSON
.
Send
(
w
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
true
,
ErrorText
:
reserr
.
Error
()})
jsonerr
:=
&
rpc
.
RpcErrorObject
{
-
32603
,
reserr
.
Error
()}
JSON
.
Send
(
w
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
&
reqParsed
.
ID
,
Error
:
jsonerr
})
return
return
}
}
rpchttplogger
.
Debug
Detail
f
(
"Generated response: %T %s"
,
response
,
response
)
rpchttplogger
.
Debugf
(
"Generated response: %T %s"
,
response
,
response
)
JSON
.
Send
(
w
,
&
rpc
.
RpcSuccessResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
false
,
Result
:
response
})
JSON
.
Send
(
w
,
&
rpc
.
RpcSuccessResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
reqParsed
.
ID
,
Result
:
response
})
}
}
return
http
.
HandlerFunc
(
fn
)
return
http
.
HandlerFunc
(
fn
)
...
...
rpc/message.go
浏览文件 @
d00e2731
...
@@ -33,30 +33,29 @@ const (
...
@@ -33,30 +33,29 @@ const (
ErrorDecodeArgs
=
"Error: Could not decode arguments"
ErrorDecodeArgs
=
"Error: Could not decode arguments"
)
)
type
ErrorResponse
struct
{
type
RpcRequest
struct
{
Error
bool
`json:"error"`
JsonRpc
string
`json:"jsonrpc"`
ErrorText
string
`json:"errorText"`
ID
int
`json:"id"`
Method
string
`json:"method"`
Params
[]
json
.
RawMessage
`json:"params"`
}
}
type
RpcSuccessResponse
struct
{
type
RpcSuccessResponse
struct
{
ID
int
`json:"id"`
ID
int
`json:"id"`
JsonRpc
string
`json:"jsonrpc"`
JsonRpc
string
`json:"jsonrpc"`
Error
bool
`json:"error"`
Result
interface
{}
`json:"result"`
Result
interface
{}
`json:"result"`
}
}
type
RpcErrorResponse
struct
{
type
RpcErrorResponse
struct
{
ID
int
`json:"id"`
ID
*
int
`json:"id"`
JsonRpc
string
`json:"jsonrpc"`
JsonRpc
string
`json:"jsonrpc"`
Error
bool
`json:"error"`
Error
*
RpcErrorObject
`json:"error"`
ErrorText
string
`json:"errortext"`
}
}
type
RpcRequest
struct
{
type
RpcErrorObject
struct
{
JsonRpc
string
`json:"jsonrpc"`
Code
int
`json:"code"`
ID
int
`json:"id"`
Message
string
`json:"message"`
Method
string
`json:"method"`
// Data interface{} `json:"data"`
Params
[]
json
.
RawMessage
`json:"params"`
}
}
func
NewErrorResponse
(
msg
string
)
error
{
func
NewErrorResponse
(
msg
string
)
error
{
...
...
rpc/ws/server.go
浏览文件 @
d00e2731
...
@@ -22,35 +22,30 @@ import (
...
@@ -22,35 +22,30 @@ import (
"net/http"
"net/http"
"code.google.com/p/go.net/websocket"
"code.google.com/p/go.net/websocket"
"github.com/ethereum/go-ethereum/eth"
"github.com/ethereum/go-ethereum/event/filter"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/rpc"
"github.com/ethereum/go-ethereum/xeth"
"github.com/ethereum/go-ethereum/xeth"
)
)
var
wslogger
=
logger
.
NewLogger
(
"RPC-WS"
)
var
wslogger
=
logger
.
NewLogger
(
"RPC-WS"
)
var
JSON
rpc
.
JsonWrapper
type
WebSocketServer
struct
{
type
WebSocketServer
struct
{
eth
*
eth
.
Ethereum
pipe
*
xeth
.
XEth
filterManager
*
filter
.
FilterManager
port
int
port
int
doneCh
chan
bool
doneCh
chan
bool
listener
net
.
Listener
listener
net
.
Listener
}
}
func
NewWebSocketServer
(
eth
*
eth
.
Ethereum
,
port
int
)
(
*
WebSocketServer
,
error
)
{
func
NewWebSocketServer
(
pipe
*
xeth
.
XEth
,
port
int
)
(
*
WebSocketServer
,
error
)
{
sport
:=
fmt
.
Sprintf
(
":%d"
,
port
)
sport
:=
fmt
.
Sprintf
(
":%d"
,
port
)
l
,
err
:=
net
.
Listen
(
"tcp"
,
sport
)
l
,
err
:=
net
.
Listen
(
"tcp"
,
sport
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
filterManager
:=
filter
.
NewFilterManager
(
eth
.
EventMux
())
return
&
WebSocketServer
{
go
filterManager
.
Start
()
pipe
,
return
&
WebSocketServer
{
eth
,
filterManager
,
port
,
port
,
make
(
chan
bool
),
make
(
chan
bool
),
l
,
l
,
...
@@ -75,7 +70,7 @@ func (self *WebSocketServer) Start() {
...
@@ -75,7 +70,7 @@ func (self *WebSocketServer) Start() {
wslogger
.
Infof
(
"Starting RPC-WS server on port %d"
,
self
.
port
)
wslogger
.
Infof
(
"Starting RPC-WS server on port %d"
,
self
.
port
)
go
self
.
handlerLoop
()
go
self
.
handlerLoop
()
api
:=
rpc
.
NewEthereumApi
(
xeth
.
New
(
self
.
eth
)
)
api
:=
rpc
.
NewEthereumApi
(
self
.
pipe
)
h
:=
self
.
apiHandler
(
api
)
h
:=
self
.
apiHandler
(
api
)
http
.
Handle
(
"/ws"
,
h
)
http
.
Handle
(
"/ws"
,
h
)
...
@@ -96,27 +91,29 @@ func (s *WebSocketServer) apiHandler(api *rpc.EthereumApi) http.Handler {
...
@@ -96,27 +91,29 @@ func (s *WebSocketServer) apiHandler(api *rpc.EthereumApi) http.Handler {
}
}
func
sockHandler
(
api
*
rpc
.
EthereumApi
)
websocket
.
Handler
{
func
sockHandler
(
api
*
rpc
.
EthereumApi
)
websocket
.
Handler
{
var
jsonrpcver
string
=
"2.0"
fn
:=
func
(
conn
*
websocket
.
Conn
)
{
fn
:=
func
(
conn
*
websocket
.
Conn
)
{
for
{
for
{
wslogger
.
Debugln
(
"Handling request"
)
wslogger
.
Debugln
(
"Handling request"
)
var
reqParsed
rpc
.
RpcRequest
var
reqParsed
rpc
.
RpcRequest
if
err
:=
websocket
.
JSON
.
Receive
(
conn
,
&
reqParsed
);
err
!=
nil
{
if
err
:=
websocket
.
JSON
.
Receive
(
conn
,
&
reqParsed
);
err
!=
nil
{
wslogger
.
Debugln
(
rpc
.
ErrorParseRequest
)
jsonerr
:=
&
rpc
.
RpcErrorObject
{
-
32700
,
rpc
.
ErrorParseRequest
}
websocket
.
JSON
.
Send
(
conn
,
rpc
.
RpcErrorResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
true
,
ErrorText
:
rpc
.
ErrorParseRequest
})
JSON
.
Send
(
conn
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
nil
,
Error
:
jsonerr
})
continue
continue
}
}
var
response
interface
{}
var
response
interface
{}
reserr
:=
api
.
GetRequestReply
(
&
reqParsed
,
&
response
)
reserr
:=
api
.
GetRequestReply
(
&
reqParsed
,
&
response
)
if
reserr
!=
nil
{
if
reserr
!=
nil
{
wslogger
.
Errorln
(
reserr
)
wslogger
.
Warnln
(
reserr
)
websocket
.
JSON
.
Send
(
conn
,
rpc
.
RpcErrorResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
true
,
ErrorText
:
reserr
.
Error
()})
jsonerr
:=
&
rpc
.
RpcErrorObject
{
-
32603
,
reserr
.
Error
()}
JSON
.
Send
(
conn
,
&
rpc
.
RpcErrorResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
&
reqParsed
.
ID
,
Error
:
jsonerr
})
continue
continue
}
}
wslogger
.
Debugf
(
"Generated response: %T %s"
,
response
,
response
)
wslogger
.
Debugf
(
"Generated response: %T %s"
,
response
,
response
)
websocket
.
JSON
.
Send
(
conn
,
rpc
.
RpcSuccessResponse
{
JsonRpc
:
reqParsed
.
JsonRpc
,
ID
:
reqParsed
.
ID
,
Error
:
false
,
Result
:
response
})
JSON
.
Send
(
conn
,
&
rpc
.
RpcSuccessResponse
{
JsonRpc
:
jsonrpcver
,
ID
:
reqParsed
.
ID
,
Result
:
response
})
}
}
}
}
return
websocket
.
Handler
(
fn
)
return
websocket
.
Handler
(
fn
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录