Skip to content

Commit

Permalink
CR Fix: Rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
shleikes committed Dec 5, 2024
1 parent 7f73f93 commit 52233d5
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion protocol/chainlib/consumer_websocket_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ func TestWebsocketConnectionLimiter(t *testing.T) {

// Test the connection
for _, expectSuccess := range tt.expectSuccess {
canOpen, _ := wcl.canOpenConnection(mockWsConn)
canOpen, _ := wcl.CanOpenConnection(mockWsConn)
if expectSuccess {
assert.True(t, canOpen, "Expected connection to be allowed")
} else {
Expand Down
4 changes: 2 additions & 2 deletions protocol/chainlib/jsonRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (apil *JsonRPCChainListener) Serve(ctx context.Context, cmdFlags common.Con
app := createAndSetupBaseAppListener(cmdFlags, apil.endpoint.HealthCheckPath, apil.healthReporter)

app.Use("/ws", func(c *fiber.Ctx) error {
apil.websocketConnectionLimiter.handleFiberRateLimitFlags(c)
apil.websocketConnectionLimiter.HandleFiberRateLimitFlags(c)

// IsWebSocketUpgrade returns true if the client
// requested upgrade to the WebSocket protocol.
Expand All @@ -375,7 +375,7 @@ func (apil *JsonRPCChainListener) Serve(ctx context.Context, cmdFlags common.Con
apiInterface := apil.endpoint.ApiInterface

webSocketCallback := websocket.New(func(websocketConn *websocket.Conn) {
canOpenConnection, decreaseIpConnection := apil.websocketConnectionLimiter.canOpenConnection(websocketConn)
canOpenConnection, decreaseIpConnection := apil.websocketConnectionLimiter.CanOpenConnection(websocketConn)
defer decreaseIpConnection()
if !canOpenConnection {
return
Expand Down
4 changes: 2 additions & 2 deletions protocol/chainlib/tendermintRPC.go
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ func (apil *TendermintRpcChainListener) Serve(ctx context.Context, cmdFlags comm
apiInterface := apil.endpoint.ApiInterface

app.Use("/ws", func(c *fiber.Ctx) error {
apil.websocketConnectionLimiter.handleFiberRateLimitFlags(c)
apil.websocketConnectionLimiter.HandleFiberRateLimitFlags(c)
// IsWebSocketUpgrade returns true if the client
// requested upgrade to the WebSocket protocol.
if websocket.IsWebSocketUpgrade(c) {
Expand All @@ -400,7 +400,7 @@ func (apil *TendermintRpcChainListener) Serve(ctx context.Context, cmdFlags comm
return fiber.ErrUpgradeRequired
})
webSocketCallback := websocket.New(func(websocketConn *websocket.Conn) {
canOpenConnection, decreaseIpConnection := apil.websocketConnectionLimiter.canOpenConnection(websocketConn)
canOpenConnection, decreaseIpConnection := apil.websocketConnectionLimiter.CanOpenConnection(websocketConn)
defer decreaseIpConnection()
if !canOpenConnection {
return
Expand Down
8 changes: 4 additions & 4 deletions protocol/chainlib/websocket_connection_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type WebsocketConnectionLimiter struct {
lock sync.RWMutex
}

func (wcl *WebsocketConnectionLimiter) handleFiberRateLimitFlags(c *fiber.Ctx) {
func (wcl *WebsocketConnectionLimiter) HandleFiberRateLimitFlags(c *fiber.Ctx) {
userAgent := c.Get(fiber.HeaderUserAgent)
// Store the User-Agent in locals for later use
c.Locals(fiber.HeaderUserAgent, userAgent)
Expand Down Expand Up @@ -68,7 +68,7 @@ func (wcl *WebsocketConnectionLimiter) getConnectionLimit(websocketConn Websocke
return utils.Max(MaximumNumberOfParallelWebsocketConnectionsPerIp, connectionLimitHeaderValue)
}

func (wcl *WebsocketConnectionLimiter) canOpenConnection(websocketConn WebsocketConnection) (bool, func()) {
func (wcl *WebsocketConnectionLimiter) CanOpenConnection(websocketConn WebsocketConnection) (bool, func()) {
// Check which connection limit is higher and use that.
connectionLimit := wcl.getConnectionLimit(websocketConn)
decreaseIpConnectionCallback := func() {}
Expand All @@ -93,7 +93,7 @@ func (wcl *WebsocketConnectionLimiter) canOpenConnection(websocketConn Websocket
return false, decreaseIpConnectionCallback
}
// If under limit, increment and return cleanup function
wcl.addIpConnectionAndGetCurrentAmount(key)
wcl.addIpConnection(key)
decreaseIpConnectionCallback = func() { wcl.decreaseIpConnection(key) }
}
return true, decreaseIpConnectionCallback
Expand All @@ -105,7 +105,7 @@ func (wcl *WebsocketConnectionLimiter) getCurrentAmountOfConnections(key string)
return wcl.ipToNumberOfActiveConnections[key]
}

func (wcl *WebsocketConnectionLimiter) addIpConnectionAndGetCurrentAmount(key string) {
func (wcl *WebsocketConnectionLimiter) addIpConnection(key string) {
wcl.lock.Lock()
defer wcl.lock.Unlock()
// wether it exists or not we add 1.
Expand Down

0 comments on commit 52233d5

Please sign in to comment.