var that = this;
+ var default_user_id = 'kiwi',
+ default_system_id = 'UNIX-KiwiIRC';
+
// Option defaults
opts = opts || {};
opts.bind_addr = opts.bind_addr || '0.0.0.0';
opts.bind_port = opts.bind_port || 113;
- opts.system_id = opts.system_id || 'UNIX-KiwiIRC';
- opts.user_id = opts.user_id || 'kiwi';
+ opts.system_id = opts.system_id || default_system_id;
+ opts.user_id = opts.user_id || default_user_id;
var server = net.createServer(function(socket) {
buffer += data.toString();
- // Wait until we have a full line of data before processing it
- if (buffer.indexOf('\n') === -1)
- return;
+ // If we exceeed 512 bytes, presume a flood and disconnect
+ if (buffer.length < 512) {
+
+ // Wait until we have a full line of data before processing it
+ if (buffer.indexOf('\n') === -1)
+ return;
+
+ // Get the first line of data and process it for a rsponse
+ data_line = buffer.split('\n')[0];
+ response = that.processLine(data_line);
- // Get the first line of data and process it for a rsponse
- data_line = buffer.split('\n')[0];
- response = that.processLine(data_line);
+ }
// Close down the socket while sending the response
socket.removeAllListeners();
return;
if (typeof opts.user_id === 'function') {
- user = opts.user_id(port_here, port_there).toString();
+ user = opts.user_id(port_here, port_there).toString() || default_user_id;
} else {
user = opts.user_id.toString();
}
if (typeof opts.system_id === 'function') {
system = opts.system_id(port_here, port_there).toString();
} else {
- system = opts.system_id.toString();
+ system = opts.system_id.toString() || default_system_id
}
return port_here.toString() + ' , ' + port_there.toString() + ' : USERID : ' + system + ' : ' + user;
// Apply the socket listeners
that.socket.on(socket_connect_event_name, function () {
that.connected = true;
+
+ // Make note of the port numbers for any identd lookups
+ // Nodejs < 0.9.6 has no socket.localPort so check this first
+ if (this.localPort) {
+ global.clients.port_pairs[this.localPort.toString() + '_' + this.remotePort.toString()] = that;
+ }
+
socketConnectHandler.call(that);
});
that.socket.on('close', function (had_error) {
that.connected = false;
+
+ // Remove this socket form the identd lookup
+ // Nodejs < 0.9.6 has no socket.localPort so check this first
+ if (this.localPort) {
+ delete global.clients.port_pairs[this.localPort.toString() + '_' + this.remotePort.toString()];
+ }
+
that.emit('close');
// Close the whole socket down
clients: Object.create(null),
addresses: Object.create(null),
+ // Local and foriegn port pairs for identd lookups
+ // {'65483_6667': client_obj, '54356_6697': client_obj}
+ port_pairs: {},
+
add: function (client) {
this.clients[client.hash] = client;
if (typeof this.addresses[client.real_address] === 'undefined') {
* Identd server
*/
if (global.config.identd && global.config.identd.enabled) {
- new Identd({
+ var identd_resolve_user = function(port_here, port_there) {
+ var key = port_here.toString() + '_' + port_there.toString();
+
+ if (typeof global.clients.port_pairs[key] == 'undefined') {
+ return;
+ }
+
+ return global.clients.port_pairs[key].username;
+ };
+
+ var identd_server = new Identd({
bind_addr: global.config.identd.address,
- bind_port: global.config.identd.port
- }).start();
+ bind_port: global.config.identd.port,
+ user_id: identd_resolve_user
+ });
+
+ identd_server.start();
}