Skip to content
This repository has been archived by the owner on Oct 30, 2018. It is now read-only.

queueing publishContract and ping on worker queue close to nodeID #91

Merged
merged 2 commits into from
Jan 24, 2018
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 .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ addons:
- clang
node_js:
- "6.9.1"
- "8"
before_install:
- export CXX="g++-4.8" CC="gcc-4.8"
after_script:
Expand Down
5 changes: 4 additions & 1 deletion lib/landlord.js
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,15 @@ Landlord.prototype._getKeyFromRpcMessage = function(rpc) {
case 'getConsignmentPointer':
case 'getRetrievalPointer':
case 'renewContract':
case 'ping':
case 'getStorageProof':
return rpc.params[0].nodeID; // Key based on the target farmer
case 'getStorageOffer':
return rpc.params[0].data_hash; // Key based on the data hash
case 'getMirrorNodes':
return rpc.params[0][0].hash; // Key based on the data hash
return rpc.params[1][0].nodeID; // Key based on the destination pointer
case 'publishContract':
return rpc.params[0][0]._id; // Key based on the first farmer
default:
return crypto.randomBytes(1).toString('hex'); // Select a random exchange
}
Expand Down
84 changes: 82 additions & 2 deletions test/client.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,38 @@ describe('Client', function() {
]);
});

it('publishContract', function() {
var client = complex.createClient();
var method = 'publishContract';
var contract = new storj.Contract();
var farmer = storj.Contact({
address: '127.0.0.1',
port: 3030
});
var args = [farmer, contract];
var result = client._serializeRequestArguments(method, args);
expect(result).to.deep.equal([
farmer,
{
audit_count: 10,
data_hash: null,
data_size: 1234,
farmer_id: null,
farmer_signature: null,
payment_destination: null,
payment_download_price: 0,
payment_storage_price: 0,
renter_hd_index: false,
renter_hd_key: false,
renter_id: null,
renter_signature: null,
store_begin: 2000000000,
store_end: 3000000000,
version: 0
}
]);
});

it('getStorageProof', function() {
var client = complex.createClient();
var method = 'getStorageProof';
Expand Down Expand Up @@ -431,8 +463,29 @@ describe('Client', function() {
it('getMirrorNodes', function() {
var client = complex.createClient();
var method = 'getMirrorNodes';
var args = [];
client._serializeRequestArguments(method, args);
var farmer = new storj.Contact({
address: '127.0.0.1',
port: 3030
});
var args = [
farmer
];
var result = client._serializeRequestArguments(method, args);
expect(result).to.equal(args);
});

it('ping', function() {
var client = complex.createClient();
var method = 'ping';
var farmer = new storj.Contact({
address: '127.0.0.1',
port: 3030
});
var args = [
farmer
];
var result = client._serializeRequestArguments(method, args);
expect(result).to.equal(args);
});
});

Expand Down Expand Up @@ -586,6 +639,33 @@ describe('Client', function() {

});

describe('#publishContract', function() {

it('should call send with corrent params', function(done) {
var client = complex.createClient();
client._send = sinon.stub().callsArg(2);
var contract = storj.Contract({});
var farmer1 = storj.Contact({
address: '127.0.0.1',
port: 3030
});
var farmer2 = storj.Contact({
address: '127.0.0.1',
port: 3030
});
client.publishContract([farmer1, farmer2], contract, function() {
expect(client._send.callCount).to.equal(1);
expect(client._send.args[0][0]).to.equal('publishContract');
expect(client._send.args[0][1]).to.deep.equal([
[farmer1, farmer2],
contract
]);
done();
});
});

});

describe('#ping', function() {
it('should call send with correct params', function(done) {
var client = complex.createClient();
Expand Down
45 changes: 40 additions & 5 deletions test/landlord.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,25 +572,60 @@ describe('Landlord', function() {

describe('#_getKeyFromRpcMessage', function() {

it('should use the nodeID of farmer', function() {
it('getConsignmentPointer should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'getConsignmentPointer',
params: [{ nodeID: 'nodeid' }]
})).to.equal('nodeid');
});

it('getRetrievalPointer should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'getRetrievalPointer',
params: [{ nodeID: 'nodeid' }]
})).to.equal('nodeid');
});

it('renewContract should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'renewContract',
params: [{ nodeID: 'nodeid' }]
})).to.equal('nodeid');
});

it('publishContract should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'publishContract',
params: [[{ _id: 'nodeid1' }, { _id: 'nodeid2' }]]
})).to.equal('nodeid1');
});

it('getStorageProof should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'getStorageProof',
params: [{ nodeID: 'nodeid' }]
})).to.equal('nodeid');
});

it('should use the data hash of contract', function() {
it('ping should use the nodeID of farmer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'ping',
params: [{ nodeID: 'nodeid' }]
})).to.equal('nodeid');
});

it('getStorageOffer should use the data hash of contract', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'getStorageOffer',
params: [{ data_hash: 'datahash' }]
})).to.equal('datahash');
});

it('should use the hash of pointer', function() {
it('getMirrorNodes should use the hash of pointer', function() {
expect(Landlord.prototype._getKeyFromRpcMessage({
method: 'getMirrorNodes',
params: [[{ hash: 'datahash' }]]
})).to.equal('datahash');
params: [[{ hash: 'datahash' }], [{ nodeID: 'nodeid' }]]
})).to.equal('nodeid');
});

it('should be random', function() {
Expand Down