Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const constants = {
VERSION: "5.4.0",
PROTOCOL_VERSION: 254,
PROTOCOL_VERSION_MIN_SIZE: 2,
UINT32_SIZE: 8, // hex
UINT64_SIZE: 16, // hex
HASH_SIZE: 16, // bin
Expand Down
7 changes: 7 additions & 0 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,13 @@ class CacheServer {
// Get the version as the first thing
var idx = 0;
if (!socket.protocolVersion) {
if (data.length < consts.PROTOCOL_VERSION_MIN_SIZE)
{
// We need more data
socket.pendingData = data;
return false;
}

socket.protocolVersion = helpers.readUInt32(data);
let buf = Buffer.allocUnsafe(consts.UINT32_SIZE);
if (socket.protocolVersion == consts.PROTOCOL_VERSION) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
},
"scripts": {
"test": "mocha test",
"coverage": "istanbul cover ./node_modules/mocha/bin/_mocha; open coverage/lcov-report/index.html",
"start": "node main.js",
"coveralls": "istanbul cover ./node_modules/mocha/bin/_mocha --report lcovonly -- -R spec && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage"
},
Expand Down
14 changes: 14 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ describe("CacheServer protocol", function() {

client.write(helpers.encodeInt32(consts.PROTOCOL_VERSION + 1));
});

it("should recognize a 2 byte version sent 1 byte at a time", function (done) {
this.slow(250);

client.on('data', function(data) {
var ver = helpers.readUInt32(data);
assert(ver == consts.PROTOCOL_VERSION, "Expected " + consts.PROTOCOL_VERSION + " Received " + ver);
done();
});

var ver = "fe";
client.write(ver[0]);
sleep(50).then(() => { client.write(ver[1]); });
});
});

describe("Transactions", function () {
Expand Down