drachtio is an open-source, nodejs-based ecosystem for creating any kind of VoIP server-based application: registrar, proxy, back-to-back user agent, and many others. Furthermore, when coupled with the drachtio media resource function, rich media-processing applications can be easily built as well. Nodejs developers experienced with the express or connect middleware frameworks will find drachtio very familiar.
Note: API documentation on the key application classes can be found here
The prerequisites: you will need to install a drachtio SIP server somewhere in your network to handle the SIP message processing.
$ git clone email@example.com:davehorton/drachtio-fs-load-balancing-proxy.git$ cd fs-load-balancing-proxy$ npm install
config.js, and edit to specify the coordinates of your freeswitch servers, as well as your drachtio server process.
Then fire it up!
$ node app.js
The proxy can optionally examine the SIP headers on incoming messages and based on regex patterns, add the source address to an iptables chain. The most useful configuration is to have a specific iptables chain set up for this, e.g 'LOGDROP', and include it from the input chain. Any requests that match the specified patterns will result in the sending address being added to that chain with a DROP action. Review lib/blacklist-regex.json.example and copy it to lib/blacklist-regex.json, edit as needed.
You can also optionally enforce a specific domain on requests, and blacklist any senders that generate requests for different domains.
Contributors are welcome! Feel free to fork the repo and send me pull requests for any features or bug fixes.
The code is pretty simple, and there isn't that much of it. Here are a few notes to get you started:
app.js - the main entry point to the application is dead simple. It creates the necessary instances of the drachtio app and srf (signaling resource framework), connects to the drachtio server and the loads in the routes, which are found in
lib/proxy.js - this has the invite handler and executes the key line of code that actually makes everything happen:
req.proxy(..). It relies on
lib/cluster.js to provide the list of online freeswitch servers to proxy to, so this file is actually pretty simple as well.
lib/cluster.js - this module manages the freeswitch servers; its main responsibility is simply to keep track of which freeswitch servers are online at any point in time. It also watches for changes to the
lib/config.js file and automatically updates the list of freeswitch servers as any entries are added or removed from the config file -- there is no need to restart anything for changes to take affect.
lib/fsw.js - this modules manages the connection to an indvidual freeswitch server. It connects and receives heartbeat messages from the freeswitch server each 20 seconds. Any time the connection is lost it will automatically begin retrying to connect.
lib/config.js - this is the configuration file. You'll need to copy config.example.js to config.js to start with, then edit to your desires. The file itself is documented so it won't be further described here.