node.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. // Copyright 2015 The go-ethereum Authors
  2. // This file is part of the go-ethereum library.
  3. //
  4. // The go-ethereum library is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // The go-ethereum library is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
  16. package node
  17. import (
  18. "errors"
  19. "fmt"
  20. "net"
  21. "os"
  22. "path/filepath"
  23. "reflect"
  24. "strings"
  25. "sync"
  26. "github.com/ethereum/go-ethereum/accounts"
  27. "github.com/ethereum/go-ethereum/ethdb"
  28. "github.com/ethereum/go-ethereum/event"
  29. "github.com/ethereum/go-ethereum/internal/debug"
  30. "github.com/ethereum/go-ethereum/log"
  31. "github.com/ethereum/go-ethereum/p2p"
  32. "github.com/ethereum/go-ethereum/rpc"
  33. "github.com/prometheus/prometheus/util/flock"
  34. )
  35. // Node is a container on which services can be registered.
  36. type Node struct {
  37. eventmux *event.TypeMux // Event multiplexer used between the services of a stack
  38. config *Config
  39. accman *accounts.Manager
  40. ephemeralKeystore string // if non-empty, the key directory that will be removed by Stop
  41. instanceDirLock flock.Releaser // prevents concurrent use of instance directory
  42. serverConfig p2p.Config
  43. server *p2p.Server // Currently running P2P networking layer
  44. serviceFuncs []ServiceConstructor // Service constructors (in dependency order)
  45. services map[reflect.Type]Service // Currently running services
  46. rpcAPIs []rpc.API // List of APIs currently provided by the node
  47. inprocHandler *rpc.Server // In-process RPC request handler to process the API requests
  48. ipcEndpoint string // IPC endpoint to listen at (empty = IPC disabled)
  49. ipcListener net.Listener // IPC RPC listener socket to serve API requests
  50. ipcHandler *rpc.Server // IPC RPC request handler to process the API requests
  51. httpEndpoint string // HTTP endpoint (interface + port) to listen at (empty = HTTP disabled)
  52. httpWhitelist []string // HTTP RPC modules to allow through this endpoint
  53. httpListener net.Listener // HTTP RPC listener socket to server API requests
  54. httpHandler *rpc.Server // HTTP RPC request handler to process the API requests
  55. wsEndpoint string // Websocket endpoint (interface + port) to listen at (empty = websocket disabled)
  56. wsListener net.Listener // Websocket RPC listener socket to server API requests
  57. wsHandler *rpc.Server // Websocket RPC request handler to process the API requests
  58. stop chan struct{} // Channel to wait for termination notifications
  59. lock sync.RWMutex
  60. log log.Logger
  61. }
  62. // New creates a new P2P node, ready for protocol registration.
  63. func New(conf *Config) (*Node, error) {
  64. // Copy config and resolve the datadir so future changes to the current
  65. // working directory don't affect the node.
  66. confCopy := *conf
  67. conf = &confCopy
  68. if conf.DataDir != "" {
  69. absdatadir, err := filepath.Abs(conf.DataDir)
  70. if err != nil {
  71. return nil, err
  72. }
  73. conf.DataDir = absdatadir
  74. }
  75. // Ensure that the instance name doesn't cause weird conflicts with
  76. // other files in the data directory.
  77. if strings.ContainsAny(conf.Name, `/\`) {
  78. return nil, errors.New(`Config.Name must not contain '/' or '\'`)
  79. }
  80. if conf.Name == datadirDefaultKeyStore {
  81. return nil, errors.New(`Config.Name cannot be "` + datadirDefaultKeyStore + `"`)
  82. }
  83. if strings.HasSuffix(conf.Name, ".ipc") {
  84. return nil, errors.New(`Config.Name cannot end in ".ipc"`)
  85. }
  86. // Ensure that the AccountManager method works before the node has started.
  87. // We rely on this in cmd/geth.
  88. am, ephemeralKeystore, err := makeAccountManager(conf)
  89. if err != nil {
  90. return nil, err
  91. }
  92. if conf.Logger == nil {
  93. conf.Logger = log.New()
  94. }
  95. // Note: any interaction with Config that would create/touch files
  96. // in the data directory or instance directory is delayed until Start.
  97. return &Node{
  98. accman: am,
  99. ephemeralKeystore: ephemeralKeystore,
  100. config: conf,
  101. serviceFuncs: []ServiceConstructor{},
  102. ipcEndpoint: conf.IPCEndpoint(),
  103. httpEndpoint: conf.HTTPEndpoint(),
  104. wsEndpoint: conf.WSEndpoint(),
  105. eventmux: new(event.TypeMux),
  106. log: conf.Logger,
  107. }, nil
  108. }
  109. // Register injects a new service into the node's stack. The service created by
  110. // the passed constructor must be unique in its type with regard to sibling ones.
  111. func (n *Node) Register(constructor ServiceConstructor) error {
  112. n.lock.Lock()
  113. defer n.lock.Unlock()
  114. if n.server != nil {
  115. return ErrNodeRunning
  116. }
  117. n.serviceFuncs = append(n.serviceFuncs, constructor)
  118. return nil
  119. }
  120. // Start create a live P2P node and starts running it.
  121. func (n *Node) Start() error {
  122. n.lock.Lock()
  123. defer n.lock.Unlock()
  124. // Short circuit if the node's already running
  125. if n.server != nil {
  126. return ErrNodeRunning
  127. }
  128. if err := n.openDataDir(); err != nil {
  129. return err
  130. }
  131. // Initialize the p2p server. This creates the node key and
  132. // discovery databases.
  133. n.serverConfig = n.config.P2P
  134. n.serverConfig.PrivateKey = n.config.NodeKey()
  135. n.serverConfig.Name = n.config.NodeName()
  136. n.serverConfig.Logger = n.log
  137. if n.serverConfig.StaticNodes == nil {
  138. n.serverConfig.StaticNodes = n.config.StaticNodes()
  139. }
  140. if n.serverConfig.TrustedNodes == nil {
  141. n.serverConfig.TrustedNodes = n.config.TrustedNodes()
  142. }
  143. if n.serverConfig.NodeDatabase == "" {
  144. n.serverConfig.NodeDatabase = n.config.NodeDB()
  145. }
  146. running := &p2p.Server{Config: n.serverConfig}
  147. n.log.Info("Starting peer-to-peer node", "instance", n.serverConfig.Name)
  148. // Otherwise copy and specialize the P2P configuration
  149. services := make(map[reflect.Type]Service)
  150. for _, constructor := range n.serviceFuncs {
  151. // Create a new context for the particular service
  152. ctx := &ServiceContext{
  153. config: n.config,
  154. services: make(map[reflect.Type]Service),
  155. EventMux: n.eventmux,
  156. AccountManager: n.accman,
  157. }
  158. for kind, s := range services { // copy needed for threaded access
  159. ctx.services[kind] = s
  160. }
  161. // Construct and save the service
  162. service, err := constructor(ctx)
  163. if err != nil {
  164. return err
  165. }
  166. kind := reflect.TypeOf(service)
  167. if _, exists := services[kind]; exists {
  168. return &DuplicateServiceError{Kind: kind}
  169. }
  170. services[kind] = service
  171. }
  172. // Gather the protocols and start the freshly assembled P2P server
  173. for _, service := range services {
  174. running.Protocols = append(running.Protocols, service.Protocols()...)
  175. }
  176. if err := running.Start(); err != nil {
  177. return convertFileLockError(err)
  178. }
  179. // Start each of the services
  180. started := []reflect.Type{}
  181. for kind, service := range services {
  182. // Start the next service, stopping all previous upon failure
  183. if err := service.Start(running); err != nil {
  184. for _, kind := range started {
  185. services[kind].Stop()
  186. }
  187. running.Stop()
  188. return err
  189. }
  190. // Mark the service started for potential cleanup
  191. started = append(started, kind)
  192. }
  193. // Lastly start the configured RPC interfaces
  194. if err := n.startRPC(services); err != nil {
  195. for _, service := range services {
  196. service.Stop()
  197. }
  198. running.Stop()
  199. return err
  200. }
  201. // Finish initializing the startup
  202. n.services = services
  203. n.server = running
  204. n.stop = make(chan struct{})
  205. return nil
  206. }
  207. func (n *Node) openDataDir() error {
  208. if n.config.DataDir == "" {
  209. return nil // ephemeral
  210. }
  211. instdir := filepath.Join(n.config.DataDir, n.config.name())
  212. if err := os.MkdirAll(instdir, 0700); err != nil {
  213. return err
  214. }
  215. // Lock the instance directory to prevent concurrent use by another instance as well as
  216. // accidental use of the instance directory as a database.
  217. release, _, err := flock.New(filepath.Join(instdir, "LOCK"))
  218. if err != nil {
  219. return convertFileLockError(err)
  220. }
  221. n.instanceDirLock = release
  222. return nil
  223. }
  224. // startRPC is a helper method to start all the various RPC endpoint during node
  225. // startup. It's not meant to be called at any time afterwards as it makes certain
  226. // assumptions about the state of the node.
  227. func (n *Node) startRPC(services map[reflect.Type]Service) error {
  228. // Gather all the possible APIs to surface
  229. apis := n.apis()
  230. for _, service := range services {
  231. apis = append(apis, service.APIs()...)
  232. }
  233. // Start the various API endpoints, terminating all in case of errors
  234. if err := n.startInProc(apis); err != nil {
  235. return err
  236. }
  237. if err := n.startIPC(apis); err != nil {
  238. n.stopInProc()
  239. return err
  240. }
  241. if err := n.startHTTP(n.httpEndpoint, apis, n.config.HTTPModules, n.config.HTTPCors, n.config.HTTPVirtualHosts); err != nil {
  242. n.stopIPC()
  243. n.stopInProc()
  244. return err
  245. }
  246. if err := n.startWS(n.wsEndpoint, apis, n.config.WSModules, n.config.WSOrigins, n.config.WSExposeAll); err != nil {
  247. n.stopHTTP()
  248. n.stopIPC()
  249. n.stopInProc()
  250. return err
  251. }
  252. // All API endpoints started successfully
  253. n.rpcAPIs = apis
  254. return nil
  255. }
  256. // startInProc initializes an in-process RPC endpoint.
  257. func (n *Node) startInProc(apis []rpc.API) error {
  258. // Register all the APIs exposed by the services
  259. handler := rpc.NewServer()
  260. for _, api := range apis {
  261. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  262. return err
  263. }
  264. n.log.Debug("InProc registered", "service", api.Service, "namespace", api.Namespace)
  265. }
  266. n.inprocHandler = handler
  267. return nil
  268. }
  269. // stopInProc terminates the in-process RPC endpoint.
  270. func (n *Node) stopInProc() {
  271. if n.inprocHandler != nil {
  272. n.inprocHandler.Stop()
  273. n.inprocHandler = nil
  274. }
  275. }
  276. // startIPC initializes and starts the IPC RPC endpoint.
  277. func (n *Node) startIPC(apis []rpc.API) error {
  278. // Short circuit if the IPC endpoint isn't being exposed
  279. if n.ipcEndpoint == "" {
  280. return nil
  281. }
  282. // Register all the APIs exposed by the services
  283. handler := rpc.NewServer()
  284. for _, api := range apis {
  285. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  286. return err
  287. }
  288. n.log.Debug("IPC registered", "service", api.Service, "namespace", api.Namespace)
  289. }
  290. // All APIs registered, start the IPC listener
  291. var (
  292. listener net.Listener
  293. err error
  294. )
  295. if listener, err = rpc.CreateIPCListener(n.ipcEndpoint); err != nil {
  296. return err
  297. }
  298. go func() {
  299. n.log.Info("IPC endpoint opened", "url", n.ipcEndpoint)
  300. for {
  301. conn, err := listener.Accept()
  302. if err != nil {
  303. // Terminate if the listener was closed
  304. n.lock.RLock()
  305. closed := n.ipcListener == nil
  306. n.lock.RUnlock()
  307. if closed {
  308. return
  309. }
  310. // Not closed, just some error; report and continue
  311. n.log.Error("IPC accept failed", "err", err)
  312. continue
  313. }
  314. go handler.ServeCodec(rpc.NewJSONCodec(conn), rpc.OptionMethodInvocation|rpc.OptionSubscriptions)
  315. }
  316. }()
  317. // All listeners booted successfully
  318. n.ipcListener = listener
  319. n.ipcHandler = handler
  320. return nil
  321. }
  322. // stopIPC terminates the IPC RPC endpoint.
  323. func (n *Node) stopIPC() {
  324. if n.ipcListener != nil {
  325. n.ipcListener.Close()
  326. n.ipcListener = nil
  327. n.log.Info("IPC endpoint closed", "endpoint", n.ipcEndpoint)
  328. }
  329. if n.ipcHandler != nil {
  330. n.ipcHandler.Stop()
  331. n.ipcHandler = nil
  332. }
  333. }
  334. // startHTTP initializes and starts the HTTP RPC endpoint.
  335. func (n *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, cors []string, vhosts []string) error {
  336. // Short circuit if the HTTP endpoint isn't being exposed
  337. if endpoint == "" {
  338. return nil
  339. }
  340. // Generate the whitelist based on the allowed modules
  341. whitelist := make(map[string]bool)
  342. for _, module := range modules {
  343. whitelist[module] = true
  344. }
  345. // Register all the APIs exposed by the services
  346. handler := rpc.NewServer()
  347. for _, api := range apis {
  348. if whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) {
  349. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  350. return err
  351. }
  352. n.log.Debug("HTTP registered", "service", api.Service, "namespace", api.Namespace)
  353. }
  354. }
  355. // All APIs registered, start the HTTP listener
  356. var (
  357. listener net.Listener
  358. err error
  359. )
  360. if listener, err = net.Listen("tcp", endpoint); err != nil {
  361. return err
  362. }
  363. go rpc.NewHTTPServer(cors, vhosts, handler).Serve(listener)
  364. n.log.Info("HTTP endpoint opened", "url", fmt.Sprintf("http://%s", endpoint), "cors", strings.Join(cors, ","), "vhosts", strings.Join(vhosts, ","))
  365. // All listeners booted successfully
  366. n.httpEndpoint = endpoint
  367. n.httpListener = listener
  368. n.httpHandler = handler
  369. return nil
  370. }
  371. // stopHTTP terminates the HTTP RPC endpoint.
  372. func (n *Node) stopHTTP() {
  373. if n.httpListener != nil {
  374. n.httpListener.Close()
  375. n.httpListener = nil
  376. n.log.Info("HTTP endpoint closed", "url", fmt.Sprintf("http://%s", n.httpEndpoint))
  377. }
  378. if n.httpHandler != nil {
  379. n.httpHandler.Stop()
  380. n.httpHandler = nil
  381. }
  382. }
  383. // startWS initializes and starts the websocket RPC endpoint.
  384. func (n *Node) startWS(endpoint string, apis []rpc.API, modules []string, wsOrigins []string, exposeAll bool) error {
  385. // Short circuit if the WS endpoint isn't being exposed
  386. if endpoint == "" {
  387. return nil
  388. }
  389. // Generate the whitelist based on the allowed modules
  390. whitelist := make(map[string]bool)
  391. for _, module := range modules {
  392. whitelist[module] = true
  393. }
  394. // Register all the APIs exposed by the services
  395. handler := rpc.NewServer()
  396. for _, api := range apis {
  397. if exposeAll || whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) {
  398. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  399. return err
  400. }
  401. n.log.Debug("WebSocket registered", "service", api.Service, "namespace", api.Namespace)
  402. }
  403. }
  404. // All APIs registered, start the HTTP listener
  405. var (
  406. listener net.Listener
  407. err error
  408. )
  409. if listener, err = net.Listen("tcp", endpoint); err != nil {
  410. return err
  411. }
  412. go rpc.NewWSServer(wsOrigins, handler).Serve(listener)
  413. n.log.Info("WebSocket endpoint opened", "url", fmt.Sprintf("ws://%s", listener.Addr()))
  414. // All listeners booted successfully
  415. n.wsEndpoint = endpoint
  416. n.wsListener = listener
  417. n.wsHandler = handler
  418. return nil
  419. }
  420. // stopWS terminates the websocket RPC endpoint.
  421. func (n *Node) stopWS() {
  422. if n.wsListener != nil {
  423. n.wsListener.Close()
  424. n.wsListener = nil
  425. n.log.Info("WebSocket endpoint closed", "url", fmt.Sprintf("ws://%s", n.wsEndpoint))
  426. }
  427. if n.wsHandler != nil {
  428. n.wsHandler.Stop()
  429. n.wsHandler = nil
  430. }
  431. }
  432. // Stop terminates a running node along with all it's services. In the node was
  433. // not started, an error is returned.
  434. func (n *Node) Stop() error {
  435. n.lock.Lock()
  436. defer n.lock.Unlock()
  437. // Short circuit if the node's not running
  438. if n.server == nil {
  439. return ErrNodeStopped
  440. }
  441. // Terminate the API, services and the p2p server.
  442. n.stopWS()
  443. n.stopHTTP()
  444. n.stopIPC()
  445. n.rpcAPIs = nil
  446. failure := &StopError{
  447. Services: make(map[reflect.Type]error),
  448. }
  449. for kind, service := range n.services {
  450. if err := service.Stop(); err != nil {
  451. failure.Services[kind] = err
  452. }
  453. }
  454. n.server.Stop()
  455. n.services = nil
  456. n.server = nil
  457. // Release instance directory lock.
  458. if n.instanceDirLock != nil {
  459. if err := n.instanceDirLock.Release(); err != nil {
  460. n.log.Error("Can't release datadir lock", "err", err)
  461. }
  462. n.instanceDirLock = nil
  463. }
  464. // unblock n.Wait
  465. close(n.stop)
  466. // Remove the keystore if it was created ephemerally.
  467. var keystoreErr error
  468. if n.ephemeralKeystore != "" {
  469. keystoreErr = os.RemoveAll(n.ephemeralKeystore)
  470. }
  471. if len(failure.Services) > 0 {
  472. return failure
  473. }
  474. if keystoreErr != nil {
  475. return keystoreErr
  476. }
  477. return nil
  478. }
  479. // Wait blocks the thread until the node is stopped. If the node is not running
  480. // at the time of invocation, the method immediately returns.
  481. func (n *Node) Wait() {
  482. n.lock.RLock()
  483. if n.server == nil {
  484. n.lock.RUnlock()
  485. return
  486. }
  487. stop := n.stop
  488. n.lock.RUnlock()
  489. <-stop
  490. }
  491. // Restart terminates a running node and boots up a new one in its place. If the
  492. // node isn't running, an error is returned.
  493. func (n *Node) Restart() error {
  494. if err := n.Stop(); err != nil {
  495. return err
  496. }
  497. if err := n.Start(); err != nil {
  498. return err
  499. }
  500. return nil
  501. }
  502. // Attach creates an RPC client attached to an in-process API handler.
  503. func (n *Node) Attach() (*rpc.Client, error) {
  504. n.lock.RLock()
  505. defer n.lock.RUnlock()
  506. if n.server == nil {
  507. return nil, ErrNodeStopped
  508. }
  509. return rpc.DialInProc(n.inprocHandler), nil
  510. }
  511. // RPCHandler returns the in-process RPC request handler.
  512. func (n *Node) RPCHandler() (*rpc.Server, error) {
  513. n.lock.RLock()
  514. defer n.lock.RUnlock()
  515. if n.inprocHandler == nil {
  516. return nil, ErrNodeStopped
  517. }
  518. return n.inprocHandler, nil
  519. }
  520. // Server retrieves the currently running P2P network layer. This method is meant
  521. // only to inspect fields of the currently running server, life cycle management
  522. // should be left to this Node entity.
  523. func (n *Node) Server() *p2p.Server {
  524. n.lock.RLock()
  525. defer n.lock.RUnlock()
  526. return n.server
  527. }
  528. // Service retrieves a currently running service registered of a specific type.
  529. func (n *Node) Service(service interface{}) error {
  530. n.lock.RLock()
  531. defer n.lock.RUnlock()
  532. // Short circuit if the node's not running
  533. if n.server == nil {
  534. return ErrNodeStopped
  535. }
  536. // Otherwise try to find the service to return
  537. element := reflect.ValueOf(service).Elem()
  538. if running, ok := n.services[element.Type()]; ok {
  539. element.Set(reflect.ValueOf(running))
  540. return nil
  541. }
  542. return ErrServiceUnknown
  543. }
  544. // DataDir retrieves the current datadir used by the protocol stack.
  545. // Deprecated: No files should be stored in this directory, use InstanceDir instead.
  546. func (n *Node) DataDir() string {
  547. return n.config.DataDir
  548. }
  549. // InstanceDir retrieves the instance directory used by the protocol stack.
  550. func (n *Node) InstanceDir() string {
  551. return n.config.instanceDir()
  552. }
  553. // AccountManager retrieves the account manager used by the protocol stack.
  554. func (n *Node) AccountManager() *accounts.Manager {
  555. return n.accman
  556. }
  557. // IPCEndpoint retrieves the current IPC endpoint used by the protocol stack.
  558. func (n *Node) IPCEndpoint() string {
  559. return n.ipcEndpoint
  560. }
  561. // HTTPEndpoint retrieves the current HTTP endpoint used by the protocol stack.
  562. func (n *Node) HTTPEndpoint() string {
  563. return n.httpEndpoint
  564. }
  565. // WSEndpoint retrieves the current WS endpoint used by the protocol stack.
  566. func (n *Node) WSEndpoint() string {
  567. return n.wsEndpoint
  568. }
  569. // EventMux retrieves the event multiplexer used by all the network services in
  570. // the current protocol stack.
  571. func (n *Node) EventMux() *event.TypeMux {
  572. return n.eventmux
  573. }
  574. // OpenDatabase opens an existing database with the given name (or creates one if no
  575. // previous can be found) from within the node's instance directory. If the node is
  576. // ephemeral, a memory database is returned.
  577. func (n *Node) OpenDatabase(name string, cache, handles int) (ethdb.Database, error) {
  578. if n.config.DataDir == "" {
  579. return ethdb.NewMemDatabase()
  580. }
  581. return ethdb.NewLDBDatabase(n.config.resolvePath(name), cache, handles)
  582. }
  583. // ResolvePath returns the absolute path of a resource in the instance directory.
  584. func (n *Node) ResolvePath(x string) string {
  585. return n.config.resolvePath(x)
  586. }
  587. // apis returns the collection of RPC descriptors this node offers.
  588. func (n *Node) apis() []rpc.API {
  589. return []rpc.API{
  590. {
  591. Namespace: "admin",
  592. Version: "1.0",
  593. Service: NewPrivateAdminAPI(n),
  594. }, {
  595. Namespace: "admin",
  596. Version: "1.0",
  597. Service: NewPublicAdminAPI(n),
  598. Public: true,
  599. }, {
  600. Namespace: "debug",
  601. Version: "1.0",
  602. Service: debug.Handler,
  603. }, {
  604. Namespace: "debug",
  605. Version: "1.0",
  606. Service: NewPublicDebugAPI(n),
  607. Public: true,
  608. }, {
  609. Namespace: "web3",
  610. Version: "1.0",
  611. Service: NewPublicWeb3API(n),
  612. Public: true,
  613. },
  614. }
  615. }