Browse Source

Improved uTorrent stability by using a static (and thus the same for all threads) token.

pull/82/head
Eric Kok 11 years ago
parent
commit
7964fe33cb
  1. 1
      core/.classpath
  2. BIN
      core/libs/transdroid-connect.jar
  3. 2
      lib/src/org/transdroid/daemon/Transmission/TransmissionAdapter.java
  4. 14
      lib/src/org/transdroid/daemon/Utorrent/UtorrentAdapter.java

1
core/.classpath

@ -10,6 +10,5 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/> <classpathentry exported="true" kind="con" path="com.android.ide.eclipse.adt.DEPENDENCIES"/>
<classpathentry combineaccessrules="false" exported="true" kind="src" path="/Transdroid Torrent Connect"/>
<classpathentry kind="output" path="bin/classes"/> <classpathentry kind="output" path="bin/classes"/>
</classpath> </classpath>

BIN
core/libs/transdroid-connect.jar

Binary file not shown.

2
lib/src/org/transdroid/daemon/Transmission/TransmissionAdapter.java

@ -114,7 +114,7 @@ public class TransmissionAdapter implements IDaemonAdapter {
private DaemonSettings settings; private DaemonSettings settings;
private DefaultHttpClient httpclient; private DefaultHttpClient httpclient;
private String sessionToken; private static String sessionToken;
private long rpcVersion = -1; private long rpcVersion = -1;

14
lib/src/org/transdroid/daemon/Utorrent/UtorrentAdapter.java

@ -87,7 +87,7 @@ public class UtorrentAdapter implements IDaemonAdapter {
private DaemonSettings settings; private DaemonSettings settings;
private DefaultHttpClient httpclient; private DefaultHttpClient httpclient;
private String authtoken; private static String authtoken;
/** /**
* Initialises an adapter that provides operations to the uTorrent web daemon * Initialises an adapter that provides operations to the uTorrent web daemon
@ -286,6 +286,10 @@ public class UtorrentAdapter implements IDaemonAdapter {
} }
private JSONObject makeUtorrentRequest(String addToUrl) throws DaemonException { private JSONObject makeUtorrentRequest(String addToUrl) throws DaemonException {
return makeUtorrentRequest(addToUrl, 0);
}
private JSONObject makeUtorrentRequest(String addToUrl, int retried) throws DaemonException {
try { try {
@ -304,7 +308,11 @@ public class UtorrentAdapter implements IDaemonAdapter {
InputStream instream = response.getEntity().getContent(); InputStream instream = response.getEntity().getContent();
String result = HttpHelper.convertStreamToString(instream); String result = HttpHelper.convertStreamToString(instream);
if ((result.equals("") || result.trim().equals("invalid request"))) { if ((result.equals("") || result.trim().equals("invalid request"))) {
authtoken = null; // Auth token was invalidated; retry at max 3 times
authtoken = null; // So that ensureToken() will request a new token on the next try
if (retried < 2) {
return makeUtorrentRequest(addToUrl, retried++);
}
throw new DaemonException(ExceptionType.AuthenticationFailure, "Response was '" + result.replace("\n", "") + "' instead of a proper JSON object (and we used auth token '" + authtoken + "')"); throw new DaemonException(ExceptionType.AuthenticationFailure, "Response was '" + result.replace("\n", "") + "' instead of a proper JSON object (and we used auth token '" + authtoken + "')");
} }
JSONObject json = new JSONObject(result); JSONObject json = new JSONObject(result);
@ -329,7 +337,7 @@ public class UtorrentAdapter implements IDaemonAdapter {
if (authtoken == null) { if (authtoken == null) {
// Make a request to /gui/token.html // Make a request to /gui/token.html
// See http://trac.utorrent.com/trac/wiki/TokenSystem // See https://github.com/bittorrent/webui/wiki/TokenSystem
HttpGet httpget = new HttpGet(buildWebUIUrl() + "token.html"); HttpGet httpget = new HttpGet(buildWebUIUrl() + "token.html");
// Parse the response HTML // Parse the response HTML

Loading…
Cancel
Save