<commit_before>package com.frostwire.jlibtorrent;

import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.GenericAlert;
import com.frostwire.jlibtorrent.swig.*;
import com.frostwire.jlibtorrent.swig.session.options_t;
import com.frostwire.util.SparseArray;

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * The session holds all state that spans multiple torrents. Among other
 * things it runs the network loop and manages all torrents. Once it's
 * created, the session object will spawn the main thread that will do all
 * the work. The main thread will be idle as long it doesn't have any
 * torrents to participate in.
 * <p/>
 * This class belongs to a middle logical layer of abstraction. It's a wrapper
 * of the underlying swig session object (from libtorrent), but it does not
 * expose all the raw features, not expose a very high level interface
 * like {@link com.frostwire.jlibtorrent.DHT DHT} or
 * {@link com.frostwire.jlibtorrent.Downloader Downloader}.
 *
 * @author gubatron
 * @author aldenml
 */
public final class Session {

    private static final Logger LOG = Logger.getLogger(Session.class);

    private static final long REQUEST_STATUS_RESOLUTION_MILLIS = 500;
    private static final long ALERTS_LOOP_WAIT_MILLIS = 500;

    private static final Map<Integer, CastAlertFunction> CAST_TABLE = buildCastAlertTable();

    private final session s;

    private long lastStatusRequestTime;
    private SessionStatus lastStatus;

    private final SparseArray<ArrayList<AlertListener>> listeners;
    private final SparseArray<AlertListener[]> listenerSnapshots;
    private boolean running;

    public Session(Fingerprint print, Pair<Integer, Integer> prange, String iface) {

        int flags = session.session_flags_t.start_default_features.swigValue() | session.session_flags_t.add_default_plugins.swigValue();
        int alert_mask = alert.category_t.all_categories.swigValue();

        this.s = new session(print.getSwig(), prange.to_int_int_pair(), iface, flags, alert_mask);

        this.listeners = new SparseArray<ArrayList<AlertListener>>();
        this.listenerSnapshots = new SparseArray<AlertListener[]>();
        this.running = true;

        alertsLoop();

        s.add_dht_router(new string_int_pair("router.bittorrent.com", 6881));
    }

    public Session(Fingerprint print) {
        this(print, new Pair<Integer, Integer>(0, 0), "0.0.0.0");
    }

    public Session(Pair<Integer, Integer> prange, String iface) {
        this(new Fingerprint(), prange, iface);
    }

    public Session() {
        this(new Fingerprint());
    }

    public session getSwig() {
        return s;
    }

    public void addListener(AlertListener listener) {
        modifyListeners(true, listener);
    }<commit_msg>Added another DHT bootstrap node.<commit_after>package com.frostwire.jlibtorrent;

import com.frostwire.jlibtorrent.alerts.Alert;
import com.frostwire.jlibtorrent.alerts.GenericAlert;
import com.frostwire.jlibtorrent.swig.*;
import com.frostwire.jlibtorrent.swig.session.options_t;
import com.frostwire.util.SparseArray;

import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.*;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * The session holds all state that spans multiple torrents. Among other
 * things it runs the network loop and manages all torrents. Once it's
 * created, the session object will spawn the main thread that will do all
 * the work. The main thread will be idle as long it doesn't have any
 * torrents to participate in.
 * <p/>
 * This class belongs to a middle logical layer of abstraction. It's a wrapper
 * of the underlying swig session object (from libtorrent), but it does not
 * expose all the raw features, not expose a very high level interface
 * like {@link com.frostwire.jlibtorrent.DHT DHT} or
 * {@link com.frostwire.jlibtorrent.Downloader Downloader}.
 *
 * @author gubatron
 * @author aldenml
 */
public final class Session {

    private static final Logger LOG = Logger.getLogger(Session.class);

    private static final long REQUEST_STATUS_RESOLUTION_MILLIS = 500;
    private static final long ALERTS_LOOP_WAIT_MILLIS = 500;

    private static final Map<Integer, CastAlertFunction> CAST_TABLE = buildCastAlertTable();

    private final session s;

    private long lastStatusRequestTime;
    private SessionStatus lastStatus;

    private final SparseArray<ArrayList<AlertListener>> listeners;
    private final SparseArray<AlertListener[]> listenerSnapshots;
    private boolean running;

    public Session(Fingerprint print, Pair<Integer, Integer> prange, String iface) {

        int flags = session.session_flags_t.start_default_features.swigValue() | session.session_flags_t.add_default_plugins.swigValue();
        int alert_mask = alert.category_t.all_categories.swigValue();

        this.s = new session(print.getSwig(), prange.to_int_int_pair(), iface, flags, alert_mask);

        this.listeners = new SparseArray<ArrayList<AlertListener>>();
        this.listenerSnapshots = new SparseArray<AlertListener[]>();
        this.running = true;

        alertsLoop();

        s.add_dht_router(new string_int_pair("router.bittorrent.com", 6881));
        s.add_dht_router(new string_int_pair("dht.transmissionbt.com", 6881));
    }

    public Session(Fingerprint print) {
        this(print, new Pair<Integer, Integer>(0, 0), "0.0.0.0");
    }

    public Session(Pair<Integer, Integer> prange, String iface) {
        this(new Fingerprint(), prange, iface);
    }

    public Session() {
        this(new Fingerprint());
    }

    public session getSwig() {
        return s;
    }

    public void addListener(AlertListener listener) {
        modifyListeners(true, listener);
    }
{'fraction_non_alphanumeric': 0.09335787184206124, 'fraction_numerical': 0.006023088505939435, 'mean_word_length': 3.9983277591973243, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2261932', 'n_tokens_mistral': 1828, 'n_tokens_neox': 1744, 'n_words': 499}