udp-director
v0.1.2
Published
A tool that is capable of directing UDP traffic from a specific port to as many hosts as needed.
Downloads
7
Maintainers
Readme
udp-director
A tool that is capable of redirecting UDP traffic from a specific port to as many hosts as needed.
What is udp-director?
udp-director was born with the idea that it might be necessary to replicate UDP traffic to multiple different potential hosts on systems like kubernetes where ingress controllers can help route things automagically. The concept is simple: udp-director can listen on a port and play the "middle man" for all UDP traffic.
How can I use udp-director?
You can use it as a command line tool to do the grunt work for you without writing a single line of code OR you can use this as a regular node package if you're trying to achieve something a little more custom.
CLI Tool
Installation
To use udp-director as a command line tool, perform the following command on a machine that has node
and npm
installed on it:
npm install udp-director -g
.
After doing so, you can browse the cli tool help by performing udp-director --help
.
General Usage
There are 2 ways you can start directing your UDP traffic via the CLI tool: (1) by specifying the configuration directly with the command or (2) loading a configuration via a JSON file.
Load a configuration
To specify the configuration directly, you could use something like:
udp-director -c ~/my-director-config.json
This will tell udp-director to look for a configuration file called my-director-config.json
in your user's home directory.
For an example of the JSON structure you can use in this file, check out the example configuration.
Direct configuration
To load a configuration directly into the command line tool, you can run something like this:
udp-director 1337=192.168.1.1:20000,192.168.1.2:20000
The command above will instruct udp-director to listen for traffic on port 1337 and direct it to both "receivers" at 192.168.1.1 and 192.168.1.2 on port 20000.
Here's another example that involves a few ports to listen on:
udp-director 1337=192.168.1.1 2000=192.168.1.2:9000,192.168.1.3:9001
The command above sets up 2 directors: (1) listens at port 1337 for incoming traffic and sends it to 192.168.1.1 on port 80 (since no port was specified, 80 is the default) and (2) listens for incoming traffic on port 2000 and directs it to both "receivers" at 192.168.1.2 (port 9000) and 192.168.1.3 (port 9001).
Node.js Package
Installation
To include udp-director in your node.js application, run the following command:
npm install udp-director --save
General Usage
To use this package in your node.js application, you can do something like this:
// external dependencies
const Director = require('udp-director');
// setup some variables to make life easier
const portToListenOn = 1337;
const myArrayOfReceivers = [
{
host: '192.168.1.1',
port: 20000
}, {
host: '192.168.1.2',
port: 20000
}
];
// start directing UDP traffic
var myDirector = new Director(portToListenOn, myArrayOfReceivers);
The code above will setup a director on port 1337 to send traffic to both receivers at 192.168.1.1 and 192.168.1.2 on port 20000.
Easy enough, right?
Director Settings
You can pass custom settings to a director by performing something like:
var myDirector = new Director(portToListenOn, myArrayOfReceivers, mySettings);
Currently, the only custom settings supported by directors are:
noActivityTimeLimit
- If a UDP client hasn't set any packets to the server in this amount of time, the director will remove the client from cache and directing traffic to/from it. The current default for this setting is30000
.
API
Currently, the only public API method(s) that are available on a Director object are:
director.destroy()
- Destroy the director by removing the UDP server and all UDP clients setup for each receiver.
Docker
If you'd like to run udp-director inside a docker container, checkout the official Docker Hub repository.
License
The MIT License (MIT)
Copyright (c) 2016-2017 Carl Danley
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.