<commit_before>var http = require("http"),
	faye = require("faye"),
	authenticator = require("./authenticator");

// log all warnings
console.log("gigger server start");
faye.Logging.logLevel = 'warn';
faye.logger = function(msg) {
	console.log('logged: ' + msg);
}

// create new faye node
var bayeux = new faye.NodeAdapter({
		mount: "/faye",
		timeout: 45
	});
	
var serverAuth = {
	incoming: function(message, callback) {
		console.log("message: " + message.channel);
		var closure = function(authenticated, cause) {
			if (!authenticated) {
				cause = cause || 'no reason specified';
				console.log('not authenticated: ' + cause);
				message.error = 'Not authenticated: ' + cause;
			}
			callback(message);
		};
		
		// TODO: publish to /dispatch and subscribe to /eventRequest/* and /dispatchRequest needs auth
		
		if (message.channel === '/meta/subscribe') {
			// authenticate subscriptions to '/eventRequest/...'
			var subscription = message.subscription;
			
			if (typeof(subscription) === 'string')
				subscription = [subscription];
			
			var authNeeded = false;
			for (var i in subscription) {
				if (subscription[i].substr(0, 13) === '/eventRequest' ||
					subscription[i].substr(0, 16) === '/dispatchRequest') {
					authNeeded = true;
				}
			}
			
			if (authNeeded) {
				console.log("authentication requested on " + message.subscription)
				var authObject = message.ext && message.ext.auth;
				authenticator.authenticate(authObject, closure);
			} else {<commit_msg>removed old todo comment<commit_after>var http = require("http"),
	faye = require("faye"),
	authenticator = require("./authenticator");

// log all warnings
console.log("gigger server start");
faye.Logging.logLevel = 'warn';
faye.logger = function(msg) {
	console.log('logged: ' + msg);
}

// create new faye node
var bayeux = new faye.NodeAdapter({
		mount: "/faye",
		timeout: 45
	});
	
var serverAuth = {
	incoming: function(message, callback) {
		console.log("message: " + message.channel);
		var closure = function(authenticated, cause) {
			if (!authenticated) {
				cause = cause || 'no reason specified';
				console.log('not authenticated: ' + cause);
				message.error = 'Not authenticated: ' + cause;
			}
			callback(message);
		};
		
		if (message.channel === '/meta/subscribe') {
			// authenticate subscriptions to '/eventRequest/...'
			var subscription = message.subscription;
			
			if (typeof(subscription) === 'string')
				subscription = [subscription];
			
			var authNeeded = false;
			for (var i in subscription) {
				if (subscription[i].substr(0, 13) === '/eventRequest' ||
					subscription[i].substr(0, 16) === '/dispatchRequest') {
					authNeeded = true;
				}
			}
			
			if (authNeeded) {
				console.log("authentication requested on " + message.subscription)
				var authObject = message.ext && message.ext.auth;
				authenticator.authenticate(authObject, closure);
			} else {
{'fraction_non_alphanumeric': 0.1512547267102097, 'fraction_numerical': 0.005500171880371262, 'mean_word_length': 3.546875, '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': '182727', 'n_tokens_mistral': 1059, 'n_tokens_neox': 884, 'n_words': 219}