Skip to content

Commit

Permalink
Add rate limit parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
muXxer committed Jun 16, 2022
1 parent 1c6e1ee commit 12dcb3d
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 257 deletions.
20 changes: 17 additions & 3 deletions config_template.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
{
"app": {
"checkForUpdates": true,
"disablePlugins": [],
"enablePlugins": [],
"stopGracePeriod": "5m"
},
"inx": {
"address": "localhost:9029"
},
"faucet": {
"amount": 1000000000,
"smallAmount": 100000000,
"maxAddressBalance": 2000000000,
"maxOutputCount": 127,
"maxOutputCount": 128,
"tagMessage": "HORNET FAUCET",
"batchTimeout": "2s",
"bindAddress": "0.0.0.0:8191"
"bindAddress": "localhost:8091",
"rateLimit": {
"period": "5m",
"maxRequests": 10,
"maxBurst": 20
}
},
"profiling": {
"bindAddress": "localhost:6060"
}
}
}
2 changes: 1 addition & 1 deletion core/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var (
Name = "inx-faucet"

// Version of the app.
Version = "0.7.0"
Version = "0.8.0"
)

func App() *app.App {
Expand Down
8 changes: 7 additions & 1 deletion core/faucet/params.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package faucet

import (
"github.com/iotaledger/hive.go/app"
"time"

"github.com/iotaledger/hive.go/app"

iotago "github.com/iotaledger/iota.go/v3"
)

Expand All @@ -15,6 +16,11 @@ type ParametersFaucet struct {
TagMessage string `default:"HORNET FAUCET" usage:"the faucet transaction tag payload"`
BatchTimeout time.Duration `default:"2s" usage:"the maximum duration for collecting faucet batches"`
BindAddress string `default:"localhost:8091" usage:"the bind address on which the faucet website can be accessed from"`
RateLimit struct {
Period time.Duration `default:"5m" usage:"the period for rate limiting"`
MaxRequests int `default:"10" usage:"the maximum number of requests per period"`
MaxBurst int `default:"20" usage:"additional requests allowed in the burst period"`
}
}

var ParamsFaucet = &ParametersFaucet{
Expand Down
4 changes: 2 additions & 2 deletions core/faucet/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ func setupRoutes(e *echo.Echo) {
Skipper: rateLimiterSkipper,
Store: middleware.NewRateLimiterMemoryStoreWithConfig(
middleware.RateLimiterMemoryStoreConfig{
Rate: rate.Limit(1 / 300.0), // 1 request every 5 minutes
Burst: 10, // additional burst of 10 requests
Rate: rate.Limit(float64(ParamsFaucet.RateLimit.MaxRequests) / ParamsFaucet.RateLimit.Period.Seconds()),
Burst: ParamsFaucet.RateLimit.MaxBurst,
ExpiresIn: 5 * time.Minute,
},
),
Expand Down
45 changes: 23 additions & 22 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,40 @@ module github.com/iotaledger/inx-faucet
go 1.18

require (
github.com/iotaledger/hive.go v0.0.0-20220530162014-976ec1e82594
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-20220530162014-976ec1e82594
github.com/iotaledger/hive.go v0.0.0-20220531132324-8347a155e220
github.com/iotaledger/hive.go/serializer/v2 v2.0.0-20220531132324-8347a155e220
github.com/iotaledger/hornet v1.1.0-rc1.0.20220530165211-a0805cb7cbe0
github.com/iotaledger/inx-app v0.0.0-20220530162244-06ae0e8eb802
github.com/iotaledger/inx/go v0.0.0-20220530154855-f371ab0a309d
github.com/iotaledger/inx-app v0.0.0-20220616153354-1698415db91c
github.com/iotaledger/inx/go v0.0.0-20220615123503-f64096762c65
github.com/iotaledger/iota.go/v3 v3.0.0-20220530132039-ec319e60cc56
github.com/labstack/echo/v4 v4.7.2
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.7.1
github.com/stretchr/testify v1.7.2
go.uber.org/dig v1.14.1
golang.org/x/time v0.0.0-20220411224347-583f2d630306
google.golang.org/grpc v1.46.2
golang.org/x/time v0.0.0-20220609170525-579cf78fd858
google.golang.org/grpc v1.47.0
)

require (
filippo.io/edwards25519 v1.0.0 // indirect
github.com/DataDog/zstd v1.5.2 // indirect
github.com/HdrHistogram/hdrhistogram-go v1.1.2 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/btcsuite/btcd v0.22.1 // indirect
github.com/btcsuite/btcd v0.23.1 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.2.0 // indirect
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 // indirect
github.com/cespare/xxhash v1.1.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/cockroachdb/errors v1.9.0 // indirect
github.com/cockroachdb/logtags v0.0.0-20211118104740-dabe8e521a4f // indirect
github.com/cockroachdb/pebble v0.0.0-20220527231317-d5bc42c2884b // indirect
github.com/cockroachdb/pebble v0.0.0-20220616170629-c2c0273062ce // indirect
github.com/cockroachdb/redact v1.1.3 // indirect
github.com/davecgh/go-spew v1.1.1 // 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.3.5 // 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.18 // indirect
github.com/ethereum/go-ethereum v1.10.19 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/getsentry/sentry-go v0.13.0 // indirect
Expand All @@ -59,8 +59,8 @@ require (
github.com/ipfs/go-datastore v0.5.1 // indirect
github.com/ipfs/go-log/v2 v2.5.1 // indirect
github.com/jbenet/goprocess v0.1.4 // indirect
github.com/klauspost/compress v1.15.5 // indirect
github.com/klauspost/cpuid/v2 v2.0.12 // indirect
github.com/klauspost/compress v1.15.6 // indirect
github.com/klauspost/cpuid/v2 v2.0.13 // indirect
github.com/knadh/koanf v1.4.2-0.20220512043835-4112a7258008 // indirect
github.com/kr/pretty v0.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
Expand All @@ -82,14 +82,14 @@ require (
github.com/multiformats/go-base36 v0.1.0 // indirect
github.com/multiformats/go-multiaddr v0.5.0 // indirect
github.com/multiformats/go-multiaddr-fmt v0.1.0 // indirect
github.com/multiformats/go-multibase v0.0.3 // indirect
github.com/multiformats/go-multicodec v0.4.1 // indirect
github.com/multiformats/go-multibase v0.1.0 // indirect
github.com/multiformats/go-multicodec v0.5.0 // indirect
github.com/multiformats/go-multihash v0.1.0 // indirect
github.com/multiformats/go-varint v0.0.6 // indirect
github.com/panjf2000/ants/v2 v2.5.0 // indirect
github.com/pasztorpisti/qs v0.0.0-20171216220353-8d6c33ee906c // indirect
github.com/pelletier/go-toml v1.9.3 // indirect
github.com/pelletier/go-toml/v2 v2.0.1 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pelletier/go-toml/v2 v2.0.2 // indirect
github.com/petermattis/goid v0.0.0-20220526132513-07eaf5d0b9f4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.12.2 // indirect
Expand All @@ -111,12 +111,13 @@ require (
go.uber.org/multierr v1.8.0 // indirect
go.uber.org/zap v1.21.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/exp v0.0.0-20220518171630-0b5c67f07fdf // indirect
golang.org/x/net v0.0.0-20220526153639-5463443f8c37 // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
golang.org/x/exp v0.0.0-20220613132600-b0d781184e0d // indirect
golang.org/x/net v0.0.0-20220615171555-694bf12d69de // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
google.golang.org/genproto v0.0.0-20220527130721-00d5c0f3be58 // indirect
golang.org/x/xerrors v0.0.0-20220609144429-65e65417b02f // indirect
google.golang.org/genproto v0.0.0-20220616135557-88e70c0c3a90 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
Loading

0 comments on commit 12dcb3d

Please sign in to comment.