Skip to content
Snippets Groups Projects
Unverified Commit fa821f97 authored by Luca Moser's avatar Luca Moser Committed by GitHub
Browse files

Merge pull request #218 from iotaledger/feat/next-version

Merge 0.1.0 into master
parents 70d9ccc5 0753dc73
No related branches found
No related tags found
No related merge requests found
---
name: Bug report
about: Create a report to help us improve
title: ""
labels: bug
assignees: ''
---
<!--- Remove text and sections that do not apply -->
<!--- Please anonymize personal data such as IP addresses -->
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
- Go to ...
- Edit config to ...
- See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Environment information:**
- OS: [e.g. Ubuntu 18.04]
- RAM: [e.g. 4 GB]
- Cores: [e.g. 4 Cores]
- Type: [e.g. Raspberry Pi 3B+, VPS, ...]
- GoShimmer version [e.g. 0.2.1]
**Additional context**
Add any other context about the problem here [e.g. GoShimmer logs, errors, screenshots]
---
name: Feature request
about: Suggest an idea for this project
title: ""
labels: feature
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.
name: Release
on:
release:
types: [published]
jobs:
Release:
name: Release
runs-on: [ubuntu-latest]
container:
image: iotmod/goreleaser-cgo-cross-compiler:1.13.5
volumes: [/repo]
steps:
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Release GoShimmer
run: goreleaser --rm-dist
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Test GoShimmer
on:
push:
pull_request:
types: [opened, reopened]
jobs:
build:
name: Test GoShimmer
runs-on: ubuntu-latest
steps:
- name: Set up Go 1.13
uses: actions/setup-go@v1
with:
go-version: 1.13
- name: Check out code into the Go module directory
uses: actions/checkout@v2
- name: Run Tests
run: go test ./...
...@@ -11,6 +11,11 @@ ...@@ -11,6 +11,11 @@
# Output of the go coverage tool, specifically when used with LiteIDE # Output of the go coverage tool, specifically when used with LiteIDE
*.out *.out
# Logs
logs/*
testNodes/*
*.log
# Project files # Project files
.idea .idea
......
[submodule "IOTAtangle"]
path = IOTAtangle
url = https://github.com/glumb/IOTAtangle.git
[submodule "socket.io-client"]
path = socket.io-client
url = https://github.com/socketio/socket.io-client.git
# Documentation at http://goreleaser.com
# Project name
project_name: GoShimmer
# Environment variables
env:
- GO111MODULE=on
# Builds
builds:
# macOS AMD64
- id: goshimmer-darwin-amd64
binary: goshimmer
env:
- CGO_ENABLED=1
- CC=o64-clang
- CXX=o64-clang++
ldflags:
- -s -w -X github.com/iotaledger/goshimmer/plugins/cli.AppVersion={{.Version}}
flags:
- -tags=pow_avx
main: main.go
goos:
- darwin
goarch:
- amd64
# Linux AMD64
- id: goshimmer-linux-amd64
binary: goshimmer
env:
- CGO_ENABLED=1
ldflags:
- -s -w -X github.com/iotaledger/goshimmer/plugins/cli.AppVersion={{.Version}}
flags:
- -tags=pow_avx
main: main.go
goos:
- linux
goarch:
- amd64
# Windows AMD64
- id: goshimmer-windows-amd64
binary: goshimmer
env:
- CGO_ENABLED=1
- CC=x86_64-w64-mingw32-gcc
- CXX=x86_64-w64-mingw32-g++
ldflags:
- -s -w -X github.com/iotaledger/goshimmer/plugins/cli.AppVersion={{.Version}}
flags:
- -tags=pow_avx
main: main.go
goos:
- windows
goarch:
- amd64
# Archives
archives:
- format: tar.gz
wrap_in_directory: true
format_overrides:
- goos: windows
format: zip
name_template: "{{.ProjectName}}-{{.Version}}_{{.Os}}_{{.Arch}}"
replacements:
amd64: x86_64
386: 32bit
arm: ARM
arm64: ARM64
darwin: macOS
linux: Linux
windows: Windows
openbsd: OpenBSD
netbsd: NetBSD
freebsd: FreeBSD
dragonfly: DragonFlyBSD
files:
- README.md
- LICENSE
- config.json
# Checksum
checksum:
name_template: "checksums.txt"
# Snapshot
snapshot:
name_template: "{{ .Tag }}"
# Changelog
changelog:
skip: true
# Release
release:
prerelease: auto
name_template: "{{.ProjectName}}-{{.Version}}"
github:
owner: iotaledger
name: goshimmer
\ No newline at end of file
os: linux
language: go
go:
- 1.13
cache:
directories:
- $HOME/gopath/pkg/mod
env:
- GO111MODULE=on
# we are using go modules, so there is nothing to install
install: true
# v0.1.0 - 2020-01-31
> Note that this release is a complete breaking change, therefore node operators are instructed to upgrade.
This release mainly integrates the shared codebase between Hornet and GoShimmer called [hive.go](https://github.com/iotaledger/hive.go),
to foster improvements in both projects simultaneously. Additionally, the autopeering code from [autopeering-sim](https://github.com/iotaledger/autopeering-sim)
has been integrated into the codebase. For developers a Go client library is now available to communicate
with a GoShimmer node in order to issue, get and search zero value transactions and retrieve neighbor information.
A detailed list about the changes in v0.1.0 can be seen under the given [milestone](https://github.com/iotaledger/goshimmer/milestone/1?closed=1).
* Adds config keys to make bind addresses configurable
* Adds a `relay-checker` tool to check transaction propagation
* Adds database versioning
* Adds concrete shutdown order for plugins
* Adds BadgerDB garbage collection routine
* Adds SPA dashboard with TPS and memory chart, neighbors and Tangle explorer (`spa` plugin)
* Adds option to manually define autopeering seed/private keys
* Adds Golang CI and GitHub workflows as part of the continuous integration pipeline
* Adds back off policies when doing network operations
* Adds an open port check which checks whether NATs are configured properly
* Adds `netutil` package
* Adds the glumb visualizer backend as a plugin called `graph` (has to be manually enabled, check the readme)
* Adds rudimentary PoW as a rate control mechanism
* Adds the autopeering code from autopeering-sim
* Adds association between transactions and their address
* Adds the possibility to allow a node to function/start with gossiping disabled
* Adds buffered connections for gossip messages
* Adds an OAS/Swagger specification file for the web API
* Adds web API and refactors endpoints: `broadcastData`, `findTransactionHashes`,
`getNeighbors`, `getTransactionObjectsByHash`, `getTransactionTrytesByHash`, `getTransactionsToApprove`, `spammer`
* Adds a Go client library over the web API
* Adds a complete rewrite of the gossiping layer
* Fixes the autopeering visualizer to conform to the newest autopeering changes.
The visualizer can be accessed [here](http://ressims.iota.cafe/).
* Fixes parallel connections by improving the peer selection mechanism
* Fixes that LRU caches are not flushed correctly up on shutdown
* Fixes consistent application naming (removes instances of sole "Shimmer" in favor of "GoShimmer")
* Fixes several analysis server related issues
* Fixes race condition in the PoW code
* Fixes race condition in the `daemon` package
* Fixes several race conditions in the `analysis` package
* Fixes the database not being closed when the node shuts down
* Fixes `webauth` plugin to function properly with the web API
* Fixes solidification related issues
* Fixes several instances of overused goroutine spawning
* Upgrades to [BadgerDB](https://github.com/dgraph-io/badger) v2.0.1
* Upgrades to latest [iota.go](https://github.com/iotaledger/iota.go) library
* Removes sent count from spammed transactions
* Removes usage of `errors.Identifiable` and `github.com/pkg/errors` in favor of standard lib `errors` package
* Use `network`, `parameter`, `events`, `database`, `logger`, `daemon`, `workerpool` and `node` packages from hive.go
* Removes unused plugins (`zmq`, `dashboard`, `ui`)
\ No newline at end of file
...@@ -31,5 +31,7 @@ EXPOSE 14626/tcp ...@@ -31,5 +31,7 @@ EXPOSE 14626/tcp
# Copy the Pre-built binary file from the previous stage # Copy the Pre-built binary file from the previous stage
COPY --from=build /go/bin/goshimmer . COPY --from=build /go/bin/goshimmer .
# Copy the docker config
COPY docker.config.json config.json
ENTRYPOINT ["./goshimmer"] ENTRYPOINT ["./goshimmer"]
Subproject commit 07bba77a296a2d06277cdae56aa963abeeb5f66e
Makefile 0 → 100644
SHELL := /bin/bash
REPO := $(shell pwd)
GOFILES_NOVENDOR := $(shell go list -f "{{.Dir}}" ./...)
PACKAGES_NOVENDOR := $(shell go list ./...)
PROTOC_GEN_GO := $(GOPATH)/bin/protoc-gen-go
# Protobuf generated go files
PROTO_FILES = $(shell find . -path ./vendor -prune -o -type f -name '*.proto' -print)
PROTO_GO_FILES = $(patsubst %.proto, %.pb.go, $(PROTO_FILES))
PROTO_GO_FILES_REAL = $(shell find . -path ./vendor -prune -o -type f -name '*.pb.go' -print)
.PHONY: build
build: proto
go build -o goshimmer
# Protobuffing
.PHONY: proto
proto: $(PROTO_GO_FILES)
# If $GOPATH/bin/protoc-gen-go does not exist, we'll run this command to install it.
$(PROTOC_GEN_GO):
(GO111MODULE=off go get -v github.com/golang/protobuf/protoc-gen-go)
# Implicit compile rule for GRPC/proto files
%.pb.go: %.proto | $(PROTOC_GEN_GO)
protoc $< --go_out=plugins=grpc,paths=source_relative:.
.PHONY: clean_proto
clean_proto:
@rm -f $(PROTO_GO_FILES_REAL)
.PHONY: vet
vet:
@echo "Running go vet."
@go vet ${PACKAGES_NOVENDOR}
.PHONY: test
test: vet
go test -timeout 30s ./... ${GOPACKAGES_NOVENDOR}
# goshimmer <h1 align="center">
<br>
<a href="https://docs.iota.org/docs/node-software/0.1/goshimmer/introduction/overview.md"><img src="images/GoShimmer.png"></a>
</h1>
[![Build Status](https://travis-ci.org/iotaledger/goshimmer.svg?branch=master)](https://travis-ci.org/iotaledger/goshimmer) <h2 align="center">Prototype node software for an IOTA network without the Coordinator</h2>
## Run Shimmer <p align="center">
<a href="https://docs.iota.org/docs/node-software/0.1/goshimmer/introduction/overview.md" style="text-decoration:none;">
<img src="https://img.shields.io/badge/Documentation%20portal-blue.svg?style=for-the-badge" alt="Developer documentation portal">
</p>
<p align="center">
<a href="https://discord.iota.org/" style="text-decoration:none;"><img src="https://img.shields.io/badge/Discord-9cf.svg?logo=discord" alt="Discord"></a>
<a href="https://iota.stackexchange.com/" style="text-decoration:none;"><img src="https://img.shields.io/badge/StackExchange-9cf.svg?logo=stackexchange" alt="StackExchange"></a>
<a href="https://github.com/iotaledger/goshimmer/blob/master/LICENSE" style="text-decoration:none;"><img src="https://img.shields.io/github/license/iotaledger/goshimmer.svg" alt="Apache 2.0 license"></a>
<a href="https://golang.org/doc/install" style="text-decoration:none;"><img src="https://img.shields.io/github/go-mod/go-version/iotaledger/goshimmer" alt="Go version"></a>
<a href="" style="text-decoration:none;"><img src="https://img.shields.io/github/workflow/status/iotaledger/goshimmer/Build" alt="Build status"></a>
<a href="" style="text-decoration:none;"><img src="https://img.shields.io/github/v/release/iotaledger/goshimmer" alt="Latest release"></a>
</p>
<p align="center">
<a href="#about">About</a>
<a href="#design">Design</a>
<a href="#implemented-coordicide-modules">Implemented Coordicide modules</a>
<a href="#work-in-progress-modules">Work-in-progress modules</a>
<a href="#installation">Installation</a>
<a href="#getting-started">Getting started</a>
<a href="#client-library-and-http-api-reference">Client-Library and HTTP API reference</a>
<a href="#supporting-the-project">Supporting the project</a>
<a href="#joining-the-discussion">Joining the discussion</a>
</p>
First, you need to [install Go](https://golang.org/doc/install) if it is not already installed on your machine. It is recommended that you use the most recent version of Go. ---
### Requirements ## About
- gcc: Some packages in this repo might require to be compiled by gcc. Windows users can install [MinGW-gcc](http://tdm-gcc.tdragon.net/download). This repository is where the IOTA Foundation's Research Department runs simulations of the Coordicide modules to study and evaluate their performance.
The aim of this open repository is to give the community the opportunity to follow developments, take part in testing, and learn more about [Coordicide](https://coordicide.iota.org/).
## Build **Note:** You can find details about future development plans in our [roadmap](https://roadmap.iota.org).
If you need to develop locally and be able to build by using your local code, i.e., without waiting for pushing your commits on the repo, clone the repository directly inside the `src/github.com/iotaledger/` folder of your `$GOPATH` with the command: ## Design
``` The code in GoShimmer is modular, where each module represents either one of the [Coordicide components](https://coordicide.iota.org/) or a basic node function such as the gossip layer, ledger state, and API.
git clone git@github.com:iotaledger/goshimmer.git
```
or if you prefer https over ssh ![Coordicide blueprint](images/building-blocks.png)
``` This approach allows us to develop each module in parallel and to test GoShimmer with one or more different versions.
git clone https://github.com/iotaledger/goshimmer.git
``` Each module is defined in the `packages` directory and can be enabled, using the `plugins` directory.
**Note:** See the `main.go` file to see which plugins are currently supported.
## Implemented Coordicide modules
The `master` branch is the stable version of the GoShimmer software, which includes a minimal set of modules to allow you to send and gossip zero-value transactions.
The `master` branch includes the following Coordicide modules:
- [Node identities](https://coordicide.iota.org/module1)
- [Autopeering](https://coordicide.iota.org/module2)
The autopeering module is divided into two submodules:
- **Peer discovery:** Responsible for operations such as discovering new peers and verifying their online status
- **Neighbor selection:** Responsible for finding and managing neighbors
![Autopeering design](images/autopeering.png)
We also have a standalone autopeering simulator in this [repository](https://github.com/iotaledger/autopeering-sim).
## Work-in-progress modules
Work-in-progress modules are typically kept on a different branch such as `mana`, and are not compatible with the `master` branch. Therefore, nodes that run these branches cannot join the current network because the code either is still too experimental or it includes breaking changes.
The following Coordicide modules are a work in progress:
- [Mana](https://coordicide.iota.org/module1): The `mana` branch contains a first implementation of the mana module in the `packages` directory.
Verify that you have installed the minimal required go version (1.12.7): - [Cellular Consensus](https://coordicide.iota.org/module5.1.1): The `ca` branch contains a first implementation of the Cellular Consensus module in the `packages` directory.
- [Fast Probabilistic Consensus](https://coordicide.iota.org/module5.1.2): The `fpc` branch contains a first implementation of the Fast Probabilistic Consensus module in the `packages` directory. We also have a standalone FPC simulator in this [repository](https://github.com/iotaledger/fpc-sim).
- [Spam Protection](https://coordicide.iota.org/module3): You can find the initial simulation source code of the rate control in this [repository](https://github.com/andypandypi/IOTARateControl) and the source code of the Adaptive Proof of Work simulator [here](https://github.com/iotaledger/adaptive-pow-sim).
As well as these modules, we are working on the following node functions:
- Ledger State: The `ledger_state` branch implements a version of the [parallel-reality-based ledger state](https://iota.cafe/t/parallel-reality-based-ledger-state-using-utxo/261) (using the UTXO model).
![parallel_reality](images/outputs.png "Ledger State")
## Client-Library and HTTP API reference
You can use the Go client-library to interact with GoShimmer (located under `github.com/iotaledger/goshimmer/client`).
Alternatively, you can check out the [API docs](https://docs.iota.org/docs/node-software/0.1/goshimmer/references/api-reference)
to implement your own client or inspect the available HTTP API endpoints.
For code generation, you might want to use the [OAS/Swagger specification file](https://github.com/iotaledger/goshimmer/blob/master/plugins/webapi/api.yaml) directly.
## Installation
You have two options to install and run GoShimmer:
- Use the precompiled executable file
- Compile the code from source
### Execute the precompiled executable file
This repository includes a `goshimmer` file (for Linux and macOS) and a `goshimmer.exe` file (for Windows), which are precompiled executables.
To run the node, all you need to do is execute one of these files, depending on your operating system.
```bash
# Linux and macOS
./goshimmer
# Windows
goshimmer.exe
``` ```
### Compile the code from source
If you want to build your own executable file, you need to follow these steps.
#### Prerequisites
To complete this guide, you need to have at least [version 1.13 of Go installed](https://golang.org/doc/install) on your device.
To check if you have Go installed, run the following command:
```bash
go version go version
``` ```
You can build your executable (as well as cross compiling for other architectures) by running the `go build` tool inside the just cloned folder `goshimmer`: If Go is installed, you should see the version that's installed.
``` ---
go build -o shimmer
```
On Windows: 1. Clone the repository
```
ren shimmer shimmer.exe
```
You can then run by: ```bash
git clone https://github.com/iotaledger/goshimmer.git
```
Linux 2. Change into the `goshimmer` directory
```
./shimmer
```
Windows 3. Use one of the following commands to build your executable file, depending on your operating system
```
shimmer
```
## Docker ```bash
# Linux and macOS
go build -o goshimmer
# Windows
go build -o goshimmer.exe
```
To run Shimmer on docker, you must first build the image with **Note:** If you're using Windows PowerShell, enclose `goshimmer.exe` in single quotation marks. For example: go build -o 'goshimmer.exe'.
```
docker build -t iotaledger/goshimmer . ## Getting started
```
and then run it with When you first run GoShimmer, the node starts running and tries to connects to neighbors, using the autopeering module.
```
docker run --rm -it -v "$(pwd)/mainnetdb:/app/mainnetdb" iotaledger/goshimmer To run other modules such as the `spammer` or the Glumb visualizer `graph`, you can configure GoShimmer to enable them through plugins.
```
You may replace `$(pwd)/mainnetdb` with a custom path to the database folder.
To start Shimmer in the background, you can also simply use [Docker Compose](https://docs.docker.com/compose/) by running **Note:** For a list of all the available configuration parameters, you can run the following command:
```bash
# Linux and macOS
./goshimmer -help
# Windows
goshimmer.exe -help
``` ```
docker-compose up -d
You can configure GoShimmer in the following ways:
* Use a configuration file called `config.json`
* Use command-line options
The repository includes a `config.json` file, which the executable file will find and use when you execute it.
To use the command line, execute the file with one of the following commands, depending on your operating system
```bash
# Linux and macOS
./goshimmer --node.enablePlugins "spammer"
# Windows
goshimmer.exe --node.enablePlugins "spammer"
``` ```
Here, we use the command-line flags to enable the spammer plugin. This plugin allows you to send spam transactions to your node.
### Dashboard
GoShimmer provides access to a SPA dashboard showing TPS, memory chart, neighbors and a Tangle explorer.
You can change its configuration (e.g, bind address, port) under the section `dashboard` of the `config.json` file, for example by changing the bind address to `0.0.0.0:8081` to enable the access from remote and/or by enabling the authentication.
To access the dashboard, you can use your browser (the default address is `http://127.0.0.1:8081`).
![dashboard](images/dashboard.png "Dashboard")
### Installing the Glumb visualizer
The Glumb visualizer allows you to view the transactions in the network, using a web browser.
1. Enable the `graph` plugin either in your `config.json` file or in the command line (`--node.enablePlugins=["graph"]`)
2. If you're running GoShimmer with the precompiled executable file, do the following in the `goshimmer` directory:
```bash
git clone https://github.com/glumb/IOTAtangle.git
// only this version seems to be stable
cd IOTAtangle && git reset --hard 07bba77a296a2d06277cdae56aa963abeeb5f66e
cd ../
git clone https://github.com/socketio/socket.io-client.git
```
3. If you built the code from source, do the following in the `goshimmer` directory:
```bash
git submodule init
git submodule update
```
To open the visualizer, run GoShimmer, and go to `127.0.0.1:8083` in a web browser.
## Supporting the project
If you want to contribute to the code, consider posting a [bug report](https://github.com/iotaledger/goshimmer/issues/new-issue), feature request or a [pull request](https://github.com/iotaledger/goshimmer/pulls/).
When creating a pull request, we recommend that you do the following:
1. Clone the repository
2. Create a new branch for your fix or feature. For example, `git checkout -b fix/my-fix` or ` git checkout -b feat/my-feature`.
3. Run the `go fmt` command to make sure your code is well formatted
4. Document any exported packages
5. Target your pull request to be merged with `dev`
## Joining the discussion
If you want to get involved in the community, need help getting started, have any issues related to the repository or just want to discuss blockchain, distributed ledgers, and IoT with other people, feel free to join our [Discord](https://discord.iota.org/).
// Implements a very simple wrapper for GoShimmer's web API .
package goshimmer
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"io"
"io/ioutil"
"net/http"
webapi_broadcastData "github.com/iotaledger/goshimmer/plugins/webapi/broadcastData"
webapi_findTransactionHashes "github.com/iotaledger/goshimmer/plugins/webapi/findTransactionHashes"
webapi_getNeighbors "github.com/iotaledger/goshimmer/plugins/webapi/getNeighbors"
webapi_getTransactionObjectsByHash "github.com/iotaledger/goshimmer/plugins/webapi/getTransactionObjectsByHash"
webapi_getTransactionTrytesByHash "github.com/iotaledger/goshimmer/plugins/webapi/getTransactionTrytesByHash"
webapi_gtta "github.com/iotaledger/goshimmer/plugins/webapi/gtta"
webapi_spammer "github.com/iotaledger/goshimmer/plugins/webapi/spammer"
webapi_auth "github.com/iotaledger/goshimmer/plugins/webauth"
"github.com/iotaledger/iota.go/consts"
"github.com/iotaledger/iota.go/guards"
"github.com/iotaledger/iota.go/trinary"
)
var (
ErrBadRequest = errors.New("bad request")
ErrInternalServerError = errors.New("internal server error")
ErrNotFound = errors.New("not found")
ErrUnauthorized = errors.New("unauthorized")
ErrUnknownError = errors.New("unknown error")
ErrNotImplemented = errors.New("operation not implemented/supported/available")
)
const (
routeBroadcastData = "broadcastData"
routeGetTransactionTrytesByHash = "getTransactionTrytesByHash"
routeGetTransactionObjectsByHash = "getTransactionObjectsByHash"
routeFindTransactionsHashes = "findTransactionHashes"
routeGetNeighbors = "getNeighbors"
routeGetTransactionsToApprove = "getTransactionsToApprove"
routeSpammer = "spammer"
routeLogin = "login"
contentTypeJSON = "application/json"
)
func NewGoShimmerAPI(node string, httpClient ...http.Client) *GoShimmerAPI {
if len(httpClient) > 0 {
return &GoShimmerAPI{node: node, httpClient: httpClient[0]}
}
return &GoShimmerAPI{node: node}
}
// GoShimmerAPI is an API wrapper over the web API of GoShimmer.
type GoShimmerAPI struct {
httpClient http.Client
node string
jwt string
}
type errorresponse struct {
Error string `json:"error"`
}
func interpretBody(res *http.Response, decodeTo interface{}) error {
resBody, err := ioutil.ReadAll(res.Body)
if err != nil {
return fmt.Errorf("unable to read response body: %w", err)
}
defer res.Body.Close()
if res.StatusCode == http.StatusOK || res.StatusCode == http.StatusCreated {
return json.Unmarshal(resBody, decodeTo)
}
errRes := &errorresponse{}
if err := json.Unmarshal(resBody, errRes); err != nil {
return fmt.Errorf("unable to read error from response body: %w", err)
}
switch res.StatusCode {
case http.StatusInternalServerError:
return fmt.Errorf("%w: %s", ErrInternalServerError, errRes.Error)
case http.StatusNotFound:
return fmt.Errorf("%w: %s", ErrNotFound, errRes.Error)
case http.StatusBadRequest:
return fmt.Errorf("%w: %s", ErrBadRequest, errRes.Error)
case http.StatusUnauthorized:
return fmt.Errorf("%w: %s", ErrUnauthorized, errRes.Error)
case http.StatusNotImplemented:
return fmt.Errorf("%w: %s", ErrNotImplemented, errRes.Error)
}
return fmt.Errorf("%w: %s", ErrUnknownError, errRes.Error)
}
func (api *GoShimmerAPI) do(method string, route string, reqObj interface{}, resObj interface{}) error {
// marshal request object
var data []byte
if reqObj != nil {
var err error
data, err = json.Marshal(reqObj)
if err != nil {
return err
}
}
// construct request
req, err := http.NewRequest(method, fmt.Sprintf("%s/%s", api.node, route), func() io.Reader {
if data == nil {
return nil
}
return bytes.NewReader(data)
}())
if err != nil {
return err
}
if data != nil {
req.Header.Set("Content-Type", contentTypeJSON)
}
// add authorization header with JWT
if len(api.jwt) > 0 {
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", api.jwt))
}
// make the request
res, err := api.httpClient.Do(req)
if err != nil {
return err
}
if resObj == nil {
return nil
}
// write response into response object
if err := interpretBody(res, resObj); err != nil {
return err
}
return nil
}
// Login authorizes this API instance against the web API.
// You must call this function before any before any other call, if the web-auth plugin is enabled.
func (api *GoShimmerAPI) Login(username string, password string) error {
res := &webapi_auth.Response{}
if err := api.do(http.MethodPost, routeLogin,
&webapi_auth.Request{Username: username, Password: password}, res); err != nil {
return err
}
api.jwt = res.Token
return nil
}
// BroadcastData sends the given data by creating a zero value transaction in the backend targeting the given address.
func (api *GoShimmerAPI) BroadcastData(targetAddress trinary.Trytes, data string) (trinary.Hash, error) {
if !guards.IsHash(targetAddress) {
return "", fmt.Errorf("%w: invalid address: %s", consts.ErrInvalidHash, targetAddress)
}
res := &webapi_broadcastData.Response{}
if err := api.do(http.MethodPost, routeBroadcastData,
&webapi_broadcastData.Request{Address: targetAddress, Data: data}, res); err != nil {
return "", err
}
return res.Hash, nil
}
// GetTransactionTrytesByHash gets the corresponding transaction trytes given the transaction hashes.
func (api *GoShimmerAPI) GetTransactionTrytesByHash(txHashes trinary.Hashes) ([]trinary.Trytes, error) {
for _, hash := range txHashes {
if !guards.IsTrytes(hash) {
return nil, fmt.Errorf("%w: invalid hash: %s", consts.ErrInvalidHash, hash)
}
}
res := &webapi_getTransactionTrytesByHash.Response{}
if err := api.do(http.MethodPost, routeGetTransactionTrytesByHash,
&webapi_getTransactionTrytesByHash.Request{Hashes: txHashes}, res); err != nil {
return nil, err
}
return res.Trytes, nil
}
// GetTransactionObjectsByHash gets the transaction objects given the transaction hashes.
func (api *GoShimmerAPI) GetTransactionObjectsByHash(txHashes trinary.Hashes) ([]webapi_getTransactionObjectsByHash.Transaction, error) {
for _, hash := range txHashes {
if !guards.IsTrytes(hash) {
return nil, fmt.Errorf("%w: invalid hash: %s", consts.ErrInvalidHash, hash)
}
}
res := &webapi_getTransactionObjectsByHash.Response{}
if err := api.do(http.MethodPost, routeGetTransactionObjectsByHash,
&webapi_getTransactionObjectsByHash.Request{Hashes: txHashes}, res); err != nil {
return nil, err
}
return res.Transactions, nil
}
// FindTransactionHashes finds the given transaction hashes given the query.
func (api *GoShimmerAPI) FindTransactionHashes(query *webapi_findTransactionHashes.Request) ([]trinary.Hashes, error) {
for _, hash := range query.Addresses {
if !guards.IsTrytes(hash) {
return nil, fmt.Errorf("%w: invalid hash: %s", consts.ErrInvalidHash, hash)
}
}
res := &webapi_findTransactionHashes.Response{}
if err := api.do(http.MethodPost, routeFindTransactionsHashes, query, res); err != nil {
return nil, err
}
return res.Transactions, nil
}
// GetNeighbors gets the chosen/accepted neighbors.
// If knownPeers is set, also all known peers to the node are returned additionally.
func (api *GoShimmerAPI) GetNeighbors(knownPeers bool) (*webapi_getNeighbors.Response, error) {
res := &webapi_getNeighbors.Response{}
if err := api.do(http.MethodGet, func() string {
if !knownPeers {
return routeGetNeighbors
}
return fmt.Sprintf("%s?known=1", routeGetNeighbors)
}(), nil, res); err != nil {
return nil, err
}
return res, nil
}
// GetTips executes the tip-selection on the node to retrieve tips to approve.
func (api *GoShimmerAPI) GetTransactionsToApprove() (*webapi_gtta.Response, error) {
res := &webapi_gtta.Response{}
if err := api.do(http.MethodGet, routeGetTransactionsToApprove, nil, res); err != nil {
return nil, err
}
return res, nil
}
// ToggleSpammer toggles the node internal spammer.
func (api *GoShimmerAPI) ToggleSpammer(enable bool) (*webapi_spammer.Response, error) {
res := &webapi_spammer.Response{}
if err := api.do(http.MethodGet, func() string {
if enable {
return fmt.Sprintf("%s?cmd=start", routeSpammer)
}
return fmt.Sprintf("%s?cmd=stop", routeSpammer)
}(), nil, res); err != nil {
return nil, err
}
return res, nil
}
{ {
"node": { "analysis": {
"logLevel": 3, "client": {
"disablePlugins": [], "serverAddress": "ressims.iota.cafe:188"
"enablePlugins": [] },
"server": {
"port": 0
},
"httpServer": {
"bindAddress": "0.0.0.0:80"
}
},
"autopeering": {
"entryNodes": [
"V8LYtWWcPYYDTTXLeIEFjJEuWlsjDiI0+Pq/Cx9ai6g=@116.202.49.178:14626"
],
"port": 14626
},
"dashboard": {
"bindAddress": "127.0.0.1:8081",
"dev": false,
"basic_auth": {
"enabled": false,
"username": "goshimmer",
"password": "goshimmer"
}
}, },
"database": { "database": {
"directory": "mainnetdb" "directory": "mainnetdb"
}, },
"analysis": {
"serverPort": 0,
"serverAddress": "159.69.158.51:188"
},
"gossip": { "gossip": {
"port": 14666 "port": 14666
}, },
"zeromq": { "graph": {
"port": 5556 "bindAddress": "127.0.0.1:8082",
"domain": "",
"networkName": "GoShimmer",
"socketIOPath": "socket.io-client/dist/socket.io.js",
"webrootPath": "IOTAtangle/webroot"
}, },
"autopeering": { "logger": {
"address": "0.0.0.0", "level": "info",
"port": 14626, "disableCaller": false,
"entryNodes": [ "disableStacktrace": false,
"7f7a876a4236091257e650da8dcf195fbe3cb625@159.69.158.51:14626" "encoding": "console",
"outputPaths": [
"goshimmer.log"
], ],
"acceptRequests": true, "disableEvents": false
"sendRequests": true },
"network": {
"bindAddress": "0.0.0.0",
"externalAddress": "auto"
},
"node": {
"disablePlugins": [],
"enablePlugins": []
},
"webapi": {
"auth": {
"password": "goshimmer",
"privateKey": "",
"username": "goshimmer"
},
"bindAddress": "127.0.0.1:8080"
} }
} }
\ No newline at end of file
...@@ -3,6 +3,7 @@ version: "3" ...@@ -3,6 +3,7 @@ version: "3"
services: services:
goshimmer: goshimmer:
network_mode: host
image: iotaledger/goshimmer image: iotaledger/goshimmer
build: build:
context: ./ context: ./
...@@ -15,4 +16,3 @@ services: ...@@ -15,4 +16,3 @@ services:
- "14666:14666/tcp" - "14666:14666/tcp"
- "14626:14626/udp" - "14626:14626/udp"
- "14626:14626/tcp" - "14626:14626/tcp"
command: "--node.disablePlugins statusscreen"
{
"analysis": {
"serveraddress": "ressims.iota.cafe:188",
"serverport": 0
},
"autopeering": {
"address": "0.0.0.0",
"entrynodes": [
"V8LYtWWcPYYDTTXLeIEFjJEuWlsjDiI0+Pq/Cx9ai6g=@116.202.49.178:14626"
],
"port": 14626
},
"database": {
"directory": "mainnetdb"
},
"gossip": {
"port": 14666
},
"logger": {
"Level": "info",
"DisableCaller": true,
"DisableStacktrace": false,
"Encoding": "console",
"OutputPaths": [
"stdout",
"goshimmer.log"
],
"DisableEvents": true
},
"node": {
"disablePlugins": [
"statusscreen"
],
"enablePlugins": []
}
}
...@@ -3,29 +3,43 @@ module github.com/iotaledger/goshimmer ...@@ -3,29 +3,43 @@ module github.com/iotaledger/goshimmer
go 1.13 go 1.13
require ( require (
github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect github.com/dgraph-io/badger/v2 v2.0.1
github.com/dgraph-io/badger v1.6.0
github.com/dgrijalva/jwt-go v3.2.0+incompatible github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/ethereum/go-ethereum v1.9.3 github.com/dgryski/go-farm v0.0.0-20191112170834-c2139c5d712b // indirect
github.com/gdamore/tcell v1.2.0 github.com/gdamore/tcell v1.3.0
github.com/go-zeromq/zmq4 v0.5.0 github.com/gobuffalo/envy v1.8.1 // indirect
github.com/golang/protobuf v1.3.2 // indirect github.com/gobuffalo/logger v1.0.3 // indirect
github.com/google/open-location-code/go v0.0.0-20190903173953-119bc96a3a51 github.com/gobuffalo/packr/v2 v2.7.1
github.com/golang/protobuf v1.3.2
github.com/googollee/go-engine.io v1.4.3-0.20190924125625-798118fc0dd2
github.com/googollee/go-socket.io v1.4.3-0.20191204093753-683f8725b6d0
github.com/gorilla/websocket v1.4.1 github.com/gorilla/websocket v1.4.1
github.com/iotaledger/hive.go v0.0.0-20191229233341-c3732738ee20 github.com/iotaledger/hive.go v0.0.0-20200121213505-28904d5f037c
github.com/iotaledger/iota.go v1.0.0-beta.9 github.com/iotaledger/iota.go v1.0.0-beta.14
github.com/labstack/echo v3.3.10+incompatible github.com/labstack/echo v3.3.10+incompatible
github.com/labstack/gommon v0.3.0 // indirect github.com/labstack/gommon v0.3.0 // indirect
github.com/lucasb-eyer/go-colorful v1.0.3 // indirect
github.com/magiconair/properties v1.8.1 github.com/magiconair/properties v1.8.1
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect github.com/mattn/go-colorable v0.1.4 // indirect
github.com/pkg/errors v0.8.1 github.com/mattn/go-isatty v0.0.11 // indirect
github.com/rivo/tview v0.0.0-20190829161255-f8bc69b90341 github.com/mattn/go-runewidth v0.0.7 // indirect
github.com/rivo/uniseg v0.1.0 // indirect github.com/pelletier/go-toml v1.6.0 // indirect
github.com/sasha-s/go-deadlock v0.2.0 // indirect github.com/pkg/errors v0.9.1
github.com/rivo/tview v0.0.0-20191229165609-1ee8d9874dcf
github.com/rogpeppe/go-internal v1.5.2 // indirect
github.com/spf13/afero v1.2.2 // indirect
github.com/spf13/cast v1.3.1 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 github.com/spf13/pflag v1.0.5
golang.org/x/crypto v0.0.0-20190829043050-9756ffdc2472 github.com/spf13/viper v1.6.1
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297 github.com/stretchr/objx v0.2.0 // indirect
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd // indirect github.com/stretchr/testify v1.4.0
golang.org/x/text v0.3.2 // indirect github.com/valyala/fasttemplate v1.1.0 // indirect
gopkg.in/zeromq/goczmq.v4 v4.1.0 // indirect go.uber.org/zap v1.13.0
golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 // indirect
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7 // indirect
gopkg.in/ini.v1 v1.51.1 // indirect
gopkg.in/yaml.v2 v2.2.7 // indirect
) )
This diff is collapsed.
images/GoShimmer.png

272 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment