github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/node/doc.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  /*
    13  Package node sets up multi-protocol Sberex nodes.
    14  
    15  In the model exposed by this package, a node is a collection of services which use shared
    16  resources to provide RPC APIs. Services can also offer devp2p protocols, which are wired
    17  up to the devp2p network when the node instance is started.
    18  
    19  
    20  Resources Managed By Node
    21  
    22  All file-system resources used by a node instance are located in a directory called the
    23  data directory. The location of each resource can be overridden through additional node
    24  configuration. The data directory is optional. If it is not set and the location of a
    25  resource is otherwise unspecified, package node will create the resource in memory.
    26  
    27  To access to the devp2p network, Node configures and starts p2p.Server. Each host on the
    28  devp2p network has a unique identifier, the node key. The Node instance persists this key
    29  across restarts. Node also loads static and trusted node lists and ensures that knowledge
    30  about other hosts is persisted.
    31  
    32  JSON-RPC servers which run HTTP, WebSocket or IPC can be started on a Node. RPC modules
    33  offered by registered services will be offered on those endpoints. Users can restrict any
    34  endpoint to a subset of RPC modules. Node itself offers the "debug", "admin" and "web3"
    35  modules.
    36  
    37  Service implementations can open LevelDB databases through the service context. Package
    38  node chooses the file system location of each database. If the node is configured to run
    39  without a data directory, databases are opened in memory instead.
    40  
    41  Node also creates the shared store of encrypted Sberex account keys. Services can access
    42  the account manager through the service context.
    43  
    44  
    45  Sharing Data Directory Among Instances
    46  
    47  Multiple node instances can share a single data directory if they have distinct instance
    48  names (set through the Name config option). Sharing behaviour depends on the type of
    49  resource.
    50  
    51  devp2p-related resources (node key, static/trusted node lists, known hosts database) are
    52  stored in a directory with the same name as the instance. Thus, multiple node instances
    53  using the same data directory will store this information in different subdirectories of
    54  the data directory.
    55  
    56  LevelDB databases are also stored within the instance subdirectory. If multiple node
    57  instances use the same data directory, openening the databases with identical names will
    58  create one database for each instance.
    59  
    60  The account key store is shared among all node instances using the same data directory
    61  unless its location is changed through the KeyStoreDir configuration option.
    62  
    63  
    64  Data Directory Sharing Example
    65  
    66  In this example, two node instances named A and B are started with the same data
    67  directory. Mode instance A opens the database "db", node instance B opens the databases
    68  "db" and "db-2". The following files will be created in the data directory:
    69  
    70     data-directory/
    71          A/
    72              nodekey            -- devp2p node key of instance A
    73              nodes/             -- devp2p discovery knowledge database of instance A
    74              db/                -- LevelDB content for "db"
    75          A.ipc                  -- JSON-RPC UNIX domain socket endpoint of instance A
    76          B/
    77              nodekey            -- devp2p node key of node B
    78              nodes/             -- devp2p discovery knowledge database of instance B
    79              static-nodes.json  -- devp2p static node list of instance B
    80              db/                -- LevelDB content for "db"
    81              db-2/              -- LevelDB content for "db-2"
    82          B.ipc                  -- JSON-RPC UNIX domain socket endpoint of instance A
    83          keystore/              -- account key store, used by both instances
    84  */
    85  package node