+5
-5
@@ -1,7 +1,7 @@
|
||||
const http = require('http');
|
||||
const Debug = require('debug');
|
||||
const pump = require('pump');
|
||||
const EventEmitter = require('events');
|
||||
import http from 'http';
|
||||
import Debug from 'debug';
|
||||
import pump from 'pump';
|
||||
import EventEmitter from 'events';
|
||||
|
||||
// A client encapsulates req/res handling using an agent
|
||||
//
|
||||
@@ -129,4 +129,4 @@ class Client extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Client;
|
||||
export default Client;
|
||||
+6
-6
@@ -1,10 +1,10 @@
|
||||
const assert = require('assert';
|
||||
const http = require('http';
|
||||
const { Duplex } = require('stream';
|
||||
const WebSocket = require('ws';
|
||||
const net = require('net';
|
||||
import assert from 'assert';
|
||||
import http from 'http';
|
||||
import { Duplex } from 'stream';
|
||||
import WebSocket from 'ws';
|
||||
import net from 'net';
|
||||
|
||||
const Client = require('./Client';
|
||||
import Client from './Client';
|
||||
|
||||
class DummySocket extends Duplex {
|
||||
constructor(options) {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const { hri } = require('human-readable-ids');
|
||||
const Debug = require('debug');
|
||||
import { hri } from 'human-readable-ids';
|
||||
import Debug from 'debug';
|
||||
|
||||
const Client = require('./Client');
|
||||
const TunnelAgent = require('./TunnelAgent');
|
||||
import Client from './Client';
|
||||
import TunnelAgent from './TunnelAgent';
|
||||
|
||||
// Manage sets of clients
|
||||
//
|
||||
@@ -93,4 +93,4 @@ class ClientManager {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ClientManager;
|
||||
export default ClientManager;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
const assert = require('assert';
|
||||
const net = require('net';
|
||||
import assert from 'assert';
|
||||
import net from 'net';
|
||||
|
||||
const ClientManager = require('./ClientManager';
|
||||
import ClientManager from './ClientManager';
|
||||
|
||||
describe('ClientManager', () => {
|
||||
it('should construct with no tunnels', () => {
|
||||
|
||||
+12
-12
@@ -1,8 +1,8 @@
|
||||
const { Agent } = require('http');
|
||||
const net = require('net');
|
||||
const assert = require('assert');
|
||||
const log = require('book');
|
||||
const Debug = require('debug');
|
||||
import { Agent } from 'http';
|
||||
import net from 'net';
|
||||
import assert from 'assert';
|
||||
import log from 'book';
|
||||
import Debug from 'debug';
|
||||
|
||||
const DEFAULT_MAX_SOCKETS = 10;
|
||||
|
||||
@@ -14,7 +14,7 @@ class TunnelAgent extends Agent {
|
||||
super({
|
||||
keepAlive: true,
|
||||
// only allow keepalive to hold on to one socket
|
||||
// this prevents it = require(holding on to all the sockets so they can be used for upgrades
|
||||
// this prevents it from holding on to all the sockets so they can be used for upgrades
|
||||
maxFreeSockets: 1,
|
||||
});
|
||||
|
||||
@@ -55,7 +55,7 @@ class TunnelAgent extends Agent {
|
||||
server.on('close', this._onClose.bind(this));
|
||||
server.on('connection', this._onConnection.bind(this));
|
||||
server.on('error', (err) => {
|
||||
// These errors happen = require(killed connections, we don't worry about them
|
||||
// These errors happen from killed connections, we don't worry about them
|
||||
if (err.code == 'ECONNRESET' || err.code == 'ETIMEDOUT') {
|
||||
return;
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class TunnelAgent extends Agent {
|
||||
this.emit('end');
|
||||
}
|
||||
|
||||
// new socket connection = require(client for tunneling requests to client
|
||||
// new socket connection from client for tunneling requests to client
|
||||
_onConnection(socket) {
|
||||
// no more socket connections allowed
|
||||
if (this.connectedSockets >= this.maxTcpSockets) {
|
||||
@@ -98,7 +98,7 @@ class TunnelAgent extends Agent {
|
||||
socket.once('close', (hadError) => {
|
||||
this.debug('closed socket (error: %s)', hadError);
|
||||
this.connectedSockets -= 1;
|
||||
// remove the socket = require(available list
|
||||
// remove the socket from available list
|
||||
const idx = this.availableSockets.indexOf(socket);
|
||||
if (idx >= 0) {
|
||||
this.availableSockets.splice(idx, 1);
|
||||
@@ -113,7 +113,7 @@ class TunnelAgent extends Agent {
|
||||
|
||||
// close will be emitted after this
|
||||
socket.once('error', (err) => {
|
||||
// we do not log these errors, sessions can drop = require(clients for many reasons
|
||||
// we do not log these errors, sessions can drop from clients for many reasons
|
||||
// these are not actionable errors for our server
|
||||
socket.destroy();
|
||||
});
|
||||
@@ -139,7 +139,7 @@ class TunnelAgent extends Agent {
|
||||
this.availableSockets.push(socket);
|
||||
}
|
||||
|
||||
// fetch a socket = require(the available socket pool for the agent
|
||||
// fetch a socket from the available socket pool for the agent
|
||||
// if no socket is available, queue
|
||||
// cb(err, socket)
|
||||
createConnection(options, cb) {
|
||||
@@ -172,4 +172,4 @@ class TunnelAgent extends Agent {
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = TunnelAgent;
|
||||
export default TunnelAgent;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
const http = require('http';
|
||||
const net = require('net';
|
||||
const assert = require('assert';
|
||||
import http from 'http';
|
||||
import net from 'net';
|
||||
import assert from 'assert';
|
||||
|
||||
const TunnelAgent = require('./TunnelAgent';
|
||||
import TunnelAgent from './TunnelAgent';
|
||||
|
||||
describe('TunnelAgent', () => {
|
||||
it('should create an empty agent', async () => {
|
||||
|
||||
Reference in New Issue
Block a user