summaryrefslogtreecommitdiff
path: root/java/src
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2014-08-07 12:18:42 -0230
committerDwayne Boone <dwayne@zeroc.com>2014-08-07 12:18:42 -0230
commit232fa424a7339659b6ad2cd02fbfe89420457601 (patch)
tree978d9e9286c2915b771f8bea019276ab216eecc4 /java/src
parentWindows SSL SChannel implementation & OS X Secure Transport fixes. (diff)
downloadice-232fa424a7339659b6ad2cd02fbfe89420457601.tar.bz2
ice-232fa424a7339659b6ad2cd02fbfe89420457601.tar.xz
ice-232fa424a7339659b6ad2cd02fbfe89420457601.zip
ICE-5457 added ability to set source address for connections
Diffstat (limited to 'java/src')
-rw-r--r--java/src/IceInternal/DefaultsAndOverrides.java36
-rw-r--r--java/src/IceInternal/IPEndpointI.java112
-rw-r--r--java/src/IceInternal/Network.java121
-rw-r--r--java/src/IceInternal/PropertyNames.java29
-rw-r--r--java/src/IceInternal/ProtocolInstance.java5
-rw-r--r--java/src/IceInternal/TcpConnector.java19
-rw-r--r--java/src/IceInternal/TcpEndpointI.java13
-rw-r--r--java/src/IceInternal/UdpConnector.java17
-rw-r--r--java/src/IceInternal/UdpEndpointI.java36
-rw-r--r--java/src/IceInternal/UdpTransceiver.java7
-rw-r--r--java/src/IceSSL/ConnectorI.java15
-rw-r--r--java/src/IceSSL/EndpointI.java20
12 files changed, 312 insertions, 118 deletions
diff --git a/java/src/IceInternal/DefaultsAndOverrides.java b/java/src/IceInternal/DefaultsAndOverrides.java
index c1c233c71f0..db876a52c1f 100644
--- a/java/src/IceInternal/DefaultsAndOverrides.java
+++ b/java/src/IceInternal/DefaultsAndOverrides.java
@@ -14,11 +14,11 @@ public final class DefaultsAndOverrides
DefaultsAndOverrides(Ice.Properties properties)
{
String value;
-
+
defaultProtocol = properties.getPropertyWithDefault("Ice.Default.Protocol", "tcp");
value = properties.getProperty("Ice.Default.Host");
- if(value.length() != 0)
+ if(!value.isEmpty())
{
defaultHost = value;
}
@@ -26,9 +26,24 @@ public final class DefaultsAndOverrides
{
defaultHost = null;
}
-
+
+ value = properties.getProperty("Ice.Default.SourceAddress");
+ if(!value.isEmpty())
+ {
+ defaultSourceAddress = Network.getNumericAddress(value);
+ if(defaultSourceAddress == null)
+ {
+ throw new Ice.InitializationException("invalid IP address set for Ice.Default.SourceAddress: `" +
+ value + "'");
+ }
+ }
+ else
+ {
+ defaultSourceAddress = null;
+ }
+
value = properties.getProperty("Ice.Override.Timeout");
- if(value.length() > 0)
+ if(!value.isEmpty())
{
overrideTimeout = true;
overrideTimeoutValue = properties.getPropertyAsInt("Ice.Override.Timeout");
@@ -40,7 +55,7 @@ public final class DefaultsAndOverrides
}
value = properties.getProperty("Ice.Override.ConnectTimeout");
- if(value.length() > 0)
+ if(!value.isEmpty())
{
overrideConnectTimeout = true;
overrideConnectTimeoutValue = properties.getPropertyAsInt("Ice.Override.ConnectTimeout");
@@ -52,7 +67,7 @@ public final class DefaultsAndOverrides
}
value = properties.getProperty("Ice.Override.CloseTimeout");
- if(value.length() > 0)
+ if(!value.isEmpty())
{
overrideCloseTimeout = true;
overrideCloseTimeoutValue = properties.getPropertyAsInt("Ice.Override.CloseTimeout");
@@ -64,7 +79,7 @@ public final class DefaultsAndOverrides
}
value = properties.getProperty("Ice.Override.Compress");
- if(value.length() > 0)
+ if(!value.isEmpty())
{
overrideCompress = true;
boolean b = properties.getPropertyAsInt("Ice.Override.Compress") > 0;
@@ -82,7 +97,7 @@ public final class DefaultsAndOverrides
}
value = properties.getProperty("Ice.Override.Secure");
- if(value.length() > 0)
+ if(!value.isEmpty())
{
overrideSecure = true;
overrideSecureValue = properties.getPropertyAsInt("Ice.Override.Secure") > 0;
@@ -117,16 +132,17 @@ public final class DefaultsAndOverrides
defaultPreferSecure = properties.getPropertyAsIntWithDefault("Ice.Default.PreferSecure", 0) > 0;
- value = properties.getPropertyWithDefault("Ice.Default.EncodingVersion",
+ value = properties.getPropertyWithDefault("Ice.Default.EncodingVersion",
Ice.Util.encodingVersionToString(Protocol.currentEncoding));
defaultEncoding = Ice.Util.stringToEncodingVersion(value);
- Protocol.checkSupportedEncoding(defaultEncoding);
+ Protocol.checkSupportedEncoding(defaultEncoding);
boolean slicedFormat = properties.getPropertyAsIntWithDefault("Ice.Default.SlicedFormat", 0) > 0;
defaultFormat = slicedFormat ? Ice.FormatType.SlicedFormat : Ice.FormatType.CompactFormat;
}
final public String defaultHost;
+ final public java.net.InetSocketAddress defaultSourceAddress;
final public String defaultProtocol;
final public boolean defaultCollocationOptimization;
final public Ice.EndpointSelectionType defaultEndpointSelection;
diff --git a/java/src/IceInternal/IPEndpointI.java b/java/src/IceInternal/IPEndpointI.java
index ebf0da9bdbd..1f00c8099a4 100644
--- a/java/src/IceInternal/IPEndpointI.java
+++ b/java/src/IceInternal/IPEndpointI.java
@@ -11,11 +11,13 @@ package IceInternal;
public abstract class IPEndpointI extends EndpointI
{
- protected IPEndpointI(ProtocolInstance instance, String host, int port, String connectionId)
+ protected IPEndpointI(ProtocolInstance instance, String host, int port, java.net.InetSocketAddress sourceAddr,
+ String connectionId)
{
_instance = instance;
_host = host;
_port = port;
+ _sourceAddr = sourceAddr;
_connectionId = connectionId;
_hashInitialized = false;
}
@@ -25,6 +27,7 @@ public abstract class IPEndpointI extends EndpointI
_instance = instance;
_host = null;
_port = 0;
+ _sourceAddr = null;
_connectionId = "";
_hashInitialized = false;
}
@@ -34,6 +37,7 @@ public abstract class IPEndpointI extends EndpointI
_instance = instance;
_host = s.readString();
_port = s.readInt();
+ _sourceAddr = null;
_connectionId = "";
_hashInitialized = false;
}
@@ -130,7 +134,8 @@ public abstract class IPEndpointI extends EndpointI
return false;
}
IPEndpointI ipEndpointI = (IPEndpointI)endpoint;
- return ipEndpointI.type() == type() && ipEndpointI._host.equals(_host) && ipEndpointI._port == _port;
+ return ipEndpointI.type() == type() && ipEndpointI._host.equals(_host) && ipEndpointI._port == _port &&
+ Network.compareAddress(ipEndpointI._sourceAddr, _sourceAddr) == 0;
}
public java.util.List<Connector> connectors(java.util.List<java.net.InetSocketAddress> addresses,
@@ -184,6 +189,11 @@ public abstract class IPEndpointI extends EndpointI
s += " -p " + _port;
+ if(_sourceAddr != null)
+ {
+ s += " --sourceAddress " + _sourceAddr.getAddress().getHostAddress();
+ }
+
return s;
}
@@ -215,6 +225,12 @@ public abstract class IPEndpointI extends EndpointI
return 1;
}
+ int rc = Network.compareAddress(_sourceAddr, p._sourceAddr);
+ if(rc != 0)
+ {
+ return rc;
+ }
+
return _connectionId.compareTo(p._connectionId);
}
@@ -238,6 +254,10 @@ public abstract class IPEndpointI extends EndpointI
{
h = HashUtil.hashAdd(h, _host);
h = HashUtil.hashAdd(h, _port);
+ if(_sourceAddr != null)
+ {
+ h = HashUtil.hashAdd(h, _sourceAddr.getAddress().getHostAddress());
+ }
h = HashUtil.hashAdd(h, _connectionId);
return h;
}
@@ -246,6 +266,7 @@ public abstract class IPEndpointI extends EndpointI
{
info.host = _host;
info.port = _port;
+ info.sourceAddress = _sourceAddr == null ? "" : _sourceAddr.getAddress().getHostAddress();
}
public void initWithOptions(java.util.ArrayList<String> args, boolean oaEndpoint)
@@ -272,53 +293,73 @@ public abstract class IPEndpointI extends EndpointI
{
_host = "";
}
+
+ if(_sourceAddr == null)
+ {
+ if (!oaEndpoint)
+ {
+ _sourceAddr = _instance.defaultSourceAddress();
+ }
+ }
+ else if(oaEndpoint)
+ {
+ throw new Ice.EndpointParseException("`--sourceAddress' not valid for object adapter endpoint `" +
+ toString() + "'");
+ }
}
protected boolean checkOption(String option, String argument, String endpoint)
{
- switch(option.charAt(1))
+ if(option.equals("-h"))
{
- case 'h':
+ if(argument == null)
{
- if(argument == null)
- {
- throw new Ice.EndpointParseException("no argument provided for -h option in endpoint " + endpoint);
- }
- _host = argument;
- return true;
+ throw new Ice.EndpointParseException("no argument provided for -h option in endpoint " + endpoint);
}
-
- case 'p':
+ _host = argument;
+ }
+ else if(option.equals("-p"))
+ {
+ if(argument == null)
{
- if(argument == null)
- {
- throw new Ice.EndpointParseException("no argument provided for -p option in endpoint " + endpoint);
- }
-
- try
- {
- _port = Integer.parseInt(argument);
- }
- catch(NumberFormatException ex)
- {
- throw new Ice.EndpointParseException("invalid port value `" + argument +
- "' in endpoint " + endpoint);
- }
-
- if(_port < 0 || _port > 65535)
- {
- throw new Ice.EndpointParseException("port value `" + argument +
- "' out of range in endpoint " + endpoint);
- }
+ throw new Ice.EndpointParseException("no argument provided for -p option in endpoint " + endpoint);
+ }
- return true;
+ try
+ {
+ _port = Integer.parseInt(argument);
+ }
+ catch(NumberFormatException ex)
+ {
+ throw new Ice.EndpointParseException("invalid port value `" + argument +
+ "' in endpoint " + endpoint);
}
- default:
+ if(_port < 0 || _port > 65535)
+ {
+ throw new Ice.EndpointParseException("port value `" + argument +
+ "' out of range in endpoint " + endpoint);
+ }
+ }
+ else if(option.equals("--sourceAddress"))
+ {
+ if(argument == null)
{
- return false;
+ throw new Ice.EndpointParseException("no argument provided for --sourceAddress option in endpoint " +
+ endpoint);
}
+ _sourceAddr = Network.getNumericAddress(argument);
+ if(_sourceAddr == null)
+ {
+ throw new Ice.EndpointParseException(
+ "invalid IP address provided for --sourceAddress option in endpoint " + endpoint);
+ }
+ }
+ else
+ {
+ return false;
}
+ return true;
}
protected abstract Connector createConnector(java.net.InetSocketAddress addr, NetworkProxy proxy);
@@ -327,6 +368,7 @@ public abstract class IPEndpointI extends EndpointI
protected ProtocolInstance _instance;
protected String _host;
protected int _port;
+ protected java.net.InetSocketAddress _sourceAddr;
protected String _connectionId;
private boolean _hashInitialized;
private int _hashValue;
diff --git a/java/src/IceInternal/Network.java b/java/src/IceInternal/Network.java
index 975f5b51ffe..01f357a339d 100644
--- a/java/src/IceInternal/Network.java
+++ b/java/src/IceInternal/Network.java
@@ -16,6 +16,46 @@ public final class Network
public final static int EnableIPv6 = 1;
public final static int EnableBoth = 2;
+ private static java.util.regex.Pattern IPV4_PATTERN = null;
+ private static java.util.regex.Pattern IPV6_PATTERN = null;
+ private final static String ipv4Pattern =
+ "(([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\.){3}([01]?\\d\\d?|2[0-4]\\d|25[0-5])";
+ private final static String ipv6Pattern =
+ "(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-" +
+ "fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1" +
+ ",4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1," +
+ "4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-" +
+ "F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])" +
+ "\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}" +
+ "[0-9]){0,1}[0-9])\\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))";
+
+ static
+ {
+ try
+ {
+ IPV4_PATTERN =
+ java.util.regex.Pattern.compile(ipv4Pattern, java.util.regex.Pattern.CASE_INSENSITIVE);
+ IPV6_PATTERN =
+ java.util.regex.Pattern.compile(ipv6Pattern, java.util.regex.Pattern.CASE_INSENSITIVE);
+ }
+ catch (java.util.regex.PatternSyntaxException ex)
+ {
+ assert(false);
+ }
+ }
+
+ public static boolean
+ isNumericAddress(String ipAddress)
+ {
+ java.util.regex.Matcher ipv4 = IPV4_PATTERN.matcher(ipAddress);
+ if(ipv4.matches())
+ {
+ return true;
+ }
+ java.util.regex.Matcher ipv6 = IPV6_PATTERN.matcher(ipAddress);
+ return ipv6.matches();
+ }
+
public static boolean
connectionRefused(java.net.ConnectException ex)
{
@@ -31,7 +71,7 @@ public final class Network
if(msg != null)
{
msg = msg.toLowerCase();
-
+
final String[] msgs =
{
"connection refused", // ECONNREFUSED
@@ -156,7 +196,7 @@ public final class Network
}
catch(java.lang.reflect.InvocationTargetException ex)
{
- throw new Ice.SocketException(ex);
+ throw new Ice.SocketException(ex);
}
catch(NoSuchMethodException ex)
{
@@ -305,8 +345,22 @@ public final class Network
}
public static boolean
- doConnect(java.nio.channels.SocketChannel fd, java.net.InetSocketAddress addr)
+ doConnect(java.nio.channels.SocketChannel fd, java.net.InetSocketAddress addr,
+ java.net.InetSocketAddress sourceAddr)
{
+ if(sourceAddr != null)
+ {
+ try
+ {
+ fd.bind(sourceAddr);
+ }
+ catch(java.io.IOException ex)
+ {
+ closeSocketNoThrow(fd);
+ throw new Ice.SocketException(ex);
+ }
+ }
+
try
{
if(!fd.connect(addr))
@@ -368,7 +422,7 @@ public final class Network
{
throw new Ice.ConnectFailedException();
}
-
+
if(System.getProperty("os.name").equals("Linux"))
{
//
@@ -401,8 +455,14 @@ public final class Network
}
public static void
- doConnect(java.nio.channels.DatagramChannel fd, java.net.InetSocketAddress addr)
+ doConnect(java.nio.channels.DatagramChannel fd, java.net.InetSocketAddress addr,
+ java.net.InetSocketAddress sourceAddr)
{
+ if(sourceAddr != null)
+ {
+ doBind(fd, sourceAddr);
+ }
+
try
{
fd.connect(addr);
@@ -677,7 +737,7 @@ public final class Network
public static java.net.InetSocketAddress
getAddressForServer(String host, int port, int protocol, boolean preferIPv6)
- {
+ {
if(host == null || host.length() == 0)
{
try
@@ -699,7 +759,7 @@ public final class Network
catch(java.lang.SecurityException ex)
{
throw new Ice.SocketException(ex);
- }
+ }
}
return getAddresses(host, port, protocol, Ice.EndpointSelectionType.Ordered, preferIPv6).get(0);
}
@@ -707,6 +767,22 @@ public final class Network
public static int
compareAddress(java.net.InetSocketAddress addr1, java.net.InetSocketAddress addr2)
{
+ if(addr1 == null)
+ {
+ if(addr2 == null)
+ {
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ else if(addr2 == null)
+ {
+ return 1;
+ }
+
if(addr1.getPort() < addr2.getPort())
{
return -1;
@@ -841,7 +917,7 @@ public final class Network
{
throw new Ice.SocketException(ex);
}
-
+
//
// No Inet4Address/Inet6Address available.
//
@@ -938,7 +1014,7 @@ public final class Network
for(java.net.InetAddress addr : addrs)
{
//
- // NOTE: We don't publish link-local IPv6 addresses as these addresses can only
+ // NOTE: We don't publish link-local IPv6 addresses as these addresses can only
// be accessed in general with a scope-id.
//
if(!addr.isLinkLocalAddress())
@@ -946,14 +1022,14 @@ public final class Network
hosts.add(addr.getHostAddress());
}
}
-
+
if(includeLoopback || hosts.isEmpty())
{
if(protocolSupport != EnableIPv6)
{
hosts.add("127.0.0.1");
}
-
+
if(protocolSupport != EnableIPv4)
{
hosts.add("0:0:0:0:0:0:0:1");
@@ -962,7 +1038,7 @@ public final class Network
}
return hosts;
}
-
+
public static void
setTcpBufSize(java.nio.channels.SocketChannel socket, Ice.Properties properties, Ice.Logger logger)
{
@@ -1203,7 +1279,7 @@ public final class Network
{
bytes = addr.getAddress();
}
- return bytes != null &&
+ return bytes != null &&
((bytes.length == 16 && protocol == EnableIPv6) ||
(bytes.length == 4 && protocol == EnableIPv4));
}
@@ -1264,13 +1340,30 @@ public final class Network
}
}
+ public static java.net.InetSocketAddress
+ getNumericAddress(String address)
+ {
+ java.net.InetSocketAddress addr = null;
+ if(!address.isEmpty() && isNumericAddress(address))
+ {
+ try
+ {
+ addr = new java.net.InetSocketAddress(java.net.InetAddress.getByName(address), 0);
+ }
+ catch(java.net.UnknownHostException ex)
+ {
+ }
+ }
+ return addr;
+ }
+
static class IPAddressComparator implements java.util.Comparator<java.net.InetSocketAddress>
{
IPAddressComparator(boolean ipv6)
{
_ipv6 = ipv6;
}
-
+
public int
compare(java.net.InetSocketAddress lhs, java.net.InetSocketAddress rhs)
{
diff --git a/java/src/IceInternal/PropertyNames.java b/java/src/IceInternal/PropertyNames.java
index efd52373272..ce5eee21f7c 100644
--- a/java/src/IceInternal/PropertyNames.java
+++ b/java/src/IceInternal/PropertyNames.java
@@ -14,7 +14,7 @@ package IceInternal;
public final class PropertyNames
{
- public static final Property IceProps[] =
+ public static final Property IceProps[] =
{
new Property("Ice\\.ACM\\.Client", true, null),
new Property("Ice\\.ACM\\.Server", true, null),
@@ -107,6 +107,7 @@ public final class PropertyNames
new Property("Ice\\.Default\\.Router\\.Context\\.[^\\s]+", false, null),
new Property("Ice\\.Default\\.Router", false, null),
new Property("Ice\\.Default\\.SlicedFormat", false, null),
+ new Property("Ice\\.Default\\.SourceAddress", false, null),
new Property("Ice\\.IPv4", false, null),
new Property("Ice\\.IPv6", false, null),
new Property("Ice\\.EventLog\\.Source", false, null),
@@ -180,7 +181,7 @@ public final class PropertyNames
null
};
- public static final Property IceMXProps[] =
+ public static final Property IceMXProps[] =
{
new Property("IceMX\\.Metrics\\.[^\\s]+\\.GroupBy", false, null),
new Property("IceMX\\.Metrics\\.[^\\s]+\\.Map", false, null),
@@ -191,7 +192,7 @@ public final class PropertyNames
null
};
- public static final Property IceDiscoveryProps[] =
+ public static final Property IceDiscoveryProps[] =
{
new Property("IceDiscovery\\.Multicast\\.ACM\\.Timeout", false, null),
new Property("IceDiscovery\\.Multicast\\.ACM\\.Heartbeat", false, null),
@@ -312,7 +313,7 @@ public final class PropertyNames
null
};
- public static final Property IceGridDiscoveryProps[] =
+ public static final Property IceGridDiscoveryProps[] =
{
new Property("IceGridDiscovery\\.Reply\\.ACM\\.Timeout", false, null),
new Property("IceGridDiscovery\\.Reply\\.ACM\\.Heartbeat", false, null),
@@ -397,7 +398,7 @@ public final class PropertyNames
null
};
- public static final Property IceBoxProps[] =
+ public static final Property IceBoxProps[] =
{
new Property("IceBox\\.InheritProperties", false, null),
new Property("IceBox\\.InstanceName", false, null),
@@ -445,7 +446,7 @@ public final class PropertyNames
null
};
- public static final Property IceBoxAdminProps[] =
+ public static final Property IceBoxAdminProps[] =
{
new Property("IceBoxAdmin\\.ServiceManager\\.Proxy\\.EndpointSelection", false, null),
new Property("IceBoxAdmin\\.ServiceManager\\.Proxy\\.ConnectionCached", false, null),
@@ -460,7 +461,7 @@ public final class PropertyNames
null
};
- public static final Property IceGridAdminProps[] =
+ public static final Property IceGridAdminProps[] =
{
new Property("IceGridAdmin\\.AuthenticateUsingSSL", false, null),
new Property("IceGridAdmin\\.MetricsConfig", false, null),
@@ -514,7 +515,7 @@ public final class PropertyNames
null
};
- public static final Property IceGridProps[] =
+ public static final Property IceGridProps[] =
{
new Property("IceGrid\\.AdminRouter\\.ACM\\.Timeout", false, null),
new Property("IceGrid\\.AdminRouter\\.ACM\\.Heartbeat", false, null),
@@ -913,7 +914,7 @@ public final class PropertyNames
null
};
- public static final Property IcePatch2Props[] =
+ public static final Property IcePatch2Props[] =
{
new Property("IcePatch2\\.ACM\\.Timeout", false, null),
new Property("IcePatch2\\.ACM\\.Heartbeat", false, null),
@@ -959,7 +960,7 @@ public final class PropertyNames
null
};
- public static final Property IcePatch2ClientProps[] =
+ public static final Property IcePatch2ClientProps[] =
{
new Property("IcePatch2Client\\.ChunkSize", false, null),
new Property("IcePatch2Client\\.Directory", false, null),
@@ -969,7 +970,7 @@ public final class PropertyNames
null
};
- public static final Property IceSSLProps[] =
+ public static final Property IceSSLProps[] =
{
new Property("IceSSL\\.Alias", false, null),
new Property("IceSSL\\.CertAuthDir", false, null),
@@ -1015,7 +1016,7 @@ public final class PropertyNames
null
};
- public static final Property IceStormAdminProps[] =
+ public static final Property IceStormAdminProps[] =
{
new Property("IceStormAdmin\\.TopicManager\\.[^\\s]+", false, null),
new Property("IceStormAdmin\\.Host", false, null),
@@ -1023,7 +1024,7 @@ public final class PropertyNames
null
};
- public static final Property Glacier2Props[] =
+ public static final Property Glacier2Props[] =
{
new Property("Glacier2\\.AddSSLContext", true, null),
new Property("Glacier2\\.AddConnectionContext", false, null),
@@ -1169,7 +1170,7 @@ public final class PropertyNames
null
};
- public static final Property FreezeProps[] =
+ public static final Property FreezeProps[] =
{
new Property("Freeze\\.DbEnv\\.[^\\s]+\\.CheckpointPeriod", false, null),
new Property("Freeze\\.DbEnv\\.[^\\s]+\\.DbHome", false, null),
diff --git a/java/src/IceInternal/ProtocolInstance.java b/java/src/IceInternal/ProtocolInstance.java
index ee0b9074277..f78060cc172 100644
--- a/java/src/IceInternal/ProtocolInstance.java
+++ b/java/src/IceInternal/ProtocolInstance.java
@@ -67,6 +67,11 @@ public class ProtocolInstance
return _instance.defaultsAndOverrides().defaultHost;
}
+ public java.net.InetSocketAddress defaultSourceAddress()
+ {
+ return _instance.defaultsAndOverrides().defaultSourceAddress;
+ }
+
public Ice.EncodingVersion defaultEncoding()
{
return _instance.defaultsAndOverrides().defaultEncoding;
diff --git a/java/src/IceInternal/TcpConnector.java b/java/src/IceInternal/TcpConnector.java
index 4e1ff9ff5e1..4f199ec29a1 100644
--- a/java/src/IceInternal/TcpConnector.java
+++ b/java/src/IceInternal/TcpConnector.java
@@ -25,7 +25,7 @@ final class TcpConnector implements Connector
Network.setBlock(fd, false);
Network.setTcpBufSize(fd, _instance.properties(), _instance.logger());
final java.net.InetSocketAddress addr = _proxy != null ? _proxy.getAddress() : _addr;
- Network.doConnect(fd, addr);
+ Network.doConnect(fd, addr, _sourceAddr);
return new TcpTransceiver(_instance, fd, _proxy, _addr);
}
catch(Ice.LocalException ex)
@@ -57,18 +57,23 @@ final class TcpConnector implements Connector
//
// Only for use by TcpEndpoint
//
- TcpConnector(ProtocolInstance instance, java.net.InetSocketAddress addr, NetworkProxy proxy, int timeout,
- String connectionId)
+ TcpConnector(ProtocolInstance instance, java.net.InetSocketAddress addr, NetworkProxy proxy,
+ java.net.InetSocketAddress sourceAddr, int timeout, String connectionId)
{
_instance = instance;
_addr = addr;
_proxy = proxy;
+ _sourceAddr = sourceAddr;
_timeout = timeout;
_connectionId = connectionId;
_hashCode = 5381;
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getAddress().getHostAddress());
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getPort());
+ if(_sourceAddr != null)
+ {
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _sourceAddr.getAddress().getHostAddress());
+ }
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _timeout);
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _connectionId);
}
@@ -96,12 +101,18 @@ final class TcpConnector implements Connector
return false;
}
+ if(Network.compareAddress(_sourceAddr, p._sourceAddr) != 0)
+ {
+ return false;
+ }
+
return Network.compareAddress(_addr, p._addr) == 0;
- }
+ }
private ProtocolInstance _instance;
private java.net.InetSocketAddress _addr;
private NetworkProxy _proxy;
+ private java.net.InetSocketAddress _sourceAddr;
private int _timeout;
private String _connectionId = "";
private int _hashCode;
diff --git a/java/src/IceInternal/TcpEndpointI.java b/java/src/IceInternal/TcpEndpointI.java
index 28ab17d227c..fdbd187ee93 100644
--- a/java/src/IceInternal/TcpEndpointI.java
+++ b/java/src/IceInternal/TcpEndpointI.java
@@ -11,9 +11,10 @@ package IceInternal;
final class TcpEndpointI extends IPEndpointI
{
- public TcpEndpointI(ProtocolInstance instance, String ho, int po, int ti, String conId, boolean co)
+ public TcpEndpointI(ProtocolInstance instance, String ho, int po, java.net.InetSocketAddress sourceAddr, int ti,
+ String conId, boolean co)
{
- super(instance, ho, po, conId);
+ super(instance, ho, po, sourceAddr, conId);
_timeout = ti;
_compress = co;
}
@@ -81,7 +82,7 @@ final class TcpEndpointI extends IPEndpointI
}
else
{
- return new TcpEndpointI(_instance, _host, _port, timeout, _connectionId, _compress);
+ return new TcpEndpointI(_instance, _host, _port, _sourceAddr, timeout, _connectionId, _compress);
}
}
@@ -107,7 +108,7 @@ final class TcpEndpointI extends IPEndpointI
}
else
{
- return new TcpEndpointI(_instance, _host, _port, _timeout, _connectionId, compress);
+ return new TcpEndpointI(_instance, _host, _port, _sourceAddr, _timeout, _connectionId, compress);
}
}
@@ -292,12 +293,12 @@ final class TcpEndpointI extends IPEndpointI
protected Connector createConnector(java.net.InetSocketAddress addr, NetworkProxy proxy)
{
- return new TcpConnector(_instance, addr, proxy, _timeout, _connectionId);
+ return new TcpConnector(_instance, addr, proxy, _sourceAddr, _timeout, _connectionId);
}
protected IPEndpointI createEndpoint(String host, int port, String connectionId)
{
- return new TcpEndpointI(_instance, host, port, _timeout, connectionId, _compress);
+ return new TcpEndpointI(_instance, host, port, _sourceAddr, _timeout, connectionId, _compress);
}
private int _timeout;
diff --git a/java/src/IceInternal/UdpConnector.java b/java/src/IceInternal/UdpConnector.java
index 94ddf2d14cd..0bcd3a536e9 100644
--- a/java/src/IceInternal/UdpConnector.java
+++ b/java/src/IceInternal/UdpConnector.java
@@ -13,7 +13,7 @@ final class UdpConnector implements Connector
{
public Transceiver connect()
{
- return new UdpTransceiver(_instance, _addr, _mcastInterface, _mcastTtl);
+ return new UdpTransceiver(_instance, _addr, _sourceAddr, _mcastInterface, _mcastTtl);
}
public java.nio.channels.SelectableChannel fd()
@@ -40,11 +40,12 @@ final class UdpConnector implements Connector
//
// Only for use by UdpEndpointI
//
- UdpConnector(ProtocolInstance instance, java.net.InetSocketAddress addr, String mcastInterface, int mcastTtl,
- String connectionId)
+ UdpConnector(ProtocolInstance instance, java.net.InetSocketAddress addr, java.net.InetSocketAddress sourceAddr,
+ String mcastInterface, int mcastTtl, String connectionId)
{
_instance = instance;
_addr = addr;
+ _sourceAddr = sourceAddr;
_mcastInterface = mcastInterface;
_mcastTtl = mcastTtl;
_connectionId = connectionId;
@@ -52,6 +53,10 @@ final class UdpConnector implements Connector
_hashCode = 5381;
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getAddress().getHostAddress());
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getPort());
+ if(_sourceAddr != null)
+ {
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _sourceAddr.getAddress().getHostAddress());
+ }
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _mcastInterface);
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _mcastTtl);
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _connectionId);
@@ -85,11 +90,17 @@ final class UdpConnector implements Connector
return false;
}
+ if(Network.compareAddress(_sourceAddr, p._sourceAddr) != 0)
+ {
+ return false;
+ }
+
return Network.compareAddress(_addr, p._addr) == 0;
}
private ProtocolInstance _instance;
private java.net.InetSocketAddress _addr;
+ private java.net.InetSocketAddress _sourceAddr;
private String _mcastInterface;
private int _mcastTtl;
private String _connectionId;
diff --git a/java/src/IceInternal/UdpEndpointI.java b/java/src/IceInternal/UdpEndpointI.java
index 9bda0e86d4b..8d17a61c19c 100644
--- a/java/src/IceInternal/UdpEndpointI.java
+++ b/java/src/IceInternal/UdpEndpointI.java
@@ -11,11 +11,11 @@ package IceInternal;
final class UdpEndpointI extends IPEndpointI
{
- public UdpEndpointI(ProtocolInstance instance, String ho, int po, String mif, int mttl, boolean conn, String conId,
- boolean co)
+ public UdpEndpointI(ProtocolInstance instance, String ho, int po, java.net.InetSocketAddress sourceAddr,
+ String mcastInterface, int mttl, boolean conn, String conId, boolean co)
{
- super(instance, ho, po, conId);
- _mcastInterface = mif;
+ super(instance, ho, po, sourceAddr, conId);
+ _mcastInterface = mcastInterface;
_mcastTtl = mttl;
_connect = conn;
_compress = co;
@@ -112,8 +112,8 @@ final class UdpEndpointI extends IPEndpointI
}
else
{
- return new UdpEndpointI(_instance, _host, _port, _mcastInterface, _mcastTtl, _connect, _connectionId,
- compress);
+ return new UdpEndpointI(_instance, _host, _port, _sourceAddr, _mcastInterface, _mcastTtl, _connect,
+ _connectionId, compress);
}
}
@@ -334,16 +334,6 @@ final class UdpEndpointI extends IPEndpointI
endpoint + ":\n" + e.str);
}
}
- else if(option.equals("--interface"))
- {
- if(argument == null)
- {
- throw new Ice.EndpointParseException("no argument provided for --interface option in endpoint "
- + endpoint);
- }
-
- _mcastInterface = argument;
- }
else if(option.equals("--ttl"))
{
if(argument == null)
@@ -366,6 +356,15 @@ final class UdpEndpointI extends IPEndpointI
endpoint);
}
}
+ else if(option.equals("--interface"))
+ {
+ if(argument == null)
+ {
+ throw new Ice.EndpointParseException("no argument provided for --interface option in endpoint " +
+ endpoint);
+ }
+ _mcastInterface = argument;
+ }
else
{
return false;
@@ -375,12 +374,13 @@ final class UdpEndpointI extends IPEndpointI
protected Connector createConnector(java.net.InetSocketAddress addr, NetworkProxy proxy)
{
- return new UdpConnector(_instance, addr, _mcastInterface, _mcastTtl, _connectionId);
+ return new UdpConnector(_instance, addr, _sourceAddr, _mcastInterface, _mcastTtl, _connectionId);
}
protected IPEndpointI createEndpoint(String host, int port, String connectionId)
{
- return new UdpEndpointI(_instance, host, port, _mcastInterface, _mcastTtl, _connect, connectionId, _compress);
+ return new UdpEndpointI(_instance, host, port, _sourceAddr, _mcastInterface,_mcastTtl, _connect,
+ connectionId, _compress);
}
private String _mcastInterface = "";
diff --git a/java/src/IceInternal/UdpTransceiver.java b/java/src/IceInternal/UdpTransceiver.java
index d8344adb130..80fea501e67 100644
--- a/java/src/IceInternal/UdpTransceiver.java
+++ b/java/src/IceInternal/UdpTransceiver.java
@@ -181,7 +181,7 @@ final class UdpTransceiver implements Transceiver
//
// If we must connect, we connect to the first peer that sends us a packet.
//
- Network.doConnect(_fd, _peerAddr);
+ Network.doConnect(_fd, _peerAddr, null);
_state = StateConnected;
if(_instance.traceLevel() >= 1)
@@ -297,7 +297,8 @@ final class UdpTransceiver implements Transceiver
// Only for use by UdpEndpoint
//
@SuppressWarnings("deprecation")
- UdpTransceiver(ProtocolInstance instance, java.net.InetSocketAddress addr, String mcastInterface, int mcastTtl)
+ UdpTransceiver(ProtocolInstance instance, java.net.InetSocketAddress addr, java.net.InetSocketAddress sourceAddr,
+ String mcastInterface, int mcastTtl)
{
_instance = instance;
_state = StateNeedConnect;
@@ -316,7 +317,7 @@ final class UdpTransceiver implements Transceiver
{
configureMulticast(null, mcastInterface, mcastTtl);
}
- Network.doConnect(_fd, _addr);
+ Network.doConnect(_fd, _addr, sourceAddr);
_state = StateConnected; // We're connected now
if(_instance.traceLevel() >= 1)
diff --git a/java/src/IceSSL/ConnectorI.java b/java/src/IceSSL/ConnectorI.java
index a373c8e5084..8dc715bcbd9 100644
--- a/java/src/IceSSL/ConnectorI.java
+++ b/java/src/IceSSL/ConnectorI.java
@@ -35,7 +35,7 @@ final class ConnectorI implements IceInternal.Connector
IceInternal.Network.setBlock(fd, false);
IceInternal.Network.setTcpBufSize(fd, _instance.properties(), _instance.logger());
final java.net.InetSocketAddress addr = _proxy != null ? _proxy.getAddress() : _addr;
- IceInternal.Network.doConnect(fd, addr);
+ IceInternal.Network.doConnect(fd, addr, _sourceAddr);
try
{
javax.net.ssl.SSLEngine engine = _instance.createSSLEngine(false, _addr);
@@ -77,11 +77,12 @@ final class ConnectorI implements IceInternal.Connector
// Only for use by EndpointI.
//
ConnectorI(Instance instance, String host, java.net.InetSocketAddress addr, IceInternal.NetworkProxy proxy,
- int timeout, String connectionId)
+ java.net.InetSocketAddress sourceAddr, int timeout, String connectionId)
{
_instance = instance;
_host = host;
_addr = addr;
+ _sourceAddr = sourceAddr;
_proxy = proxy;
_timeout = timeout;
_connectionId = connectionId;
@@ -89,6 +90,10 @@ final class ConnectorI implements IceInternal.Connector
_hashCode = 5381;
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getAddress().getHostAddress());
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _addr.getPort());
+ if(_sourceAddr != null)
+ {
+ _hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _sourceAddr.getAddress().getHostAddress());
+ }
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _timeout);
_hashCode = IceInternal.HashUtil.hashAdd(_hashCode , _connectionId);
}
@@ -116,6 +121,11 @@ final class ConnectorI implements IceInternal.Connector
return false;
}
+ if(IceInternal.Network.compareAddress(_sourceAddr, p._sourceAddr) != 0)
+ {
+ return false;
+ }
+
return IceInternal.Network.compareAddress(_addr, p._addr) == 0;
}
@@ -123,6 +133,7 @@ final class ConnectorI implements IceInternal.Connector
private String _host;
private java.net.InetSocketAddress _addr;
private IceInternal.NetworkProxy _proxy;
+ private java.net.InetSocketAddress _sourceAddr;
private int _timeout;
private String _connectionId;
private int _hashCode;
diff --git a/java/src/IceSSL/EndpointI.java b/java/src/IceSSL/EndpointI.java
index dfac583deee..0df306e6373 100644
--- a/java/src/IceSSL/EndpointI.java
+++ b/java/src/IceSSL/EndpointI.java
@@ -11,9 +11,10 @@ package IceSSL;
final class EndpointI extends IceInternal.IPEndpointI
{
- public EndpointI(Instance instance, String ho, int po, int ti, String conId, boolean co)
+ public EndpointI(Instance instance, String ho, int po, java.net.InetSocketAddress sourceAddr, int ti, String conId,
+ boolean co)
{
- super(instance, ho, po, conId);
+ super(instance, ho, po, sourceAddr, conId);
_instance = instance;
_timeout = ti;
_compress = co;
@@ -46,12 +47,12 @@ final class EndpointI extends IceInternal.IPEndpointI
{
return EndpointI.this.type();
}
-
+
public boolean datagram()
{
return EndpointI.this.datagram();
}
-
+
public boolean secure()
{
return EndpointI.this.secure();
@@ -84,7 +85,7 @@ final class EndpointI extends IceInternal.IPEndpointI
}
else
{
- return new EndpointI(_instance, _host, _port, timeout, _connectionId, _compress);
+ return new EndpointI(_instance, _host, _port, _sourceAddr, timeout, _connectionId, _compress);
}
}
@@ -110,7 +111,7 @@ final class EndpointI extends IceInternal.IPEndpointI
}
else
{
- return new EndpointI(_instance, _host, _port, _timeout, _connectionId, compress);
+ return new EndpointI(_instance, _host, _port, _sourceAddr, _timeout, _connectionId, compress);
}
}
@@ -153,7 +154,8 @@ final class EndpointI extends IceInternal.IPEndpointI
public IceInternal.Acceptor acceptor(IceInternal.EndpointIHolder endpoint, String adapterName)
{
AcceptorI p = new AcceptorI(_instance, adapterName, _host, _port);
- endpoint.value = new EndpointI(_instance, _host, p.effectivePort(), _timeout, _connectionId, _compress);
+ endpoint.value =
+ new EndpointI(_instance, _host, p.effectivePort(), _sourceAddr, _timeout, _connectionId, _compress);
return p;
}
@@ -294,12 +296,12 @@ final class EndpointI extends IceInternal.IPEndpointI
protected IceInternal.Connector createConnector(java.net.InetSocketAddress addr, IceInternal.NetworkProxy proxy)
{
- return new ConnectorI(_instance, _host, addr, proxy, _timeout, _connectionId);
+ return new ConnectorI(_instance, _host, addr, proxy, _sourceAddr, _timeout, _connectionId);
}
protected IceInternal.IPEndpointI createEndpoint(String host, int port, String connectionId)
{
- return new EndpointI(_instance, host, port, _timeout, connectionId, _compress);
+ return new EndpointI(_instance, host, port, _sourceAddr, _timeout, connectionId, _compress);
}
private Instance _instance;