Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function connect (req, cltSocket, head, hostname, port) {
// tunneling https
var proxySocket = net.connect(port, hostname, () => {
cltSocket.write('HTTP/1.1 200 Connection Established\r\n' +
'Proxy-agent: node-mitmproxy\r\n' +
'\r\n');
proxySocket.write(head);
proxySocket.pipe(cltSocket);
cltSocket.pipe(proxySocket);
});
proxySocket.on('error', (e) => {
console.log(colors.red(e));
});
return proxySocket;
}
constructor(target) {
this.server = net.createServer((connection) => {
const socket = new net.Socket();
socket.connect(target);
const fragmenter = new FragmentationConnection(connection, socket);
});
this.server.listen();
}
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const server = net.createServer(common.mustNotCall());
server.listen(1, '1.1.1.1', common.mustNotCall());
server.on('error', common.mustCall(function(e) {
assert.strictEqual(e.address, '1.1.1.1');
assert.strictEqual(e.port, 1);
assert.strictEqual(e.syscall, 'listen');
}));
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const fp = '/blah/fadfa';
const server = net.createServer(common.mustNotCall());
server.listen(fp, common.mustNotCall());
server.on('error', common.mustCall(function(e) {
assert.strictEqual(e.address, fp);
}));
constructor(ip: string, port: number, networkId: string) {
this.socket = new Socket();
this.ip = ip;
this.port = port;
this.arrivedExtensionMessage = [];
this.tcpBuffer = Buffer.alloc(0);
this.genesisHash = new H256("0000000000000000000000000000000000000000000000000000000000000000");
this.recentHeaderNonce = new U256(0);
this.recentBodyNonce = new U256(0);
this.log = false;
this.networkId = networkId;
this.localKey = EC.genKeyPair();
}
connect() {
if (this.socket) this.socket.destroy();
this.socket = new net.Socket();
this.bindListeners();
this.log('connecting...');
this.connectionStatus = 'pending';
return new Promise((resolve, reject) => {
this.resolveConnection = resolve;
this.rejectConnection = reject;
this.socket.connect(PIPE_PATH);
});
}
var client_connect = function(server, stream) {
console.log('Connect peer='+server.peer.host+":"+ server.peer.port+" my="+server.my.host+":"+ server.my.port+":"+server['no_output'])
stream = net.createConnection(server.peer.port, server.peer.host, { bind: server.my });
status.connections.client.connects++;
streamer(stream, {
closed: function() {
setTimeout(function() {
client_connect(server, stream);
}, 1000);
}
}, server)
}
servers.forEach(function(server) {
connect() {
try {
this.forceDisconnect = false
this.socket = new net.Socket()
this.bindSocket()
this.socket.connect({ host: this.device.host, port: this.device.port }, () => {
this.didConnect()
this.emit('connected')
})
} catch (err) {
this.socketClosed(err)
}
}
const createServer = (port, host, connectionCallback, listenCallback) => {
const server = net.createServer(connectionCallback)
server.listen(port, host, () => {
listenCallback(server)
})
server.on('error', (err) => {throw err})
return server;
}
module.exports = function(cb) {
var server = net.createServer()
, port = 0
server.on('listening', function() {
port = server.address().port
server.close()
})
server.on('close', function() {
cb(null, port)
})
server.on('error', function(err) {
cb(err, null)
})
server.listen(0, '127.0.0.1')
}