jselbie/stunserver — pull request #13 by formula1 (2014-12-16 10:48:17+00:00)
Title: New operator

Able to start new servers with the new operator. I could probably at this point make it so that there is a TCP and UDP server. However, looking forward I found 2 major obstacles that I am not confident I can script kitty my way through.

* [libuv](https://github.com/libuv/libuv) - This is the main loop that runs in node. It is not necessary to participate in it but I am left to wonder if what I'm doing is creating a c++ wrapper to interface with nodejs. Granted, yes however I'm not sure if that is the best method. That being said, I'll see about just incorperating a `uv_run` to ensure the stun server stays alive.
* [Asyncronous Auth Check](https://github.com/formula1/stunserver/blob/master/stuncore/messagehandler.cpp#L131) - Nodejs prodominately works off of an asyncronous flow. Usually resulting in callback in callback in callback or heavilly relient on event emitters, however it also has some useful utilities like [async](https://github.com/caolan/async) and [promises](https://github.com/jakearchibald/es6-promise) which makes it bearable. That being said, because the authorization checks are syncronous, it is not as simple to integrate with it.

Here are some common databases available in node
* CouchDB - https://www.npmjs.com/package/node-couchdb
* MongoDB - https://github.com/learnboost/mongoose
* MySql - https://github.com/brianc/node-sql (though it is available, kind of taboo)

Most filesystem calls are also expected to be async - http://nodejs.org/api/fs.html

If I were to work with the server in php, this wouldn't be an issue as in php I wouldn't care how long it took. However, I node

As a result there becomes a few options

* Make the auth function poll for a response from node - There would be a mapping between the request and the hopeful response. This however will cause a block from within the server
* Make the auth function ayncronous - This is what I was going to try and do and it doesn't seem like its completely undoable as the [main failure to worry about](https://github.com/formula1/stunserver/blob/master/server/stunsocketthread.cpp#L369) seems to only have a small amount of methods afterwards. In addition, the return value isn't used so it doesn't technically matter
* Move completely towards libuv however continue to parse the data in the same manner - [the message handler](https://github.com/formula1/stunserver/blob/master/stuncore/messagehandler.cpp) would have to start becoming more independent, the config file using uv addresses, getting rid of the threading. There would be many many changes for which I had no more desire to count.

However, long story short, I would have to start editing the base. Whether its small or large