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

Add AllowClients Field to packets #14

Merged
merged 11 commits into from
Jan 14, 2022
Merged

Conversation

mochi-co
Copy link
Collaborator

Adds a new AllowClients field to the packet structure. This field can be set during the OnMessage event hook, allowing an embedding server to selectively deliver messages to one or more clients within one or more topics based on their client id. For example:

// Add OnMessage Event Hook
server.Events.OnMessage = func(cl events.Client, pk events.Packet) (pkx events.Packet, err error) {
  pkx = pk
    
  // Example of using AllowClients to selectively deliver/drop messages.
  // Only a client with the id of `allowed-client` will received messages on the topic.
  if pkx.TopicName == "a/b/restricted" {
    pkx.AllowClients = []string{"allowed-client"} // slice of known client ids
  }

  return pkx, nil
}

If AllowClients is nil or not set, it is ignored and the message is delivered as normal.

All unit tests passing, paho compatibility tests passing

mochi added 11 commits January 14, 2022 16:58
Check if a slice of strings contains a string (until slices package available)
AllowClients field can be specified during onMessage event to selectively deliver messages
If AllowClients has been set on a packet, ensure only clients in the slice are sent the message
previously new clients generated a new server object, so system stats were not shared. This change ensures all test clients use the same server
@mochi-co mochi-co added the enhancement New feature or request label Jan 14, 2022
@mochi-co mochi-co self-assigned this Jan 14, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jan 14, 2022

Codecov Report

Merging #14 (fc61cc9) into master (fb13648) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #14   +/-   ##
=======================================
  Coverage   98.96%   98.96%           
=======================================
  Files          18       19    +1     
  Lines        2020     2027    +7     
=======================================
+ Hits         1999     2006    +7     
  Misses         19       19           
  Partials        2        2           
Impacted Files Coverage Δ
server/internal/packets/packets.go 100.00% <ø> (ø)
server/internal/clients/clients.go 98.92% <100.00%> (ø)
server/internal/utils/utils.go 100.00% <100.00%> (ø)
server/server.go 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update fb13648...fc61cc9. Read the comment docs.

@mochi-co mochi-co linked an issue Jan 14, 2022 that may be closed by this pull request
@mochi-co mochi-co merged commit 994adea into master Jan 14, 2022
@mochi-co mochi-co deleted the feature/allow-clients-value branch January 14, 2022 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Event OnMessage stop publish message
2 participants