forked from I2P_Developers/i2p.i2p
SOCKS: Fix NPE on lookup failure in SOCKS 4a
Remove duplicate lookups in SOCKS 5 Log tweaks Streaming, i2ptunnel: Catch null destination in connect() calls Synchronize Connection.setRemotePeer(); remove _remotePeerSet field
This commit is contained in:
@ -825,16 +825,23 @@ class Connection {
|
||||
public void schedule(SimpleTimer.TimedEvent event, long msToWait) {
|
||||
_timer.addEvent(event, msToWait);
|
||||
}
|
||||
|
||||
private boolean _remotePeerSet = false;
|
||||
|
||||
/** who are we talking with
|
||||
* @return peer Destination
|
||||
* @return peer Destination or null if unset
|
||||
*/
|
||||
public synchronized Destination getRemotePeer() { return _remotePeer; }
|
||||
|
||||
/**
|
||||
* @param peer non-null
|
||||
*/
|
||||
public Destination getRemotePeer() { return _remotePeer; }
|
||||
public void setRemotePeer(Destination peer) {
|
||||
if (_remotePeerSet) throw new RuntimeException("Remote peer already set [" + _remotePeer + ", " + peer + "]");
|
||||
_remotePeerSet = true;
|
||||
_remotePeer = peer;
|
||||
if (peer == null)
|
||||
throw new NullPointerException();
|
||||
synchronized(this) {
|
||||
if (_remotePeer != null)
|
||||
throw new RuntimeException("Remote peer already set [" + _remotePeer + ", " + peer + "]");
|
||||
_remotePeer = peer;
|
||||
}
|
||||
// now that we know who the other end is, get the rtt etc. from the cache
|
||||
_connectionManager.updateOptsFromShare(this);
|
||||
}
|
||||
@ -1220,7 +1227,7 @@ class Connection {
|
||||
buf.append(" from ");
|
||||
else
|
||||
buf.append(" to ");
|
||||
if (_remotePeerSet)
|
||||
if (_remotePeer != null)
|
||||
buf.append(_remotePeer.calculateHash().toBase64().substring(0,4));
|
||||
else
|
||||
buf.append("unknown");
|
||||
|
@ -395,12 +395,14 @@ class ConnectionManager {
|
||||
* Build a new connection to the given peer. This blocks if there is no
|
||||
* connection delay, otherwise it returns immediately.
|
||||
*
|
||||
* @param peer Destination to contact
|
||||
* @param peer Destination to contact, non-null
|
||||
* @param opts Connection's options
|
||||
* @param session generally the session from the constructor, but could be a subsession
|
||||
* @return new connection, or null if we have exceeded our limit
|
||||
*/
|
||||
public Connection connect(Destination peer, ConnectionOptions opts, I2PSession session) {
|
||||
if (peer == null)
|
||||
throw new NullPointerException();
|
||||
Connection con = null;
|
||||
long expiration = _context.clock().now();
|
||||
long tmout = opts.getConnectTimeout();
|
||||
|
@ -479,7 +479,13 @@ class ConnectionPacketHandler {
|
||||
if (con.getSendStreamId() <= 0) {
|
||||
if (packet.isFlagSet(Packet.FLAG_SYNCHRONIZE)) {
|
||||
con.setSendStreamId(packet.getReceiveStreamId());
|
||||
con.setRemotePeer(packet.getOptionalFrom());
|
||||
Destination dest = packet.getOptionalFrom();
|
||||
if (dest == null) {
|
||||
if (_log.shouldWarn())
|
||||
_log.warn("SYN Packet without FROM");
|
||||
return false;
|
||||
}
|
||||
con.setRemotePeer(dest);
|
||||
return true;
|
||||
} else {
|
||||
// neither RST nor SYN and we dont have the stream id yet?
|
||||
|
@ -524,6 +524,8 @@ public class I2PSocketManagerFull implements I2PSocketManager {
|
||||
*/
|
||||
public I2PSocket connect(Destination peer, I2PSocketOptions options)
|
||||
throws I2PException, NoRouteToHostException {
|
||||
if (peer == null)
|
||||
throw new NullPointerException();
|
||||
if (options == null)
|
||||
options = _defaultOptions;
|
||||
ConnectionOptions opts = null;
|
||||
|
Reference in New Issue
Block a user