Skip to content
Open
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
9 changes: 8 additions & 1 deletion bin/thor
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ cli.usage('[options] ws://localhost')
.option('-G, --generator <file>', 'custom message generators')
.option('-M, --masked', 'send the messaged with a mask')
.option('-b, --binary', 'send binary messages instead of utf-8')
.option('-S, --SSLcertificate <file>','supply the SSL certificate location for wss connections')
.version(require('../package.json').version)
.parse(process.argv);

Expand Down Expand Up @@ -56,7 +57,13 @@ cluster.setupMaster({
: path.resolve(__dirname, '../generator.js'),
cli.protocol,
!!cli.masked,
!!cli.binary
!!cli.binary,
cli.SSLcertificate
? path.resolve(process.cwd(), cli.SSLcertificate)
: undefined ,
cli.SSLcertificate
? 'true'
: 'false',
]
});

Expand Down
15 changes: 13 additions & 2 deletions mjolnir.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
'use strict';

var fs = require('fs');
var Socket = require('ws')
, connections = {}
, concurrent = 0;
Expand All @@ -14,7 +15,9 @@ var session = require(process.argv[2]);
//
var masked = process.argv[4] === 'true'
, binary = process.argv[5] === 'true'
, protocol = +process.argv[3] || 13;
, protocol = +process.argv[3] || 13
, SSLcertificate = process.argv[6]
, isSSL = process.argv[7] === 'true';

process.on('message', function message(task) {
var now = Date.now();
Expand All @@ -40,9 +43,17 @@ process.on('message', function message(task) {
// End of the line, we are gonna start generating new connections.
if (!task.url) return;

var socket = new Socket(task.url, {
var socket;
if (isSSL)
{socket = new Socket(task.url, {
protocolVersion: protocol,
ca : [fs.readFileSync(SSLcertificate)]
}); }
else
{ socket = new Socket(task.url, {
protocolVersion: protocol
});
}

socket.on('open', function open() {
process.send({ type: 'open', duration: Date.now() - now, id: task.id, concurrent: concurrent });
Expand Down