Search in sources :

Example 1 with BTContext

use of com.frostwire.bittorrent.BTContext in project frostwire by frostwire.

the class Initializer method startBittorrentCore.

private void startBittorrentCore() {
    SharingSettings.initTorrentDataDirSetting();
    SharingSettings.initTorrentsDirSetting();
    File homeDir = new File(CommonUtils.getUserSettingsDir() + File.separator + "libtorrent" + File.separator);
    if (!homeDir.exists()) {
        homeDir.mkdirs();
    }
    // port range [37000, 57000]
    int port0 = 37000 + new Random().nextInt(20000);
    // 10 retries
    int port1 = port0 + 10;
    if (ConnectionSettings.MANUAL_PORT_RANGE.getValue()) {
        port0 = ConnectionSettings.PORT_RANGE_0.getValue();
        port1 = ConnectionSettings.PORT_RANGE_1.getValue();
    }
    String iface = "0.0.0.0";
    if (ConnectionSettings.CUSTOM_NETWORK_INTERFACE.getValue()) {
        iface = ConnectionSettings.CUSTOM_INETADRESS.getValue();
    }
    if (iface.equals("0.0.0.0")) {
        iface = "0.0.0.0:%1$d,[::]:%1$d";
    } else {
        // quick IPv6 test
        if (iface.contains(":")) {
            iface = "[" + iface + "]";
        }
        iface = iface + ":%1$d";
    }
    String if_string = String.format(iface, port0);
    BTContext ctx = new BTContext();
    ctx.homeDir = homeDir;
    ctx.torrentsDir = SharingSettings.TORRENTS_DIR_SETTING.getValue();
    ctx.dataDir = SharingSettings.TORRENT_DATA_DIR_SETTING.getValue();
    ctx.interfaces = if_string;
    ctx.retries = port1 - port0;
    ctx.enableDht = SharingSettings.ENABLE_DISTRIBUTED_HASH_TABLE.getValue();
    BTEngine.ctx = ctx;
    BTEngine.onCtxSetupComplete();
    BTEngine btEngine = BTEngine.getInstance();
    btEngine.start();
    VPNStatusRefresher.getInstance().addRefreshListener(new VPNDropGuard());
}
Also used : BTEngine(com.frostwire.bittorrent.BTEngine) Random(java.util.Random) BTContext(com.frostwire.bittorrent.BTContext) File(java.io.File)

Aggregations

BTContext (com.frostwire.bittorrent.BTContext)1 BTEngine (com.frostwire.bittorrent.BTEngine)1 File (java.io.File)1 Random (java.util.Random)1