config.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. // Copyright 2014 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. "crypto/ecdsa"
  19. "fmt"
  20. "io/ioutil"
  21. "os"
  22. "path/filepath"
  23. "runtime"
  24. "strings"
  25. "sync"
  26. "github.com/ethereum/go-ethereum/accounts"
  27. "github.com/ethereum/go-ethereum/accounts/external"
  28. "github.com/ethereum/go-ethereum/accounts/keystore"
  29. "github.com/ethereum/go-ethereum/accounts/pluggable"
  30. "github.com/ethereum/go-ethereum/accounts/scwallet"
  31. "github.com/ethereum/go-ethereum/accounts/usbwallet"
  32. "github.com/ethereum/go-ethereum/common"
  33. "github.com/ethereum/go-ethereum/crypto"
  34. "github.com/ethereum/go-ethereum/log"
  35. "github.com/ethereum/go-ethereum/p2p"
  36. "github.com/ethereum/go-ethereum/p2p/enode"
  37. "github.com/ethereum/go-ethereum/params"
  38. "github.com/ethereum/go-ethereum/plugin"
  39. "github.com/ethereum/go-ethereum/rpc"
  40. )
  41. const (
  42. datadirPrivateKey = "nodekey" // Path within the datadir to the node's private key
  43. datadirDefaultKeyStore = "keystore" // Path within the datadir to the keystore
  44. datadirStaticNodes = "static-nodes.json" // Path within the datadir to the static node list
  45. datadirTrustedNodes = "trusted-nodes.json" // Path within the datadir to the trusted node list
  46. datadirNodeDatabase = "nodes" // Path within the datadir to store the node infos
  47. )
  48. // Config represents a small collection of configuration values to fine tune the
  49. // P2P network layer of a protocol stack. These values can be further extended by
  50. // all registered services.
  51. type Config struct {
  52. // Name sets the instance name of the node. It must not contain the / character and is
  53. // used in the devp2p node identifier. The instance name of geth is "geth". If no
  54. // value is specified, the basename of the current executable is used.
  55. Name string `toml:"-"`
  56. // UserIdent, if set, is used as an additional component in the devp2p node identifier.
  57. UserIdent string `toml:",omitempty"`
  58. // Version should be set to the version number of the program. It is used
  59. // in the devp2p node identifier.
  60. Version string `toml:"-"`
  61. // DataDir is the file system folder the node should use for any data storage
  62. // requirements. The configured data directory will not be directly shared with
  63. // registered services, instead those can use utility methods to create/access
  64. // databases or flat files. This enables ephemeral nodes which can fully reside
  65. // in memory.
  66. DataDir string
  67. // RaftLogDir is the file system folder the node use for raft-state, raft-snap and
  68. // raft-wal folders.
  69. RaftLogDir string
  70. // Configuration of peer-to-peer networking.
  71. P2P p2p.Config
  72. // Quorum
  73. QP2P *p2p.Config `toml:",omitempty"`
  74. // KeyStoreDir is the file system folder that contains private keys. The directory can
  75. // be specified as a relative path, in which case it is resolved relative to the
  76. // current directory.
  77. //
  78. // If KeyStoreDir is empty, the default location is the "keystore" subdirectory of
  79. // DataDir. If DataDir is unspecified and KeyStoreDir is empty, an ephemeral directory
  80. // is created by New and destroyed when the node is stopped.
  81. KeyStoreDir string `toml:",omitempty"`
  82. // ExternalSigner specifies an external URI for a clef-type signer
  83. ExternalSigner string `toml:",omitempty"`
  84. // UseLightweightKDF lowers the memory and CPU requirements of the key store
  85. // scrypt KDF at the expense of security.
  86. UseLightweightKDF bool `toml:",omitempty"`
  87. // InsecureUnlockAllowed allows user to unlock accounts in unsafe http environment.
  88. InsecureUnlockAllowed bool `toml:",omitempty"`
  89. // NoUSB disables hardware wallet monitoring and connectivity.
  90. NoUSB bool `toml:",omitempty"`
  91. // USB enables hardware wallet monitoring and connectivity.
  92. USB bool `toml:",omitempty"`
  93. // SmartCardDaemonPath is the path to the smartcard daemon's socket
  94. SmartCardDaemonPath string `toml:",omitempty"`
  95. // IPCPath is the requested location to place the IPC endpoint. If the path is
  96. // a simple file name, it is placed inside the data directory (or on the root
  97. // pipe path on Windows), whereas if it's a resolvable path name (absolute or
  98. // relative), then that specific path is enforced. An empty path disables IPC.
  99. IPCPath string
  100. // HTTPHost is the host interface on which to start the HTTP RPC server. If this
  101. // field is empty, no HTTP API endpoint will be started.
  102. HTTPHost string
  103. // HTTPPort is the TCP port number on which to start the HTTP RPC server. The
  104. // default zero value is/ valid and will pick a port number randomly (useful
  105. // for ephemeral nodes).
  106. HTTPPort int `toml:",omitempty"`
  107. // HTTPCors is the Cross-Origin Resource Sharing header to send to requesting
  108. // clients. Please be aware that CORS is a browser enforced security, it's fully
  109. // useless for custom HTTP clients.
  110. HTTPCors []string `toml:",omitempty"`
  111. // HTTPVirtualHosts is the list of virtual hostnames which are allowed on incoming requests.
  112. // This is by default {'localhost'}. Using this prevents attacks like
  113. // DNS rebinding, which bypasses SOP by simply masquerading as being within the same
  114. // origin. These attacks do not utilize CORS, since they are not cross-domain.
  115. // By explicitly checking the Host-header, the server will not allow requests
  116. // made against the server with a malicious host domain.
  117. // Requests using ip address directly are not affected
  118. HTTPVirtualHosts []string `toml:",omitempty"`
  119. // HTTPModules is a list of API modules to expose via the HTTP RPC interface.
  120. // If the module list is empty, all RPC API endpoints designated public will be
  121. // exposed.
  122. HTTPModules []string
  123. // HTTPTimeouts allows for customization of the timeout values used by the HTTP RPC
  124. // interface.
  125. HTTPTimeouts rpc.HTTPTimeouts
  126. // HTTPPathPrefix specifies a path prefix on which http-rpc is to be served.
  127. HTTPPathPrefix string `toml:",omitempty"`
  128. // WSHost is the host interface on which to start the websocket RPC server. If
  129. // this field is empty, no websocket API endpoint will be started.
  130. WSHost string
  131. // WSPort is the TCP port number on which to start the websocket RPC server. The
  132. // default zero value is/ valid and will pick a port number randomly (useful for
  133. // ephemeral nodes).
  134. WSPort int `toml:",omitempty"`
  135. // WSPathPrefix specifies a path prefix on which ws-rpc is to be served.
  136. WSPathPrefix string `toml:",omitempty"`
  137. // WSOrigins is the list of domain to accept websocket requests from. Please be
  138. // aware that the server can only act upon the HTTP request the client sends and
  139. // cannot verify the validity of the request header.
  140. WSOrigins []string `toml:",omitempty"`
  141. // WSModules is a list of API modules to expose via the websocket RPC interface.
  142. // If the module list is empty, all RPC API endpoints designated public will be
  143. // exposed.
  144. WSModules []string
  145. // WSExposeAll exposes all API modules via the WebSocket RPC interface rather
  146. // than just the public ones.
  147. //
  148. // *WARNING* Only set this if the node is running in a trusted network, exposing
  149. // private APIs to untrusted users is a major security risk.
  150. WSExposeAll bool `toml:",omitempty"`
  151. // GraphQLCors is the Cross-Origin Resource Sharing header to send to requesting
  152. // clients. Please be aware that CORS is a browser enforced security, it's fully
  153. // useless for custom HTTP clients.
  154. GraphQLCors []string `toml:",omitempty"`
  155. // GraphQLVirtualHosts is the list of virtual hostnames which are allowed on incoming requests.
  156. // This is by default {'localhost'}. Using this prevents attacks like
  157. // DNS rebinding, which bypasses SOP by simply masquerading as being within the same
  158. // origin. These attacks do not utilize CORS, since they are not cross-domain.
  159. // By explicitly checking the Host-header, the server will not allow requests
  160. // made against the server with a malicious host domain.
  161. // Requests using ip address directly are not affected
  162. GraphQLVirtualHosts []string `toml:",omitempty"`
  163. // Logger is a custom logger to use with the p2p.Server.
  164. Logger log.Logger `toml:",omitempty"`
  165. staticNodesWarning bool
  166. trustedNodesWarning bool
  167. oldGethResourceWarning bool
  168. // AllowUnprotectedTxs allows non EIP-155 protected transactions to be send over RPC.
  169. AllowUnprotectedTxs bool `toml:",omitempty"`
  170. // Quorum
  171. Plugins *plugin.Settings `toml:",omitempty"`
  172. EnableNodePermission bool `toml:",omitempty"` // comes from EnableNodePermissionFlag --permissioned.
  173. EnableMultitenancy bool `toml:",omitempty"` // comes from MultitenancyFlag flag
  174. }
  175. // IPCEndpoint resolves an IPC endpoint based on a configured value, taking into
  176. // account the set data folders as well as the designated platform we're currently
  177. // running on.
  178. func (c *Config) IPCEndpoint() string {
  179. // Short circuit if IPC has not been enabled
  180. if c.IPCPath == "" {
  181. return ""
  182. }
  183. // On windows we can only use plain top-level pipes
  184. if runtime.GOOS == "windows" {
  185. if strings.HasPrefix(c.IPCPath, `\\.\pipe\`) {
  186. return c.IPCPath
  187. }
  188. return `\\.\pipe\` + c.IPCPath
  189. }
  190. // Resolve names into the data directory full paths otherwise
  191. if filepath.Base(c.IPCPath) == c.IPCPath {
  192. if c.DataDir == "" {
  193. return filepath.Join(os.TempDir(), c.IPCPath)
  194. }
  195. return filepath.Join(c.DataDir, c.IPCPath)
  196. }
  197. return c.IPCPath
  198. }
  199. // NodeDB returns the path to the discovery node database.
  200. func (c *Config) NodeDB() string {
  201. if c.DataDir == "" {
  202. return "" // ephemeral
  203. }
  204. return c.ResolvePath(datadirNodeDatabase)
  205. }
  206. func (c *Config) QNodeDB() string {
  207. if c.DataDir == "" {
  208. return "" // ephemeral
  209. }
  210. return c.ResolvePath("qnodes")
  211. }
  212. // DefaultIPCEndpoint returns the IPC path used by default.
  213. func DefaultIPCEndpoint(clientIdentifier string) string {
  214. if clientIdentifier == "" {
  215. clientIdentifier = strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
  216. if clientIdentifier == "" {
  217. panic("empty executable name")
  218. }
  219. }
  220. config := &Config{DataDir: DefaultDataDir(), IPCPath: clientIdentifier + ".ipc"}
  221. return config.IPCEndpoint()
  222. }
  223. // HTTPEndpoint resolves an HTTP endpoint based on the configured host interface
  224. // and port parameters.
  225. func (c *Config) HTTPEndpoint() string {
  226. if c.HTTPHost == "" {
  227. return ""
  228. }
  229. return fmt.Sprintf("%s:%d", c.HTTPHost, c.HTTPPort)
  230. }
  231. // DefaultHTTPEndpoint returns the HTTP endpoint used by default.
  232. func DefaultHTTPEndpoint() string {
  233. config := &Config{HTTPHost: DefaultHTTPHost, HTTPPort: DefaultHTTPPort}
  234. return config.HTTPEndpoint()
  235. }
  236. // WSEndpoint resolves a websocket endpoint based on the configured host interface
  237. // and port parameters.
  238. func (c *Config) WSEndpoint() string {
  239. if c.WSHost == "" {
  240. return ""
  241. }
  242. return fmt.Sprintf("%s:%d", c.WSHost, c.WSPort)
  243. }
  244. // DefaultWSEndpoint returns the websocket endpoint used by default.
  245. func DefaultWSEndpoint() string {
  246. config := &Config{WSHost: DefaultWSHost, WSPort: DefaultWSPort}
  247. return config.WSEndpoint()
  248. }
  249. // ExtRPCEnabled returns the indicator whether node enables the external
  250. // RPC(http, ws or graphql).
  251. func (c *Config) ExtRPCEnabled() bool {
  252. return c.HTTPHost != "" || c.WSHost != ""
  253. }
  254. // NodeName returns the devp2p node identifier.
  255. func (c *Config) NodeName() string {
  256. name := c.name()
  257. // Backwards compatibility: previous versions used title-cased "Geth", keep that.
  258. if name == "geth" || name == "geth-testnet" {
  259. name = "Geth"
  260. }
  261. if c.UserIdent != "" {
  262. name += "/" + c.UserIdent
  263. }
  264. if c.Version != "" {
  265. name += "/v" + c.Version
  266. }
  267. name += "/" + runtime.GOOS + "-" + runtime.GOARCH
  268. name += "/" + runtime.Version()
  269. return name
  270. }
  271. func (c *Config) name() string {
  272. if c.Name == "" {
  273. progname := strings.TrimSuffix(filepath.Base(os.Args[0]), ".exe")
  274. if progname == "" {
  275. panic("empty executable name, set Config.Name")
  276. }
  277. return progname
  278. }
  279. return c.Name
  280. }
  281. // These resources are resolved differently for "geth" instances.
  282. var isOldGethResource = map[string]bool{
  283. "chaindata": true,
  284. "nodes": true,
  285. "nodekey": true,
  286. "static-nodes.json": false, // no warning for these because they have their
  287. "trusted-nodes.json": false, // own separate warning.
  288. }
  289. // ResolvePath resolves path in the instance directory.
  290. func (c *Config) ResolvePath(path string) string {
  291. if filepath.IsAbs(path) {
  292. return path
  293. }
  294. if c.DataDir == "" {
  295. return ""
  296. }
  297. // Backwards-compatibility: ensure that data directory files created
  298. // by geth 1.4 are used if they exist.
  299. if warn, isOld := isOldGethResource[path]; isOld {
  300. oldpath := ""
  301. if c.name() == "geth" {
  302. oldpath = filepath.Join(c.DataDir, path)
  303. }
  304. if oldpath != "" && common.FileExist(oldpath) {
  305. if warn {
  306. c.warnOnce(&c.oldGethResourceWarning, "Using deprecated resource file %s, please move this file to the 'geth' subdirectory of datadir.", oldpath)
  307. }
  308. return oldpath
  309. }
  310. }
  311. return filepath.Join(c.instanceDir(), path)
  312. }
  313. func (c *Config) instanceDir() string {
  314. if c.DataDir == "" {
  315. return ""
  316. }
  317. return filepath.Join(c.DataDir, c.name())
  318. }
  319. // NodeKey retrieves the currently configured private key of the node, checking
  320. // first any manually set key, falling back to the one found in the configured
  321. // data folder. If no key can be found, a new one is generated.
  322. func (c *Config) NodeKey() *ecdsa.PrivateKey {
  323. // Use any specifically configured key.
  324. if c.P2P.PrivateKey != nil {
  325. return c.P2P.PrivateKey
  326. }
  327. // Generate ephemeral key if no datadir is being used.
  328. if c.DataDir == "" {
  329. key, err := crypto.GenerateKey()
  330. if err != nil {
  331. log.Crit(fmt.Sprintf("Failed to generate ephemeral node key: %v", err))
  332. }
  333. return key
  334. }
  335. keyfile := c.ResolvePath(datadirPrivateKey)
  336. if key, err := crypto.LoadECDSA(keyfile); err == nil {
  337. return key
  338. }
  339. // No persistent key found, generate and store a new one.
  340. key, err := crypto.GenerateKey()
  341. if err != nil {
  342. log.Crit(fmt.Sprintf("Failed to generate node key: %v", err))
  343. }
  344. instanceDir := filepath.Join(c.DataDir, c.name())
  345. if err := os.MkdirAll(instanceDir, 0700); err != nil {
  346. log.Error(fmt.Sprintf("Failed to persist node key: %v", err))
  347. return key
  348. }
  349. keyfile = filepath.Join(instanceDir, datadirPrivateKey)
  350. if err := crypto.SaveECDSA(keyfile, key); err != nil {
  351. log.Error(fmt.Sprintf("Failed to persist node key: %v", err))
  352. }
  353. return key
  354. }
  355. // StaticNodes returns a list of node enode URLs configured as static nodes.
  356. func (c *Config) StaticNodes() []*enode.Node {
  357. return c.parsePersistentNodes(&c.staticNodesWarning, c.ResolvePath(datadirStaticNodes))
  358. }
  359. // TrustedNodes returns a list of node enode URLs configured as trusted nodes.
  360. func (c *Config) TrustedNodes() []*enode.Node {
  361. return c.parsePersistentNodes(&c.trustedNodesWarning, c.ResolvePath(datadirTrustedNodes))
  362. }
  363. // parsePersistentNodes parses a list of discovery node URLs loaded from a .json
  364. // file from within the data directory.
  365. func (c *Config) parsePersistentNodes(w *bool, path string) []*enode.Node {
  366. // Short circuit if no node config is present
  367. if c.DataDir == "" {
  368. return nil
  369. }
  370. if _, err := os.Stat(path); err != nil {
  371. return nil
  372. }
  373. c.warnOnce(w, "Found deprecated node list file %s, please use the TOML config file instead.", path)
  374. // Load the nodes from the config file.
  375. var nodelist []string
  376. if err := common.LoadJSON(path, &nodelist); err != nil {
  377. log.Error(fmt.Sprintf("Can't load node list file: %v", err))
  378. return nil
  379. }
  380. // Interpret the list as a discovery node array
  381. var nodes []*enode.Node
  382. for _, url := range nodelist {
  383. if url == "" {
  384. continue
  385. }
  386. node, err := enode.Parse(enode.ValidSchemes, url)
  387. if err != nil {
  388. log.Error(fmt.Sprintf("Node URL %s: %v\n", url, err))
  389. continue
  390. }
  391. nodes = append(nodes, node)
  392. }
  393. return nodes
  394. }
  395. // AccountConfig determines the settings for scrypt and keydirectory
  396. func (c *Config) AccountConfig() (int, int, string, error) {
  397. scryptN := keystore.StandardScryptN
  398. scryptP := keystore.StandardScryptP
  399. if c.UseLightweightKDF {
  400. scryptN = keystore.LightScryptN
  401. scryptP = keystore.LightScryptP
  402. }
  403. var (
  404. keydir string
  405. err error
  406. )
  407. switch {
  408. case filepath.IsAbs(c.KeyStoreDir):
  409. keydir = c.KeyStoreDir
  410. case c.DataDir != "":
  411. if c.KeyStoreDir == "" {
  412. keydir = filepath.Join(c.DataDir, datadirDefaultKeyStore)
  413. } else {
  414. keydir, err = filepath.Abs(c.KeyStoreDir)
  415. }
  416. case c.KeyStoreDir != "":
  417. keydir, err = filepath.Abs(c.KeyStoreDir)
  418. }
  419. return scryptN, scryptP, keydir, err
  420. }
  421. // Quorum
  422. //
  423. // Make sure plugin base dir exists
  424. func (c *Config) ResolvePluginBaseDir() error {
  425. if c.Plugins == nil {
  426. return nil
  427. }
  428. baseDir := c.Plugins.BaseDir.String()
  429. if baseDir == "" {
  430. baseDir = filepath.Join(c.DataDir, "plugins")
  431. }
  432. if !common.FileExist(baseDir) {
  433. if err := os.MkdirAll(baseDir, 0755); err != nil {
  434. return err
  435. }
  436. }
  437. absBaseDir, err := filepath.Abs(baseDir)
  438. if err != nil {
  439. return err
  440. }
  441. c.Plugins.BaseDir = plugin.EnvironmentAwaredValue(absBaseDir)
  442. return nil
  443. }
  444. // check if smart-contract-based permissioning is enabled by reading `--permissioned` flag and checking permission config file
  445. func (c *Config) IsPermissionEnabled() bool {
  446. fullPath := filepath.Join(c.DataDir, params.PERMISSION_MODEL_CONFIG)
  447. if _, err := os.Stat(fullPath); err != nil {
  448. log.Warn(fmt.Sprintf("%s file is missing. Smart-contract-based permission service will be disabled", params.PERMISSION_MODEL_CONFIG), "error", err)
  449. return false
  450. }
  451. return true
  452. }
  453. func makeAccountManager(conf *Config) (*accounts.Manager, string, error) {
  454. scryptN, scryptP, keydir, err := conf.AccountConfig()
  455. var ephemeral string
  456. if keydir == "" {
  457. // There is no datadir.
  458. keydir, err = ioutil.TempDir("", "go-ethereum-keystore")
  459. ephemeral = keydir
  460. }
  461. if err != nil {
  462. return nil, "", err
  463. }
  464. if err := os.MkdirAll(keydir, 0700); err != nil {
  465. return nil, "", err
  466. }
  467. // Assemble the account manager and supported backends
  468. var backends []accounts.Backend
  469. if len(conf.ExternalSigner) > 0 {
  470. log.Info("Using external signer", "url", conf.ExternalSigner)
  471. if extapi, err := external.NewExternalBackend(conf.ExternalSigner); err == nil {
  472. backends = append(backends, extapi)
  473. } else {
  474. return nil, "", fmt.Errorf("error connecting to external signer: %v", err)
  475. }
  476. }
  477. if len(backends) == 0 {
  478. // For now, we're using EITHER external signer OR local signers.
  479. // If/when we implement some form of lockfile for USB and keystore wallets,
  480. // we can have both, but it's very confusing for the user to see the same
  481. // accounts in both externally and locally, plus very racey.
  482. backends = append(backends, keystore.NewKeyStore(keydir, scryptN, scryptP))
  483. if conf.USB {
  484. // Start a USB hub for Ledger hardware wallets
  485. if ledgerhub, err := usbwallet.NewLedgerHub(); err != nil {
  486. log.Warn(fmt.Sprintf("Failed to start Ledger hub, disabling: %v", err))
  487. } else {
  488. backends = append(backends, ledgerhub)
  489. }
  490. // Start a USB hub for Trezor hardware wallets (HID version)
  491. if trezorhub, err := usbwallet.NewTrezorHubWithHID(); err != nil {
  492. log.Warn(fmt.Sprintf("Failed to start HID Trezor hub, disabling: %v", err))
  493. } else {
  494. backends = append(backends, trezorhub)
  495. }
  496. // Start a USB hub for Trezor hardware wallets (WebUSB version)
  497. if trezorhub, err := usbwallet.NewTrezorHubWithWebUSB(); err != nil {
  498. log.Warn(fmt.Sprintf("Failed to start WebUSB Trezor hub, disabling: %v", err))
  499. } else {
  500. backends = append(backends, trezorhub)
  501. }
  502. }
  503. if len(conf.SmartCardDaemonPath) > 0 {
  504. // Start a smart card hub
  505. if schub, err := scwallet.NewHub(conf.SmartCardDaemonPath, scwallet.Scheme, keydir); err != nil {
  506. log.Warn(fmt.Sprintf("Failed to start smart card hub, disabling: %v", err))
  507. } else {
  508. backends = append(backends, schub)
  509. }
  510. }
  511. if conf.Plugins != nil {
  512. if _, ok := conf.Plugins.Providers[plugin.AccountPluginInterfaceName]; ok {
  513. pluginBackend := pluggable.NewBackend()
  514. backends = append(backends, pluginBackend)
  515. }
  516. }
  517. }
  518. return accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: conf.InsecureUnlockAllowed}, backends...), ephemeral, nil
  519. }
  520. var warnLock sync.Mutex
  521. func (c *Config) warnOnce(w *bool, format string, args ...interface{}) {
  522. warnLock.Lock()
  523. defer warnLock.Unlock()
  524. if *w {
  525. return
  526. }
  527. l := c.Logger
  528. if l == nil {
  529. l = log.Root()
  530. }
  531. l.Warn(fmt.Sprintf(format, args...))
  532. *w = true
  533. }