mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-23 00:13:13 +09:00
Filter plugin messages forwarded to links
Drop events forwarded to a slave or instance that does not have the plugin the event is defined in. Reject requests for the same reason.
This commit is contained in:
1 parent
ca2839594e
commit
a194508f52
8 files changed
+108
-37
No files matched your search
+37
-2
@@ -3,15 +3,36 @@
|
||||
const schema = require("lib/schema");
|
||||
const errors = require("lib/errors");
|
||||
|
||||
/**
|
||||
* Represents a message that can be sent over the link
|
||||
*
|
||||
* @memberof module:lib/link
|
||||
*/
|
||||
class Message {
|
||||
/**
|
||||
* Name of the plugin this message belongs to, or null.
|
||||
* @returns {?string}
|
||||
**/
|
||||
get plugin() {
|
||||
if (this._plugin === undefined) {
|
||||
let index = this.type.indexOf(":");
|
||||
this._plugin = index === -1 ? null : this.type.slice(0, index);
|
||||
}
|
||||
|
||||
return this._plugin;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents a request sent over the link
|
||||
*
|
||||
* A request-response message that can be innitated by either party of the
|
||||
* link.
|
||||
*
|
||||
* @extends module:lib/link.Message
|
||||
* @memberof module:lib/link
|
||||
*/
|
||||
class Request {
|
||||
class Request extends Message {
|
||||
|
||||
/**
|
||||
* Creates a request
|
||||
@@ -37,6 +58,7 @@ class Request {
|
||||
constructor({
|
||||
type, links, forwardTo = null, requestProperties = {}, responseProperties = {}
|
||||
}) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.links = links;
|
||||
this.forwardTo = forwardTo;
|
||||
@@ -362,9 +384,10 @@ messages.getMetrics = new Request({
|
||||
* A one way message without any response or recipt confirmation that
|
||||
* can be innitiated by either party of the link.
|
||||
*
|
||||
* @extends module:lib/link.Message
|
||||
* @memberof module:lib/link
|
||||
*/
|
||||
class Event {
|
||||
class Event extends Message {
|
||||
|
||||
/**
|
||||
* Creates an event
|
||||
@@ -390,6 +413,7 @@ class Event {
|
||||
* properties that are valid in the data payload of this event.
|
||||
*/
|
||||
constructor({ type, links, forwardTo = null, broadcastTo = null, eventProperties = {} }) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.links = links;
|
||||
this.forwardTo = forwardTo;
|
||||
@@ -509,6 +533,16 @@ messages.debugWsMessage = new Event({
|
||||
},
|
||||
});
|
||||
|
||||
messages.instanceInitialized = new Event({
|
||||
type: "instance_initialized",
|
||||
links: ["instance-slave"],
|
||||
eventProperties: {
|
||||
"plugins": {
|
||||
type: "object",
|
||||
additionalProperties: { type: "string" },
|
||||
}
|
||||
},
|
||||
});
|
||||
messages.instanceStopped = new Event({
|
||||
type: 'instance_stopped',
|
||||
links: ['instance-slave'],
|
||||
@@ -583,6 +617,7 @@ function attachAllMessages(link) {
|
||||
|
||||
|
||||
module.exports = {
|
||||
Message,
|
||||
Request,
|
||||
Event,
|
||||
|
||||
|
||||
Reference in new issue
Block a user