use of net.i2p.client.streaming.I2PSocketOptions in project i2p.i2p by i2p.
the class I2PTunnelHTTPClient method getDefaultOptions.
/**
* Create the default options (using the default timeout, etc).
* Warning, this does not make a copy of I2PTunnel's client options,
* it modifies them directly.
* unused?
*/
@Override
protected I2PSocketOptions getDefaultOptions() {
Properties defaultOpts = getTunnel().getClientOptions();
if (!defaultOpts.contains(I2PSocketOptions.PROP_READ_TIMEOUT)) {
defaultOpts.setProperty(I2PSocketOptions.PROP_READ_TIMEOUT, "" + DEFAULT_READ_TIMEOUT);
}
// if (!defaultOpts.contains("i2p.streaming.inactivityTimeout"))
// defaultOpts.setProperty("i2p.streaming.inactivityTimeout", ""+DEFAULT_READ_TIMEOUT);
// delayed start
verifySocketManager();
I2PSocketOptions opts = sockMgr.buildOptions(defaultOpts);
if (!defaultOpts.containsKey(I2PSocketOptions.PROP_CONNECT_TIMEOUT)) {
opts.setConnectTimeout(DEFAULT_CONNECT_TIMEOUT);
}
return opts;
}
use of net.i2p.client.streaming.I2PSocketOptions in project i2p.i2p by i2p.
the class I2PTunnelDCCClient method clientConnectionRun.
/**
* Accept one connection only.
*/
protected void clientConnectionRun(Socket s) {
I2PSocket i2ps = null;
if (_log.shouldLog(Log.INFO))
_log.info("Opening DCC connection to " + _dest + ':' + _remotePort);
Destination dest = _context.namingService().lookup(_dest);
if (dest == null) {
_log.error("Could not find leaseset for DCC connection to " + _dest + ':' + _remotePort);
closeSocket(s);
stop();
notifyEvent(CONNECT_STOP_EVENT, Integer.valueOf(getLocalPort()));
return;
}
I2PSocketOptions opts = sockMgr.buildOptions();
opts.setPort(_remotePort);
try {
i2ps = createI2PSocket(dest, opts);
Thread t = new Runner(s, i2ps);
// we are called from an unlimited thread pool, so run inline
// t.start();
t.run();
} catch (IOException ex) {
_log.error("Could not make DCC connection to " + _dest + ':' + _remotePort, ex);
notifyEvent(CONNECT_STOP_EVENT, Integer.valueOf(getLocalPort()));
} catch (I2PException ex) {
_log.error("Could not make DCC connection to " + _dest + ':' + _remotePort, ex);
notifyEvent(CONNECT_STOP_EVENT, Integer.valueOf(getLocalPort()));
} finally {
// only because we are running it inline
closeSocket(s);
if (i2ps != null) {
try {
i2ps.close();
} catch (IOException ioe) {
}
}
}
stop();
}
use of net.i2p.client.streaming.I2PSocketOptions in project i2p.i2p by i2p.
the class I2PSOCKSTunnel method buildOptions.
/**
* Because getDefaultOptions() in super() is protected
* @since 0.8.2
*/
public I2PSocketOptions buildOptions(Properties overrides) {
Properties defaultOpts = getTunnel().getClientOptions();
defaultOpts.putAll(overrides);
// delayed start
verifySocketManager();
I2PSocketOptions opts = sockMgr.buildOptions(defaultOpts);
if (!defaultOpts.containsKey(I2PSocketOptions.PROP_CONNECT_TIMEOUT))
opts.setConnectTimeout(60 * 1000);
return opts;
}
use of net.i2p.client.streaming.I2PSocketOptions in project i2p.i2p by i2p.
the class SOCKS4aServer method getDestinationI2PSocket.
/**
* Get an I2PSocket that can be used to send/receive 8-bit clean data
* to/from the destination of the SOCKS connection.
*
* @return an I2PSocket connected with the destination
*/
public I2PSocket getDestinationI2PSocket(I2PSOCKSTunnel t) throws SOCKSException {
setupServer();
if (connHostName == null) {
_log.error("BUG: destination host name has not been initialized!");
throw new SOCKSException("BUG! See the logs!");
}
if (connPort == 0) {
_log.error("BUG: destination port has not been initialized!");
throw new SOCKSException("BUG! See the logs!");
}
// for errors
DataOutputStream out;
try {
out = new DataOutputStream(clientSock.getOutputStream());
} catch (IOException e) {
throw new SOCKSException("Connection error", e);
}
// FIXME: here we should read our config file, select an
// outproxy, and instantiate the proper socket class that
// handles the outproxy itself (SOCKS4a, SOCKS4a, HTTP CONNECT...).
I2PSocket destSock;
try {
if (connHostName.toLowerCase(Locale.US).endsWith(".i2p")) {
Destination dest = _context.namingService().lookup(connHostName);
if (dest == null) {
try {
sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
} catch (IOException ioe) {
}
throw new SOCKSException("Host not found");
}
if (_log.shouldDebug())
_log.debug("connecting to " + connHostName + "...");
Properties overrides = new Properties();
I2PSocketOptions sktOpts = t.buildOptions(overrides);
sktOpts.setPort(connPort);
destSock = t.createI2PSocket(dest, sktOpts);
} else if ("localhost".equals(connHostName) || "127.0.0.1".equals(connHostName)) {
String err = "No localhost accesses allowed through the Socks Proxy";
_log.error(err);
try {
sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
} catch (IOException ioe) {
}
throw new SOCKSException(err);
/**
**
* } else if (connPort == 80) {
* // rewrite GET line to include hostname??? or add Host: line???
* // or forward to local eepProxy (but that's a Socket not an I2PSocket)
* // use eepProxy configured outproxies?
* String err = "No handler for HTTP outproxy implemented - to: " + connHostName;
* _log.error(err);
* try {
* sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
* } catch (IOException ioe) {}
* throw new SOCKSException(err);
***
*/
} else {
Outproxy outproxy = getOutproxyPlugin();
if (outproxy != null) {
try {
destSock = new SocketWrapper(outproxy.connect(connHostName, connPort));
} catch (IOException ioe) {
try {
sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
} catch (IOException ioe2) {
}
throw new SOCKSException("connect failed via outproxy plugin", ioe);
}
} else {
List<String> proxies = t.getProxies(connPort);
if (proxies == null || proxies.isEmpty()) {
String err = "No outproxy configured for port " + connPort + " and no default configured either - host: " + connHostName;
_log.error(err);
try {
sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
} catch (IOException ioe) {
}
throw new SOCKSException(err);
}
int p = _context.random().nextInt(proxies.size());
String proxy = proxies.get(p);
Destination dest = _context.namingService().lookup(proxy);
if (dest == null) {
try {
sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
} catch (IOException ioe) {
}
throw new SOCKSException("Outproxy not found");
}
if (_log.shouldDebug())
_log.debug("connecting to port " + connPort + " proxy " + proxy + " for " + connHostName + "...");
// this isn't going to work, these need to be socks outproxies so we need
// to do a socks session to them?
destSock = t.createI2PSocket(dest);
}
}
confirmConnection();
_log.debug("connection confirmed - exchanging data...");
} catch (DataFormatException e) {
try {
sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
} catch (IOException ioe) {
}
throw new SOCKSException("Error in destination format", e);
} catch (IOException e) {
try {
sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
} catch (IOException ioe) {
}
throw new SOCKSException("Error connecting", e);
} catch (I2PException e) {
try {
sendRequestReply(Reply.CONNECTION_REFUSED, InetAddress.getByName("127.0.0.1"), 0, out);
} catch (IOException ioe) {
}
throw new SOCKSException("Error connecting", e);
}
return destSock;
}
use of net.i2p.client.streaming.I2PSocketOptions in project i2p.i2p by i2p.
the class SOCKS5Server method outproxyConnect.
/**
* Act as a SOCKS 5 client to connect to an outproxy
* @return open socket or throws error
* @since 0.8.2
*/
private I2PSocket outproxyConnect(I2PSOCKSTunnel tun, String proxy) throws IOException, I2PException {
Properties overrides = new Properties();
overrides.setProperty("option.i2p.streaming.connectDelay", "1000");
I2PSocketOptions proxyOpts = tun.buildOptions(overrides);
Destination dest = _context.namingService().lookup(proxy);
if (dest == null)
throw new SOCKSException("Outproxy not found");
I2PSocket destSock = tun.createI2PSocket(dest, proxyOpts);
OutputStream out = null;
InputStream in = null;
try {
out = destSock.getOutputStream();
in = destSock.getInputStream();
boolean authAvail = Boolean.parseBoolean(props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_AUTH));
String configUser = null;
String configPW = null;
if (authAvail) {
configUser = props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_USER_PREFIX + proxy);
configPW = props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_PW_PREFIX + proxy);
if (configUser == null || configPW == null) {
configUser = props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_USER);
configPW = props.getProperty(I2PTunnelHTTPClientBase.PROP_OUTPROXY_PW);
}
}
SOCKS5Client.connect(in, out, connHostName, connPort, configUser, configPW);
} catch (IOException e) {
try {
destSock.close();
} catch (IOException ioe) {
}
if (in != null)
try {
in.close();
} catch (IOException ioe) {
}
if (out != null)
try {
out.close();
} catch (IOException ioe) {
}
throw e;
}
// that's it, caller will send confirmation to our client
return destSock;
}
Aggregations