From 19bb08defa27335487eb7d84a8832fb3e7dd5c0a Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Sun, 2 Jun 2019 21:40:52 +0100 Subject: [PATCH] Move problematic ipc code that caused Mesh not to compile for Linux amd64 out of rpc package --- cmd/clef/main.go | 2 +- node/node.go | 2 +- rpc/client.go | 4 ++-- rpc/endpoints.go | 19 ------------------- rpc/endpoints/endpoints.go | 27 +++++++++++++++++++++++++++ rpc/ipc.go | 31 +++++++++++++++---------------- swarm/swarm_test.go | 4 ++-- 7 files changed, 48 insertions(+), 41 deletions(-) create mode 100644 rpc/endpoints/endpoints.go diff --git a/cmd/clef/main.go b/cmd/clef/main.go index fecfcafaff..58c66c1a94 100644 --- a/cmd/clef/main.go +++ b/cmd/clef/main.go @@ -475,7 +475,7 @@ func signer(c *cli.Context) error { ipcapiURL = filepath.Join(configDir, "clef.ipc") } - listener, _, err := rpc.StartIPCEndpoint(ipcapiURL, rpcAPI) + listener, _, err := endpoints.StartIPCEndpoint(ipcapiURL, rpcAPI) if err != nil { utils.Fatalf("Could not start IPC api: %v", err) } diff --git a/node/node.go b/node/node.go index 78bb492f00..abe0978b4c 100644 --- a/node/node.go +++ b/node/node.go @@ -335,7 +335,7 @@ func (n *Node) startIPC(apis []rpc.API) error { if n.ipcEndpoint == "" { return nil // IPC disabled. } - listener, handler, err := rpc.StartIPCEndpoint(n.ipcEndpoint, apis) + listener, handler, err := endpoints.StartIPCEndpoint(n.ipcEndpoint, apis) if err != nil { return err } diff --git a/rpc/client.go b/rpc/client.go index 02029dc8f6..614bfc7de1 100644 --- a/rpc/client.go +++ b/rpc/client.go @@ -177,8 +177,8 @@ func DialContext(ctx context.Context, rawurl string) (*Client, error) { return DialWebsocket(ctx, rawurl, "") case "stdio": return DialStdIO(ctx) - case "": - return DialIPC(ctx, rawurl) + // case "": + // return DialIPC(ctx, rawurl) default: return nil, fmt.Errorf("no known transport for URL scheme %q", u.Scheme) } diff --git a/rpc/endpoints.go b/rpc/endpoints.go index 8ca6d4eb0c..2f82836f3a 100644 --- a/rpc/endpoints.go +++ b/rpc/endpoints.go @@ -81,22 +81,3 @@ func StartWSEndpoint(endpoint string, apis []API, modules []string, wsOrigins [] return listener, handler, err } - -// StartIPCEndpoint starts an IPC endpoint. -func StartIPCEndpoint(ipcEndpoint string, apis []API) (net.Listener, *Server, error) { - // Register all the APIs exposed by the services. - handler := NewServer() - for _, api := range apis { - if err := handler.RegisterName(api.Namespace, api.Service); err != nil { - return nil, nil, err - } - log.Debug("IPC registered", "namespace", api.Namespace) - } - // All APIs registered, start the IPC listener. - listener, err := ipcListen(ipcEndpoint) - if err != nil { - return nil, nil, err - } - go handler.ServeListener(listener) - return listener, handler, nil -} diff --git a/rpc/endpoints/endpoints.go b/rpc/endpoints/endpoints.go new file mode 100644 index 0000000000..25ab26fa7a --- /dev/null +++ b/rpc/endpoints/endpoints.go @@ -0,0 +1,27 @@ +package endpoints + +import ( + "net" + + "github.com/0xProject/go-ethereum/rpc" + "github.com/ethereum/go-ethereum/log" +) + +// StartIPCEndpoint starts an IPC endpoint. +func StartIPCEndpoint(ipcEndpoint string, apis []rpc.API) (net.Listener, *rpc.Server, error) { + // Register all the APIs exposed by the services. + handler := rpc.NewServer() + for _, api := range apis { + if err := handler.RegisterName(api.Namespace, api.Service); err != nil { + return nil, nil, err + } + log.Debug("IPC registered", "namespace", api.Namespace) + } + // All APIs registered, start the IPC listener. + listener, err := ipcListen(ipcEndpoint) + if err != nil { + return nil, nil, err + } + go handler.ServeListener(listener) + return listener, handler, nil +} diff --git a/rpc/ipc.go b/rpc/ipc.go index ad8ce03098..1a6ee7bb1d 100644 --- a/rpc/ipc.go +++ b/rpc/ipc.go @@ -17,7 +17,6 @@ package rpc import ( - "context" "net" "github.com/ethereum/go-ethereum/log" @@ -39,18 +38,18 @@ func (s *Server) ServeListener(l net.Listener) error { } } -// DialIPC create a new IPC client that connects to the given endpoint. On Unix it assumes -// the endpoint is the full path to a unix socket, and Windows the endpoint is an -// identifier for a named pipe. -// -// The context is used for the initial connection establishment. It does not -// affect subsequent interactions with the client. -func DialIPC(ctx context.Context, endpoint string) (*Client, error) { - return newClient(ctx, func(ctx context.Context) (ServerCodec, error) { - conn, err := newIPCConnection(ctx, endpoint) - if err != nil { - return nil, err - } - return NewJSONCodec(conn), err - }) -} +// // DialIPC create a new IPC client that connects to the given endpoint. On Unix it assumes +// // the endpoint is the full path to a unix socket, and Windows the endpoint is an +// // identifier for a named pipe. +// // +// // The context is used for the initial connection establishment. It does not +// // affect subsequent interactions with the client. +// func DialIPC(ctx context.Context, endpoint string) (*Client, error) { +// return newClient(ctx, func(ctx context.Context) (ServerCodec, error) { +// conn, err := newIPCConnection(ctx, endpoint) +// if err != nil { +// return nil, err +// } +// return NewJSONCodec(conn), err +// }) +// } diff --git a/swarm/swarm_test.go b/swarm/swarm_test.go index 2a5b28513a..65a44c727e 100644 --- a/swarm/swarm_test.go +++ b/swarm/swarm_test.go @@ -28,9 +28,9 @@ import ( "testing" "time" + "github.com/0xProject/go-ethereum/rpc/endpoints" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/swarm/api" ) @@ -52,7 +52,7 @@ func TestNewSwarm(t *testing.T) { ipcEndpoint = `\\.\pipe\TestSwarm-` + hex.EncodeToString(b) } - _, server, err := rpc.StartIPCEndpoint(ipcEndpoint, nil) + _, server, err := endpoints.StartIPCEndpoint(ipcEndpoint, nil) if err != nil { t.Error(err) }