<commit_before>var EventEmitter = require('events').EventEmitter;
var net = require('net');
var Tracker = require('./Tracker');

var Server = new EventEmitter;

/**
 * Constructor
 * @param {options} options
 */
Server = function (opts) {
  this.config = {
    timeout: 120    // in s
  };
  
  if( typeof opts === 'object') {
    for (var key in opts) {
      if (typeof this.config[key] !== 'undefined') {
        this.config[key] = opts[key];
      }
    }
  }
  
  this.trackers = [];
  
  var server = this;
  this.tcpServers = [];
  
  /* Start servers for protocols */
  
  /* Incutex TK104 */
  this.tcpServers[Tracker.TK104.protocol] = net.CreateServer( function(connection) {
    var tracker = new Tracker(Tracker.TK104.protocol, connection, {timeout: server.config.timeout});
    
    tracker.on('connect', function(imei) { server.emit('connect', imei, tracker); });
    
    tracker.on('message', function(message) { server.emit('message', message, tracker); });
    tracker.on('position', function(pos) { server.emit('position', pos, tracker); });
    
    tracker.on('packet.in', function(packet) { server.emit('packet.in', packet, tracker); });
    tracker.on('packet.out', function(packet) { server.emit('packet.out', packet, tracker); });
    
    tracker.on('error', function(err, data) { server.emit('error', err, data); });
    
    tracker.on('timeout', function() { server.emit('timeout', tracker); });
    tracker.on('disconnect', function() {
        for (var i in server.trackers) {
            if (server.trackers[i] == tracker) {
                server.emit('disconnect', tracker);
                delete server.trackers[i];
              }
          }
    });
      
    server.trackers.push(tracker);
    
  }).listen(Tracker.TK104.port, function() {  server.emit('listen', Tracker.TK104.protocol, Tracker.TK104.port); });
  
  /* Konga KT90 */
  this.tcpServers[Tracker.KT90.protocol] = net.CreateServer( function(connection) {
    var tracker = new Tracker(Tracker.KT90.protocol, connection, {timeout: server.config.timeout});
    
    tracker.on('connect', function(imei) { server.emit('connect', imei, tracker); });
    
    tracker.on('message', function(message){ server.emit('message', message, tracker); });
    tracker.on('position', function(pos) { server.emit('position', pos, tracker); });
    
    tracker.on('packet.in', function(packet){ server.emit('packet.in', packet, tracker); });
    tracker.on('packet.out', function(packet){ server.emit('packet.out', packet, tracker); });
    
    tracker.on('error', function(err, data){ server.emit('error', err, data); });
    
    tracker.on('timeout', function() { server.emit('timeout', tracker); });
    tracker.on('disconnect', function() {
        for (var i in server.trackers) {
            if (server.trackers[i] == tracker) {
                server.emit('disconnect', tracker);
                delete server.trackers[i];
              }
          }
    });
      
    server.trackers.push(tracker);
    
  }).listen(Tracker.KT90.port, function() {  server.emit('listen', Tracker.KT90.protocol, Tracker.KT90.port); });
  
  return this;
}

module.exports = Server;<commit_msg>First release<commit_after>"use strict";

var EventEmitter = require('events').EventEmitter,
	Util = require('util'),
	net = require('net');

var Tracker = require('./Tracker').Tracker;
var ProtocolConfig = require('./Tracker').ProtocolConfig;

var Config = require('./Message').Config;

/**
 * Constructor
 * @param {options} options
 */
function Server(opts) {
  
  this.config = new Config( opts );
    
  this.trackers = [];
  this.tcpServers = [];

  var _this = this;
    
  /* Start servers for protocols */
  for (var key in ProtocolConfig) {
	(function(key) {		// to initialize by value, not by reference
		_this.tcpServers[key] = net.createServer( function(connection) {
			var tracker = new Tracker(key, connection, _this.config);

			tracker.on('connect', function(imei) 	{ _this.emit('connect', imei, tracker); });
			
			tracker.on('message', function(message) { _this.emit('message', message, tracker); });
			tracker.on('position', function(pos) 	{ _this.emit('position', pos, tracker); });
			
			tracker.on('packet.in', function(packet) { _this.emit('packet.in', packet, tracker); });
			tracker.on('packet.out', function(packet) { _this.emit('packet.out', packet, tracker); });
			
			tracker.on('error', function(err, data) { _this.emit('error', err, data); });
			
			tracker.on('timeout', function() 		{ _this.emit('timeout', tracker); });
			tracker.on('disconnect', function() 	{
				for (var i in _this.trackers) {
					if (_this.trackers[i] == tracker) {
						_this.emit('disconnect', tracker);
						delete _this.trackers[i];
					  }
				  }
			});
			  
			_this.trackers.push(tracker);
			
		  }).listen( ProtocolConfig[key].port, function() {
				_this.emit('listen', ProtocolConfig[key].name, this.address().port);
		  });
    })(key);
  } // for all protocols
    
  return this;
}

Util.inherits(Server, EventEmitter);
module.exports = Server;
{'fraction_non_alphanumeric': 0.1781825381112651, 'fraction_numerical': 0.006533359730746387, 'mean_word_length': 3.2849872773536894, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3458856', 'n_tokens_mistral': 1704, 'n_tokens_neox': 1564, 'n_words': 312}