Skip to content
Snippets Groups Projects
Commit bf8e025b authored by Josh Brooks's avatar Josh Brooks
Browse files

Update bucket for every CMIX message sent

parent 235d84b2
No related branches found
No related tags found
2 merge requests!117Release,!83Add EKV backed leaky bucket storage
...@@ -50,6 +50,7 @@ func (c *Client) SendUnsafe(m message.Send, param params.Unsafe) ([]id.Round, ...@@ -50,6 +50,7 @@ func (c *Client) SendUnsafe(m message.Send, param params.Unsafe) ([]id.Round,
func (c *Client) SendCMIX(msg format.Message, recipientID *id.ID, func (c *Client) SendCMIX(msg format.Message, recipientID *id.ID,
param params.CMIX) (id.Round, ephemeral.Id, error) { param params.CMIX) (id.Round, ephemeral.Id, error) {
jww.INFO.Printf("SendCMIX(%s)", string(msg.GetContents())) jww.INFO.Printf("SendCMIX(%s)", string(msg.GetContents()))
c.OnSend(1)
return c.network.SendCMIX(msg, recipientID, param) return c.network.SendCMIX(msg, recipientID, param)
} }
...@@ -58,6 +59,7 @@ func (c *Client) SendCMIX(msg format.Message, recipientID *id.ID, ...@@ -58,6 +59,7 @@ func (c *Client) SendCMIX(msg format.Message, recipientID *id.ID,
// round ID of the round the payload was sent or an error if it fails. // round ID of the round the payload was sent or an error if it fails.
func (c *Client) SendManyCMIX(messages []message.TargetedCmixMessage, func (c *Client) SendManyCMIX(messages []message.TargetedCmixMessage,
params params.CMIX) (id.Round, []ephemeral.Id, error) { params params.CMIX) (id.Round, []ephemeral.Id, error) {
c.OnSend(uint32(len(messages)))
return c.network.SendManyCMIX(messages, params) return c.network.SendManyCMIX(messages, params)
} }
...@@ -73,3 +75,13 @@ func (c *Client) NewCMIXMessage(contents []byte) (format.Message, error) { ...@@ -73,3 +75,13 @@ func (c *Client) NewCMIXMessage(contents []byte) (format.Message, error) {
msg.SetContents(contents) msg.SetContents(contents)
return msg, nil return msg, nil
} }
// OnSend performs a bucket addition on a call to Client.SendCMIX or
// Client.SendManyCMIX, updating the bucket for the amount of messages sent.
func (c *Client) OnSend(messages uint32) {
rateLimitingParam := c.storage.GetBucketParams().Get()
c.storage.GetBucket().AddWithExternalParams(messages,
rateLimitingParam.Capacity, rateLimitingParam.LeakedTokens,
rateLimitingParam.LeakDuration)
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment