Browse Source

Update trackers

pull/407/head
Alon Albert 7 years ago
parent
commit
e165d7cb46
  1. 36
      app/src/main/java/org/transdroid/daemon/Deluge/DelugeDirectAdapter.java

36
app/src/main/java/org/transdroid/daemon/Deluge/DelugeDirectAdapter.java

@ -75,6 +75,7 @@ import org.transdroid.daemon.task.RetrieveTask;
import org.transdroid.daemon.task.RetrieveTaskSuccessResult; import org.transdroid.daemon.task.RetrieveTaskSuccessResult;
import org.transdroid.daemon.task.SetFilePriorityTask; import org.transdroid.daemon.task.SetFilePriorityTask;
import org.transdroid.daemon.task.SetLabelTask; import org.transdroid.daemon.task.SetLabelTask;
import org.transdroid.daemon.task.SetTrackersTask;
import org.transdroid.daemon.task.SetTransferRatesTask; import org.transdroid.daemon.task.SetTransferRatesTask;
import se.dimovski.rencode.Rencode; import se.dimovski.rencode.Rencode;
@ -138,6 +139,7 @@ public class DelugeDirectAdapter implements IDaemonAdapter {
private static final String RPC_PATH = "path"; private static final String RPC_PATH = "path";
private static final String RPC_SIZE = "size"; private static final String RPC_SIZE = "size";
private static final String RPC_TRACKER_TIER = "tier";
private static final String RPC_TRACKER_URL = "url"; private static final String RPC_TRACKER_URL = "url";
private static final String RPC_MAX_DOWNLOAD = "max_download_speed"; private static final String RPC_MAX_DOWNLOAD = "max_download_speed";
@ -218,7 +220,7 @@ public class DelugeDirectAdapter implements IDaemonAdapter {
case GetTorrentDetails: case GetTorrentDetails:
return doGetTorrentDetails((GetTorrentDetailsTask) task); return doGetTorrentDetails((GetTorrentDetailsTask) task);
case SetTrackers: case SetTrackers:
return notSupported(task); return doSetTrackers((SetTrackersTask) task);
case SetAlternativeMode: case SetAlternativeMode:
return notSupported(task); return notSupported(task);
case GetStats: case GetStats:
@ -278,8 +280,7 @@ public class DelugeDirectAdapter implements IDaemonAdapter {
} }
private DaemonTaskResult doControl(DaemonTask task, String method) throws DaemonException { private DaemonTaskResult doControl(DaemonTask task, String method) throws DaemonException {
final Object torrentIds = new String[]{task.getTargetTorrent().getUniqueID()}; sendRequest(method, (Object) getTorrentIdsArg(task));
sendRequest(method, torrentIds);
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
} }
@ -328,8 +329,7 @@ public class DelugeDirectAdapter implements IDaemonAdapter {
// We first need a listing of all the files (because we can only set the priorities all at once) // We first need a listing of all the files (because we can only set the priorities all at once)
final ArrayList<TorrentFile> files = getTorrentFiles(task.getTargetTorrent()); final ArrayList<TorrentFile> files = getTorrentFiles(task.getTargetTorrent());
// prepare args // prepare options arg
final String[] torrentIds = {task.getTargetTorrent().getUniqueID()};
final Map<String, Object> optionsArgs = new HashMap<>(); final Map<String, Object> optionsArgs = new HashMap<>();
// Build a fast access set of file to change // Build a fast access set of file to change
@ -347,10 +347,11 @@ public class DelugeDirectAdapter implements IDaemonAdapter {
} }
optionsArgs.put(RPC_FILE_PRIORITIES, priorities); optionsArgs.put(RPC_FILE_PRIORITIES, priorities);
sendRequest(RPC_METHOD_SET_TORRENT_OPTIONS, torrentIds, optionsArgs); sendRequest(RPC_METHOD_SET_TORRENT_OPTIONS, getTorrentIdsArg(task), optionsArgs);
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
} }
@NonNull
private DaemonTaskResult doSetTransferRates(SetTransferRatesTask task) throws DaemonException { private DaemonTaskResult doSetTransferRates(SetTransferRatesTask task) throws DaemonException {
final Map<String, Object> config = new HashMap<>(); final Map<String, Object> config = new HashMap<>();
config.put(RPC_MAX_DOWNLOAD, task.getDownloadRate() == null ? -1 : task.getDownloadRate()); config.put(RPC_MAX_DOWNLOAD, task.getDownloadRate() == null ? -1 : task.getDownloadRate());
@ -359,6 +360,20 @@ public class DelugeDirectAdapter implements IDaemonAdapter {
return new DaemonTaskSuccessResult(task); return new DaemonTaskSuccessResult(task);
} }
@NonNull
private DaemonTaskResult doSetTrackers(SetTrackersTask task) throws DaemonException {
final List<Map<String, Object>> trackers = new ArrayList<>();
final ArrayList<String> newTrackers = task.getNewTrackers();
for (int i = 0, n = newTrackers.size(); i < n; i++) {
final Map<String, Object> tracker = new HashMap<>();
tracker.put(RPC_TRACKER_TIER, i);
tracker.put(RPC_TRACKER_URL, newTrackers.get(i));
trackers.add(tracker);
}
sendRequest(RPC_METHOD_SETTRACKERS, task.getTargetTorrent().getUniqueID(), trackers);
return new DaemonTaskSuccessResult(task);
}
@NonNull @NonNull
private List<Torrent> getTorrents() throws DaemonException { private List<Torrent> getTorrents() throws DaemonException {
final Map response = (Map) sendRequest( final Map response = (Map) sendRequest(
@ -719,18 +734,19 @@ public class DelugeDirectAdapter implements IDaemonAdapter {
return (int) o; return (int) o;
} }
private static class MutableInt { @NonNull
private String[] getTorrentIdsArg(DaemonTask task) {
return new String[]{task.getTargetTorrent().getUniqueID()};
}
private static class MutableInt {
int value = 1; int value = 1;
MutableInt(int value) { MutableInt(int value) {
this.value = value; this.value = value;
} }
void increment() { void increment() {
++value; ++value;
} }
int get() { int get() {
return value; return value;
} }

Loading…
Cancel
Save