Skip to content
Browse files

fix: name queues uid,offset

  • Loading branch information...
1 parent 910a19c commit 3c9d2402c3910665376e010445d8dde424ba6875 @networkimprov committed Apr 6, 2012
Showing with 23 additions and 21 deletions.
  1. +14 −13 mqlib.js
  2. +9 −8 mqserver.js
View
27 mqlib.js
@@ -608,21 +608,24 @@ Link.prototype = {
that.conn.write(1, 'binary', packMsg({op:'added', error:'new nodename required'}));
return;
}
- if (!that.uid)
- sRegSvc.verify(iReq.userId, iReq.prevNode, function(err, ok) {
- if (err || !ok) {
+ var aThatNode = that.node;
+ var aThatUid = that.uid || iReq.userId;
+ if (!that.node)
+ sRegSvc.verify(iReq.userId, iReq.prevNode, function(err, offset) {
+ if (err) {
if (that.conn)
- that.conn.write(1, 'binary', packMsg({op:'added', error:'authentication failed'}));
+ that.conn.write(1, 'binary', packMsg({op:'added', error:err.message}));
return;
}
+ aThatNode = aThatUid+','+offset;
fCopy();
});
else
fCopy();
function fCopy() {
- sRegSvc.reregister(iReq.userId, iReq.newNode, iReq.prevNode, null, function(err, ignore, offset) {
+ sRegSvc.reregister(aThatUid, iReq.newNode, iReq.prevNode, null, function(err, ignore, offset) {
if (offset)
- copyQueue(iReq.userId, iReq.userId+iReq.prevNode, iReq.userId+iReq.newNode, fRespond);
+ copyQueue(aThatUid, aThatNode, aThatUid+','+offset, fRespond);
else
fRespond();
function fRespond() {
@@ -637,13 +640,11 @@ Link.prototype = {
var that = this;
clearTimeout(that.loginTimer);
that.loginTimer = null;
- sRegSvc.verify(iReq.userId, iReq.nodeId, function(err, ok) {
+ sRegSvc.verify(iReq.userId, iReq.nodeId, function(err, offset) {
if (!that.conn)
return;
- var aNode = iReq.userId+iReq.nodeId;
- if (err || !ok) var aErr = 'invalid login';
- else if (aNode in sActive) var aErr = 'node already active';
- else if (sShutdown) var aErr = 'shutdown';
+ var aNode = iReq.userId+','+offset;
+ var aErr = err ? err.message : aNode in sActive ? 'node already active' : sShutdown ? 'shutdown' : null;
if (aErr) {
that.conn.write(1, 'binary', packMsg({op:'quit', info:aErr}));
that.conn.close();
@@ -781,8 +782,8 @@ Link.prototype = {
iAckErr += (iAckErr && '\n') + err.message;
} else {
for (var aN in list)
- if (uid in iReq.to || uid+aN !== that.node)
- aTo[uid+aN] = uid in iReq.to ? iReq.to[uid] : 1;
+ if (uid in iReq.to || uid+','+aN !== that.node)
+ aTo[uid+','+aN] = uid in iReq.to ? iReq.to[uid] : 1;
}
if (--aToCount > 0)
return;
View
17 mqserver.js
@@ -223,19 +223,20 @@ RegDb.prototype = {
} ,
verify: function(iUid, iNode, iCallback) {
- var that = this;
+ var aErr = !(iUid in this.db.uid) ? new Error('userId unknown')
+ : !(iNode in this.db.uid[iUid].nodes) ? new Error('nodeId unknown') : null;
+ var aOffset = aErr ? undefined : this.db.uid[iUid].nodes[iNode];
process.nextTick(function() {
- iCallback(null, iUid in that.db.uid && iNode in that.db.uid[iUid].nodes);
+ iCallback(aErr, aOffset);
});
} ,
getNodes: function(iUid, iCallback) {
- var that = this;
- var aList, aErr = that.db.uid[iUid] ? null : new Error('no such uid');
- if (that.db.uid[iUid]) {
- aList = {};
- for (var a in that.db.uid[iUid].nodes)
- aList[a] = true;
+ var aErr = this.db.uid[iUid] ? null : new Error('userId unknown');
+ if (this.db.uid[iUid]) {
+ var aList = {};
+ for (var a in this.db.uid[iUid].nodes)
+ aList[this.db.uid[iUid].nodes[a]] = true;
}
process.nextTick(function() {
iCallback(aErr, iUid, aList);

0 comments on commit 3c9d240

Please sign in to comment.
Something went wrong with that request. Please try again.