<commit_before>package satori.session;

import java.net.Socket;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

import satori.common.SView;
import satori.config.SConfig;
import satori.task.STask;
import satori.task.STaskException;
import satori.task.STaskManager;
import satori.thrift.gen.User;

public class SSession {
	private final String host = SConfig.getHost();
	private final int thrift_port = SConfig.getThriftPort();
	private final int blobs_port = SConfig.getBlobsPort();
	private final boolean use_ssl = SConfig.getUseSSL();
	private String username = null;
	private String password = null;
	private String token = "";
	private TTransport transport = null;
	private TProtocol protocol = null;
	
	public String getHost() { return host; }
	public int getBlobsPort() { return blobs_port; }
	public boolean getUseSSL() { return use_ssl; }
	public String getUsername() { return username; }
	public String getPassword() { return password; }
	
	private Socket createUnsecureSocket() throws Exception {
		return new Socket(host, thrift_port);
	}
	private Socket createSecureSocket() throws Exception {
		SSLContext context = SSLContext.getInstance("TLSv1");
		context.init(null, new TrustManager[] { new X509TrustManager() {
			@Override public X509Certificate[] getAcceptedIssuers() { return null; }
			@Override public void checkClientTrusted(X509Certificate[] certs, String authType) {}
			@Override public void checkServerTrusted(X509Certificate[] certs, String authType) {}
		} }, new SecureRandom());
		SSLSocketFactory socket_factory = context.getSocketFactory();
		SSLSocket socket = (SSLSocket)socket_factory.createSocket(host, thrift_port);
		socket.setEnabledProtocols(new String[] { "TLSv1" });
		return socket;
	}
	private void createProtocol() throws Exception {
		Socket socket = use_ssl ? createSecureSocket() : createUnsecureSocket();
		transport = new TFramedTransport(new TSocket(socket));
		protocol = new TBinaryProtocol(transport);
	}
	private void closeProtocol() { transport.close(); }
	
	private static volatile SSession instance = null;
	private static final List<SView> views = new ArrayList<SView>();
	
	private static class LoginTask implements STask {
		private final String username, password;
		public LoginTask(String username, String password) {
			this.username = username;
			this.password = password;
		}
		@Override public void run() throws Exception {
			SSession session = new SSession();
			STaskManager.log("Connecting to server...");
			session.createProtocol();
			STaskManager.log("Logging in to server...");
			User.Iface iface = new User.Client(session.protocol);
			session.token = iface.User_authenticate("", username, password);
			session.username = username;
			session.password = password;
			instance = session;
		}
	}
	private static class AnonymousLoginTask implements STask {
		@Override public void run() throws Exception {
			SSession session = new SSession();
			STaskManager.log("Connecting to server...");
			session.createProtocol();
			instance = session;
		}
	}
	
	public static void login(String username, String password) throws STaskException {
		if (instance != null) instance.closeProtocol();
		try { STaskManager.execute(new LoginTask(username, password)); }
		finally { updateViews(); }
	}
	public static void anonymousLogin() throws STaskException {
		if (instance != null) instance.closeProtocol();
		try { STaskManager.execute(new AnonymousLoginTask()); }
		finally { updateViews(); }
	}
	public static void logout() throws STaskException {<commit_msg>little correction<commit_after>package satori.session;

import java.net.Socket;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;

import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;

import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.protocol.TProtocol;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TSocket;
import org.apache.thrift.transport.TTransport;

import satori.common.SView;
import satori.config.SConfig;
import satori.task.STask;
import satori.task.STaskException;
import satori.task.STaskManager;
import satori.thrift.gen.User;

public class SSession {
	private final String host = SConfig.getHost();
	private final int thrift_port = SConfig.getThriftPort();
	private final int blobs_port = SConfig.getBlobsPort();
	private final boolean use_ssl = SConfig.getUseSSL();
	private String username = null;
	private String password = null;
	private String token = "";
	private TTransport transport = null;
	private TProtocol protocol = null;
	
	public String getHost() { return host; }
	public int getBlobsPort() { return blobs_port; }
	public boolean getUseSSL() { return use_ssl; }
	public String getUsername() { return username; }
	public String getPassword() { return password; }
	
	private Socket createUnsecureSocket() throws Exception {
		return new Socket(host, thrift_port);
	}
	private Socket createSecureSocket() throws Exception {
		SSLContext context = SSLContext.getInstance("TLSv1");
		context.init(null, new TrustManager[] { new X509TrustManager() {
			@Override public X509Certificate[] getAcceptedIssuers() { return null; }
			@Override public void checkClientTrusted(X509Certificate[] certs, String authType) {}
			@Override public void checkServerTrusted(X509Certificate[] certs, String authType) {}
		} }, new SecureRandom());
		SSLSocketFactory socket_factory = context.getSocketFactory();
		SSLSocket socket = (SSLSocket)socket_factory.createSocket(host, thrift_port);
		socket.setEnabledProtocols(new String[] { "TLSv1" });
		return socket;
	}
	private void createProtocol() throws Exception {
		Socket socket = use_ssl ? createSecureSocket() : createUnsecureSocket();
		transport = new TFramedTransport(new TSocket(socket));
		protocol = new TBinaryProtocol(transport);
	}
	private void closeProtocol() { transport.close(); }
	
	private static volatile SSession instance = null;
	private static final List<SView> views = new ArrayList<SView>();
	
	private static class LoginTask implements STask {
		private final String username, password;
		public LoginTask(String username, String password) {
			this.username = username;
			this.password = password;
		}
		@Override public void run() throws Exception {
			SSession session = new SSession();
			STaskManager.log("Connecting to server...");
			session.createProtocol();
			STaskManager.log("Logging in to server...");
			User.Iface iface = new User.Client(session.protocol);
			session.token = iface.User_authenticate("", username, password);
			session.username = username;
			session.password = password;
			instance = session;
		}
	}
	private static class AnonymousLoginTask implements STask {
		@Override public void run() throws Exception {
			SSession session = new SSession();
			STaskManager.log("Connecting to server...");
			session.createProtocol();
			instance = session;
		}
	}
	
	public static void login(String username, String password) throws STaskException {
		if (instance != null) instance.closeProtocol();
		instance = null;
		try { STaskManager.execute(new LoginTask(username, password)); }
		finally { updateViews(); }
	}
	public static void anonymousLogin() throws STaskException {
		if (instance != null) instance.closeProtocol();
		instance = null;
		try { STaskManager.execute(new AnonymousLoginTask()); }
		finally { updateViews(); }
	}
	public static void logout() throws STaskException {
{'fraction_non_alphanumeric': 0.10362694300518134, 'fraction_numerical': 0.004934616333580064, 'mean_word_length': 5.236153846153846, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2267238', 'n_tokens_mistral': 2453, 'n_tokens_neox': 2297, 'n_words': 635}