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. "net"
  20. "os"
  21. "path/filepath"
  22. "reflect"
  23. "strings"
  24. "sync"
  25. "syscall"
  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/logger"
  31. "github.com/ethereum/go-ethereum/logger/glog"
  32. "github.com/ethereum/go-ethereum/p2p"
  33. "github.com/ethereum/go-ethereum/rpc"
  34. "github.com/syndtr/goleveldb/leveldb/storage"
  35. )
  36. var (
  37. ErrDatadirUsed = errors.New("datadir already used")
  38. ErrNodeStopped = errors.New("node not started")
  39. ErrNodeRunning = errors.New("node already running")
  40. ErrServiceUnknown = errors.New("unknown service")
  41. datadirInUseErrnos = map[uint]bool{11: true, 32: true, 35: true}
  42. )
  43. // Node is a container on which services can be registered.
  44. type Node struct {
  45. eventmux *event.TypeMux // Event multiplexer used between the services of a stack
  46. config *Config
  47. accman *accounts.Manager
  48. ephemeralKeystore string // if non-empty, the key directory that will be removed by Stop
  49. instanceDirLock storage.Storage // prevents concurrent use of instance directory
  50. serverConfig p2p.Config
  51. server *p2p.Server // Currently running P2P networking layer
  52. serviceFuncs []ServiceConstructor // Service constructors (in dependency order)
  53. services map[reflect.Type]Service // Currently running services
  54. rpcAPIs []rpc.API // List of APIs currently provided by the node
  55. inprocHandler *rpc.Server // In-process RPC request handler to process the API requests
  56. ipcEndpoint string // IPC endpoint to listen at (empty = IPC disabled)
  57. ipcListener net.Listener // IPC RPC listener socket to serve API requests
  58. ipcHandler *rpc.Server // IPC RPC request handler to process the API requests
  59. httpEndpoint string // HTTP endpoint (interface + port) to listen at (empty = HTTP disabled)
  60. httpWhitelist []string // HTTP RPC modules to allow through this endpoint
  61. httpListener net.Listener // HTTP RPC listener socket to server API requests
  62. httpHandler *rpc.Server // HTTP RPC request handler to process the API requests
  63. wsEndpoint string // Websocket endpoint (interface + port) to listen at (empty = websocket disabled)
  64. wsListener net.Listener // Websocket RPC listener socket to server API requests
  65. wsHandler *rpc.Server // Websocket RPC request handler to process the API requests
  66. stop chan struct{} // Channel to wait for termination notifications
  67. lock sync.RWMutex
  68. }
  69. // New creates a new P2P node, ready for protocol registration.
  70. func New(conf *Config) (*Node, error) {
  71. // Copy config and resolve the datadir so future changes to the current
  72. // working directory don't affect the node.
  73. confCopy := *conf
  74. conf = &confCopy
  75. if conf.DataDir != "" {
  76. absdatadir, err := filepath.Abs(conf.DataDir)
  77. if err != nil {
  78. return nil, err
  79. }
  80. conf.DataDir = absdatadir
  81. }
  82. // Ensure that the instance name doesn't cause weird conflicts with
  83. // other files in the data directory.
  84. if strings.ContainsAny(conf.Name, `/\`) {
  85. return nil, errors.New(`Config.Name must not contain '/' or '\'`)
  86. }
  87. if conf.Name == datadirDefaultKeyStore {
  88. return nil, errors.New(`Config.Name cannot be "` + datadirDefaultKeyStore + `"`)
  89. }
  90. if strings.HasSuffix(conf.Name, ".ipc") {
  91. return nil, errors.New(`Config.Name cannot end in ".ipc"`)
  92. }
  93. // Ensure that the AccountManager method works before the node has started.
  94. // We rely on this in cmd/geth.
  95. am, ephemeralKeystore, err := makeAccountManager(conf)
  96. if err != nil {
  97. return nil, err
  98. }
  99. // Note: any interaction with Config that would create/touch files
  100. // in the data directory or instance directory is delayed until Start.
  101. return &Node{
  102. accman: am,
  103. ephemeralKeystore: ephemeralKeystore,
  104. config: conf,
  105. serviceFuncs: []ServiceConstructor{},
  106. ipcEndpoint: conf.IPCEndpoint(),
  107. httpEndpoint: conf.HTTPEndpoint(),
  108. wsEndpoint: conf.WSEndpoint(),
  109. eventmux: new(event.TypeMux),
  110. }, nil
  111. }
  112. // Register injects a new service into the node's stack. The service created by
  113. // the passed constructor must be unique in its type with regard to sibling ones.
  114. func (n *Node) Register(constructor ServiceConstructor) error {
  115. n.lock.Lock()
  116. defer n.lock.Unlock()
  117. if n.server != nil {
  118. return ErrNodeRunning
  119. }
  120. n.serviceFuncs = append(n.serviceFuncs, constructor)
  121. return nil
  122. }
  123. // Start create a live P2P node and starts running it.
  124. func (n *Node) Start() error {
  125. n.lock.Lock()
  126. defer n.lock.Unlock()
  127. // Short circuit if the node's already running
  128. if n.server != nil {
  129. return ErrNodeRunning
  130. }
  131. if err := n.openDataDir(); err != nil {
  132. return err
  133. }
  134. // Initialize the p2p server. This creates the node key and
  135. // discovery databases.
  136. n.serverConfig = p2p.Config{
  137. PrivateKey: n.config.NodeKey(),
  138. Name: n.config.NodeName(),
  139. Discovery: !n.config.NoDiscovery,
  140. DiscoveryV5: n.config.DiscoveryV5,
  141. DiscoveryV5Addr: n.config.DiscoveryV5Addr,
  142. BootstrapNodes: n.config.BootstrapNodes,
  143. BootstrapNodesV5: n.config.BootstrapNodesV5,
  144. StaticNodes: n.config.StaticNodes(),
  145. TrustedNodes: n.config.TrusterNodes(),
  146. NodeDatabase: n.config.NodeDB(),
  147. ListenAddr: n.config.ListenAddr,
  148. NAT: n.config.NAT,
  149. Dialer: n.config.Dialer,
  150. NoDial: n.config.NoDial,
  151. MaxPeers: n.config.MaxPeers,
  152. MaxPendingPeers: n.config.MaxPendingPeers,
  153. }
  154. running := &p2p.Server{Config: n.serverConfig}
  155. glog.V(logger.Info).Infoln("instance:", n.serverConfig.Name)
  156. // Otherwise copy and specialize the P2P configuration
  157. services := make(map[reflect.Type]Service)
  158. for _, constructor := range n.serviceFuncs {
  159. // Create a new context for the particular service
  160. ctx := &ServiceContext{
  161. config: n.config,
  162. services: make(map[reflect.Type]Service),
  163. EventMux: n.eventmux,
  164. AccountManager: n.accman,
  165. }
  166. for kind, s := range services { // copy needed for threaded access
  167. ctx.services[kind] = s
  168. }
  169. // Construct and save the service
  170. service, err := constructor(ctx)
  171. if err != nil {
  172. return err
  173. }
  174. kind := reflect.TypeOf(service)
  175. if _, exists := services[kind]; exists {
  176. return &DuplicateServiceError{Kind: kind}
  177. }
  178. services[kind] = service
  179. }
  180. // Gather the protocols and start the freshly assembled P2P server
  181. for _, service := range services {
  182. running.Protocols = append(running.Protocols, service.Protocols()...)
  183. }
  184. if err := running.Start(); err != nil {
  185. if errno, ok := err.(syscall.Errno); ok && datadirInUseErrnos[uint(errno)] {
  186. return ErrDatadirUsed
  187. }
  188. return err
  189. }
  190. // Start each of the services
  191. started := []reflect.Type{}
  192. for kind, service := range services {
  193. // Start the next service, stopping all previous upon failure
  194. if err := service.Start(running); err != nil {
  195. for _, kind := range started {
  196. services[kind].Stop()
  197. }
  198. running.Stop()
  199. return err
  200. }
  201. // Mark the service started for potential cleanup
  202. started = append(started, kind)
  203. }
  204. // Lastly start the configured RPC interfaces
  205. if err := n.startRPC(services); err != nil {
  206. for _, service := range services {
  207. service.Stop()
  208. }
  209. running.Stop()
  210. return err
  211. }
  212. // Finish initializing the startup
  213. n.services = services
  214. n.server = running
  215. n.stop = make(chan struct{})
  216. return nil
  217. }
  218. func (n *Node) openDataDir() error {
  219. if n.config.DataDir == "" {
  220. return nil // ephemeral
  221. }
  222. instdir := filepath.Join(n.config.DataDir, n.config.name())
  223. if err := os.MkdirAll(instdir, 0700); err != nil {
  224. return err
  225. }
  226. // Try to open the instance directory as LevelDB storage. This creates a lock file
  227. // which prevents concurrent use by another instance as well as accidental use of the
  228. // instance directory as a database.
  229. storage, err := storage.OpenFile(instdir, true)
  230. if err != nil {
  231. return err
  232. }
  233. n.instanceDirLock = storage
  234. return nil
  235. }
  236. // startRPC is a helper method to start all the various RPC endpoint during node
  237. // startup. It's not meant to be called at any time afterwards as it makes certain
  238. // assumptions about the state of the node.
  239. func (n *Node) startRPC(services map[reflect.Type]Service) error {
  240. // Gather all the possible APIs to surface
  241. apis := n.apis()
  242. for _, service := range services {
  243. apis = append(apis, service.APIs()...)
  244. }
  245. // Start the various API endpoints, terminating all in case of errors
  246. if err := n.startInProc(apis); err != nil {
  247. return err
  248. }
  249. if err := n.startIPC(apis); err != nil {
  250. n.stopInProc()
  251. return err
  252. }
  253. if err := n.startHTTP(n.httpEndpoint, apis, n.config.HTTPModules, n.config.HTTPCors); err != nil {
  254. n.stopIPC()
  255. n.stopInProc()
  256. return err
  257. }
  258. if err := n.startWS(n.wsEndpoint, apis, n.config.WSModules, n.config.WSOrigins); err != nil {
  259. n.stopHTTP()
  260. n.stopIPC()
  261. n.stopInProc()
  262. return err
  263. }
  264. // All API endpoints started successfully
  265. n.rpcAPIs = apis
  266. return nil
  267. }
  268. // startInProc initializes an in-process RPC endpoint.
  269. func (n *Node) startInProc(apis []rpc.API) error {
  270. // Register all the APIs exposed by the services
  271. handler := rpc.NewServer()
  272. for _, api := range apis {
  273. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  274. return err
  275. }
  276. glog.V(logger.Debug).Infof("InProc registered %T under '%s'", api.Service, api.Namespace)
  277. }
  278. n.inprocHandler = handler
  279. return nil
  280. }
  281. // stopInProc terminates the in-process RPC endpoint.
  282. func (n *Node) stopInProc() {
  283. if n.inprocHandler != nil {
  284. n.inprocHandler.Stop()
  285. n.inprocHandler = nil
  286. }
  287. }
  288. // startIPC initializes and starts the IPC RPC endpoint.
  289. func (n *Node) startIPC(apis []rpc.API) error {
  290. // Short circuit if the IPC endpoint isn't being exposed
  291. if n.ipcEndpoint == "" {
  292. return nil
  293. }
  294. // Register all the APIs exposed by the services
  295. handler := rpc.NewServer()
  296. for _, api := range apis {
  297. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  298. return err
  299. }
  300. glog.V(logger.Debug).Infof("IPC registered %T under '%s'", api.Service, api.Namespace)
  301. }
  302. // All APIs registered, start the IPC listener
  303. var (
  304. listener net.Listener
  305. err error
  306. )
  307. if listener, err = rpc.CreateIPCListener(n.ipcEndpoint); err != nil {
  308. return err
  309. }
  310. go func() {
  311. glog.V(logger.Info).Infof("IPC endpoint opened: %s", n.ipcEndpoint)
  312. for {
  313. conn, err := listener.Accept()
  314. if err != nil {
  315. // Terminate if the listener was closed
  316. n.lock.RLock()
  317. closed := n.ipcListener == nil
  318. n.lock.RUnlock()
  319. if closed {
  320. return
  321. }
  322. // Not closed, just some error; report and continue
  323. glog.V(logger.Error).Infof("IPC accept failed: %v", err)
  324. continue
  325. }
  326. go handler.ServeCodec(rpc.NewJSONCodec(conn), rpc.OptionMethodInvocation|rpc.OptionSubscriptions)
  327. }
  328. }()
  329. // All listeners booted successfully
  330. n.ipcListener = listener
  331. n.ipcHandler = handler
  332. return nil
  333. }
  334. // stopIPC terminates the IPC RPC endpoint.
  335. func (n *Node) stopIPC() {
  336. if n.ipcListener != nil {
  337. n.ipcListener.Close()
  338. n.ipcListener = nil
  339. glog.V(logger.Info).Infof("IPC endpoint closed: %s", n.ipcEndpoint)
  340. }
  341. if n.ipcHandler != nil {
  342. n.ipcHandler.Stop()
  343. n.ipcHandler = nil
  344. }
  345. }
  346. // startHTTP initializes and starts the HTTP RPC endpoint.
  347. func (n *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, cors string) error {
  348. // Short circuit if the HTTP endpoint isn't being exposed
  349. if endpoint == "" {
  350. return nil
  351. }
  352. // Generate the whitelist based on the allowed modules
  353. whitelist := make(map[string]bool)
  354. for _, module := range modules {
  355. whitelist[module] = true
  356. }
  357. // Register all the APIs exposed by the services
  358. handler := rpc.NewServer()
  359. for _, api := range apis {
  360. if whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) {
  361. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  362. return err
  363. }
  364. glog.V(logger.Debug).Infof("HTTP registered %T under '%s'", api.Service, api.Namespace)
  365. }
  366. }
  367. // All APIs registered, start the HTTP listener
  368. var (
  369. listener net.Listener
  370. err error
  371. )
  372. if listener, err = net.Listen("tcp", endpoint); err != nil {
  373. return err
  374. }
  375. go rpc.NewHTTPServer(cors, handler).Serve(listener)
  376. glog.V(logger.Info).Infof("HTTP endpoint opened: http://%s", endpoint)
  377. // All listeners booted successfully
  378. n.httpEndpoint = endpoint
  379. n.httpListener = listener
  380. n.httpHandler = handler
  381. return nil
  382. }
  383. // stopHTTP terminates the HTTP RPC endpoint.
  384. func (n *Node) stopHTTP() {
  385. if n.httpListener != nil {
  386. n.httpListener.Close()
  387. n.httpListener = nil
  388. glog.V(logger.Info).Infof("HTTP endpoint closed: http://%s", n.httpEndpoint)
  389. }
  390. if n.httpHandler != nil {
  391. n.httpHandler.Stop()
  392. n.httpHandler = nil
  393. }
  394. }
  395. // startWS initializes and starts the websocket RPC endpoint.
  396. func (n *Node) startWS(endpoint string, apis []rpc.API, modules []string, wsOrigins string) error {
  397. // Short circuit if the WS endpoint isn't being exposed
  398. if endpoint == "" {
  399. return nil
  400. }
  401. // Generate the whitelist based on the allowed modules
  402. whitelist := make(map[string]bool)
  403. for _, module := range modules {
  404. whitelist[module] = true
  405. }
  406. // Register all the APIs exposed by the services
  407. handler := rpc.NewServer()
  408. for _, api := range apis {
  409. if whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) {
  410. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  411. return err
  412. }
  413. glog.V(logger.Debug).Infof("WebSocket registered %T under '%s'", api.Service, api.Namespace)
  414. }
  415. }
  416. // All APIs registered, start the HTTP listener
  417. var (
  418. listener net.Listener
  419. err error
  420. )
  421. if listener, err = net.Listen("tcp", endpoint); err != nil {
  422. return err
  423. }
  424. go rpc.NewWSServer(wsOrigins, handler).Serve(listener)
  425. glog.V(logger.Info).Infof("WebSocket endpoint opened: ws://%s", endpoint)
  426. // All listeners booted successfully
  427. n.wsEndpoint = endpoint
  428. n.wsListener = listener
  429. n.wsHandler = handler
  430. return nil
  431. }
  432. // stopWS terminates the websocket RPC endpoint.
  433. func (n *Node) stopWS() {
  434. if n.wsListener != nil {
  435. n.wsListener.Close()
  436. n.wsListener = nil
  437. glog.V(logger.Info).Infof("WebSocket endpoint closed: ws://%s", n.wsEndpoint)
  438. }
  439. if n.wsHandler != nil {
  440. n.wsHandler.Stop()
  441. n.wsHandler = nil
  442. }
  443. }
  444. // Stop terminates a running node along with all it's services. In the node was
  445. // not started, an error is returned.
  446. func (n *Node) Stop() error {
  447. n.lock.Lock()
  448. defer n.lock.Unlock()
  449. // Short circuit if the node's not running
  450. if n.server == nil {
  451. return ErrNodeStopped
  452. }
  453. // Terminate the API, services and the p2p server.
  454. n.stopWS()
  455. n.stopHTTP()
  456. n.stopIPC()
  457. n.rpcAPIs = nil
  458. failure := &StopError{
  459. Services: make(map[reflect.Type]error),
  460. }
  461. for kind, service := range n.services {
  462. if err := service.Stop(); err != nil {
  463. failure.Services[kind] = err
  464. }
  465. }
  466. n.server.Stop()
  467. n.services = nil
  468. n.server = nil
  469. // Release instance directory lock.
  470. if n.instanceDirLock != nil {
  471. n.instanceDirLock.Close()
  472. n.instanceDirLock = nil
  473. }
  474. // unblock n.Wait
  475. close(n.stop)
  476. // Remove the keystore if it was created ephemerally.
  477. var keystoreErr error
  478. if n.ephemeralKeystore != "" {
  479. keystoreErr = os.RemoveAll(n.ephemeralKeystore)
  480. }
  481. if len(failure.Services) > 0 {
  482. return failure
  483. }
  484. if keystoreErr != nil {
  485. return keystoreErr
  486. }
  487. return nil
  488. }
  489. // Wait blocks the thread until the node is stopped. If the node is not running
  490. // at the time of invocation, the method immediately returns.
  491. func (n *Node) Wait() {
  492. n.lock.RLock()
  493. if n.server == nil {
  494. return
  495. }
  496. stop := n.stop
  497. n.lock.RUnlock()
  498. <-stop
  499. }
  500. // Restart terminates a running node and boots up a new one in its place. If the
  501. // node isn't running, an error is returned.
  502. func (n *Node) Restart() error {
  503. if err := n.Stop(); err != nil {
  504. return err
  505. }
  506. if err := n.Start(); err != nil {
  507. return err
  508. }
  509. return nil
  510. }
  511. // Attach creates an RPC client attached to an in-process API handler.
  512. func (n *Node) Attach() (*rpc.Client, error) {
  513. n.lock.RLock()
  514. defer n.lock.RUnlock()
  515. if n.server == nil {
  516. return nil, ErrNodeStopped
  517. }
  518. return rpc.DialInProc(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. }