Skip to content

Commit

Permalink
Removed IPC
Browse files Browse the repository at this point in the history
  • Loading branch information
gameofpointers authored and wizeguyy committed Jan 25, 2023
1 parent 15abe41 commit 1a71465
Show file tree
Hide file tree
Showing 14 changed files with 3 additions and 386 deletions.
1 change: 0 additions & 1 deletion cmd/go-quai/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@ func defaultNodeConfig() node.Config {
cfg.Version = params.VersionWithCommit(gitCommit, gitDate)
cfg.HTTPModules = append(cfg.HTTPModules, "eth")
cfg.WSModules = append(cfg.WSModules, "eth")
cfg.IPCPath = "quai.ipc"
return cfg
}

Expand Down
4 changes: 1 addition & 3 deletions cmd/go-quai/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,6 @@ var (
utils.WSApiFlag,
utils.WSAllowedOriginsFlag,
utils.WSPathPrefixFlag,
utils.IPCDisabledFlag,
utils.IPCPathFlag,
utils.InsecureUnlockAllowedFlag,
utils.RPCGlobalGasCapFlag,
utils.RPCGlobalTxFeeCapFlag,
Expand Down Expand Up @@ -293,7 +291,7 @@ func quai(ctx *cli.Context) error {
}

// startNode boots up the system node and all registered protocols, after which
// it unlocks any requested accounts, and starts the RPC/IPC interfaces and the
// it unlocks any requested accounts, and starts the RPC interfaces and the
// miner.
func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend) {
debug.Memsize.Add("node", stack)
Expand Down
2 changes: 0 additions & 2 deletions cmd/go-quai/usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ var AppHelpFlagGroups = []flags.FlagGroup{
{
Name: "API AND CONSOLE",
Flags: []cli.Flag{
utils.IPCDisabledFlag,
utils.IPCPathFlag,
utils.HTTPEnabledFlag,
utils.HTTPListenAddrFlag,
utils.HTTPPortFlag,
Expand Down
21 changes: 0 additions & 21 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,14 +427,6 @@ var (
Usage: "Disables db compaction after import",
}
// RPC settings
IPCDisabledFlag = cli.BoolFlag{
Name: "ipcdisable",
Usage: "Disable the IPC-RPC server",
}
IPCPathFlag = DirectoryFlag{
Name: "ipcpath",
Usage: "Filename for IPC socket/pipe within the datadir (explicit paths escape it)",
}
HTTPEnabledFlag = cli.BoolFlag{
Name: "http",
Usage: "Enable the HTTP-RPC server",
Expand Down Expand Up @@ -959,18 +951,6 @@ func makeSubUrls(ctx *cli.Context) []string {
return strings.Split(ctx.GlobalString(SubUrls.Name), ",")
}

// setIPC creates an IPC path configuration from the set command line flags,
// returning an empty string if IPC was explicitly disabled, or the set path.
func setIPC(ctx *cli.Context, cfg *node.Config) {
CheckExclusive(ctx, IPCDisabledFlag, IPCPathFlag)
switch {
case ctx.GlobalBool(IPCDisabledFlag.Name):
cfg.IPCPath = ""
case ctx.GlobalIsSet(IPCPathFlag.Name):
cfg.IPCPath = ctx.GlobalString(IPCPathFlag.Name)
}
}

// MakeDatabaseHandles raises out the number of allowed file handles per process
// for Geth and returns half of the allowance to assign to the database.
func MakeDatabaseHandles() int {
Expand Down Expand Up @@ -1099,7 +1079,6 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
// SetNodeConfig applies node-related command line flags to the config.
func SetNodeConfig(ctx *cli.Context, cfg *node.Config) {
SetP2PConfig(ctx, &cfg.P2P)
setIPC(ctx, cfg)
setHTTP(ctx, cfg)
setWS(ctx, cfg)
setNodeUserIdent(ctx, cfg)
Expand Down
43 changes: 0 additions & 43 deletions node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ type Config struct {
// USB enables hardware wallet monitoring and connectivity.
USB bool `toml:",omitempty"`

// IPCPath is the requested location to place the IPC endpoint. If the path is
// a simple file name, it is placed inside the data directory (or on the root
// pipe path on Windows), whereas if it's a resolvable path name (absolute or
// relative), then that specific path is enforced. An empty path disables IPC.
IPCPath string

// HTTPHost is the host interface on which to start the HTTP RPC server. If this
// field is empty, no HTTP API endpoint will be started.
HTTPHost string
Expand Down Expand Up @@ -177,31 +171,6 @@ type Config struct {
AllowUnprotectedTxs bool `toml:",omitempty"`
}

// IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
// account the set data folders as well as the designated platform we're currently
// running on.
func (c *Config) IPCEndpoint() string {
// Short circuit if IPC has not been enabled
if c.IPCPath == "" {
return ""
}
// On windows we can only use plain top-level pipes
if runtime.GOOS == "windows" {
if strings.HasPrefix(c.IPCPath, `\\.\pipe\`) {
return c.IPCPath
}
return `\\.\pipe\` + c.IPCPath
}
// Resolve names into the data directory full paths otherwise
if filepath.Base(c.IPCPath) == c.IPCPath {
if c.DataDir == "" {
return filepath.Join(os.TempDir(), c.IPCPath)
}
return filepath.Join(c.DataDir, c.IPCPath)
}
return c.IPCPath
}

// NodeDB returns the path to the discovery node database.
func (c *Config) NodeDB() string {
if c.DataDir == "" {
Expand All @@ -210,18 +179,6 @@ func (c *Config) NodeDB() string {
return c.ResolvePath(datadirNodeDatabase)
}

// DefaultIPCEndpoint returns the IPC path used by default.
func DefaultIPCEndpoint(clientIdentifier string) string {
if clientIdentifier == "" {
clientIdentifier = strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
if clientIdentifier == "" {
panic("empty executable name")
}
}
config := &Config{DataDir: DefaultDataDir(), IPCPath: clientIdentifier + ".ipc"}
return config.IPCEndpoint()
}

// HTTPEndpoint resolves an HTTP endpoint based on the configured host interface
// and port parameters.
func (c *Config) HTTPEndpoint() string {
Expand Down
4 changes: 1 addition & 3 deletions node/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ devp2p network has a unique identifier, the node key. The Node instance persists
across restarts. Node also loads static and trusted node lists and ensures that knowledge
about other hosts is persisted.
JSON-RPC servers which run HTTP, WebSocket or IPC can be started on a Node. RPC modules
JSON-RPC servers which run HTTP, WebSocket can be started on a Node. RPC modules
offered by registered services will be offered on those endpoints. Users can restrict any
endpoint to a subset of RPC modules. Node itself offers the "debug", "admin" and "web3"
modules.
Expand Down Expand Up @@ -114,14 +114,12 @@ directory. Node instance A opens the database "db", node instance B opens the da
nodekey -- devp2p node key of instance A
nodes/ -- devp2p discovery knowledge database of instance A
db/ -- LevelDB content for "db"
A.ipc -- JSON-RPC UNIX domain socket endpoint of instance A
B/
nodekey -- devp2p node key of node B
nodes/ -- devp2p discovery knowledge database of instance B
static-nodes.json -- devp2p static node list of instance B
db/ -- LevelDB content for "db"
db-2/ -- LevelDB content for "db-2"
B.ipc -- JSON-RPC UNIX domain socket endpoint of instance B
keystore/ -- account key store, used by both instances
*/
package node
18 changes: 0 additions & 18 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ type Node struct {
rpcAPIs []rpc.API // List of APIs currently provided by the node
http *httpServer //
ws *httpServer //
ipc *ipcServer // Stores information about the ipc http server
inprocHandler *rpc.Server // In-process RPC request handler to process the API requests

databases map[*closeTrackingDB]struct{} // All open databases
Expand Down Expand Up @@ -91,9 +90,6 @@ func New(conf *Config) (*Node, error) {
if conf.Name == datadirDefaultKeyStore {
return nil, errors.New(`Config.Name cannot be "` + datadirDefaultKeyStore + `"`)
}
if strings.HasSuffix(conf.Name, ".ipc") {
return nil, errors.New(`Config.Name cannot end in ".ipc"`)
}

node := &Node{
config: conf,
Expand Down Expand Up @@ -146,7 +142,6 @@ func New(conf *Config) (*Node, error) {
// Configure RPC servers.
node.http = newHTTPServer(node.log, conf.HTTPTimeouts)
node.ws = newHTTPServer(node.log, rpc.DefaultHTTPTimeouts)
node.ipc = newIPCServer(node.log, conf.IPCEndpoint())

return node, nil
}
Expand Down Expand Up @@ -341,13 +336,6 @@ func (n *Node) startRPC() error {
return err
}

// Configure IPC.
if n.ipc.endpoint != "" {
if err := n.ipc.start(n.rpcAPIs); err != nil {
return err
}
}

// Configure HTTP.
if n.config.HTTPHost != "" {
config := httpConfig{
Expand Down Expand Up @@ -396,7 +384,6 @@ func (n *Node) wsServerForPort(port int) *httpServer {
func (n *Node) stopRPC() {
n.http.stop()
n.ws.stop()
n.ipc.stop()
n.stopInProc()
}

Expand Down Expand Up @@ -519,11 +506,6 @@ func (n *Node) AccountManager() *accounts.Manager {
return n.accman
}

// IPCEndpoint retrieves the current IPC endpoint used by the protocol stack.
func (n *Node) IPCEndpoint() string {
return n.ipc.endpoint
}

// HTTPEndpoint returns the URL of the HTTP server. Note that this URL does not
// contain the JSON-RPC path prefix set by HTTPPathPrefix.
func (n *Node) HTTPEndpoint() string {
Expand Down
45 changes: 0 additions & 45 deletions node/rpcstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -470,51 +470,6 @@ func newGzipHandler(next http.Handler) http.Handler {
})
}

type ipcServer struct {
log log.Logger
endpoint string

mu sync.Mutex
listener net.Listener
srv *rpc.Server
}

func newIPCServer(log log.Logger, endpoint string) *ipcServer {
return &ipcServer{log: log, endpoint: endpoint}
}

// Start starts the httpServer's http.Server
func (is *ipcServer) start(apis []rpc.API) error {
is.mu.Lock()
defer is.mu.Unlock()

if is.listener != nil {
return nil // already running
}
listener, srv, err := rpc.StartIPCEndpoint(is.endpoint, apis)
if err != nil {
is.log.Warn("IPC opening failed", "url", is.endpoint, "error", err)
return err
}
is.log.Info("IPC endpoint opened", "url", is.endpoint)
is.listener, is.srv = listener, srv
return nil
}

func (is *ipcServer) stop() error {
is.mu.Lock()
defer is.mu.Unlock()

if is.listener == nil {
return nil // not running
}
err := is.listener.Close()
is.srv.Stop()
is.listener, is.srv = nil, nil
is.log.Info("IPC endpoint closed", "url", is.endpoint)
return err
}

// RegisterApis checks the given modules' availability, generates an allowlist based on the allowed modules,
// and then registers all of the APIs exposed by the services.
func RegisterApis(apis []rpc.API, modules []string, srv *rpc.Server, exposeAll bool) error {
Expand Down
4 changes: 1 addition & 3 deletions rpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ func (op *requestOp) wait(ctx context.Context, c *Client) (*jsonrpcMessage, erro
// The currently supported URL schemes are "http", "https", "ws" and "wss". If rawurl is a
// file name with no URL scheme, a local socket connection is established using UNIX
// domain sockets on supported platforms and named pipes on Windows. If you want to
// configure transport options, use DialHTTP, DialWebsocket or DialIPC instead.
// configure transport options, use DialHTTP, DialWebsocket.
//
// For websocket connections, the origin is set to the local host name.
//
Expand All @@ -178,8 +178,6 @@ func DialContext(ctx context.Context, rawurl string) (*Client, error) {
return DialWebsocket(ctx, rawurl, "")
case "stdio":
return DialStdIO(ctx)
case "":
return DialIPC(ctx, rawurl)
default:
return nil, fmt.Errorf("no known transport for URL scheme %q", u.Scheme)
}
Expand Down
52 changes: 0 additions & 52 deletions rpc/endpoints.go

This file was deleted.

Loading

0 comments on commit 1a71465

Please sign in to comment.