Reject joins for channels mapped to other partitions

This commit is contained in:
calzoneman 2016-06-07 22:47:49 -07:00
parent 77465e6b49
commit a360cd8808
2 changed files with 23 additions and 2 deletions

View file

@ -71,6 +71,7 @@ var Server = function () {
initModule = new BackendModule(); initModule = new BackendModule();
} else if (Config.get('enable-partition')) { } else if (Config.get('enable-partition')) {
initModule = new PartitionModule(); initModule = new PartitionModule();
self.partitionDecider = initModule.getPartitionDecider();
} else { } else {
initModule = new LegacyModule(); initModule = new LegacyModule();
} }
@ -186,8 +187,15 @@ Server.prototype.isChannelLoaded = function (name) {
}; };
Server.prototype.getChannel = function (name) { Server.prototype.getChannel = function (name) {
var self = this;
var cname = name.toLowerCase(); var cname = name.toLowerCase();
if (this.partitionDecider &&
!this.partitionDecider.isChannelOnThisPartition(cname)) {
const error = new Error(`Channel '${cname}' is mapped to a different partition`);
error.code = 'EWRONGPART';
throw error;
}
var self = this;
for (var i = 0; i < self.channels.length; i++) { for (var i = 0; i < self.channels.length; i++) {
if (self.channels[i].uniqueName === cname) if (self.channels[i].uniqueName === cname)
return self.channels[i]; return self.channels[i];

View file

@ -53,7 +53,20 @@ function User(socket) {
} }
self.waitFlag(Flags.U_READY, function () { self.waitFlag(Flags.U_READY, function () {
var chan = Server.getServer().getChannel(data.name); var chan;
try {
chan = Server.getServer().getChannel(data.name);
} catch (error) {
if (error.code !== 'EWRONGPART') {
throw error;
}
self.socket.emit("errorMsg", {
msg: "Channel '" + data.name + "' is hosted on another server. " +
"Try refreshing the page to update the connection URL."
});
return;
}
chan.joinUser(self, data); chan.joinUser(self, data);
}); });
}); });