Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename rate limit key ws to semtechws/lbslns #7119

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 (f *lbsLNS) ID() string { return "lbslns" }

Check failure on line 43 in pkg/gatewayserver/io/semtechws/lbslns/format.go

View workflow job for this annotation

GitHub Actions / Code Quality

unused-receiver: method receiver 'f' is not referenced in method's body, consider removing or renaming it as _ (revive)

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
Loading