Skip to content

Commit

Permalink
ignore unsupported messages
Browse files Browse the repository at this point in the history
  • Loading branch information
snogcel committed Aug 19, 2016
1 parent 6b73e73 commit 1e600e8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
29 changes: 29 additions & 0 deletions lib/messages/builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,35 @@ function builder(options) {
dsq: 'DSQueue',
ssc: 'SyncStatusCount'
},
unsupportedCommandsMap: [
'sendheaders',
'ix',
'txlvote',
'spork',
'getsporks',
'mnw',
'mnget',
'mn scan error',
'mnvs',
'mvote',
'mprop',
'fbs',
'fbvote',
'mn quorum',
'mnb',
'mnp',
'dsa',
'dsi',
'dsf',
'dss',
'dsc',
'dssu',
'dstx',
'dseg',
'govsync',
'govobj',
'govobjvote'
],
commands: {}
};

Expand Down
4 changes: 2 additions & 2 deletions lib/messages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ Messages.prototype._discardUntilNextMessage = function(dataBuffer) {
};

Messages.prototype._buildFromBuffer = function(command, payload) {
if (command === 'sendheaders') return; // BIP 130, ignore 'sendheaders' command
if (!this.builder.commands[command]) {
throw new Error('Unsupported message command: ' + command);
if (this.builder.unsupportedCommandsMap.indexOf(command) > -1) return; // ignore unsupported message commands
throw new Error('Unrecognized message command: ' + command); // throw error if unrecognized message command
}
return this.builder.commands[command].fromBuffer(payload);
};
Expand Down
2 changes: 1 addition & 1 deletion test/messages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ describe('Messages', function() {
var bufs = buildMessage(invalidCommand);
messages.parseBuffer(bufs);
};
fails.should.throw('Unsupported message command: malicious');
fails.should.throw('Unrecognized message command: malicious');
});

it('ignores malformed messages', function() {
Expand Down

0 comments on commit 1e600e8

Please sign in to comment.