aboutsummaryrefslogtreecommitdiffstats
path: root/rpc/comms/ipc.go
diff options
context:
space:
mode:
authorBas van Kervel <bas@ethdev.com>2015-06-19 00:23:13 +0800
committerBas van Kervel <bas@ethdev.com>2015-06-22 15:17:09 +0800
commitf20256377731097c9478ede750efffd46d83b494 (patch)
tree25ea2b0de5382ed25dde5ff2021214625f3e9865 /rpc/comms/ipc.go
parent36a6b16a3bec15131318ebed1c8c2f9204a5a328 (diff)
downloadgo-tangerine-f20256377731097c9478ede750efffd46d83b494.tar.gz
go-tangerine-f20256377731097c9478ede750efffd46d83b494.tar.zst
go-tangerine-f20256377731097c9478ede750efffd46d83b494.zip
added attach over ipc command
Diffstat (limited to 'rpc/comms/ipc.go')
-rw-r--r--rpc/comms/ipc.go68
1 files changed, 64 insertions, 4 deletions
diff --git a/rpc/comms/ipc.go b/rpc/comms/ipc.go
index a07203803..7e7375eaf 100644
--- a/rpc/comms/ipc.go
+++ b/rpc/comms/ipc.go
@@ -1,8 +1,13 @@
package comms
import (
+ "fmt"
+ "net"
+
"github.com/ethereum/go-ethereum/rpc/api"
"github.com/ethereum/go-ethereum/rpc/codec"
+ "github.com/ethereum/go-ethereum/rpc/shared"
+ "encoding/json"
)
type IpcConfig struct {
@@ -10,19 +15,74 @@ type IpcConfig struct {
}
type ipcClient struct {
- codec codec.ApiCoder
+ endpoint string
+ codec codec.Codec
+ coder codec.ApiCoder
}
func (self *ipcClient) Close() {
- self.codec.Close()
+ self.coder.Close()
}
func (self *ipcClient) Send(req interface{}) error {
- return self.codec.WriteResponse(req)
+ var err error
+ if r, ok := req.(*shared.Request); ok {
+ if err = self.coder.WriteResponse(r); err != nil {
+ if _, ok := err.(*net.OpError); ok { // connection lost, retry once
+ if err = self.reconnect(); err == nil {
+ err = self.coder.WriteResponse(r)
+ }
+ }
+ }
+ return err
+ }
+
+ return fmt.Errorf("Invalid request (%T)", req)
}
func (self *ipcClient) Recv() (interface{}, error) {
- return self.codec.ReadResponse()
+ res, err := self.coder.ReadResponse()
+ if err != nil {
+ return nil, err
+ }
+
+ if r, ok := res.(shared.SuccessResponse); ok {
+ return r.Result, nil
+ }
+
+ if r, ok := res.(shared.ErrorResponse); ok {
+ return r.Error, nil
+ }
+
+ return res, err
+}
+
+func (self *ipcClient) SupportedModules() (map[string]string, error) {
+ req := shared.Request{
+ Id: 1,
+ Jsonrpc: "2.0",
+ Method: "modules",
+ }
+
+ if err := self.coder.WriteResponse(req); err != nil {
+ return nil, err
+ }
+
+ res, err := self.coder.ReadResponse()
+ if err != nil {
+ return nil, err
+ }
+
+ if sucRes, ok := res.(shared.SuccessResponse); ok {
+ data, _ := json.Marshal(sucRes.Result)
+ modules := make(map[string]string)
+ err = json.Unmarshal(data, &modules)
+ if err == nil {
+ return modules, nil
+ }
+ }
+
+ return nil, fmt.Errorf("Invalid response")
}
// Create a new IPC client, UNIX domain socket on posix, named pipe on Windows