node.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  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. BootstrapNodes: n.config.BootstrapNodes,
  142. StaticNodes: n.config.StaticNodes(),
  143. TrustedNodes: n.config.TrusterNodes(),
  144. NodeDatabase: n.config.NodeDB(),
  145. ListenAddr: n.config.ListenAddr,
  146. ListenAddrV5: n.config.ListenAddrV5,
  147. NAT: n.config.NAT,
  148. Dialer: n.config.Dialer,
  149. NoDial: n.config.NoDial,
  150. MaxPeers: n.config.MaxPeers,
  151. MaxPendingPeers: n.config.MaxPendingPeers,
  152. }
  153. running := &p2p.Server{Config: n.serverConfig}
  154. glog.V(logger.Info).Infoln("instance:", n.serverConfig.Name)
  155. // Otherwise copy and specialize the P2P configuration
  156. services := make(map[reflect.Type]Service)
  157. for _, constructor := range n.serviceFuncs {
  158. // Create a new context for the particular service
  159. ctx := &ServiceContext{
  160. config: n.config,
  161. services: make(map[reflect.Type]Service),
  162. EventMux: n.eventmux,
  163. AccountManager: n.accman,
  164. }
  165. for kind, s := range services { // copy needed for threaded access
  166. ctx.services[kind] = s
  167. }
  168. // Construct and save the service
  169. service, err := constructor(ctx)
  170. if err != nil {
  171. return err
  172. }
  173. kind := reflect.TypeOf(service)
  174. if _, exists := services[kind]; exists {
  175. return &DuplicateServiceError{Kind: kind}
  176. }
  177. services[kind] = service
  178. }
  179. // Gather the protocols and start the freshly assembled P2P server
  180. for _, service := range services {
  181. running.Protocols = append(running.Protocols, service.Protocols()...)
  182. }
  183. if err := running.Start(); err != nil {
  184. if errno, ok := err.(syscall.Errno); ok && datadirInUseErrnos[uint(errno)] {
  185. return ErrDatadirUsed
  186. }
  187. return err
  188. }
  189. // Start each of the services
  190. started := []reflect.Type{}
  191. for kind, service := range services {
  192. // Start the next service, stopping all previous upon failure
  193. if err := service.Start(running); err != nil {
  194. for _, kind := range started {
  195. services[kind].Stop()
  196. }
  197. running.Stop()
  198. return err
  199. }
  200. // Mark the service started for potential cleanup
  201. started = append(started, kind)
  202. }
  203. // Lastly start the configured RPC interfaces
  204. if err := n.startRPC(services); err != nil {
  205. for _, service := range services {
  206. service.Stop()
  207. }
  208. running.Stop()
  209. return err
  210. }
  211. // Finish initializing the startup
  212. n.services = services
  213. n.server = running
  214. n.stop = make(chan struct{})
  215. return nil
  216. }
  217. func (n *Node) openDataDir() error {
  218. if n.config.DataDir == "" {
  219. return nil // ephemeral
  220. }
  221. instdir := filepath.Join(n.config.DataDir, n.config.name())
  222. if err := os.MkdirAll(instdir, 0700); err != nil {
  223. return err
  224. }
  225. // Try to open the instance directory as LevelDB storage. This creates a lock file
  226. // which prevents concurrent use by another instance as well as accidental use of the
  227. // instance directory as a database.
  228. storage, err := storage.OpenFile(instdir, true)
  229. if err != nil {
  230. return err
  231. }
  232. n.instanceDirLock = storage
  233. return nil
  234. }
  235. // startRPC is a helper method to start all the various RPC endpoint during node
  236. // startup. It's not meant to be called at any time afterwards as it makes certain
  237. // assumptions about the state of the node.
  238. func (n *Node) startRPC(services map[reflect.Type]Service) error {
  239. // Gather all the possible APIs to surface
  240. apis := n.apis()
  241. for _, service := range services {
  242. apis = append(apis, service.APIs()...)
  243. }
  244. // Start the various API endpoints, terminating all in case of errors
  245. if err := n.startInProc(apis); err != nil {
  246. return err
  247. }
  248. if err := n.startIPC(apis); err != nil {
  249. n.stopInProc()
  250. return err
  251. }
  252. if err := n.startHTTP(n.httpEndpoint, apis, n.config.HTTPModules, n.config.HTTPCors); err != nil {
  253. n.stopIPC()
  254. n.stopInProc()
  255. return err
  256. }
  257. if err := n.startWS(n.wsEndpoint, apis, n.config.WSModules, n.config.WSOrigins); err != nil {
  258. n.stopHTTP()
  259. n.stopIPC()
  260. n.stopInProc()
  261. return err
  262. }
  263. // All API endpoints started successfully
  264. n.rpcAPIs = apis
  265. return nil
  266. }
  267. // startInProc initializes an in-process RPC endpoint.
  268. func (n *Node) startInProc(apis []rpc.API) error {
  269. // Register all the APIs exposed by the services
  270. handler := rpc.NewServer()
  271. for _, api := range apis {
  272. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  273. return err
  274. }
  275. glog.V(logger.Debug).Infof("InProc registered %T under '%s'", api.Service, api.Namespace)
  276. }
  277. n.inprocHandler = handler
  278. return nil
  279. }
  280. // stopInProc terminates the in-process RPC endpoint.
  281. func (n *Node) stopInProc() {
  282. if n.inprocHandler != nil {
  283. n.inprocHandler.Stop()
  284. n.inprocHandler = nil
  285. }
  286. }
  287. // startIPC initializes and starts the IPC RPC endpoint.
  288. func (n *Node) startIPC(apis []rpc.API) error {
  289. // Short circuit if the IPC endpoint isn't being exposed
  290. if n.ipcEndpoint == "" {
  291. return nil
  292. }
  293. // Register all the APIs exposed by the services
  294. handler := rpc.NewServer()
  295. for _, api := range apis {
  296. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  297. return err
  298. }
  299. glog.V(logger.Debug).Infof("IPC registered %T under '%s'", api.Service, api.Namespace)
  300. }
  301. // All APIs registered, start the IPC listener
  302. var (
  303. listener net.Listener
  304. err error
  305. )
  306. if listener, err = rpc.CreateIPCListener(n.ipcEndpoint); err != nil {
  307. return err
  308. }
  309. go func() {
  310. glog.V(logger.Info).Infof("IPC endpoint opened: %s", n.ipcEndpoint)
  311. for {
  312. conn, err := listener.Accept()
  313. if err != nil {
  314. // Terminate if the listener was closed
  315. n.lock.RLock()
  316. closed := n.ipcListener == nil
  317. n.lock.RUnlock()
  318. if closed {
  319. return
  320. }
  321. // Not closed, just some error; report and continue
  322. glog.V(logger.Error).Infof("IPC accept failed: %v", err)
  323. continue
  324. }
  325. go handler.ServeCodec(rpc.NewJSONCodec(conn), rpc.OptionMethodInvocation|rpc.OptionSubscriptions)
  326. }
  327. }()
  328. // All listeners booted successfully
  329. n.ipcListener = listener
  330. n.ipcHandler = handler
  331. return nil
  332. }
  333. // stopIPC terminates the IPC RPC endpoint.
  334. func (n *Node) stopIPC() {
  335. if n.ipcListener != nil {
  336. n.ipcListener.Close()
  337. n.ipcListener = nil
  338. glog.V(logger.Info).Infof("IPC endpoint closed: %s", n.ipcEndpoint)
  339. }
  340. if n.ipcHandler != nil {
  341. n.ipcHandler.Stop()
  342. n.ipcHandler = nil
  343. }
  344. }
  345. // startHTTP initializes and starts the HTTP RPC endpoint.
  346. func (n *Node) startHTTP(endpoint string, apis []rpc.API, modules []string, cors string) error {
  347. // Short circuit if the HTTP endpoint isn't being exposed
  348. if endpoint == "" {
  349. return nil
  350. }
  351. // Generate the whitelist based on the allowed modules
  352. whitelist := make(map[string]bool)
  353. for _, module := range modules {
  354. whitelist[module] = true
  355. }
  356. // Register all the APIs exposed by the services
  357. handler := rpc.NewServer()
  358. for _, api := range apis {
  359. if whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) {
  360. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  361. return err
  362. }
  363. glog.V(logger.Debug).Infof("HTTP registered %T under '%s'", api.Service, api.Namespace)
  364. }
  365. }
  366. // All APIs registered, start the HTTP listener
  367. var (
  368. listener net.Listener
  369. err error
  370. )
  371. if listener, err = net.Listen("tcp", endpoint); err != nil {
  372. return err
  373. }
  374. go rpc.NewHTTPServer(cors, handler).Serve(listener)
  375. glog.V(logger.Info).Infof("HTTP endpoint opened: http://%s", endpoint)
  376. // All listeners booted successfully
  377. n.httpEndpoint = endpoint
  378. n.httpListener = listener
  379. n.httpHandler = handler
  380. return nil
  381. }
  382. // stopHTTP terminates the HTTP RPC endpoint.
  383. func (n *Node) stopHTTP() {
  384. if n.httpListener != nil {
  385. n.httpListener.Close()
  386. n.httpListener = nil
  387. glog.V(logger.Info).Infof("HTTP endpoint closed: http://%s", n.httpEndpoint)
  388. }
  389. if n.httpHandler != nil {
  390. n.httpHandler.Stop()
  391. n.httpHandler = nil
  392. }
  393. }
  394. // startWS initializes and starts the websocket RPC endpoint.
  395. func (n *Node) startWS(endpoint string, apis []rpc.API, modules []string, wsOrigins string) error {
  396. // Short circuit if the WS endpoint isn't being exposed
  397. if endpoint == "" {
  398. return nil
  399. }
  400. // Generate the whitelist based on the allowed modules
  401. whitelist := make(map[string]bool)
  402. for _, module := range modules {
  403. whitelist[module] = true
  404. }
  405. // Register all the APIs exposed by the services
  406. handler := rpc.NewServer()
  407. for _, api := range apis {
  408. if whitelist[api.Namespace] || (len(whitelist) == 0 && api.Public) {
  409. if err := handler.RegisterName(api.Namespace, api.Service); err != nil {
  410. return err
  411. }
  412. glog.V(logger.Debug).Infof("WebSocket registered %T under '%s'", api.Service, api.Namespace)
  413. }
  414. }
  415. // All APIs registered, start the HTTP listener
  416. var (
  417. listener net.Listener
  418. err error
  419. )
  420. if listener, err = net.Listen("tcp", endpoint); err != nil {
  421. return err
  422. }
  423. go rpc.NewWSServer(wsOrigins, handler).Serve(listener)
  424. glog.V(logger.Info).Infof("WebSocket endpoint opened: ws://%s", endpoint)
  425. // All listeners booted successfully
  426. n.wsEndpoint = endpoint
  427. n.wsListener = listener
  428. n.wsHandler = handler
  429. return nil
  430. }
  431. // stopWS terminates the websocket RPC endpoint.
  432. func (n *Node) stopWS() {
  433. if n.wsListener != nil {
  434. n.wsListener.Close()
  435. n.wsListener = nil
  436. glog.V(logger.Info).Infof("WebSocket endpoint closed: ws://%s", n.wsEndpoint)
  437. }
  438. if n.wsHandler != nil {
  439. n.wsHandler.Stop()
  440. n.wsHandler = nil
  441. }
  442. }
  443. // Stop terminates a running node along with all it's services. In the node was
  444. // not started, an error is returned.
  445. func (n *Node) Stop() error {
  446. n.lock.Lock()
  447. defer n.lock.Unlock()
  448. // Short circuit if the node's not running
  449. if n.server == nil {
  450. return ErrNodeStopped
  451. }
  452. // Terminate the API, services and the p2p server.
  453. n.stopWS()
  454. n.stopHTTP()
  455. n.stopIPC()
  456. n.rpcAPIs = nil
  457. failure := &StopError{
  458. Services: make(map[reflect.Type]error),
  459. }
  460. for kind, service := range n.services {
  461. if err := service.Stop(); err != nil {
  462. failure.Services[kind] = err
  463. }
  464. }
  465. n.server.Stop()
  466. n.services = nil
  467. n.server = nil
  468. // Release instance directory lock.
  469. if n.instanceDirLock != nil {
  470. n.instanceDirLock.Close()
  471. n.instanceDirLock = nil
  472. }
  473. // unblock n.Wait
  474. close(n.stop)
  475. // Remove the keystore if it was created ephemerally.
  476. var keystoreErr error
  477. if n.ephemeralKeystore != "" {
  478. keystoreErr = os.RemoveAll(n.ephemeralKeystore)
  479. }
  480. if len(failure.Services) > 0 {
  481. return failure
  482. }
  483. if keystoreErr != nil {
  484. return keystoreErr
  485. }
  486. return nil
  487. }
  488. // Wait blocks the thread until the node is stopped. If the node is not running
  489. // at the time of invocation, the method immediately returns.
  490. func (n *Node) Wait() {
  491. n.lock.RLock()
  492. if n.server == nil {
  493. return
  494. }
  495. stop := n.stop
  496. n.lock.RUnlock()
  497. <-stop
  498. }
  499. // Restart terminates a running node and boots up a new one in its place. If the
  500. // node isn't running, an error is returned.
  501. func (n *Node) Restart() error {
  502. if err := n.Stop(); err != nil {
  503. return err
  504. }
  505. if err := n.Start(); err != nil {
  506. return err
  507. }
  508. return nil
  509. }
  510. // Attach creates an RPC client attached to an in-process API handler.
  511. func (n *Node) Attach() (*rpc.Client, error) {
  512. n.lock.RLock()
  513. defer n.lock.RUnlock()
  514. if n.server == nil {
  515. return nil, ErrNodeStopped
  516. }
  517. return rpc.DialInProc(n.inprocHandler), nil
  518. }
  519. // Server retrieves the currently running P2P network layer. This method is meant
  520. // only to inspect fields of the currently running server, life cycle management
  521. // should be left to this Node entity.
  522. func (n *Node) Server() *p2p.Server {
  523. n.lock.RLock()
  524. defer n.lock.RUnlock()
  525. return n.server
  526. }
  527. // Service retrieves a currently running service registered of a specific type.
  528. func (n *Node) Service(service interface{}) error {
  529. n.lock.RLock()
  530. defer n.lock.RUnlock()
  531. // Short circuit if the node's not running
  532. if n.server == nil {
  533. return ErrNodeStopped
  534. }
  535. // Otherwise try to find the service to return
  536. element := reflect.ValueOf(service).Elem()
  537. if running, ok := n.services[element.Type()]; ok {
  538. element.Set(reflect.ValueOf(running))
  539. return nil
  540. }
  541. return ErrServiceUnknown
  542. }
  543. // DataDir retrieves the current datadir used by the protocol stack.
  544. // Deprecated: No files should be stored in this directory, use InstanceDir instead.
  545. func (n *Node) DataDir() string {
  546. return n.config.DataDir
  547. }
  548. // InstanceDir retrieves the instance directory used by the protocol stack.
  549. func (n *Node) InstanceDir() string {
  550. return n.config.instanceDir()
  551. }
  552. // AccountManager retrieves the account manager used by the protocol stack.
  553. func (n *Node) AccountManager() *accounts.Manager {
  554. return n.accman
  555. }
  556. // IPCEndpoint retrieves the current IPC endpoint used by the protocol stack.
  557. func (n *Node) IPCEndpoint() string {
  558. return n.ipcEndpoint
  559. }
  560. // HTTPEndpoint retrieves the current HTTP endpoint used by the protocol stack.
  561. func (n *Node) HTTPEndpoint() string {
  562. return n.httpEndpoint
  563. }
  564. // WSEndpoint retrieves the current WS endpoint used by the protocol stack.
  565. func (n *Node) WSEndpoint() string {
  566. return n.wsEndpoint
  567. }
  568. // EventMux retrieves the event multiplexer used by all the network services in
  569. // the current protocol stack.
  570. func (n *Node) EventMux() *event.TypeMux {
  571. return n.eventmux
  572. }
  573. // OpenDatabase opens an existing database with the given name (or creates one if no
  574. // previous can be found) from within the node's instance directory. If the node is
  575. // ephemeral, a memory database is returned.
  576. func (n *Node) OpenDatabase(name string, cache, handles int) (ethdb.Database, error) {
  577. if n.config.DataDir == "" {
  578. return ethdb.NewMemDatabase()
  579. }
  580. return ethdb.NewLDBDatabase(n.config.resolvePath(name), cache, handles)
  581. }
  582. // ResolvePath returns the absolute path of a resource in the instance directory.
  583. func (n *Node) ResolvePath(x string) string {
  584. return n.config.resolvePath(x)
  585. }
  586. // apis returns the collection of RPC descriptors this node offers.
  587. func (n *Node) apis() []rpc.API {
  588. return []rpc.API{
  589. {
  590. Namespace: "admin",
  591. Version: "1.0",
  592. Service: NewPrivateAdminAPI(n),
  593. }, {
  594. Namespace: "admin",
  595. Version: "1.0",
  596. Service: NewPublicAdminAPI(n),
  597. Public: true,
  598. }, {
  599. Namespace: "debug",
  600. Version: "1.0",
  601. Service: debug.Handler,
  602. }, {
  603. Namespace: "debug",
  604. Version: "1.0",
  605. Service: NewPublicDebugAPI(n),
  606. Public: true,
  607. }, {
  608. Namespace: "web3",
  609. Version: "1.0",
  610. Service: NewPublicWeb3API(n),
  611. Public: true,
  612. },
  613. }
  614. }