Browse Source

Improve logging on Deluge RPC connections without SSL configured. Closes #424.

pull/426/merge
Eric Kok 6 years ago
parent
commit
9d97fe2ec2
  1. 22
      app/src/main/java/org/transdroid/daemon/Deluge/DelugeCommon.java
  2. 19
      app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcClient.java

22
app/src/main/java/org/transdroid/daemon/Deluge/DelugeCommon.java

@ -18,18 +18,18 @@ @@ -18,18 +18,18 @@
package org.transdroid.daemon.Deluge;
import android.support.annotation.NonNull;
import org.transdroid.daemon.Priority;
import org.transdroid.daemon.TorrentStatus;
/**
* Common constants and methods used by both adapters.
*
* @author alon.albert
*/
class DelugeCommon {
static final String RPC_DETAILS = "files";
static final String RPC_DOWNLOAD_LOCATION = "download_location";
static final String RPC_DOWNLOAD_LOCATION = "download_location";
static final String RPC_DOWNLOADEDEVER = "total_done";
static final String RPC_ETA = "eta";
static final String RPC_FILE = "file";
@ -38,7 +38,7 @@ class DelugeCommon { @@ -38,7 +38,7 @@ class DelugeCommon {
static final String RPC_HASH = "hash";
static final String RPC_INDEX = "index";
static final String RPC_LABEL = "label";
static final String RPC_KEY = "key";
static final String RPC_KEY = "key";
static final String RPC_MAXDOWNLOAD = "max_download_speed";
static final String RPC_MAXUPLOAD = "max_upload_speed";
static final String RPC_MESSAGE = "message";
@ -66,9 +66,9 @@ class DelugeCommon { @@ -66,9 +66,9 @@ class DelugeCommon {
static final String RPC_METHOD_SETTRACKERS = "core.set_torrent_trackers";
static final String RPC_METHOD_SET_TORRENT_OPTIONS = "core.set_torrent_options";
static final String RPC_METHOD_STATUS = "core.get_torrent_status";
static final String RPC_METHOD_GET_RSS_CONFIG = "yarss2.get_config";
static final String RPC_MOVE_COMPLETED = "move_completed";
static final String RPC_MOVE_COMPLETED_PATH = "move_completed_path";
static final String RPC_METHOD_GET_RSS_CONFIG = "yarss2.get_config";
static final String RPC_MOVE_COMPLETED = "move_completed";
static final String RPC_MOVE_COMPLETED_PATH = "move_completed_path";
static final String RPC_NAME = "name";
static final String RPC_NUMPEERS = "num_peers";
static final String RPC_NUMSEEDS = "num_seeds";
@ -78,13 +78,13 @@ class DelugeCommon { @@ -78,13 +78,13 @@ class DelugeCommon {
static final String RPC_RATEDOWNLOAD = "download_payload_rate";
static final String RPC_RATEUPLOAD = "upload_payload_rate";
static final String RPC_RESULT = "result";
static final String RPC_RSSFEED_KEY = "rssfeed_key";
static final String RPC_RSSFEEDS = "rssfeeds";
static final String RPC_RSSFEED_KEY = "rssfeed_key";
static final String RPC_RSSFEEDS = "rssfeeds";
static final String RPC_SAVEPATH = "save_path";
static final String RPC_SESSION_ID = "_session_id";
static final String RPC_SIZE = "size";
static final String RPC_STATUS = "state";
static final String RPC_SUBSCRIPTIONS = "subscriptions";
static final String RPC_SUBSCRIPTIONS = "subscriptions";
static final String RPC_TIMEADDED = "time_added";
static final String RPC_TORRENTS = "torrents";
static final String RPC_TOTALPEERS = "total_peers";
@ -98,8 +98,8 @@ class DelugeCommon { @@ -98,8 +98,8 @@ class DelugeCommon {
static final String[] RPC_DETAILS_FIELDS_ARRAY = {RPC_TRACKERS, RPC_TRACKER_STATUS,};
static final String[] RPC_FIELDS_ARRAY = {RPC_HASH, RPC_NAME, RPC_STATUS, RPC_SAVEPATH, RPC_RATEDOWNLOAD, RPC_RATEUPLOAD, RPC_NUMPEERS,
RPC_NUMSEEDS, RPC_TOTALPEERS, RPC_TOTALSEEDS, RPC_ETA, RPC_DOWNLOADEDEVER, RPC_UPLOADEDEVER, RPC_TOTALSIZE, RPC_PARTDONE, RPC_LABEL,
RPC_MESSAGE, RPC_TIMEADDED, RPC_TRACKER_STATUS,};
RPC_NUMSEEDS, RPC_TOTALPEERS, RPC_TOTALSEEDS, RPC_ETA, RPC_DOWNLOADEDEVER, RPC_UPLOADEDEVER, RPC_TOTALSIZE, RPC_PARTDONE, RPC_LABEL,
RPC_MESSAGE, RPC_TIMEADDED, RPC_TRACKER_STATUS,};
static final String[] RPC_FILE_FIELDS_ARRAY = {RPC_DETAILS, RPC_FILEPROGRESS, RPC_FILEPRIORITIES,};
static TorrentStatus convertDelugeState(String state) {

19
app/src/main/java/org/transdroid/daemon/Deluge/DelugeRpcClient.java

@ -18,27 +18,23 @@ @@ -18,27 +18,23 @@
package org.transdroid.daemon.Deluge;
import android.support.annotation.NonNull;
import org.transdroid.daemon.DaemonException;
import org.transdroid.daemon.DaemonException.ExceptionType;
import org.transdroid.daemon.DaemonSettings;
import org.transdroid.daemon.util.TlsSniSocketFactory;
import se.dimovski.rencode.Rencode;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.HashMap;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.zip.DeflaterOutputStream;
import java.util.zip.InflaterInputStream;
import se.dimovski.rencode.Rencode;
import static org.transdroid.daemon.Deluge.DelugeCommon.RPC_METHOD_DAEMON_LOGIN;
/**
@ -59,14 +55,10 @@ class DelugeRpcClient implements Closeable { @@ -59,14 +55,10 @@ class DelugeRpcClient implements Closeable {
if (settings.shouldUseAuthentication()) {
sendRequest(RPC_METHOD_DAEMON_LOGIN, settings.getUsername(), settings.getPassword());
}
} catch (NoSuchAlgorithmException e) {
throw new DaemonException(ExceptionType.ConnectionError, "Failed to open socket: " + e.getMessage());
} catch (UnknownHostException e) {
throw new DaemonException(ExceptionType.AuthenticationFailure, "Failed to sign in: " + e.getMessage());
} catch (IOException e) {
throw new DaemonException(ExceptionType.ConnectionError, "Failed to open socket: " + e.getMessage());
} catch (KeyManagementException e) {
throw new DaemonException(ExceptionType.ConnectionError, "Failed to open socket: " + e.getMessage());
}
}
@ -148,10 +140,10 @@ class DelugeRpcClient implements Closeable { @@ -148,10 +140,10 @@ class DelugeRpcClient implements Closeable {
}
@NonNull
private Socket openSocket(DaemonSettings settings) throws NoSuchAlgorithmException, KeyManagementException, IOException {
private Socket openSocket(DaemonSettings settings) throws IOException, DaemonException {
if (!settings.getSsl()) {
// Non-ssl connections
return new Socket(settings.getAddress(), settings.getPort());
throw new DaemonException(ExceptionType.ConnectionError, "Deluge RPC Adapter must have SSL enabled");
}
final TlsSniSocketFactory socketFactory;
if (settings.getSslTrustKey() != null && settings.getSslTrustKey().length() != 0) {
@ -162,11 +154,6 @@ class DelugeRpcClient implements Closeable { @@ -162,11 +154,6 @@ class DelugeRpcClient implements Closeable {
socketFactory = new TlsSniSocketFactory();
}
return socketFactory.createSocket(null, settings.getAddress(), settings.getPort(), false);
// final TrustManager[] trustAllCerts = new TrustManager[]{new IgnoreSSLTrustManager()};
// final SSLContext sslContext = SSLContext.getInstance("TLSv1");
// sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
// return sslContext.getSocketFactory().createSocket(address, port);
}
}

Loading…
Cancel
Save