Merge branch 'develop' of https://github.com/tendermint/tendermint into develop

Conflicts:
	p2p/peer.go
	rpc/core/net.go
	rpc/core/types/responses.go
This commit is contained in:
Ethan Buchman
2015-04-21 02:00:58 -07:00
29 changed files with 375 additions and 114 deletions
@@ -1,12 +1,11 @@
package core
import (
"github.com/tendermint/tendermint/binary"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
sm "github.com/tendermint/tendermint/state"
)
//-----------------------------------------------------------------------------
func ListValidators() (*ctypes.ResponseListValidators, error) {
var blockHeight uint
var bondedValidators []*sm.Validator
@@ -25,3 +24,8 @@ func ListValidators() (*ctypes.ResponseListValidators, error) {
return &ctypes.ResponseListValidators{blockHeight, bondedValidators, unbondingValidators}, nil
}
func DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) {
jsonBytes := binary.JSONBytes(consensusState.GetRoundState())
return &ctypes.ResponseDumpConsensusState{string(jsonBytes)}, nil
}
-1
View File
@@ -2,7 +2,6 @@ package core
import (
"fmt"
. "github.com/tendermint/tendermint/common"
ctypes "github.com/tendermint/tendermint/rpc/core/types"
"github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/types"
+1 -4
View File
@@ -42,11 +42,8 @@ func NetInfo() (*ctypes.ResponseNetInfo, error) {
peers := []ctypes.Peer{}
for _, peer := range p2pSwitch.Peers().List() {
peers = append(peers, ctypes.Peer{
//Address: peer.Connection().RemoteAddress.String(),
Host: peer.Nodeinfo.Host,
NodeInfo: *peer.NodeInfo,
IsOutbound: peer.IsOutbound(),
P2PPort: peer.Nodeinfo.P2PPort,
RPCPort: peer.Nodeinfo.RPCPort,
})
}
return &ctypes.ResponseNetInfo{
+1
View File
@@ -14,6 +14,7 @@ var Routes = map[string]*rpc.RPCFunc{
"call": rpc.NewRPCFunc(Call, []string{"address", "data"}),
"call_code": rpc.NewRPCFunc(CallCode, []string{"code", "data"}),
"list_validators": rpc.NewRPCFunc(ListValidators, []string{}),
"dump_consensus_state": rpc.NewRPCFunc(DumpConsensusState, []string{}),
"dump_storage": rpc.NewRPCFunc(DumpStorage, []string{"address"}),
"broadcast_tx": rpc.NewRPCFunc(BroadcastTx, []string{"tx"}),
"list_accounts": rpc.NewRPCFunc(ListAccounts, []string{}),
+5 -3
View File
@@ -78,9 +78,7 @@ type ResponseNetInfo struct {
}
type Peer struct {
Host string // ip
P2PPort uint16
RPCPort uint16
types.NodeInfo
IsOutbound bool
}
@@ -93,3 +91,7 @@ type ResponseListValidators struct {
BondedValidators []*sm.Validator
UnbondingValidators []*sm.Validator
}
type ResponseDumpConsensusState struct {
ConsensusState string
}
+58
View File
@@ -18,6 +18,7 @@ type Client interface {
BroadcastTx(tx types.Tx) (*ctypes.ResponseBroadcastTx, error)
Call(address []byte, data []byte) (*ctypes.ResponseCall, error)
CallCode(code []byte, data []byte) (*ctypes.ResponseCall, error)
DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error)
DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error)
GenPrivAccount() (*ctypes.ResponseGenPrivAccount, error)
GetAccount(address []byte) (*ctypes.ResponseGetAccount, error)
@@ -150,6 +151,36 @@ func (c *ClientHTTP) CallCode(code []byte, data []byte) (*ctypes.ResponseCall, e
return response.Result, nil
}
func (c *ClientHTTP) DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) {
values, err := argsToURLValues(nil)
if err != nil {
return nil, err
}
resp, err := http.PostForm(c.addr+reverseFuncMap["DumpConsensusState"], values)
if err != nil {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return nil, err
}
var response struct {
Result *ctypes.ResponseDumpConsensusState `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientHTTP) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error) {
values, err := argsToURLValues([]string{"address"}, address)
if err != nil {
@@ -558,6 +589,33 @@ func (c *ClientJSON) CallCode(code []byte, data []byte) (*ctypes.ResponseCall, e
return response.Result, nil
}
func (c *ClientJSON) DumpConsensusState() (*ctypes.ResponseDumpConsensusState, error) {
request := rpc.RPCRequest{
JSONRPC: "2.0",
Method: reverseFuncMap["DumpConsensusState"],
Params: []interface{}{},
Id: 0,
}
body, err := c.RequestResponse(request)
if err != nil {
return nil, err
}
var response struct {
Result *ctypes.ResponseDumpConsensusState `json:"result"`
Error string `json:"error"`
Id string `json:"id"`
JSONRPC string `json:"jsonrpc"`
}
binary.ReadJSON(&response, body, &err)
if err != nil {
return nil, err
}
if response.Error != "" {
return nil, fmt.Errorf(response.Error)
}
return response.Result, nil
}
func (c *ClientJSON) DumpStorage(address []byte) (*ctypes.ResponseDumpStorage, error) {
request := rpc.RPCRequest{
JSONRPC: "2.0",
+9 -6
View File
@@ -13,16 +13,19 @@ import (
"github.com/tendermint/tendermint/alert"
"github.com/tendermint/tendermint/binary"
. "github.com/tendermint/tendermint/common"
"github.com/tendermint/tendermint/p2p"
)
func StartHTTPServer(listenAddr string, handler http.Handler) {
log.Info(Fmt("Starting RPC HTTP server on %s", listenAddr))
go func() {
res := http.ListenAndServe(
listenAddr,
listener := p2p.NewDefaultListener("tcp", listenAddr, false)
netListener := listener.(*p2p.DefaultListener).NetListener()
res := http.Serve(
netListener,
RecoverAndLogHandler(handler),
)
log.Crit("RPC HTTPServer stopped", "result", res)
log.Crit("RPC HTTP server stopped", "result", res)
}()
}
@@ -30,7 +33,7 @@ func WriteRPCResponse(w http.ResponseWriter, res RPCResponse) {
buf, n, err := new(bytes.Buffer), new(int64), new(error)
binary.WriteJSON(res, buf, n, err)
if *err != nil {
log.Warn("Failed to write JSON RPCResponse", "error", err)
log.Warn("Failed to write RPC response", "error", err)
}
w.Header().Set("Content-Type", "application/json")
@@ -67,7 +70,7 @@ func RecoverAndLogHandler(handler http.Handler) http.Handler {
WriteRPCResponse(rww, res)
} else {
// For the rest,
log.Error("Panic in HTTP handler", "error", e, "stack", string(debug.Stack()))
log.Error("Panic in RPC HTTP handler", "error", e, "stack", string(debug.Stack()))
rww.WriteHeader(http.StatusInternalServerError)
WriteRPCResponse(rww, NewRPCResponse(nil, Fmt("Internal Server Error: %v", e)))
}
@@ -78,7 +81,7 @@ func RecoverAndLogHandler(handler http.Handler) http.Handler {
if rww.Status == -1 {
rww.Status = 200
}
log.Debug("Served HTTP response",
log.Debug("Served RPC HTTP response",
"method", r.Method, "url", r.URL,
"status", rww.Status, "duration", durationMS,
"remoteAddr", r.RemoteAddr,