Skip to content

Commit 718b25c

Browse files
committed
Merge branch 'master' into gitlaura-cancel-cloud-install
2 parents 659b1d9 + 737a46d commit 718b25c

9 files changed

Lines changed: 66 additions & 42 deletions

File tree

Gruntfile.coffee

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,8 @@ config =
314314
# with a couple of fixes.
315315
'./src/cloud/social/shim/net.js:net'
316316
'./src/cloud/social/shim/dns.js:dns'
317-
# Subset of ssh2-streams (all except SFTP) which works well in
318-
# the browser.
319-
'./src/cloud/social/alias/ssh2-streams.js:ssh2-streams'
317+
# Alternative that works for freedomjs modules.
318+
'./src/cloud/social/alias/brorand.js:brorand'
320319
# Fallback for crypto-browserify's randombytes, for Firefox.
321320
'./src/cloud/social/alias/randombytes.js:randombytes'
322321
]
@@ -327,9 +326,8 @@ config =
327326
# with a couple of fixes.
328327
'./src/cloud/social/shim/net.js:net'
329328
'./src/cloud/social/shim/dns.js:dns'
330-
# Subset of ssh2-streams (all except SFTP) which works well in
331-
# the browser.
332-
'./src/cloud/social/alias/ssh2-streams.js:ssh2-streams'
329+
# Alternative that works for freedomjs modules.
330+
'./src/cloud/social/alias/brorand.js:brorand'
333331
# Fallback for crypto-browserify's randombytes, for Firefox.
334332
'./src/cloud/social/alias/randombytes.js:randombytes'
335333
]

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,7 @@
6060
"lodash": "^3.10.1",
6161
"request": "^2.53.0",
6262
"socks5-http-client": "^1.0.2",
63-
"ssh2": "0.4.12",
64-
"ssh2-streams": "0.0.18",
63+
"ssh2": "0.5.0",
6564
"tslint": "^3.3.0",
6665
"typescript": "~1.8.2",
6766
"typings": "^0.7.12",

src/cloud/install/installer.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/// <reference path='../../../../third_party/typings/browser.d.ts' />
22

3+
require('../social/monkey/process');
4+
35
import arraybuffers = require('../../arraybuffers/arraybuffers');
46
import linefeeder = require('../../net/linefeeder');
57
import logging = require('../../logging/logging');

src/cloud/social/alias/brorand.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// brorand alias which works in a freedomjs module context.
2+
// Uses randombytes, for which we have an alias which works
3+
// for Firefox.
4+
5+
const randombytes = require('randombytes');
6+
7+
module.exports = function rand(len) {
8+
return randombytes(len);
9+
};
10+
11+
function Rand(fallback) {
12+
// no-op: always use randombytes
13+
}
14+
module.exports.Rand = Rand;
15+
16+
Rand.prototype.generate = function generate(len) {
17+
return randombytes(len);
18+
};

src/cloud/social/alias/randombytes.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ try {
1414
cryptoAvailable = false;
1515
}
1616

17-
module.exports = function(size) {
17+
module.exports = function(size, cb) {
1818
var buffer = new Buffer(size);
1919
if (cryptoAvailable) {
2020
// Although this looks weird, it's how crypto-browserify does it too:
@@ -25,5 +25,9 @@ module.exports = function(size) {
2525
buffer[i] = Math.floor(Math.random() * 256);
2626
}
2727
}
28-
return buffer;
28+
if (cb) {
29+
cb(undefined, buffer);
30+
} else {
31+
return buffer;
32+
}
2933
}

src/cloud/social/alias/ssh2-streams.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/cloud/social/monkey/process.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Monkey patch for browserify's process shim, for ssh2-streams.
2+
3+
// Node.js 4.2 is an LTS release and, very roughly, is what the
4+
// browserify shims, e.g. Buffer, provide.
5+
process.version = '4.2.0';
6+
7+
process.binding = function() {
8+
return {};
9+
};

src/cloud/social/provider.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
/// <reference path='../../../../third_party/typings/browser.d.ts' />
22

3+
require('../social/monkey/process');
4+
35
import arraybuffers = require('../../arraybuffers/arraybuffers');
46
import linefeeder = require('../../net/linefeeder');
57
import logging = require('../../logging/logging');

src/integration-tests/socks-echo/slow.core-env.spec.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ function slowTestDescription(useChurn:boolean) {
3333
testerFactoryManager.close();
3434
});
3535

36-
// The default TCP SYN timeout is two minutes, so to be safe we
37-
// set a test timeout of four minutes.
38-
jasmine.DEFAULT_TIMEOUT_INTERVAL = 240000;
36+
// 100 MB download through CHURN takes about 10 minutes.
37+
// Set the limit to 20 minutes for safety.
38+
jasmine.DEFAULT_TIMEOUT_INTERVAL = 20 * 60 * 1000;
3939

4040
// Opens 200 connections, sends 1 KB on each, and receives 250 KB on each
4141
it('download load test', (done) => {
@@ -51,26 +51,29 @@ function slowTestDescription(useChurn:boolean) {
5151
}
5252
return Promise.all(connectionPromises);
5353
}).then((connectionIds:string[]) => {
54-
var completions = connectionIds.map((connectionId:string) : Promise<void> => {
55-
var resolve :Function;
56-
var result :Promise<void> = new Promise<void>((F, R) => { resolve = F; });
57-
var isDone = false;
58-
var outputString = '';
59-
testModule.on('receivedData', (event:ReceivedDataEvent) => {
60-
if (event.connectionId != connectionId) {
61-
return;
54+
// Maps connectionIds to the number of bytes received so far. Counters
55+
// start at 0, and entries are deleted when all data has been received
56+
// for a connection. When all entries have been deleted, the test passes.
57+
let counters :{[id:string]: number} = {};
58+
testModule.on('receivedData', (event:ReceivedDataEvent) => {
59+
const id = event.connectionId;
60+
if (id in counters) {
61+
counters[id] += event.response.byteLength;
62+
} else {
63+
throw new Error('Unexpected connectionId ' + id);
64+
}
65+
if (counters[id] === repeat * blockSize) {
66+
delete counters[id];
67+
// Check if we have deleted the last id.
68+
if (Object.keys(counters).length === 0) {
69+
done();
6270
}
63-
expect(isDone).toBe(false);
64-
if (event.response.byteLength === repeat * blockSize) {
65-
isDone = true;
66-
resolve();
67-
}
68-
});
69-
return testModule.sendData(connectionId, testBlock).then(() => {
70-
return result;
71-
});
71+
}
72+
});
73+
connectionIds.map((id:string) => {
74+
counters[id] = 0;
75+
testModule.sendData(id, testBlock);
7276
});
73-
Promise.all(completions).then(done);
7477
});
7578
});
7679

0 commit comments

Comments
 (0)