Set ipc channel as user agent client

pull/1710/head
Bas van Kervel 9 years ago
parent d51d0022ce
commit d910148a96
  1. 10
      rpc/comms/ipc.go
  2. 23
      rpc/comms/ipc_unix.go
  3. 23
      rpc/comms/ipc_windows.go
  4. 10
      rpc/jeth.go

@ -42,17 +42,13 @@ func (self *ipcClient) Close() {
self.coder.Close()
}
func (self *ipcClient) Send(req interface{}) error {
func (self *ipcClient) Send(msg interface{}) error {
var err error
if r, ok := req.(*shared.Request); ok {
if err = self.coder.WriteResponse(r); err != nil {
if err = self.coder.WriteResponse(msg); err != nil {
if err = self.reconnect(); err == nil {
err = self.coder.WriteResponse(r)
err = self.coder.WriteResponse(msg)
}
}
return err
}
return err
}

@ -26,6 +26,7 @@ import (
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/rpc/useragent"
)
func newIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) {
@ -34,7 +35,18 @@ func newIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) {
return nil, err
}
return &ipcClient{cfg.Endpoint, c, codec, codec.New(c)}, nil
coder := codec.New(c)
msg := shared.Request{
Id: 0,
Method: useragent.EnableUserAgentMethod,
Jsonrpc: shared.JsonRpcVersion,
Params: []byte("[]"),
}
coder.WriteResponse(msg)
coder.Recv()
return &ipcClient{cfg.Endpoint, c, codec, coder}, nil
}
func (self *ipcClient) reconnect() error {
@ -42,6 +54,15 @@ func (self *ipcClient) reconnect() error {
c, err := net.DialUnix("unix", nil, &net.UnixAddr{self.endpoint, "unix"})
if err == nil {
self.coder = self.codec.New(c)
msg := shared.Request{
Id: 0,
Method: useragent.EnableUserAgentMethod,
Jsonrpc: shared.JsonRpcVersion,
Params: []byte("[]"),
}
self.coder.WriteResponse(msg)
self.coder.Recv()
}
return err

@ -32,6 +32,7 @@ import (
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/rpc/codec"
"github.com/ethereum/go-ethereum/rpc/shared"
"github.com/ethereum/go-ethereum/rpc/useragent"
)
var (
@ -656,13 +657,33 @@ func newIpcClient(cfg IpcConfig, codec codec.Codec) (*ipcClient, error) {
return nil, err
}
return &ipcClient{cfg.Endpoint, c, codec, codec.New(c)}, nil
coder := codec.New(c)
msg := shared.Request{
Id: 0,
Method: useragent.EnableUserAgentMethod,
Jsonrpc: shared.JsonRpcVersion,
Params: []byte("[]"),
}
coder.WriteResponse(msg)
coder.Recv()
return &ipcClient{cfg.Endpoint, c, codec, coder}, nil
}
func (self *ipcClient) reconnect() error {
c, err := Dial(self.endpoint)
if err == nil {
self.coder = self.codec.New(c)
req := shared.Request{
Id: 0,
Method: useragent.EnableUserAgentMethod,
Jsonrpc: shared.JsonRpcVersion,
Params: []byte("[]"),
}
self.coder.WriteResponse(req)
self.coder.Recv()
}
return err
}

@ -40,16 +40,6 @@ type Jeth struct {
}
func NewJeth(ethApi shared.EthereumApi, re *jsre.JSRE, client comms.EthereumClient, fe xeth.Frontend) *Jeth {
// enable the jeth as the user agent
req := shared.Request{
Id: 0,
Method: useragent.EnableUserAgentMethod,
Jsonrpc: shared.JsonRpcVersion,
Params: []byte("[]"),
}
client.Send(&req)
client.Recv()
return &Jeth{ethApi, re, client, fe}
}

Loading…
Cancel
Save