2019-10-02 20:57:18 -04:00
|
|
|
/**
|
|
|
|
* @description MQTT broker reference implementation based on AEDES
|
|
|
|
* @author Joko Banu Sastriawan
|
|
|
|
* @copyright Intel Corporation 2018-2019
|
|
|
|
* @license Apache-2.0
|
|
|
|
* @version v0.0.1
|
|
|
|
*/
|
|
|
|
|
|
|
|
module.exports.CreateMQTTBroker = function (parent, db, args) {
|
2019-10-04 15:18:56 -04:00
|
|
|
|
|
|
|
// Internal objects container
|
2019-10-02 20:57:18 -04:00
|
|
|
var obj = {}
|
|
|
|
obj.parent = parent;
|
|
|
|
obj.db = db;
|
|
|
|
obj.args = args;
|
|
|
|
obj.aedes = require("aedes")();
|
2019-10-04 15:18:56 -04:00
|
|
|
|
2019-10-02 20:57:18 -04:00
|
|
|
// argument parsing -- tbd
|
2019-10-04 15:18:56 -04:00
|
|
|
|
2019-10-02 20:57:18 -04:00
|
|
|
// event handling and filtering
|
|
|
|
// authentication filter
|
|
|
|
obj.aedes.authenticate = function (client, username, password, callback) {
|
|
|
|
// TODO: add authentication handler
|
2019-10-04 15:18:56 -04:00
|
|
|
obj.parent.debug("mqtt", "Authentication with " + username + ":" + password);
|
2019-10-02 20:57:18 -04:00
|
|
|
callback(null, true);
|
|
|
|
}
|
2019-10-04 15:18:56 -04:00
|
|
|
|
2019-10-02 20:57:18 -04:00
|
|
|
// check if a client can publish a packet
|
|
|
|
obj.aedes.authorizePublish = function (client, packet, callback) {
|
2019-10-04 15:18:56 -04:00
|
|
|
// TODO: add authorized publish control
|
|
|
|
obj.parent.debug("mqtt", "AuthorizePublish");
|
2019-10-02 20:57:18 -04:00
|
|
|
callback(null);
|
|
|
|
}
|
2019-10-04 15:18:56 -04:00
|
|
|
|
|
|
|
// Check if a client can publish a packet
|
2019-10-02 20:57:18 -04:00
|
|
|
obj.aedes.authorizeSubscribe = function (client, sub, callback) {
|
2019-10-04 15:18:56 -04:00
|
|
|
// TODO: add subscription control here
|
|
|
|
obj.parent.debug("mqtt", "AuthorizeSubscribe");
|
2019-10-02 20:57:18 -04:00
|
|
|
callback(null, sub);
|
|
|
|
}
|
2019-10-04 15:18:56 -04:00
|
|
|
|
|
|
|
// Check if a client can publish a packet
|
2019-10-02 20:57:18 -04:00
|
|
|
obj.aedes.authorizeForward = function (client, packet) {
|
2019-10-04 15:18:56 -04:00
|
|
|
// TODO: add forwarding control
|
|
|
|
obj.parent.debug("mqtt", "AuthorizeForward");
|
2019-10-02 20:57:18 -04:00
|
|
|
return packet;
|
|
|
|
}
|
2019-10-04 15:18:56 -04:00
|
|
|
|
|
|
|
obj.handle = obj.aedes.handle;
|
|
|
|
return obj;
|
2019-10-02 20:57:18 -04:00
|
|
|
}
|