Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

Commit

Permalink
Add option to enforce identical app name in pings
Browse files Browse the repository at this point in the history
Always reject pings from wrong app name

temp test

pin npm

clean up
  • Loading branch information
yulunli committed Jun 15, 2017
1 parent f85fd4b commit 8da302e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ language: node_js
node_js:
- "0.10"
- "4.4.7"
before_install: npm i npm@latest -g
before_install: npm i npm@2 -g

addons:
apt:
Expand All @@ -19,4 +19,4 @@ matrix:
fast_finish: true

script:
- test/travis
- test/travis
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ function RingPop(options) {
MEMBERSHIP_UPDATE_FLUSH_INTERVAL;
this.maxReverseFullSyncJobs = options.maxReverseFullSyncJobs ||
MAX_REVERSE_FULL_SYNC_JOBS;
// If set to true, ping requests without identical app name return error
this.requiresAppInPing = options.requiresAppInPing || false;

// Initialize Config before all other gossip, membership, forwarding,
// and hash ring dependencies.
Expand Down
2 changes: 1 addition & 1 deletion lib/gossip/ping-sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ PingSender.prototype.onPing = function onPing(err, res, callback) {
});
this.ring.membership.update(res.changes);
callback(err, res);
return;
};

PingSender.prototype.sendChanges = function sendChanges(changes, callback) {
Expand All @@ -74,6 +73,7 @@ PingSender.prototype.sendChanges = function sendChanges(changes, callback) {
checksum: self.ring.membership.checksum,
changes: changes,
source: self.ring.whoami(),
app: self.ring.app,
sourceIncarnationNumber: self.ring.membership.getIncarnationNumber()
}, callback);
};
Expand Down
14 changes: 13 additions & 1 deletion server/protocol/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ module.exports = function createPingHandler(ringpop) {
return callback(new Error('need req body with source, changes, and checksum'));
}

if (body.hasOwnProperty('app')) {
if (body.app !== ringpop.app) {
ringpop.logger.warn('Rejected ping from wrong ringpop app', body);
return callback(new Error('Pinged ringpop has a different app name'));
}
} else {
if (ringpop.requiresAppInPing) {
ringpop.logger.warn('Rejected ping from unknown ringpop app', body);
return callback(new Error('Pinged ringpop requires app name'));
}
}

var source = body.source;
var sourceIncarnationNumber = body.sourceIncarnationNumber;
var changes = body.changes;
Expand All @@ -57,7 +69,7 @@ module.exports = function createPingHandler(ringpop) {
ringpop.dissemination.tryStartReverseFullSync(source, ringpop.maxJoinDuration);
}
callback(null, null, {
changes: res.changes,
changes: res.changes
});
};
};
23 changes: 23 additions & 0 deletions test/integration/gossip_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

'use strict';

var sendPing = require('../../lib/gossip/ping-sender.js').sendPing;
var sendPingReqs = require('../../lib/gossip/ping-req-sender.js');
var testRingpopCluster = require('../lib/test-ringpop-cluster.js');
var stopGossiping = require('../lib/gossip-utils').stopGossiping;
Expand Down Expand Up @@ -208,3 +209,25 @@ testRingpopCluster({
assert.end();
});
});

testRingpopCluster({
size: 2,
tapAfterConvergence: function tapAfterConvergence(cluster) {
stopGossiping(cluster);
}
}, 'ping with wrong app name is always rejected', function t(bootRes, cluster, assert) {
assert.plan(1);

var pingSender = cluster[0];
var pingTarget = pingSender.membership.findMemberByAddress(cluster[1].whoami());

pingSender.app = pingSender.app + 'foo';

sendPing({
ringpop: pingSender,
target: pingTarget
}, function onPing(err, res) {
assert.ok(err, 'expects ping error when app name differs');
assert.end();
});
});

0 comments on commit 8da302e

Please sign in to comment.