forked from I2P_Developers/i2p.i2p
Replace URL with URI where possible
URL bad for anon and has traps like equals()
This commit is contained in:
@ -3,8 +3,8 @@ package org.klomp.snark;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URISyntaxException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -590,10 +590,10 @@ public class I2PSnarkUtil {
|
|||||||
*/
|
*/
|
||||||
public boolean isKnownOpenTracker(String url) {
|
public boolean isKnownOpenTracker(String url) {
|
||||||
try {
|
try {
|
||||||
URL u = new URL(url);
|
URI u = new URI(url);
|
||||||
String host = u.getHost();
|
String host = u.getHost();
|
||||||
return host != null && SnarkManager.KNOWN_OPENTRACKERS.contains(host);
|
return host != null && SnarkManager.KNOWN_OPENTRACKERS.contains(host);
|
||||||
} catch (MalformedURLException mue) {
|
} catch (URISyntaxException use) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,8 +23,8 @@ package org.klomp.snark;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.URI;
|
||||||
import java.net.URL;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -880,13 +880,13 @@ public class TrackerClient implements Runnable {
|
|||||||
* @since 0.7.12
|
* @since 0.7.12
|
||||||
*/
|
*/
|
||||||
public static boolean isValidAnnounce(String ann) {
|
public static boolean isValidAnnounce(String ann) {
|
||||||
URL url;
|
URI url;
|
||||||
try {
|
try {
|
||||||
url = new URL(ann);
|
url = new URI(ann);
|
||||||
} catch (MalformedURLException mue) {
|
} catch (URISyntaxException use) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return url.getProtocol().equals("http") &&
|
return "http".equals(url.getScheme()) && url.getHost() != null &&
|
||||||
(url.getHost().endsWith(".i2p") || url.getHost().equals("i2p"));
|
(url.getHost().endsWith(".i2p") || url.getHost().equals("i2p"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -896,13 +896,13 @@ public class TrackerClient implements Runnable {
|
|||||||
* @since 0.9.5
|
* @since 0.9.5
|
||||||
*/
|
*/
|
||||||
private static Hash getHostHash(String ann) {
|
private static Hash getHostHash(String ann) {
|
||||||
URL url;
|
URI url;
|
||||||
try {
|
try {
|
||||||
url = new URL(ann);
|
url = new URI(ann);
|
||||||
} catch (MalformedURLException mue) {
|
} catch (URISyntaxException use) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!url.getProtocol().equals("http"))
|
if (!"http".equals(url.getScheme()))
|
||||||
return null;
|
return null;
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
if (host.endsWith(".i2p"))
|
if (host.endsWith(".i2p"))
|
||||||
|
@ -5,7 +5,8 @@ import java.io.IOException;
|
|||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@ -112,8 +113,8 @@ public class I2PSocketEepGet extends EepGet {
|
|||||||
if (_socket != null) try { _socket.close(); } catch (IOException ioe) {}
|
if (_socket != null) try { _socket.close(); } catch (IOException ioe) {}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
URL url = new URL(_actualURL);
|
URI url = new URI(_actualURL);
|
||||||
if ("http".equals(url.getProtocol())) {
|
if ("http".equals(url.getScheme())) {
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
int port = url.getPort();
|
int port = url.getPort();
|
||||||
if (port <= 0 || port > 65535)
|
if (port <= 0 || port > 65535)
|
||||||
@ -123,13 +124,13 @@ public class I2PSocketEepGet extends EepGet {
|
|||||||
// Rewrite the url to strip out the /i2p/,
|
// Rewrite the url to strip out the /i2p/,
|
||||||
// as the naming service accepts B64KEY (but not B64KEY.i2p atm)
|
// as the naming service accepts B64KEY (but not B64KEY.i2p atm)
|
||||||
if ("i2p".equals(host)) {
|
if ("i2p".equals(host)) {
|
||||||
String file = url.getFile();
|
String file = url.getPath();
|
||||||
try {
|
try {
|
||||||
int slash = 1 + file.substring(1).indexOf("/");
|
int slash = 1 + file.substring(1).indexOf("/");
|
||||||
host = file.substring(1, slash);
|
host = file.substring(1, slash);
|
||||||
_actualURL = "http://" + host + file.substring(slash);
|
_actualURL = "http://" + host + file.substring(slash);
|
||||||
} catch (IndexOutOfBoundsException ioobe) {
|
} catch (IndexOutOfBoundsException ioobe) {
|
||||||
throw new IOException("Bad /i2p/ format: " + _actualURL);
|
throw new MalformedURLException("Bad /i2p/ format: " + _actualURL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -173,12 +174,14 @@ public class I2PSocketEepGet extends EepGet {
|
|||||||
opts.setPort(port);
|
opts.setPort(port);
|
||||||
_socket = _socketManager.connect(dest, opts);
|
_socket = _socketManager.connect(dest, opts);
|
||||||
} else {
|
} else {
|
||||||
throw new IOException("Unsupported protocol: " + _actualURL);
|
throw new MalformedURLException("Unsupported protocol: " + _actualURL);
|
||||||
}
|
}
|
||||||
} catch (MalformedURLException mue) {
|
} catch (URISyntaxException use) {
|
||||||
throw new IOException("Request URL is invalid: " + _actualURL);
|
IOException ioe = new MalformedURLException("Bad URL");
|
||||||
|
ioe.initCause(use);
|
||||||
|
throw ioe;
|
||||||
} catch (I2PException ie) {
|
} catch (I2PException ie) {
|
||||||
throw new IOException(ie.toString());
|
throw new IOException("I2P error", ie);
|
||||||
}
|
}
|
||||||
|
|
||||||
_proxyIn = _socket.getInputStream();
|
_proxyIn = _socket.getInputStream();
|
||||||
@ -202,7 +205,14 @@ public class I2PSocketEepGet extends EepGet {
|
|||||||
@Override
|
@Override
|
||||||
protected String getRequest() throws IOException {
|
protected String getRequest() throws IOException {
|
||||||
StringBuilder buf = new StringBuilder(2048);
|
StringBuilder buf = new StringBuilder(2048);
|
||||||
URL url = new URL(_actualURL);
|
URI url;
|
||||||
|
try {
|
||||||
|
url = new URI(_actualURL);
|
||||||
|
} catch (URISyntaxException use) {
|
||||||
|
IOException ioe = new MalformedURLException("Bad URL");
|
||||||
|
ioe.initCause(use);
|
||||||
|
throw ioe;
|
||||||
|
}
|
||||||
//String host = url.getHost();
|
//String host = url.getHost();
|
||||||
String path = url.getPath();
|
String path = url.getPath();
|
||||||
String query = url.getQuery();
|
String query = url.getQuery();
|
||||||
|
@ -2,8 +2,8 @@ package net.i2p.router.web;
|
|||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.net.MalformedURLException;
|
import java.net.URISyntaxException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -37,10 +37,10 @@ public class ConfigReseedHandler extends FormHandler {
|
|||||||
addFormError(_t("You must enter a URL"));
|
addFormError(_t("You must enter a URL"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
URL url;
|
URI url;
|
||||||
try {
|
try {
|
||||||
url = new URL(val);
|
url = new URI(val);
|
||||||
} catch (MalformedURLException mue) {
|
} catch (URISyntaxException mue) {
|
||||||
addFormError(_t("Bad URL {0}", val));
|
addFormError(_t("Bad URL {0}", val));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,8 @@ import java.io.InputStreamReader;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
@ -115,18 +116,16 @@ public class UrlLauncher implements ClientApp {
|
|||||||
* @return success
|
* @return success
|
||||||
*/
|
*/
|
||||||
private static boolean waitForServer(String urlString) {
|
private static boolean waitForServer(String urlString) {
|
||||||
URL url;
|
URI url;
|
||||||
try {
|
try {
|
||||||
url = new URL(urlString);
|
url = new URI(urlString);
|
||||||
} catch (MalformedURLException e) {
|
} catch (URISyntaxException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
int port = url.getPort();
|
int port = url.getPort();
|
||||||
if (port <= 0) {
|
if (port <= 0) {
|
||||||
port = url.getDefaultPort();
|
port = "https".equals(url.getScheme()) ? 443 : 80;
|
||||||
if (port <= 0)
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
SocketAddress sa;
|
SocketAddress sa;
|
||||||
try {
|
try {
|
||||||
@ -261,8 +260,8 @@ public class UrlLauncher implements ClientApp {
|
|||||||
private static boolean validateUrlFormat(String urlString) {
|
private static boolean validateUrlFormat(String urlString) {
|
||||||
try {
|
try {
|
||||||
// just to check validity
|
// just to check validity
|
||||||
new URL(urlString);
|
new URI(urlString);
|
||||||
} catch (MalformedURLException e) {
|
} catch (URISyntaxException e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -15,7 +15,8 @@ import java.net.InetSocketAddress;
|
|||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -321,12 +322,12 @@ public class EepGet {
|
|||||||
* @return a filename to save the resource as on local filesystem
|
* @return a filename to save the resource as on local filesystem
|
||||||
*/
|
*/
|
||||||
public static String suggestName(String url) {
|
public static String suggestName(String url) {
|
||||||
URL nameURL = null; // URL object
|
URI nameURL = null;
|
||||||
String name; // suggested name
|
String name; // suggested name
|
||||||
|
|
||||||
try {
|
try {
|
||||||
nameURL = new URL(url);
|
nameURL = new URI(url);
|
||||||
} catch (MalformedURLException e) {
|
} catch (URISyntaxException e) {
|
||||||
System.err.println("Please enter a properly formed URL.");
|
System.err.println("Please enter a properly formed URL.");
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
}
|
}
|
||||||
@ -722,24 +723,25 @@ public class EepGet {
|
|||||||
|
|
||||||
if (_redirectLocation != null) {
|
if (_redirectLocation != null) {
|
||||||
// we also are here after a 407
|
// we also are here after a 407
|
||||||
//try {
|
try {
|
||||||
if (_redirectLocation.startsWith("http://")) {
|
if (_redirectLocation.startsWith("http://")) {
|
||||||
_actualURL = _redirectLocation;
|
_actualURL = _redirectLocation;
|
||||||
} else {
|
} else {
|
||||||
// the Location: field has been required to be an absolute URI at least since
|
// the Location: field has been required to be an absolute URI at least since
|
||||||
// RFC 1945 (HTTP/1.0 1996), so it isn't clear what the point of this is.
|
// RFC 1945 (HTTP/1.0 1996), so it isn't clear what the point of this is.
|
||||||
// This oddly adds a ":" even if no port, but that seems to work.
|
// This oddly adds a ":" even if no port, but that seems to work.
|
||||||
URL url = new URL(_actualURL);
|
URI url = new URI(_actualURL);
|
||||||
if (_redirectLocation.startsWith("/"))
|
if (_redirectLocation.startsWith("/"))
|
||||||
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation;
|
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation;
|
||||||
else
|
else
|
||||||
// this blows up completely on a redirect to https://, for example
|
// this blows up completely on a redirect to https://, for example
|
||||||
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + "/" + _redirectLocation;
|
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + "/" + _redirectLocation;
|
||||||
}
|
}
|
||||||
// an MUE is an IOE
|
} catch (URISyntaxException use) {
|
||||||
//} catch (MalformedURLException mue) {
|
IOException ioe = new MalformedURLException("Redirected to invalid URL");
|
||||||
// throw new IOException("Redirected from an invalid URL");
|
ioe.initCause(use);
|
||||||
//}
|
throw ioe;
|
||||||
|
}
|
||||||
|
|
||||||
AuthState as = _authState;
|
AuthState as = _authState;
|
||||||
if (_responseCode == 407) {
|
if (_responseCode == 407) {
|
||||||
@ -1226,9 +1228,9 @@ public class EepGet {
|
|||||||
if (_shouldProxy) {
|
if (_shouldProxy) {
|
||||||
_proxy = InternalSocket.getSocket(_proxyHost, _proxyPort);
|
_proxy = InternalSocket.getSocket(_proxyHost, _proxyPort);
|
||||||
} else {
|
} else {
|
||||||
//try {
|
try {
|
||||||
URL url = new URL(_actualURL);
|
URI url = new URI(_actualURL);
|
||||||
if ("http".equals(url.getProtocol())) {
|
if ("http".equals(url.getScheme())) {
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
String hostlc = host.toLowerCase(Locale.US);
|
String hostlc = host.toLowerCase(Locale.US);
|
||||||
if (hostlc.endsWith(".i2p"))
|
if (hostlc.endsWith(".i2p"))
|
||||||
@ -1248,10 +1250,11 @@ public class EepGet {
|
|||||||
} else {
|
} else {
|
||||||
throw new MalformedURLException("URL is not supported:" + _actualURL);
|
throw new MalformedURLException("URL is not supported:" + _actualURL);
|
||||||
}
|
}
|
||||||
// an MUE is an IOE
|
} catch (URISyntaxException use) {
|
||||||
//} catch (MalformedURLException mue) {
|
IOException ioe = new MalformedURLException("Request URL is invalid");
|
||||||
// throw new IOException("Request URL is invalid");
|
ioe.initCause(use);
|
||||||
//}
|
throw ioe;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_proxyIn = _proxy.getInputStream();
|
_proxyIn = _proxy.getInputStream();
|
||||||
if (!(_proxy instanceof InternalSocket))
|
if (!(_proxy instanceof InternalSocket))
|
||||||
@ -1273,7 +1276,14 @@ public class EepGet {
|
|||||||
boolean post = false;
|
boolean post = false;
|
||||||
if ( (_postData != null) && (_postData.length() > 0) )
|
if ( (_postData != null) && (_postData.length() > 0) )
|
||||||
post = true;
|
post = true;
|
||||||
URL url = new URL(_actualURL);
|
URI url;
|
||||||
|
try {
|
||||||
|
url = new URI(_actualURL);
|
||||||
|
} catch (URISyntaxException use) {
|
||||||
|
IOException ioe = new MalformedURLException("Bad URL");
|
||||||
|
ioe.initCause(use);
|
||||||
|
throw ioe;
|
||||||
|
}
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
if (host == null || host.length() <= 0)
|
if (host == null || host.length() <= 0)
|
||||||
throw new MalformedURLException("Bad URL, no host");
|
throw new MalformedURLException("Bad URL, no host");
|
||||||
|
@ -6,7 +6,9 @@ import java.io.ByteArrayOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.URL;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
|
||||||
import gnu.getopt.Getopt;
|
import gnu.getopt.Getopt;
|
||||||
|
|
||||||
@ -176,24 +178,25 @@ public class EepHead extends EepGet {
|
|||||||
|
|
||||||
// Should we even follow redirects for HEAD?
|
// Should we even follow redirects for HEAD?
|
||||||
if (_redirectLocation != null) {
|
if (_redirectLocation != null) {
|
||||||
//try {
|
try {
|
||||||
if (_redirectLocation.startsWith("http://")) {
|
if (_redirectLocation.startsWith("http://")) {
|
||||||
_actualURL = _redirectLocation;
|
_actualURL = _redirectLocation;
|
||||||
} else {
|
} else {
|
||||||
// the Location: field has been required to be an absolute URI at least since
|
// the Location: field has been required to be an absolute URI at least since
|
||||||
// RFC 1945 (HTTP/1.0 1996), so it isn't clear what the point of this is.
|
// RFC 1945 (HTTP/1.0 1996), so it isn't clear what the point of this is.
|
||||||
// This oddly adds a ":" even if no port, but that seems to work.
|
// This oddly adds a ":" even if no port, but that seems to work.
|
||||||
URL url = new URL(_actualURL);
|
URI url = new URI(_actualURL);
|
||||||
if (_redirectLocation.startsWith("/"))
|
if (_redirectLocation.startsWith("/"))
|
||||||
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation;
|
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + _redirectLocation;
|
||||||
else
|
else
|
||||||
// this blows up completely on a redirect to https://, for example
|
// this blows up completely on a redirect to https://, for example
|
||||||
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + "/" + _redirectLocation;
|
_actualURL = "http://" + url.getHost() + ":" + url.getPort() + "/" + _redirectLocation;
|
||||||
}
|
}
|
||||||
// an MUE is an IOE
|
} catch (URISyntaxException use) {
|
||||||
//} catch (MalformedURLException mue) {
|
IOException ioe = new MalformedURLException("Redirected to invalid URL");
|
||||||
// throw new IOException("Redirected from an invalid URL");
|
ioe.initCause(use);
|
||||||
//}
|
throw ioe;
|
||||||
|
}
|
||||||
AuthState as = _authState;
|
AuthState as = _authState;
|
||||||
if (_responseCode == 407) {
|
if (_responseCode == 407) {
|
||||||
if (!_shouldProxy)
|
if (!_shouldProxy)
|
||||||
@ -252,7 +255,14 @@ public class EepHead extends EepGet {
|
|||||||
@Override
|
@Override
|
||||||
protected String getRequest() throws IOException {
|
protected String getRequest() throws IOException {
|
||||||
StringBuilder buf = new StringBuilder(512);
|
StringBuilder buf = new StringBuilder(512);
|
||||||
URL url = new URL(_actualURL);
|
URI url;
|
||||||
|
try {
|
||||||
|
url = new URI(_actualURL);
|
||||||
|
} catch (URISyntaxException use) {
|
||||||
|
IOException ioe = new MalformedURLException("Bad URL");
|
||||||
|
ioe.initCause(use);
|
||||||
|
throw ioe;
|
||||||
|
}
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
int port = url.getPort();
|
int port = url.getPort();
|
||||||
String path = url.getPath();
|
String path = url.getPath();
|
||||||
|
@ -6,7 +6,8 @@ import java.io.IOException;
|
|||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import gnu.getopt.Getopt;
|
import gnu.getopt.Getopt;
|
||||||
@ -167,7 +168,14 @@ public class PartialEepGet extends EepGet {
|
|||||||
@Override
|
@Override
|
||||||
protected String getRequest() throws IOException {
|
protected String getRequest() throws IOException {
|
||||||
StringBuilder buf = new StringBuilder(2048);
|
StringBuilder buf = new StringBuilder(2048);
|
||||||
URL url = new URL(_actualURL);
|
URI url;
|
||||||
|
try {
|
||||||
|
url = new URI(_actualURL);
|
||||||
|
} catch (URISyntaxException use) {
|
||||||
|
IOException ioe = new MalformedURLException("Bad URL");
|
||||||
|
ioe.initCause(use);
|
||||||
|
throw ioe;
|
||||||
|
}
|
||||||
String host = url.getHost();
|
String host = url.getHost();
|
||||||
if (host == null || host.length() <= 0)
|
if (host == null || host.length() <= 0)
|
||||||
throw new MalformedURLException("Bad URL, no host");
|
throw new MalformedURLException("Bad URL, no host");
|
||||||
|
@ -46,7 +46,8 @@ import java.io.PipedInputStream;
|
|||||||
import java.io.PipedOutputStream;
|
import java.io.PipedOutputStream;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.security.KeyStore;
|
import java.security.KeyStore;
|
||||||
import java.security.GeneralSecurityException;
|
import java.security.GeneralSecurityException;
|
||||||
import java.security.cert.CertificateException;
|
import java.security.cert.CertificateException;
|
||||||
@ -553,11 +554,11 @@ public class SSLEepGet extends EepGet {
|
|||||||
|
|
||||||
String req = getRequest();
|
String req = getRequest();
|
||||||
|
|
||||||
//try {
|
String host;
|
||||||
URL url = new URL(_actualURL);
|
int port;
|
||||||
String host = null;
|
try {
|
||||||
int port = 0;
|
URI url = new URI(_actualURL);
|
||||||
if ("https".equals(url.getProtocol())) {
|
if ("https".equals(url.getScheme())) {
|
||||||
host = url.getHost();
|
host = url.getHost();
|
||||||
if (host.toLowerCase(Locale.US).endsWith(".i2p"))
|
if (host.toLowerCase(Locale.US).endsWith(".i2p"))
|
||||||
throw new MalformedURLException("I2P addresses unsupported");
|
throw new MalformedURLException("I2P addresses unsupported");
|
||||||
@ -589,10 +590,11 @@ public class SSLEepGet extends EepGet {
|
|||||||
} else {
|
} else {
|
||||||
throw new MalformedURLException("Only https supported: " + _actualURL);
|
throw new MalformedURLException("Only https supported: " + _actualURL);
|
||||||
}
|
}
|
||||||
// an MUE is an IOE
|
} catch (URISyntaxException use) {
|
||||||
//} catch (MalformedURLException mue) {
|
IOException ioe = new MalformedURLException("Redirected to invalid URL");
|
||||||
// throw new IOException("Request URL is invalid");
|
ioe.initCause(use);
|
||||||
//}
|
throw ioe;
|
||||||
|
}
|
||||||
|
|
||||||
_proxyIn = _proxy.getInputStream();
|
_proxyIn = _proxy.getInputStream();
|
||||||
_proxyOut = _proxy.getOutputStream();
|
_proxyOut = _proxy.getOutputStream();
|
||||||
|
@ -3,7 +3,7 @@ package net.i2p.router.networkdb.reseed;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
@ -131,7 +131,7 @@ public class ReseedChecker {
|
|||||||
* @throws IllegalArgumentException if it doesn't end with zip or su3
|
* @throws IllegalArgumentException if it doesn't end with zip or su3
|
||||||
* @since 0.9.19
|
* @since 0.9.19
|
||||||
*/
|
*/
|
||||||
public boolean requestReseed(URL url) throws IllegalArgumentException {
|
public boolean requestReseed(URI url) throws IllegalArgumentException {
|
||||||
if (_inProgress.compareAndSet(false, true)) {
|
if (_inProgress.compareAndSet(false, true)) {
|
||||||
Reseeder reseeder = new Reseeder(_context, this);
|
Reseeder reseeder = new Reseeder(_context, this);
|
||||||
try {
|
try {
|
||||||
|
@ -7,10 +7,8 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.URL;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
@ -153,7 +151,7 @@ public class Reseeder {
|
|||||||
* @throws IllegalArgumentException if it doesn't end with zip or su3
|
* @throws IllegalArgumentException if it doesn't end with zip or su3
|
||||||
* @since 0.9.19
|
* @since 0.9.19
|
||||||
*/
|
*/
|
||||||
void requestReseed(URL url) throws IllegalArgumentException {
|
void requestReseed(URI url) throws IllegalArgumentException {
|
||||||
ReseedRunner reseedRunner = new ReseedRunner(url);
|
ReseedRunner reseedRunner = new ReseedRunner(url);
|
||||||
// set to daemon so it doesn't hang a shutdown
|
// set to daemon so it doesn't hang a shutdown
|
||||||
Thread reseed = new I2PAppThread(reseedRunner, "Reseed", true);
|
Thread reseed = new I2PAppThread(reseedRunner, "Reseed", true);
|
||||||
@ -239,7 +237,7 @@ public class Reseeder {
|
|||||||
/** bytes per sec for each su3 downloaded */
|
/** bytes per sec for each su3 downloaded */
|
||||||
private final List<Long> _bandwidths;
|
private final List<Long> _bandwidths;
|
||||||
private static final int MAX_DATE_SETS = 2;
|
private static final int MAX_DATE_SETS = 2;
|
||||||
private final URL _url;
|
private final URI _url;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Start a reseed from the default URL list
|
* Start a reseed from the default URL list
|
||||||
@ -256,7 +254,7 @@ public class Reseeder {
|
|||||||
* @throws IllegalArgumentException if it doesn't end with zip or su3
|
* @throws IllegalArgumentException if it doesn't end with zip or su3
|
||||||
* @since 0.9.19
|
* @since 0.9.19
|
||||||
*/
|
*/
|
||||||
public ReseedRunner(URL url) throws IllegalArgumentException {
|
public ReseedRunner(URI url) throws IllegalArgumentException {
|
||||||
String lc = url.getPath().toLowerCase(Locale.US);
|
String lc = url.getPath().toLowerCase(Locale.US);
|
||||||
if (!(lc.endsWith(".zip") || lc.endsWith(".su3")))
|
if (!(lc.endsWith(".zip") || lc.endsWith(".su3")))
|
||||||
throw new IllegalArgumentException("Reseed URL must end with .zip or .su3");
|
throw new IllegalArgumentException("Reseed URL must end with .zip or .su3");
|
||||||
@ -412,7 +410,7 @@ public class Reseeder {
|
|||||||
* @return count of routerinfos successfully fetched, or -1 if no valid URLs
|
* @return count of routerinfos successfully fetched, or -1 if no valid URLs
|
||||||
*/
|
*/
|
||||||
private int reseed(boolean echoStatus) {
|
private int reseed(boolean echoStatus) {
|
||||||
List<URL> URLList = new ArrayList<URL>();
|
List<URI> URLList = new ArrayList<URI>();
|
||||||
String URLs = _context.getProperty(PROP_RESEED_URL);
|
String URLs = _context.getProperty(PROP_RESEED_URL);
|
||||||
boolean defaulted = URLs == null;
|
boolean defaulted = URLs == null;
|
||||||
boolean SSLDisable = _context.getBooleanProperty(PROP_SSL_DISABLE);
|
boolean SSLDisable = _context.getBooleanProperty(PROP_SSL_DISABLE);
|
||||||
@ -429,29 +427,29 @@ public class Reseeder {
|
|||||||
if (!u.endsWith("/"))
|
if (!u.endsWith("/"))
|
||||||
u = u + '/';
|
u = u + '/';
|
||||||
try {
|
try {
|
||||||
URLList.add(new URL(u));
|
URLList.add(new URI(u));
|
||||||
} catch (MalformedURLException mue) {}
|
} catch (URISyntaxException mue) {}
|
||||||
}
|
}
|
||||||
Collections.shuffle(URLList, _context.random());
|
Collections.shuffle(URLList, _context.random());
|
||||||
if (!SSLDisable && !SSLRequired) {
|
if (!SSLDisable && !SSLRequired) {
|
||||||
// put the non-SSL at the end of the SSL
|
// put the non-SSL at the end of the SSL
|
||||||
List<URL> URLList2 = new ArrayList<URL>();
|
List<URI> URLList2 = new ArrayList<URI>();
|
||||||
tok = new StringTokenizer(DEFAULT_SEED_URL, " ,");
|
tok = new StringTokenizer(DEFAULT_SEED_URL, " ,");
|
||||||
while (tok.hasMoreTokens()) {
|
while (tok.hasMoreTokens()) {
|
||||||
String u = tok.nextToken().trim();
|
String u = tok.nextToken().trim();
|
||||||
if (!u.endsWith("/"))
|
if (!u.endsWith("/"))
|
||||||
u = u + '/';
|
u = u + '/';
|
||||||
try {
|
try {
|
||||||
URLList2.add(new URL(u));
|
URLList2.add(new URI(u));
|
||||||
} catch (MalformedURLException mue) {}
|
} catch (URISyntaxException mue) {}
|
||||||
}
|
}
|
||||||
Collections.shuffle(URLList2, _context.random());
|
Collections.shuffle(URLList2, _context.random());
|
||||||
URLList.addAll(URLList2);
|
URLList.addAll(URLList2);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// custom list given
|
// custom list given
|
||||||
List<URL> SSLList = new ArrayList<URL>();
|
List<URI> SSLList = new ArrayList<URI>();
|
||||||
List<URL> nonSSLList = new ArrayList<URL>();
|
List<URI> nonSSLList = new ArrayList<URI>();
|
||||||
StringTokenizer tok = new StringTokenizer(URLs, " ,");
|
StringTokenizer tok = new StringTokenizer(URLs, " ,");
|
||||||
while (tok.hasMoreTokens()) {
|
while (tok.hasMoreTokens()) {
|
||||||
// format tokens
|
// format tokens
|
||||||
@ -461,12 +459,12 @@ public class Reseeder {
|
|||||||
// check if ssl or not then add to respective list
|
// check if ssl or not then add to respective list
|
||||||
if (u.startsWith("https")) {
|
if (u.startsWith("https")) {
|
||||||
try {
|
try {
|
||||||
SSLList.add(new URL(u));
|
SSLList.add(new URI(u));
|
||||||
} catch (MalformedURLException mue) {}
|
} catch (URISyntaxException mue) {}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
nonSSLList.add(new URL(u));
|
nonSSLList.add(new URI(u));
|
||||||
} catch (MalformedURLException mue) {}
|
} catch (URISyntaxException mue) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// shuffle lists
|
// shuffle lists
|
||||||
@ -482,8 +480,8 @@ public class Reseeder {
|
|||||||
}
|
}
|
||||||
if (!isSNISupported()) {
|
if (!isSNISupported()) {
|
||||||
try {
|
try {
|
||||||
URLList.remove(new URL("https://netdb.i2p2.no/"));
|
URLList.remove(new URI("https://netdb.i2p2.no/"));
|
||||||
} catch (MalformedURLException mue) {}
|
} catch (URISyntaxException mue) {}
|
||||||
}
|
}
|
||||||
if (URLList.isEmpty()) {
|
if (URLList.isEmpty()) {
|
||||||
System.out.println("No valid reseed URLs");
|
System.out.println("No valid reseed URLs");
|
||||||
@ -501,19 +499,19 @@ public class Reseeder {
|
|||||||
* @param echoStatus apparently always false
|
* @param echoStatus apparently always false
|
||||||
* @return count of routerinfos successfully fetched
|
* @return count of routerinfos successfully fetched
|
||||||
*/
|
*/
|
||||||
private int reseed(List<URL> URLList, boolean echoStatus) {
|
private int reseed(List<URI> URLList, boolean echoStatus) {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (int i = 0; i < URLList.size() && _isRunning; i++) {
|
for (int i = 0; i < URLList.size() && _isRunning; i++) {
|
||||||
if (_context.router().gracefulShutdownInProgress()) {
|
if (_context.router().gracefulShutdownInProgress()) {
|
||||||
System.out.println("Reseed aborted, shutdown in progress");
|
System.out.println("Reseed aborted, shutdown in progress");
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
URL url = URLList.get(i);
|
URI url = URLList.get(i);
|
||||||
int dl = 0;
|
int dl = 0;
|
||||||
if (ENABLE_SU3) {
|
if (ENABLE_SU3) {
|
||||||
try {
|
try {
|
||||||
dl = reseedSU3(new URL(url.toString() + SU3_FILENAME), echoStatus);
|
dl = reseedSU3(new URI(url.toString() + SU3_FILENAME), echoStatus);
|
||||||
} catch (MalformedURLException mue) {}
|
} catch (URISyntaxException mue) {}
|
||||||
}
|
}
|
||||||
if (ENABLE_NON_SU3) {
|
if (ENABLE_NON_SU3) {
|
||||||
if (dl <= 0)
|
if (dl <= 0)
|
||||||
@ -557,7 +555,7 @@ public class Reseeder {
|
|||||||
* @param echoStatus apparently always false
|
* @param echoStatus apparently always false
|
||||||
* @return count of routerinfos successfully fetched
|
* @return count of routerinfos successfully fetched
|
||||||
**/
|
**/
|
||||||
private int reseedOne(URL seedURL, boolean echoStatus) {
|
private int reseedOne(URI seedURL, boolean echoStatus) {
|
||||||
try {
|
try {
|
||||||
// Don't use context clock as we may be adjusting the time
|
// Don't use context clock as we may be adjusting the time
|
||||||
final long timeLimit = System.currentTimeMillis() + MAX_TIME_PER_HOST;
|
final long timeLimit = System.currentTimeMillis() + MAX_TIME_PER_HOST;
|
||||||
@ -659,7 +657,7 @@ public class Reseeder {
|
|||||||
* @return count of routerinfos successfully fetched
|
* @return count of routerinfos successfully fetched
|
||||||
* @since 0.9.14
|
* @since 0.9.14
|
||||||
**/
|
**/
|
||||||
public int reseedSU3(URL seedURL, boolean echoStatus) {
|
public int reseedSU3(URI seedURL, boolean echoStatus) {
|
||||||
return reseedSU3OrZip(seedURL, true, echoStatus);
|
return reseedSU3OrZip(seedURL, true, echoStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -673,7 +671,7 @@ public class Reseeder {
|
|||||||
* @return count of routerinfos successfully fetched
|
* @return count of routerinfos successfully fetched
|
||||||
* @since 0.9.19
|
* @since 0.9.19
|
||||||
**/
|
**/
|
||||||
public int reseedZip(URL seedURL, boolean echoStatus) {
|
public int reseedZip(URI seedURL, boolean echoStatus) {
|
||||||
return reseedSU3OrZip(seedURL, false, echoStatus);
|
return reseedSU3OrZip(seedURL, false, echoStatus);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -687,7 +685,7 @@ public class Reseeder {
|
|||||||
* @return count of routerinfos successfully fetched
|
* @return count of routerinfos successfully fetched
|
||||||
* @since 0.9.19
|
* @since 0.9.19
|
||||||
**/
|
**/
|
||||||
private int reseedSU3OrZip(URL seedURL, boolean isSU3, boolean echoStatus) {
|
private int reseedSU3OrZip(URI seedURL, boolean isSU3, boolean echoStatus) {
|
||||||
int fetched = 0;
|
int fetched = 0;
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
File contentRaw = null;
|
File contentRaw = null;
|
||||||
@ -869,7 +867,7 @@ public class Reseeder {
|
|||||||
if (ourHash != null && DataHelper.eq(hash, ourHash.getData()))
|
if (ourHash != null && DataHelper.eq(hash, ourHash.getData()))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
URL url = new URL(seedURL + (seedURL.endsWith("/") ? "" : "/") + ROUTERINFO_PREFIX + peer + ROUTERINFO_SUFFIX);
|
URI url = new URI(seedURL + (seedURL.endsWith("/") ? "" : "/") + ROUTERINFO_PREFIX + peer + ROUTERINFO_SUFFIX);
|
||||||
|
|
||||||
byte data[] = readURL(url);
|
byte data[] = readURL(url);
|
||||||
if (data == null || data.length <= 0)
|
if (data == null || data.length <= 0)
|
||||||
@ -878,7 +876,7 @@ public class Reseeder {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** @return null on error */
|
/** @return null on error */
|
||||||
private byte[] readURL(URL url) throws IOException {
|
private byte[] readURL(URI url) throws IOException {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(4*1024);
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(4*1024);
|
||||||
EepGet get;
|
EepGet get;
|
||||||
boolean ssl = url.toString().startsWith("https");
|
boolean ssl = url.toString().startsWith("https");
|
||||||
@ -923,7 +921,7 @@ public class Reseeder {
|
|||||||
* @return null on error
|
* @return null on error
|
||||||
* @since 0.9.14
|
* @since 0.9.14
|
||||||
*/
|
*/
|
||||||
private File fetchURL(URL url) throws IOException {
|
private File fetchURL(URI url) throws IOException {
|
||||||
File out = new File(_context.getTempDir(), "reseed-" + _context.random().nextInt() + ".tmp");
|
File out = new File(_context.getTempDir(), "reseed-" + _context.random().nextInt() + ".tmp");
|
||||||
EepGet get;
|
EepGet get;
|
||||||
boolean ssl = url.toString().startsWith("https");
|
boolean ssl = url.toString().startsWith("https");
|
||||||
|
@ -4,9 +4,9 @@
|
|||||||
package net.i2p.router.transport;
|
package net.i2p.router.transport;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.MalformedURLException;
|
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.net.URL;
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -823,17 +823,17 @@ class UPnP extends ControlPoint implements DeviceChangeListener, EventListener {
|
|||||||
String him = _router.getURLBase();
|
String him = _router.getURLBase();
|
||||||
if (him != null && him.length() > 0) {
|
if (him != null && him.length() > 0) {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(him);
|
URI url = new URI(him);
|
||||||
hisIP = url.getHost();
|
hisIP = url.getHost();
|
||||||
} catch (MalformedURLException mue) {}
|
} catch (URISyntaxException use) {}
|
||||||
}
|
}
|
||||||
if (hisIP == null) {
|
if (hisIP == null) {
|
||||||
him = _router.getLocation();
|
him = _router.getLocation();
|
||||||
if (him != null && him.length() > 0) {
|
if (him != null && him.length() > 0) {
|
||||||
try {
|
try {
|
||||||
URL url = new URL(him);
|
URI url = new URI(him);
|
||||||
hisIP = url.getHost();
|
hisIP = url.getHost();
|
||||||
} catch (MalformedURLException mue) {}
|
} catch (URISyntaxException use) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hisIP == null)
|
if (hisIP == null)
|
||||||
|
Reference in New Issue
Block a user