use of com.frostwire.bittorrent.BTEngine in project frostwire by frostwire.
the class TransfersFragment method onCheckDHT.
private void onCheckDHT() {
if (textDHTPeers == null || !TransfersFragment.this.isAdded() || BTEngine.ctx == null) {
return;
}
textDHTPeers.setVisibility(View.VISIBLE);
showTorrentSettingsOnClick = true;
// No Internet
if (!NetworkManager.instance().isDataUp()) {
textDHTPeers.setText(R.string.check_internet_connection);
return;
}
// Saving Data on Mobile
if (TransferManager.instance().isMobileAndDataSavingsOn()) {
textDHTPeers.setText(R.string.bittorrent_off_data_saver_on);
return;
}
// BitTorrent Turned off
if (Engine.instance().isStopped() || Engine.instance().isDisconnected()) {
// takes you to main settings screen so you can turn it back on.
showTorrentSettingsOnClick = false;
textDHTPeers.setText(R.string.bittorrent_off);
return;
}
BTEngine btEngine = BTEngine.getInstance();
boolean dhtEnabled = btEngine.isDhtRunning();
long dhtPeers = btEngine.stats().dhtNodes();
// No DHT
if (!dhtEnabled) {
textDHTPeers.setVisibility(View.INVISIBLE);
return;
}
// DHT On.
textDHTPeers.setText(dhtPeers + " " + TransfersFragment.this.getString(R.string.dht_contacts));
}
use of com.frostwire.bittorrent.BTEngine in project frostwire by frostwire.
the class TorrentPreferenceFragment method setupTorrentOptions.
private void setupTorrentOptions() {
SwitchPreferenceCompat pref = findPreference(Constants.PREF_KEY_NETWORK_ENABLE_DHT);
pref.setOnPreferenceChangeListener((preference, newValue) -> {
boolean newStatus = (boolean) newValue;
if (newStatus) {
BTEngine.getInstance().startDht();
} else {
BTEngine.getInstance().stopDht();
}
return true;
});
final BTEngine e = BTEngine.getInstance();
setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_DOWNLOAD_SPEED, e);
setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_UPLOAD_SPEED, e);
setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_DOWNLOADS, e);
setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_UPLOADS, e);
setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_TOTAL_CONNECTIONS, e);
setupFWSeekbarPreference(Constants.PREF_KEY_TORRENT_MAX_PEERS, e);
}
use of com.frostwire.bittorrent.BTEngine in project frostwire by frostwire.
the class TransferManager method loadTorrentsTask.
private void loadTorrentsTask() {
bittorrentDownloadsList.clear();
bittorrentDownloadsMap.clear();
final BTEngine btEngine = BTEngine.getInstance();
btEngine.setListener(new BTEngineAdapter() {
@Override
public void downloadAdded(BTEngine engine, BTDownload dl) {
String name = dl.getName();
if (name != null && name.contains("fetch_magnet")) {
return;
}
File savePath = dl.getSavePath();
if (savePath != null && savePath.toString().contains("fetch_magnet")) {
return;
}
UIBittorrentDownload uiBittorrentDownload = new UIBittorrentDownload(TransferManager.this, dl);
bittorrentDownloadsList.add(uiBittorrentDownload);
bittorrentDownloadsMap.put(dl.getInfoHash(), uiBittorrentDownload);
}
@Override
public void downloadUpdate(BTEngine engine, BTDownload dl) {
try {
BittorrentDownload bittorrentDownload = bittorrentDownloadsMap.get(dl.getInfoHash());
if (bittorrentDownload instanceof UIBittorrentDownload) {
UIBittorrentDownload bt = (UIBittorrentDownload) bittorrentDownload;
bt.updateUI(dl);
}
} catch (Throwable e) {
LOG.error("Error updating bittorrent download", e);
}
}
});
btEngine.restoreDownloads();
}
use of com.frostwire.bittorrent.BTEngine 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());
}
use of com.frostwire.bittorrent.BTEngine in project frostwire by frostwire.
the class TorrentConnectionPaneItem method applyOptions.
@Override
public boolean applyOptions() throws IOException {
BTEngine btEngine = BTEngine.getInstance();
applyDHTOptions(btEngine);
applyVPNDropProtectionOption(btEngine);
btEngine.maxConnections(MAX_GLOBAL_NUM_CONNECTIONS_FIELD.getValue());
btEngine.maxPeers(MAX_PEERS_FIELD.getValue());
btEngine.maxActiveDownloads(MAX_ACTIVE_DOWNLOADS_FIELD.getValue());
btEngine.maxActiveSeeds(MAX_ACTIVE_SEEDS_FIELD.getValue());
return false;
}
Aggregations