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

Feature: Pre-registered links and simplified client-server setup #183

Merged
merged 6 commits into from
Jan 29, 2019

Conversation

kelindar
Copy link
Contributor

@kelindar kelindar commented Jan 26, 2019

Overview

This PR introduces a new concept of links which brings a couple of benefits.

  1. It helps to cope with the short message length and the limited transmission bandwidth in wireless networks, the pre-registered channel name in the PUBLISH messages can replaced by a short, two-byte long "link name". A registration procedure is defined to allow clients to register their channel names with emitter broker by sending a request to emitter/link/ channel.
  2. It simplifies the creation of trust relationship between a client and a server by (a) auto-creating a sub-channel with suffixed connection identifier and (b) optionally auto-subscribing to that private link. A secure channel key is transparently created by the broker for the auto-created channel and the key is used when publishing to the link.

Creating Links

In order to create a link, a JSON-formatted message must be sent to emitter/link/ MQTT topic. The message should contain at least the alphanumeric name (max 2 characters), a valid key and a channel. It optionally can contain a "subscribe" or "private" flags.

If subscribe flag is set to true and a channel key has a subscribe (read) permission, then emitter broker will automatically subscribe the client to the channel.

{ 
   "name": "0", 
   "key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", 
   "channel": "a/b/c/", 
   "private": false, 
   "subscribe": false
}

If the private flag is set to true and a channel key has an "extend" permission as shown in the screenshot below, then the channel will be made private by appending a connection identifier string to the provided channel.

image

{ 
   "name": "1", 
   "key": "k44Ss59ZSxg6Zyz39kLwN-2t5AETnGpm", 
   "channel": "a/b/c/", 
   "private": true, 
   "subscribe": true
}

For example, if you request the above private link to be created, 3 things will happen on emitter broker:

  1. The broker will create a sub-channel with a secure key for the new private link (e.g. .../a/b/c/F45JPXDSXVRWBUKTDNCCM4PGQ/ )
  2. The broker will subscribe (as requested) to that private sub-channel.
  3. The broker will map a link with name 1 to that private sub-channel (e.g. 1 -> .../a/b/c/F45JPXDSXVRWBUKTDNCCM4PGQ/

Then, by simply issuing a PUBLISH onto the topic 1 the broker will route the message in the private channel. Note that you can still manually create a wildcard key for a/#/ in order to create a "server" client which will be able to see everything.

internal/broker/handlers.go Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Jan 26, 2019

Coverage Status

Coverage decreased (-0.2%) to 90.722% when pulling 829fe3c on feat-dial into 656216c on master.

@kelindar kelindar changed the title Feature: Dial mechanism for simplified client-server apps Feature: Pre-registered links and simplified client-server setup Jan 27, 2019
@kelindar kelindar mentioned this pull request Jan 27, 2019
Copy link
Member

@Florimond Florimond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Florimond Florimond merged commit 6f36cb9 into master Jan 29, 2019
@kelindar kelindar deleted the feat-dial branch February 9, 2019 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants