Skip to content

Commit

Permalink
Merge pull request #7119 from TheThingsNetwork/feature/semtechws
Browse files Browse the repository at this point in the history
Rename rate limit key `ws` to `semtechws/lbslns`
  • Loading branch information
johanstokking authored May 31, 2024
2 parents f37fcd9 + 1f41f8f commit 4e4483f
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ For details about compatibility between different releases, see the **Commitment

### Changed

- The rate limit key for LoRa Basics Station has changed from `gs:accept:ws` to `gs:accept:semtechws/lbslns`.

### Deprecated

### Removed
Expand Down
2 changes: 2 additions & 0 deletions pkg/gatewayserver/io/semtechws/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ type Endpoints struct {

// Formatter abstracts messages to/from websocket based gateways.
type Formatter interface {
// ID returns the ID of the formatter.
ID() string
// Endpoints fetches the connection endpoints for the protocol.
Endpoints() Endpoints
// HandleConnectionInfo handles connection information requests from web socket based protocols.
Expand Down
2 changes: 2 additions & 0 deletions pkg/gatewayserver/io/semtechws/lbslns/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func NewFormatter(maxRoundTripDelay time.Duration) semtechws.Formatter {
}
}

func (f *lbsLNS) ID() string { return "lbslns" }

func (f *lbsLNS) Endpoints() semtechws.Endpoints {
return semtechws.Endpoints{
ConnectionInfo: "/router-info",
Expand Down
4 changes: 2 additions & 2 deletions pkg/gatewayserver/io/semtechws/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type srv struct {
formatter Formatter
}

func (*srv) Protocol() string { return "ws" }
func (s *srv) Protocol() string { return "semtechws/" + s.formatter.ID() }
func (*srv) SupportsDownlinkClaim() bool { return false }
func (*srv) DutyCycleStyle() scheduling.DutyCycleStyle {
return scheduling.DutyCycleStyleBlockingWindow
Expand Down Expand Up @@ -96,7 +96,7 @@ func New(ctx context.Context, server io.Server, formatter Formatter, cfg Config)

router := w.RootRouter()
router.Use(
ratelimit.HTTPMiddleware(server.RateLimiter(), "gs:accept:ws"),
ratelimit.HTTPMiddleware(server.RateLimiter(), "gs:accept:"+s.Protocol()),
)

eps := s.formatter.Endpoints()
Expand Down
2 changes: 1 addition & 1 deletion pkg/gatewayserver/io/semtechws/ws_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1800,7 +1800,7 @@ func TestRateLimit(t *testing.T) {
Name: "accept connections",
MaxPerMin: maxRate,
MaxBurst: maxRate,
Associations: []string{"gs:accept:ws"},
Associations: []string{"gs:accept:semtechws/lbslns"},
}},
}
withServer(t, defaultConfig, conf, func(t *testing.T, _ *mockis.MockDefinition, serverAddress string) {
Expand Down

0 comments on commit 4e4483f

Please sign in to comment.