Git Product home page Git Product logo

node-udp-proxy's Introduction

udp-proxy

##v.0.2.0
###by: ok 2013

UDP-proxy for node.js

Supports both IPv6 and IPv4, and bridging in between (see example below).

Installation

npm install udp-proxy

udp-proxy has no dependencies beyond node.js itself

Usage

Example:

// Let's create a DNS-proxy that proxies IPv4 udp-requests to googles IPv6 DNS-server
var proxy = require('udp-proxy'),
	options = {
		address: '2001:4860:4860::8888',
		port: 53,
		ipv6: true,
		localaddress: '0.0.0.0',
		localport: 53535,
		localipv6: false,
		proxyaddress: '::0',
		timeOutTime: 10000
	};

// This is the function that creates the server, each connection is handled internally
var server = proxy.createServer(options);

// Show some nice colors when the server starts
server.on('listening', function (details) {
	console.log('DNS - IPv4 to IPv6 proxy }>=<{ by: ok 2012');
	console.log('udp-proxy-server ready on ' + details.server.family + '  ' + details.server.address + ':' + details.server.port);
	console.log('traffic is forwarded to ' + details.target.family + '  ' + details.target.address + ':' + details.target.port + rs);
});

// 'bound' means the connection to server has been made and the proxying is in action
server.on('bound', function (details) {
	console.log('proxy is bound to ' + details.route.address + ':' + details.route.port);
	console.log('peer is bound to ' + details.peer.address + ':' + details.peer.port);
});

// 'message' is emitted when the server gets a message
server.on('message', function (message, sender) {
	console.log('message from ' + sender.address + ':' + sender.port);
});

// 'proxyMsg' is emitted when the bound socket gets a message and it's send back to the peer the socket was bound to
server.on('proxyMsg', function (message, sender) {
	console.log('answer from ' + sender.address + ':' + sender.port);
});

// 'proxyClose' is emitted when the socket times out without new messages
server.on('proxyClose', function (details) {
	console.log('disconnecting socket from ' + details.peer.address);
});

server.on('proxyError', function (err) {
	console.log('ProxyError! ' + err);
});

server.on('error', function (err) {
	console.log('Error! ' + err);
});

Methods

var proxy = require('udp-proxy');

  • requires the proxy-module

var server = proxy.createServer(options);

  • .createServer(options) creates an instance of udp-proxy with the given options
    • options must be an object consisting of:
      • address: string (the address you want to proxy to)
        • default: 'localhost'
      • port: number (the port you want to proxy to)
        • default: 41234
      • ipv6: boolean (if the target uses IPv6)
        • default: false
      • localaddress: string (the interface-addresses to use for the server)
        • default: '0.0.0.0' (::0 if localipv6 is set to true)
      • localport: number (the port for the server to listen on)
        • default: 0 (random)
      • localipv6: boolean (if you want the server to use IPv6)
        • default: false
      • proxyaddress: string (if you want to set on which interface the proxy connects out)
        • default: 0.0.0.0 (::0 if ipv6 is set to true)
      • timeOutTime: number the time it takes for socket to time out (in ms)
        • default: 10000 (10s)

the proxy always connects outwards with a random port

Events

server.on('event', function (args) { });

  • 'listening', details
    • details is an object with two objects:
      • target address
      • server address
  • 'bound', details
    • details is an object with two objects:
      • route address
      • peer address
  • 'message', message, sender
    • message is the payload from user using the proxy
    • sender is the user address
  • 'proxyMsg', message, sender
    • message is the answer to the message from the user
    • sender is the answerer address
  • 'error', err
    • in case of an error err has the error-messages
  • 'proxyError', err
    • if the message could not be proxied err has the error-messages
  • 'proxyClose', details
    • when a socket is closed after no new messages in set timeout
  • 'close'
    • self-explanatory

address object contains:

  • address: string ip-address
  • family: string IPv6 or IPv4
  • port: number udp-port

Tests

Run node test to run the tests.

License

MIT

node-udp-proxy's People

Contributors

gildean avatar

Watchers

 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.