github.com/susy-go/susy-graviton@v0.0.0-20190614130430-36cddae42305/swarm/README.md (about)

     1  ## Swarm
     2  
     3  [https://swarm.sophon.org](https://swarm.sophon.org)
     4  
     5  Swarm is a distributed storage platform and content distribution service, a native base layer service of the sophon susyweb stack. The primary objective of Swarm is to provide a decentralized and redundant store for dapp code and data as well as block chain and state data. Swarm is also set out to provide various base layer services for susyweb, including node-to-node messaging, media streaming, decentralised database services and scalable state-channel infrastructure for decentralised service economies.
     6  
     7  [![Travis](https://travis-ci.org/susy-go/susy-graviton.svg?branch=master)](https://travis-ci.org/susy-go/susy-graviton)
     8  [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/sophysphere/orange-lounge?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
     9  
    10  ## Table of Contents
    11  
    12  *  [Building the source](#building-the-source)
    13  *  [Running Swarm](#running-swarm)
    14  *  [Documentation](#documentation)
    15  *  [Developers Guide](#developers-guide)
    16     *  [Go Environment](#development-environment)
    17     *  [Vendored Dependencies](#vendored-dependencies)
    18     *  [Testing](#testing)
    19     *  [Profiling Swarm](#profiling-swarm)
    20     *  [Metrics and Instrumentation in Swarm](#metrics-and-instrumentation-in-swarm)
    21  *  [Public Gateways](#public-gateways)
    22  *  [Swarm Dapps](#swarm-dapps)
    23  *  [Contributing](#contributing)
    24  *  [License](#license)
    25  
    26  ## Building the source
    27  
    28  Building Swarm requires Go (version 1.10 or later).
    29  
    30      go get -d github.com/susy-go/susy-graviton
    31  
    32      go install github.com/susy-go/susy-graviton/cmd/swarm
    33  
    34  ## Running Swarm
    35  
    36  Going through all the possible command line flags is out of scope here, but we've enumerated a few common parameter combos to get you up to speed quickly on how you can run your own Swarm node.
    37  
    38  To run Swarm you need an Sophon account. You can create a new account by running the following command:
    39  
    40      graviton account new
    41  
    42  You will be prompted for a password:
    43  
    44      Your new account is locked with a password. Please give a password. Do not forget this password.
    45      Passphrase:
    46      Repeat passphrase:
    47  
    48  Once you have specified the password, the output will be the Sophon address representing that account. For example:
    49  
    50      Address: {2f1cd699b0bf461dcfbf0098ad8f5587b038f0f1}
    51  
    52  Using this account, connect to Swarm with
    53  
    54      swarm --bzzaccount <your-account-here>
    55  
    56      # in our example
    57  
    58      swarm --bzzaccount 2f1cd699b0bf461dcfbf0098ad8f5587b038f0f1
    59  
    60  
    61  ### Verifying that your local Swarm node is running
    62  
    63  When running, Swarm is accessible through an HTTP API on port 8500.
    64  
    65  Confirm that it is up and running by pointing your browser to http://localhost:8500
    66  
    67  ### Sophon Name Service resolution
    68  
    69  The Sophon Name Service is the Sophon equivalent of DNS in the classic web. In order to use ENS to resolve names to Swarm content hashes (e.g. `bzz://theswarm.sof`), `swarm` has to connect to a `graviton` instance, which is synced with the Sophon mainnet. This is done using the `--ens-api` flag.
    70  
    71      swarm --bzzaccount <your-account-here> \
    72            --ens-api '$HOME/.sophon/graviton.ipc'
    73  
    74      # in our example
    75  
    76      swarm --bzzaccount 2f1cd699b0bf461dcfbf0098ad8f5587b038f0f1 \
    77            --ens-api '$HOME/.sophon/graviton.ipc'
    78  
    79  For more information on usage, features or command line flags, please consult the Documentation.
    80  
    81  
    82  ## Documentation
    83  
    84  Swarm documentation can be found at [https://swarm-guide.readthedocs.io](https://swarm-guide.readthedocs.io).
    85  
    86  
    87  ## Developers Guide
    88  
    89  ### Go Environment
    90  
    91  We assume that you have Go v1.10 installed, and `GOPATH` is set.
    92  
    93  You must have your working copy under `$GOPATH/src/github.com/susy-go/susy-graviton`.
    94  
    95  Most likely you will be working from your fork of `susy-graviton`, let's say from `github.com/nirname/susy-graviton`. Clone or move your fork into the right place:
    96  
    97  ```
    98  git clone git@github.com:nirname/susy-graviton.git $GOPATH/src/github.com/susy-go/susy-graviton
    99  ```
   100  
   101  
   102  ### Vendored Dependencies
   103  
   104  All dependencies are tracked in the `vendor` directory. We use `govendor` to manage them.
   105  
   106  If you want to add a new dependency, run `govendor fetch <import-path>`, then commit the result.
   107  
   108  If you want to update all dependencies to their latest upstream version, run `govendor fetch +v`.
   109  
   110  
   111  ### Testing
   112  
   113  This section explains how to run unit, integration, and end-to-end tests in your development sandbox.
   114  
   115  Testing one library:
   116  
   117  ```
   118  go test -v -cpu 4 ./swarm/api
   119  ```
   120  
   121  Note: Using options -cpu (number of cores allowed) and -v (logging even if no error) is recommended.
   122  
   123  Testing only some methods:
   124  
   125  ```
   126  go test -v -cpu 4 ./sof -run TestMethod
   127  ```
   128  
   129  Note: here all tests with prefix TestMethod will be run, so if you got TestMethod, TestMethod1, then both!
   130  
   131  Running benchmarks:
   132  
   133  ```
   134  go test -v -cpu 4 -bench . -run BenchmarkJoin
   135  ```
   136  
   137  
   138  ### Profiling Swarm
   139  
   140  This section explains how to add Go `pprof` profiler to Swarm
   141  
   142  If `swarm` is started with the `--pprof` option, a debugging HTTP server is made available on port 6060.
   143  
   144  You can bring up http://localhost:6060/debug/pprof to see the heap, running routines etc.
   145  
   146  By clicking full goroutine stack dump (clicking http://localhost:6060/debug/pprof/goroutine?debug=2) you can generate trace that is useful for debugging.
   147  
   148  
   149  ### Metrics and Instrumentation in Swarm
   150  
   151  This section explains how to visualize and use existing Swarm metrics and how to instrument Swarm with a new metric.
   152  
   153  Swarm metrics system is based on the `go-metrics` library.
   154  
   155  The most common types of measurements we use in Swarm are `counters` and `resetting timers`. Consult the `go-metrics` documentation for full reference of available types.
   156  
   157  ```
   158  # incrementing a counter
   159  metrics.GetOrRegisterCounter("network.stream.received_chunks", nil).Inc(1)
   160  
   161  # measuring latency with a resetting timer
   162  start := time.Now()
   163  t := metrics.GetOrRegisterResettingTimer("http.request.GET.time"), nil)
   164  ...
   165  t := UpdateSince(start)
   166  ```
   167  
   168  #### Visualizing metrics
   169  
   170  Swarm supports an InfluxDB exporter. Consult the help section to learn about the command line arguments used to configure it:
   171  
   172  ```
   173  swarm --help | grep metrics
   174  ```
   175  
   176  We use Grafana and InfluxDB to visualise metrics reported by Swarm. We keep our Grafana dashboards under version control at `./swarm/grafana_dashboards`. You could use them or design your own.
   177  
   178  We have built a tool to help with automatic start of Grafana and InfluxDB and provisioning of dashboards at https://github.com/nonsense/statsof , which requires that you have Docker installed.
   179  
   180  Once you have `statsof` installed, and you have Docker running locally, you have to:
   181  
   182  1. Run `statsof` and keep it running in the background
   183  ```
   184  statsof --rm --grafana-dashboards-folder $GOPATH/src/github.com/susy-go/susy-graviton/swarm/grafana_dashboards --influxdb-database metrics
   185  ```
   186  
   187  2. Run `swarm` with at least the following params:
   188  ```
   189  --metrics \
   190  --metrics.influxdb.export \
   191  --metrics.influxdb.endpoint "http://localhost:8086" \
   192  --metrics.influxdb.username "admin" \
   193  --metrics.influxdb.password "admin" \
   194  --metrics.influxdb.database "metrics"
   195  ```
   196  
   197  3. Open Grafana at http://localhost:3000 and view the dashboards to gain insight into Swarm.
   198  
   199  
   200  ## Public Gateways
   201  
   202  Swarm offers a local HTTP proxy API that Dapps can use to interact with Swarm. The Sophon Foundation is hosting a public gateway, which allows free access so that people can try Swarm without running their own node.
   203  
   204  The Swarm public gateways are temporary and users should not rely on their existence for production services.
   205  
   206  The Swarm public gateway can be found at https://swarm-gateways.net and is always running the latest `stable` Swarm release.
   207  
   208  ## Swarm Dapps
   209  
   210  You can find a few reference Swarm decentralised applications at: https://swarm-gateways.net/bzz:/swarmapps.sof
   211  
   212  Their source code can be found at: https://github.com/sophysphere/swarm-dapps
   213  
   214  ## Contributing
   215  
   216  Thank you for considering to help out with the source code! We welcome contributions from
   217  anyone on the internet, and are grateful for even the smallest of fixes!
   218  
   219  If you'd like to contribute to Swarm, please fork, fix, commit and send a pull request
   220  for the maintainers to review and merge into the main code base. If you wish to submit more
   221  complex changes though, please check up with the core devs first on [our Swarm gitter channel](https://gitter.im/sophysphere/orange-lounge)
   222  to ensure those changes are in line with the general philosophy of the project and/or get some
   223  early feedback which can make both your efforts much lighter as well as our review and merge
   224  procedures quick and simple.
   225  
   226  Please make sure your contributions adhere to our coding guidelines:
   227  
   228   * Code must adhere to the official Go [formatting](https://golang.org/doc/effective_go.html#formatting) guidelines (i.e. uses [gofmt](https://golang.org/cmd/gofmt/)).
   229   * Code must be documented adhering to the official Go [commentary](https://golang.org/doc/effective_go.html#commentary) guidelines.
   230   * Pull requests need to be based on and opened against the `master` branch.
   231   * [Code review guidelines](https://github.com/susy-go/susy-graviton/wiki/Code-Review-Guidelines).
   232   * Commit messages should be prefixed with the package(s) they modify.
   233     * E.g. "swarm/fuse: ignore default manifest entry"
   234  
   235  
   236  ## License
   237  
   238  The susy-graviton library (i.e. all code outside of the `cmd` directory) is licensed under the
   239  [GNU Lesser General Public License v3.0](https://www.gnu.org/licenses/lgpl-3.0.en.html), also
   240  included in our repository in the `COPYING.LESSER` file.
   241  
   242  The susy-graviton binaries (i.e. all code inside of the `cmd` directory) is licensed under the
   243  [GNU General Public License v3.0](https://www.gnu.org/licenses/gpl-3.0.en.html), also included
   244  in our repository in the `COPYING` file.