Skip to content

Commit

Permalink
Merge pull request #9 from filecoin-project/feat/netcli
Browse files Browse the repository at this point in the history
Network CLI
  • Loading branch information
whyrusleeping authored Jul 9, 2019
2 parents 8474e34 + 9960be9 commit 0a1d697
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion jsonrpc/rpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@ import (
"encoding/json"
"errors"
"fmt"
"io/ioutil"
"net/http"
"reflect"
"sync/atomic"

logging "github.com/ipfs/go-log"
)

var log = logging.Logger("rpc")

const clientDebug = true

var (
errorType = reflect.TypeOf(new(error)).Elem()
contextType = reflect.TypeOf(new(context.Context)).Elem()
Expand All @@ -33,7 +40,9 @@ func (e *ErrClient) Unwrap(err error) error {
type result reflect.Value

func (r *result) UnmarshalJSON(raw []byte) error {
return json.Unmarshal(raw, reflect.Value(*r).Interface())
err := json.Unmarshal(raw, reflect.Value(*r).Interface())
log.Debugw("rpc unmarshal response", "raw", string(raw), "err", err)
return err
}

type clientResponse struct {
Expand Down Expand Up @@ -148,8 +157,23 @@ func NewClient(addr string, namespace string, handler interface{}) ClientCloser

// process response

if clientDebug {
rsp, err := ioutil.ReadAll(httpResp.Body)
if err != nil {
return processError(err)
}
if err := httpResp.Body.Close(); err != nil {
return processError(err)
}

log.Debugw("rpc response", "body", string(rsp))

httpResp.Body = ioutil.NopCloser(bytes.NewReader(rsp))
}

var resp clientResponse
if valOut != -1 {
log.Debugw("rpc result", "type", ftyp.Out(valOut))
resp.Result = result(reflect.New(ftyp.Out(valOut)))
}

Expand Down

0 comments on commit 0a1d697

Please sign in to comment.