Giter VIP home page Giter VIP logo

persistent-tunnel's Introduction

persistent-tunnel

HTTP Agent for tunneling proxies with persistent sockets

Motivation

This tunneling agent combines the latest http.Agent with a custom createConnection function that returns the socket of an established tunnel.

Inspired from

Use cases

Simple tunneling

var tunnel = require('persistent-tunnel');

var tunnelingAgent = new tunnel.Agent({
  proxy: {
    host: 'localhost',
    port: 3128
  }
});
tunnelingAgent.createConnection = tunnel.createConnection;

var req = http.request({
  host: 'example.com',
  port: 80,
  agent: tunnelingAgent
});

Simple tunneling with persistent tunnels

var tunnel = require('persistent-tunnel');

var tunnelingAgent = new tunnel.Agent({
  keepAlive: true   // create persistent sockets over tunnel
  proxy: {
    host: 'localhost',
    port: 3128
  },
});
tunnelingAgent.createConnection = tunnel.createConnection;

var req = http.request({
  host: 'example.com',
  port: 80,
  agent: tunnelingAgent
});

Simple tunneling with persistent tunnels that expire after a timeout

var tunnel = require('persistent-tunnel');

var tunnelingAgent = new tunnel.Agent({
  keepAlive: true,
  proxy: {
    host: 'localhost',
    port: 3128
    timeout: 2000 // tunnel sockets close after 2s of inactivity
  },
});
tunnelingAgent.createConnection = tunnel.createConnection;

var req = http.request({
  host: 'example.com',
  port: 80,
  agent: tunnelingAgent
});

Configuration

keepAlive setting

When keepAlive is set to true, socket pooling / reuse is enabled by the HTTP Agent. In addition to managing the pool, the HTTP Agent calls setKeepAlive() on each pooled socket so that TCP KeepAlive packets are sent over the established connection in small intervals. Any intermediate TCP Load Balancers / Proxies along the tunnel connection should detect the TCP KeepAlive packets and keep the connection alive.

timeout setting

When timeout is set, the connection will get severed if no data has been transfered over the socket for the specified time. TCP KeepAlive packets do not count as data. The timeout setting is useful for making sure that idle sockets will eventually get destroy()'ed and release their resources.

If no timeout value is set, the pooled tunneling sockets will be kept alive forever.

In any case, if a tunnel connection gets dropped for any reason, the underlying socket will emit an error that will result in it being removed from the HTTP Agent pool (and its resources released, too).

TODO

  • https support
  • proxy authorization

Support

If you're having any problem, please raise an issue on GitHub and the Resin.io team will be happy to help.

License

Licensed under the MIT license.

persistent-tunnel's People

Contributors

lekkas avatar

Watchers

James Cloos avatar vulcanoIO - Open Source Sandbox and RE malwares avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.