diff options
author | Bas van Kervel <bas@ethdev.com> | 2015-10-15 22:07:19 +0800 |
---|---|---|
committer | Bas van Kervel <bas@ethdev.com> | 2015-12-14 23:34:05 +0800 |
commit | eae81465c1c815c317cd30e4de6bdf4d59df2340 (patch) | |
tree | b6f4b7787967a58416171adb79fd12ac29d89577 /rpc/comms | |
parent | 8db9d44ca9fb6baf406256cae491c475de2f4989 (diff) | |
download | dexon-eae81465c1c815c317cd30e4de6bdf4d59df2340.tar.gz dexon-eae81465c1c815c317cd30e4de6bdf4d59df2340.tar.zst dexon-eae81465c1c815c317cd30e4de6bdf4d59df2340.zip |
rpc: new RPC implementation with pub/sub support
Diffstat (limited to 'rpc/comms')
-rw-r--r-- | rpc/comms/ipc.go | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/rpc/comms/ipc.go b/rpc/comms/ipc.go index 882d62ab4..3ba747b1d 100644 --- a/rpc/comms/ipc.go +++ b/rpc/comms/ipc.go @@ -69,13 +69,28 @@ func (self *ipcClient) SupportedModules() (map[string]string, error) { req := shared.Request{ Id: 1, Jsonrpc: "2.0", - Method: "modules", + Method: "rpc_modules", } if err := self.coder.WriteResponse(req); err != nil { return nil, err } + res, _ := self.coder.ReadResponse() + if sucRes, ok := res.(*shared.SuccessResponse); ok { + data, _ := json.Marshal(sucRes.Result) + modules := make(map[string]string) + if err := json.Unmarshal(data, &modules); err == nil { + return modules, nil + } + } + + // old version uses modules instead of rpc_modules, this can be removed after full migration + req.Method = "modules" + if err := self.coder.WriteResponse(req); err != nil { + return nil, err + } + res, err := self.coder.ReadResponse() if err != nil { return nil, err @@ -108,6 +123,11 @@ func StartIpc(cfg IpcConfig, codec codec.Codec, initializer InitFunc) error { return nil } +// CreateListener creates an listener, on Unix platforms this is a unix socket, on Windows this is a named pipe +func CreateListener(cfg IpcConfig) (net.Listener, error) { + return ipcListen(cfg) +} + func ipcLoop(cfg IpcConfig, codec codec.Codec, initializer InitFunc, l net.Listener) { glog.V(logger.Info).Infof("IPC service started (%s)\n", cfg.Endpoint) defer os.Remove(cfg.Endpoint) |