Skip to content

Commit

Permalink
- Use httpserver from inx-app (#15)
Browse files Browse the repository at this point in the history
- Added DebugRequestLoggerEnabled
- Update deps
  • Loading branch information
alexsporn authored Aug 4, 2022
1 parent f5f0a93 commit 5c2239b
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 128 deletions.
3 changes: 2 additions & 1 deletion config_defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"workers": 0,
"autostart": false,
"nonLazyTipsThreshold": 0,
"semiLazyTipsThreshold": 30
"semiLazyTipsThreshold": 30,
"debugRequestLoggerEnabled": false
},
"profiling": {
"enabled": false,
Expand Down
2 changes: 1 addition & 1 deletion core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
Name = "inx-spammer"

// Version of the app.
Version = "1.0.0-beta.3"
Version = "1.0.0-beta.4"
)

func App() *app.App {
Expand Down
18 changes: 2 additions & 16 deletions core/spammer/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ import (
"net/http"
"time"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/pkg/errors"
"go.uber.org/dig"

"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/hive.go/timeutil"
"github.com/iotaledger/inx-app/httpserver"
"github.com/iotaledger/inx-app/nodebridge"
"github.com/iotaledger/inx-spammer/pkg/daemon"
"github.com/iotaledger/inx-spammer/pkg/spammer"
Expand Down Expand Up @@ -149,13 +148,7 @@ func run() error {
if err := CoreComponent.Daemon().BackgroundWorker("API", func(ctx context.Context) {
CoreComponent.LogInfo("Starting API ... done")

e := newEcho()

apiErrorHandler := spammer.ErrorHandler()
e.HTTPErrorHandler = func(err error, c echo.Context) {
CoreComponent.LogDebugf("Error: %s", err)
apiErrorHandler(err, c)
}
e := httpserver.NewEcho(CoreComponent.Logger(), nil, ParamsSpammer.DebugRequestLoggerEnabled)

CoreComponent.LogInfo("Starting API server...")

Expand Down Expand Up @@ -191,10 +184,3 @@ func run() error {

return nil
}

func newEcho() *echo.Echo {
e := echo.New()
e.HideBanner = true
e.Use(middleware.Recover())
return e
}
2 changes: 2 additions & 0 deletions core/spammer/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type ParametersSpammer struct {
// SemiLazyTipsThreshold is the maximum amount of tips in the semi-lazy tip-pool before the spammer tries to reduce these (0 = disable).
// This is used to support the network if someone attacks the tangle by spamming a lot of tips.
SemiLazyTipsThreshold uint32 `default:"30" usage:"the maximum amount of tips in the semi-lazy tip-pool before the spammer tries to reduce these (0 = disable)"`
// DebugRequestLoggerEnabled defines whether the debug logging for requests should be enabled
DebugRequestLoggerEnabled bool `default:"false" usage:"whether the debug logging for requests should be enabled"`
}

var ParamsSpammer = &ParametersSpammer{}
Expand Down
30 changes: 16 additions & 14 deletions documentation/docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: This section describes the configuration parameters and their types
keywords:
- IOTA Node
- Hornet Node
- Faucet
- Spammer
- Configuration
- JSON
- Customize
Expand Down Expand Up @@ -64,18 +64,19 @@ Example:

## <a id="spammer"></a> 3. Spammer

| Name | Description | Type | Default value |
| --------------------- | ----------------------------------------------------------------------------------------------------------- | ------- | ------------------------------ |
| bindAddress | The bind address on which the Spammer HTTP server listens | string | "localhost:9092" |
| message | The message to embed within the spam blocks | string | "We are all made of stardust." |
| tag | The tag of the block | string | "HORNET Spammer" |
| tagSemiLazy | The tag of the block if the semi-lazy pool is used (uses "tag" if empty) | string | "HORNET Spammer Semi-Lazy" |
| cpuMaxUsage | Workers remains idle for a while when cpu usage gets over this limit (0 = disable) | float | 0.8 |
| bpsRateLimit | The blocks per second rate limit for the spammer (0 = no limit) | float | 0.0 |
| workers | The amount of parallel running spammers | int | 0 |
| autostart | Automatically start the spammer on startup | boolean | false |
| nonLazyTipsThreshold | The maximum amount of tips in the non-lazy tip-pool before the spammer tries to reduce these (0 = always) | uint | 0 |
| semiLazyTipsThreshold | The maximum amount of tips in the semi-lazy tip-pool before the spammer tries to reduce these (0 = disable) | uint | 30 |
| Name | Description | Type | Default value |
| ------------------------- | ----------------------------------------------------------------------------------------------------------- | ------- | ------------------------------ |
| bindAddress | The bind address on which the Spammer HTTP server listens | string | "localhost:9092" |
| message | The message to embed within the spam blocks | string | "We are all made of stardust." |
| tag | The tag of the block | string | "HORNET Spammer" |
| tagSemiLazy | The tag of the block if the semi-lazy pool is used (uses "tag" if empty) | string | "HORNET Spammer Semi-Lazy" |
| cpuMaxUsage | Workers remains idle for a while when cpu usage gets over this limit (0 = disable) | float | 0.8 |
| bpsRateLimit | The blocks per second rate limit for the spammer (0 = no limit) | float | 0.0 |
| workers | The amount of parallel running spammers | int | 0 |
| autostart | Automatically start the spammer on startup | boolean | false |
| nonLazyTipsThreshold | The maximum amount of tips in the non-lazy tip-pool before the spammer tries to reduce these (0 = always) | uint | 0 |
| semiLazyTipsThreshold | The maximum amount of tips in the semi-lazy tip-pool before the spammer tries to reduce these (0 = disable) | uint | 30 |
| debugRequestLoggerEnabled | Whether the debug logging for requests should be enabled | boolean | false |

Example:

Expand All @@ -91,7 +92,8 @@ Example:
"workers": 0,
"autostart": false,
"nonLazyTipsThreshold": 0,
"semiLazyTipsThreshold": 30
"semiLazyTipsThreshold": 30,
"debugRequestLoggerEnabled": false
}
}
```
Expand Down
10 changes: 6 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ go 1.18
require (
github.com/iotaledger/hive.go v0.0.0-20220714075325-11202fe498d6
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-20220714075325-11202fe498d6 // indirect
github.com/iotaledger/inx-app v1.0.0-beta.5
github.com/iotaledger/inx/go v1.0.0-beta.3 // indirect
github.com/iotaledger/inx-app v1.0.0-beta.6
github.com/iotaledger/inx/go v1.0.0-beta.4 // indirect
github.com/iotaledger/iota.go/v3 v3.0.0-beta.4
github.com/labstack/echo/v4 v4.7.2
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -69,12 +69,14 @@ require (
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/net v0.0.0-20220802222814-0bcc04d9c69b // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220731174439-a90be440212d // indirect
golang.org/x/sys v0.0.0-20220803195053-6e608f9ce704 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 // indirect
google.golang.org/genproto v0.0.0-20220803205849-8f55acc8769f // indirect
google.golang.org/grpc v1.48.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)

require github.com/dustin/go-humanize v1.0.0 // indirect
18 changes: 10 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 h1:YLtO71vCjJRCBcrPMtQ9nqBsqpA1
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs=
github.com/dgraph-io/badger v1.5.4/go.mod h1:VZxzAIRPHRVNRKRo6AXrX9BJegn6il06VMTZVJYCIjQ=
github.com/dgryski/go-farm v0.0.0-20190323231341-8198c7b169ec/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/dustin/go-humanize v1.0.0 h1:VSnTsYCnlFHaM2/igO1h6X3HA71jcobQuxemgkq4zYo=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/eclipse/paho.mqtt.golang v1.4.1 h1:tUSpviiL5G3P9SZZJPC4ZULZJsxQKXxfENpMvdbAXAI=
github.com/eclipse/paho.mqtt.golang v1.4.1/go.mod h1:JGt0RsEwEX+Xa/agj90YJ9d9DH2b7upDZMK9HRbFvCA=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
Expand Down Expand Up @@ -233,10 +235,10 @@ github.com/iotaledger/hive.go v0.0.0-20220714075325-11202fe498d6 h1:2XEsyh+LCSKJ
github.com/iotaledger/hive.go v0.0.0-20220714075325-11202fe498d6/go.mod h1:qY0Eg2w/r+Ot0KrocMQHrtHzrcYKxDAEf33c6nSd8mI=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-20220714075325-11202fe498d6 h1:ayhSELd1o+qjaDV2kdlH4+0M8Y/V0BshjwjUiLNMOW4=
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-20220714075325-11202fe498d6/go.mod h1:7fVUqbLY+iBjCNjFwzbhOyS07OZJFIYJEDNJAItzMw8=
github.com/iotaledger/inx-app v1.0.0-beta.5 h1:A8OhAotymxraHnfsA2swcjelLW5i3Y7MBnhVb7czo2k=
github.com/iotaledger/inx-app v1.0.0-beta.5/go.mod h1:w+fmEjD22xJkX0NP9gz9Em8HYaTIt6JOJi7qApitMgc=
github.com/iotaledger/inx/go v1.0.0-beta.3 h1:dfqHDuiLnxnrjnMthT3h65jN6aXzes2VvNe0WFjN7vM=
github.com/iotaledger/inx/go v1.0.0-beta.3/go.mod h1:yDhKgqnasqydYMossxUM7JcJnIbas4Zp823sM/0AB+s=
github.com/iotaledger/inx-app v1.0.0-beta.6 h1:TvFw1ui+oTPGVIPYR0bDEIfk//j64LloQishQLVAjTw=
github.com/iotaledger/inx-app v1.0.0-beta.6/go.mod h1:LYJVsN3U2IJGu/Xi3yYwHlho/BflrNrJSKQx8PPtY6A=
github.com/iotaledger/inx/go v1.0.0-beta.4 h1:Om1ORLy4hMQy0rg6oREyuBY1/6ULqdZmGG9tHILGg5o=
github.com/iotaledger/inx/go v1.0.0-beta.4/go.mod h1:ONo8cSWyo4Nb4fuyeSFmZf4Vf71wZuyisxDTfH46ZBo=
github.com/iotaledger/iota.go v1.0.0 h1:tqm1FxJ/zOdzbrAaQ5BQpVF8dUy2eeGlSeWlNG8GoXY=
github.com/iotaledger/iota.go v1.0.0/go.mod h1:RiKYwDyY7aCD1L0YRzHSjOsJ5mUR9yvQpvhZncNcGQI=
github.com/iotaledger/iota.go/v3 v3.0.0-beta.4 h1:T4yWpxaAEu/itx6QK7CaNfNMtgsdCKacdpIktiUdo78=
Expand Down Expand Up @@ -588,8 +590,8 @@ golang.org/x/sys v0.0.0-20220114195835-da31bd327af9/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220128215802-99c3d69c2c27/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220503163025-988cb79eb6c6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220731174439-a90be440212d h1:Sv5ogFZatcgIMMtBSTTAgMYsicp25MXBubjXNDKwm80=
golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220803195053-6e608f9ce704 h1:Y7NOhdqIOU8kYI7BxsgL38d0ot0raxvcW+EMQU2QrT4=
golang.org/x/sys v0.0.0-20220803195053-6e608f9ce704/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
Expand Down Expand Up @@ -709,8 +711,8 @@ google.golang.org/genproto v0.0.0-20200618031413-b414f8b61790/go.mod h1:jDfRM7Fc
google.golang.org/genproto v0.0.0-20200729003335-053ba62fc06f/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20200804131852-c06518451d9c/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20200825200019-8632dd797987/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78 h1:QntLWYqZeuBtJkth3m/6DLznnI0AHJr+AgJXvVh/izw=
google.golang.org/genproto v0.0.0-20220802133213-ce4fa296bf78/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc=
google.golang.org/genproto v0.0.0-20220803205849-8f55acc8769f h1:ywoA0TLvF/4n7P2lr/+bNRueYxWYUJZbRwV3hyYt8gY=
google.golang.org/genproto v0.0.0-20220803205849-8f55acc8769f/go.mod h1:iHe1svFLAZg9VWz891+QbRMwUv9O/1Ww+/mngYeThbc=
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
Expand Down
45 changes: 0 additions & 45 deletions pkg/spammer/restapi.go

This file was deleted.

27 changes: 14 additions & 13 deletions tools/gendoc/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ require (
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect
github.com/dustin/go-humanize v1.0.0 // indirect
github.com/eclipse/paho.mqtt.golang v1.4.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/ethereum/go-ethereum v1.10.20 // indirect
github.com/ethereum/go-ethereum v1.10.21 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/fbiville/markdown-table-formatter v0.3.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
Expand All @@ -33,10 +34,10 @@ require (
github.com/hashicorp/go-version v1.6.0 // indirect
github.com/iancoleman/orderedmap v0.2.0 // indirect
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-20220714075325-11202fe498d6 // indirect
github.com/iotaledger/inx-app v1.0.0-beta.1 // indirect
github.com/iotaledger/inx/go v1.0.0-beta.1 // indirect
github.com/iotaledger/inx-app v1.0.0-beta.6 // indirect
github.com/iotaledger/inx/go v1.0.0-beta.4 // indirect
github.com/iotaledger/iota.go v1.0.0 // indirect
github.com/iotaledger/iota.go/v3 v3.0.0-beta.1 // indirect
github.com/iotaledger/iota.go/v3 v3.0.0-beta.4 // indirect
github.com/knadh/koanf v1.4.2 // indirect
github.com/labstack/echo/v4 v4.7.2 // indirect
github.com/labstack/gommon v0.3.2-0.20220410183028-64116baad496 // indirect
Expand All @@ -53,7 +54,7 @@ require (
github.com/prometheus/client_golang v1.12.2 // indirect
github.com/prometheus/client_model v0.2.0 // indirect
github.com/prometheus/common v0.37.0 // indirect
github.com/prometheus/procfs v0.7.3 // indirect
github.com/prometheus/procfs v0.8.0 // indirect
github.com/sasha-s/go-deadlock v0.3.1 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/spf13/cast v1.5.0 // indirect
Expand All @@ -66,18 +67,18 @@ require (
github.com/valyala/fasttemplate v1.2.1 // indirect
github.com/yusufpapurcu/wmi v1.2.2 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/dig v1.14.1 // indirect
go.uber.org/dig v1.15.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
golang.org/x/net v0.0.0-20220708220712-1185a9018129 // indirect
golang.org/x/sync v0.0.0-20220601150217-0de741cfad7f // indirect
golang.org/x/sys v0.0.0-20220712014510-0a85c31ab51e // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/net v0.0.0-20220802222814-0bcc04d9c69b // indirect
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4 // indirect
golang.org/x/sys v0.0.0-20220803195053-6e608f9ce704 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20220609170525-579cf78fd858 // indirect
golang.org/x/time v0.0.0-20220722155302-e5dcc9cfc0b9 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/genproto v0.0.0-20220714211235-042d03aeabc9 // indirect
google.golang.org/genproto v0.0.0-20220803205849-8f55acc8769f // indirect
google.golang.org/grpc v1.48.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
Loading

0 comments on commit 5c2239b

Please sign in to comment.