Skip to content

Commit

Permalink
setting user agent and better disconnection limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ranlavanet committed Dec 4, 2024
1 parent 0b5efac commit ead2816
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions protocol/chainlib/websocket_connection_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ type WebsocketConnectionLimiter struct {
}

func (wcl *WebsocketConnectionLimiter) handleFiberRateLimitFlags(c *fiber.Ctx) {
userAgent := c.Get("User-Agent")
utils.LavaFormatDebug("User-Agent", utils.LogAttr("userAgent", userAgent))
userAgent := c.Get(fiber.HeaderUserAgent)
// Store the User-Agent in locals for later use
c.Locals("User-Agent", userAgent)
c.Locals(fiber.HeaderUserAgent, userAgent)

forwardedFor := c.Get(common.IP_FORWARDING_HEADER_NAME)
if forwardedFor == "" {
Expand Down Expand Up @@ -79,7 +78,7 @@ func (wcl *WebsocketConnectionLimiter) canOpenConnection(websocketConn *websocke
numberOfActiveConnections := wcl.addIpConnectionAndGetCurrentAmount(key)

if numberOfActiveConnections > connectionLimit {
websocketConn.WriteMessage(1, []byte(fmt.Sprintf("Too Many Open Connections, limited to %d", connectionLimit)))
websocketConn.WriteMessage(websocket.CloseMessage, websocket.FormatCloseMessage(websocket.CloseNormalClosure, fmt.Sprintf("Too Many Open Connections, limited to %d", connectionLimit)))
return false, func() { wcl.decreaseIpConnection(key) }
}
}
Expand Down

0 comments on commit ead2816

Please sign in to comment.