Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added external_port to TP, FD_SOCK and STATE_TRANSFER (https://issues…

  • Loading branch information...
commit 144931816a0fc53c0ab00a5cf0ebaa6304bc2ed3 1 parent 49c801e
@belaban authored
View
2  src/org/jgroups/Global.java
@@ -29,6 +29,8 @@
public static final String BIND_ADDR="jgroups.bind_addr";
public static final String EXTERNAL_ADDR="jgroups.external_addr";
+ public static final String EXTERNAL_PORT="jgroups.external_port";
+
public static final String BIND_INTERFACE="jgroups.bind_interface";
public static final String IGNORE_BIND_ADDRESS_PROPERTY="jgroups.ignore.bind_addr";
View
1  src/org/jgroups/blocks/BasicConnectionTable.java
@@ -59,6 +59,7 @@
* be contacted on). If external_addr is null, it will default to the same address that the server socket is bound to.
*/
InetAddress external_addr=null;
+ int external_port=0;
int max_port=0; // maximum port to bind to (if < srv_port, no limit)
Thread acceptor=null; // continuously calls srv_sock.accept()
boolean running=false;
View
18 src/org/jgroups/blocks/ConnectionTableNIO.java
@@ -91,11 +91,12 @@ public ConnectionTableNIO(int srv_port, long reaper_interval,
* @param max_port
* @throws Exception
*/
- public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress external_addr, int srv_port, int max_port)
+ public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress external_addr, int external_port, int srv_port, int max_port)
throws Exception
{
setReceiver(r);
this.external_addr=external_addr;
+ this.external_port=external_port;
this.bind_addr=bind_addr;
this.srv_port=srv_port;
this.max_port=max_port;
@@ -104,12 +105,13 @@ public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress externa
}
- public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress external_addr,
+ public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress external_addr, int external_port,
int srv_port, int max_port, boolean doStart)
throws Exception
{
setReceiver(r);
this.external_addr=external_addr;
+ this.external_port=external_port;
this.bind_addr=bind_addr;
this.srv_port=srv_port;
this.max_port=max_port;
@@ -130,13 +132,15 @@ public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress externa
* @param conn_expire_time
* @throws Exception
*/
- public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress external_addr, int srv_port, int max_port,
+ public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress external_addr, int external_port,
+ int srv_port, int max_port,
long reaper_interval, long conn_expire_time
) throws Exception
{
setReceiver(r);
this.bind_addr=bind_addr;
this.external_addr=external_addr;
+ this.external_port=external_port;
this.srv_port=srv_port;
this.max_port=max_port;
this.reaper_interval=reaper_interval;
@@ -146,7 +150,7 @@ public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress externa
}
- public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress external_addr,
+ public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress external_addr, int external_port,
int srv_port, int max_port,
long reaper_interval, long conn_expire_time, boolean doStart
) throws Exception
@@ -154,6 +158,7 @@ public ConnectionTableNIO(Receiver r, InetAddress bind_addr, InetAddress externa
setReceiver(r);
this.bind_addr=bind_addr;
this.external_addr=external_addr;
+ this.external_port=external_port;
this.srv_port=srv_port;
this.max_port=max_port;
this.reaper_interval=reaper_interval;
@@ -298,8 +303,9 @@ public final void start() throws Exception {
init();
srv_sock=createServerSocket(srv_port, max_port);
- if (external_addr!=null)
- local_addr=new IpAddress(external_addr, srv_sock.getLocalPort());
+ if (external_addr!=null) {
+ local_addr=new IpAddress(external_addr, external_port == 0? srv_sock.getLocalPort() : external_port);
+ }
else if (bind_addr != null)
local_addr=new IpAddress(bind_addr, srv_sock.getLocalPort());
else
View
16 src/org/jgroups/blocks/TCPConnectionMap.java
@@ -1,7 +1,6 @@
package org.jgroups.blocks;
import org.jgroups.Address;
-import org.jgroups.Global;
import org.jgroups.Version;
import org.jgroups.logging.Log;
import org.jgroups.logging.LogFactory;
@@ -49,11 +48,12 @@ public TCPConnectionMap(String service_name,
Receiver r,
InetAddress bind_addr,
InetAddress external_addr,
+ int external_port,
int srv_port,
int max_port,
ThreadGroup group
) throws Exception {
- this(service_name, f,socket_factory, r,bind_addr,external_addr,srv_port,max_port,0,0, group);
+ this(service_name, f,socket_factory, r,bind_addr,external_addr,external_port, srv_port,max_port,0,0, group);
}
public TCPConnectionMap(String service_name,
@@ -61,13 +61,14 @@ public TCPConnectionMap(String service_name,
Receiver r,
InetAddress bind_addr,
InetAddress external_addr,
+ int external_port,
int srv_port,
int max_port,
long reaper_interval,
long conn_expire_time,
ThreadGroup group
) throws Exception {
- this(service_name, f, null, r, bind_addr, external_addr, srv_port, max_port, reaper_interval, conn_expire_time, group);
+ this(service_name, f, null, r, bind_addr, external_addr, external_port, srv_port, max_port, reaper_interval, conn_expire_time, group);
}
public TCPConnectionMap(String service_name,
@@ -76,6 +77,7 @@ public TCPConnectionMap(String service_name,
Receiver r,
InetAddress bind_addr,
InetAddress external_addr,
+ int external_port,
int srv_port,
int max_port,
long reaper_interval,
@@ -90,8 +92,12 @@ public TCPConnectionMap(String service_name,
this.socket_factory=socket_factory;
this.srv_sock=Util.createServerSocket(this.socket_factory, service_name, bind_addr, srv_port, max_port);
- if(external_addr != null)
- local_addr=new IpAddress(external_addr, srv_sock.getLocalPort());
+ if(external_addr != null) {
+ if(external_port <= 0)
+ local_addr=new IpAddress(external_addr, srv_sock.getLocalPort());
+ else
+ local_addr=new IpAddress(external_addr, external_port);
+ }
else if(bind_addr != null)
local_addr=new IpAddress(bind_addr, srv_sock.getLocalPort());
else
View
20 src/org/jgroups/protocols/FD_SOCK.java
@@ -49,7 +49,11 @@
"the local IP (e.g. 192.168.1.100) of the host then on each host, set \"external_addr\" TCP transport " +
"parameter to the external (public IP) address of the firewall.",
systemProperty=Global.EXTERNAL_ADDR,writable=false)
- protected InetAddress external_addr=null ;
+ protected InetAddress external_addr=null;
+
+ @Property(description="Used to map the internal port (bind_port) to an external port. Only used if > 0",
+ systemProperty=Global.EXTERNAL_PORT,writable=false)
+ protected int external_port=0;
@Property(name="bind_interface", converter=PropertyConverters.BindInterface.class,
description="The interface (NIC) which should be used by this transport", dependsUpon="bind_addr")
@@ -268,13 +272,15 @@ public Object up(Event evt) {
return null;
case Event.CONFIG:
- if(bind_addr == null) {
- Map<String,Object> config=(Map<String,Object>)evt.getArg();
+ Map<String,Object> config=(Map<String,Object>)evt.getArg();
+ if(bind_addr == null)
bind_addr=(InetAddress)config.get("bind_addr");
- }
- if(external_addr == null) {
- Map<String,Object> config=(Map<String,Object>)evt.getArg();
+ if(external_addr == null)
external_addr=(InetAddress)config.get("external_addr");
+ if(external_port <= 0) {
+ Object val=config.get("external_port");
+ if(val != null)
+ external_port=(Integer)val;
}
break;
}
@@ -561,7 +567,7 @@ void sendPingSignal(int signal) {
void startServerSocket() throws Exception {
srv_sock=Util.createServerSocket(getSocketFactory(),
"jgroups.fd_sock.srv_sock", bind_addr, start_port, start_port+port_range); // grab a random unused port above 10000
- srv_sock_addr=new IpAddress(external_addr != null? external_addr : bind_addr, srv_sock.getLocalPort());
+ srv_sock_addr=new IpAddress(external_addr != null? external_addr : bind_addr, external_port > 0? external_port : srv_sock.getLocalPort());
if(srv_sock_handler != null) {
srv_sock_handler.start(); // won't start if already running
}
View
4 src/org/jgroups/protocols/TCP.java
@@ -64,6 +64,7 @@ public void start() throws Exception {
conn_expire_time,
bind_addr,
external_addr,
+ external_port,
bind_port,
bind_port+port_range,
getChannelThreadGroup()
@@ -122,6 +123,7 @@ protected TCPConnectionMap createConnectionMap(long reaperInterval,
long connExpireTime,
InetAddress bindAddress,
InetAddress externalAddress,
+ int external_port,
int startPort,
int endPort,
ThreadGroup group
@@ -134,6 +136,7 @@ protected TCPConnectionMap createConnectionMap(long reaperInterval,
this,
bindAddress,
externalAddress,
+ external_port,
startPort,
endPort,
group
@@ -156,6 +159,7 @@ protected TCPConnectionMap createConnectionMap(long reaperInterval,
this,
bindAddress,
externalAddress,
+ external_port,
startPort,
endPort,
reaperInterval,
View
8 src/org/jgroups/protocols/TCP_NIO.java
@@ -29,10 +29,10 @@
*/
protected ConnectionTableNIO getConnectionTable(long ri, long cet,
InetAddress b_addr, InetAddress bc_addr,
- int s_port, int e_port) throws Exception {
+ int external_port, int s_port, int e_port) throws Exception {
ConnectionTableNIO retval=null;
if (ri == 0 && cet == 0) {
- retval = new ConnectionTableNIO(this, b_addr, bc_addr, s_port, e_port, false );
+ retval = new ConnectionTableNIO(this, b_addr, bc_addr, external_port, s_port, e_port, false );
}
else {
if (ri == 0) {
@@ -43,7 +43,7 @@ protected ConnectionTableNIO getConnectionTable(long ri, long cet,
cet = 1000 * 60 * 5;
if(log.isWarnEnabled()) log.warn("conn_expire_time was 0, set it to " + cet);
}
- retval = new ConnectionTableNIO(this, b_addr, bc_addr, s_port, e_port, ri, cet, false);
+ retval = new ConnectionTableNIO(this, b_addr, bc_addr, external_port, s_port, e_port, ri, cet, false);
}
retval.setThreadFactory(getThreadFactory());
retval.setProcessorMaxThreads(getProcessorMaxThreads());
@@ -66,7 +66,7 @@ public void send(Address dest, byte[] data, int offset, int length) throws Excep
}
public void start() throws Exception {
- ct=getConnectionTable(reaper_interval,conn_expire_time,bind_addr,external_addr,bind_port,bind_port+port_range);
+ ct=getConnectionTable(reaper_interval,conn_expire_time,bind_addr,external_addr,external_port,bind_port,bind_port+port_range);
ct.setUseSendQueues(use_send_queues);
// ct.addConnectionListener(this);
ct.setReceiveBufferSize(recv_buf_size);
View
8 src/org/jgroups/protocols/TP.java
@@ -86,7 +86,11 @@
"the local IP (e.g. 192.168.1.100) of the host then on each host, set \"external_addr\" TCP transport " +
"parameter to the external (public IP) address of the firewall.",
systemProperty=Global.EXTERNAL_ADDR,writable=false)
- protected InetAddress external_addr=null ;
+ protected InetAddress external_addr=null;
+
+ @Property(description="Used to map the internal port (bind_port) to an external port. Only used if > 0",
+ systemProperty=Global.EXTERNAL_PORT,writable=false)
+ protected int external_port=0;
@Property(name="bind_interface", converter=PropertyConverters.BindInterface.class,
description="The interface (NIC) which should be used by this transport", dependsUpon="bind_addr",
@@ -903,6 +907,8 @@ else if(timer_type.equalsIgnoreCase("wheel")) {
m.put("bind_addr", bind_addr);
if(external_addr != null)
m.put("external_addr", external_addr);
+ if(external_port > 0)
+ m.put("external_port", external_port);
if(!m.isEmpty())
up(new Event(Event.CONFIG, m));
View
7 src/org/jgroups/protocols/UDP.java
@@ -397,7 +397,12 @@ protected void destroySockets() {
protected IpAddress createLocalAddress() {
if(sock == null || sock.isClosed())
return null;
- return new IpAddress(external_addr != null? external_addr : sock.getLocalAddress(), sock.getLocalPort());
+ if(external_addr != null) {
+ if(external_port > 0)
+ return new IpAddress(external_addr, external_port);
+ return new IpAddress(external_addr, sock.getLocalPort());
+ }
+ return new IpAddress(sock.getLocalAddress(), sock.getLocalPort());
}
View
11 src/org/jgroups/protocols/pbcast/STATE_SOCK.java
@@ -57,6 +57,10 @@
systemProperty=Global.EXTERNAL_ADDR,writable=false)
protected InetAddress external_addr=null ;
+ @Property(description="Used to map the internal port (bind_port) to an external port. Only used if > 0",
+ systemProperty=Global.EXTERNAL_PORT,writable=false)
+ protected int external_port=0;
+
@Property(name="bind_interface", converter=PropertyConverters.BindInterface.class,
description="The interface (NIC) which should be used by this transport", dependsUpon="bind_addr")
protected String bind_interface_str=null;
@@ -166,6 +170,11 @@ protected void handleConfig(Map<String,Object> config) {
bind_addr=(InetAddress)config.get("bind_addr");
if(external_addr == null)
external_addr=(InetAddress)config.get("external_addr");
+ if(external_port <= 0) {
+ Object val=config.get("external_port");
+ if(val != null)
+ external_port=(Integer)val;
+ }
}
@@ -184,7 +193,7 @@ public StateProviderAcceptor(ExecutorService pool, ServerSocket stateServingSock
this.pool=pool;
this.serverSocket=stateServingSocket;
if(external_addr != null)
- this.address=new IpAddress(external_addr, serverSocket.getLocalPort());
+ this.address=new IpAddress(external_addr, external_port > 0? external_port : serverSocket.getLocalPort());
else
this.address=new IpAddress(bind_addr, serverSocket.getLocalPort());
}
View
12 tests/junit-functional/org/jgroups/blocks/ConnectionMapTest.java
@@ -82,12 +82,12 @@ public void receive(Address sender, byte[] data, int offset, int length) {}
ct1=new TCPConnectionMap("ConnectionMapTest1",
new DefaultThreadFactory(GLOBAL, "ConnectionMapTest", true),
- null, dummy, loopback_addr, null, PORT1, PORT1,GLOBAL);
+ null, dummy, loopback_addr, null, 0, PORT1, PORT1,GLOBAL);
ct1.start();
ct2=new TCPConnectionMap("ConnectionMapTest2",
new DefaultThreadFactory(GLOBAL, "ConnectionMapTest", true),
- null, dummy, loopback_addr, null, PORT2, PORT2,GLOBAL);
+ null, dummy, loopback_addr, null, 0, PORT2, PORT2,GLOBAL);
ct2.start();
int num_conns;
@@ -142,12 +142,12 @@ public void run() {
public void testStopConnectionMapNoSendQueues() throws Exception {
ct1=new TCPConnectionMap("ConnectionMapTest1",
new DefaultThreadFactory(GLOBAL, "ConnectionMapTest", true),
- new DummyReceiver(), loopback_addr, null, PORT1, PORT1, 60000, 120000,GLOBAL);
+ new DummyReceiver(), loopback_addr, null, 0, PORT1, PORT1, 60000, 120000,GLOBAL);
ct1.setUseSendQueues(false);
ct1.start();
ct2=new TCPConnectionMap("ConnectionMapTest2",
new DefaultThreadFactory(GLOBAL, "ConnectionMapTest", true),
- new DummyReceiver(), loopback_addr, null, PORT2, PORT2, 60000, 120000,GLOBAL);
+ new DummyReceiver(), loopback_addr, null, 0, PORT2, PORT2, 60000, 120000,GLOBAL);
ct2.setUseSendQueues(false);
ct2.start();
_testStop(ct1, ct2);
@@ -156,11 +156,11 @@ public void testStopConnectionMapNoSendQueues() throws Exception {
public void testStopConnectionMapWithSendQueues() throws Exception {
ct1=new TCPConnectionMap("ConnectionMapTest1",
new DefaultThreadFactory(GLOBAL, "ConnectionMapTest", true),
- new DummyReceiver(), loopback_addr, null, PORT1, PORT1, 60000, 120000,GLOBAL);
+ new DummyReceiver(), loopback_addr, null, 0, PORT1, PORT1, 60000, 120000,GLOBAL);
ct1.start();
ct2=new TCPConnectionMap("ConnectionMapTest2",
new DefaultThreadFactory(GLOBAL, "ConnectionMapTest", true),
- new DummyReceiver(), loopback_addr, null, PORT2, PORT2, 60000, 120000,GLOBAL);
+ new DummyReceiver(), loopback_addr, null, 0, PORT2, PORT2, 60000, 120000,GLOBAL);
ct2.start();
_testStop(ct1, ct2);
}
View
4 tests/junit-functional/org/jgroups/tests/ConnectionMapUnitTest.java
@@ -26,13 +26,13 @@
protected void setUp() throws Exception {
ct1=new TCPConnectionMap("TCPConnectionMap1",
new DefaultThreadFactory(group, "test", true),
- null, null, null, null, port1, port1, group);
+ null, null, null, null, 0, port1, port1, group);
ct1.setUseSendQueues(false);
ct1.start();
ct2=new TCPConnectionMap("TCPConnectionMap2",
new DefaultThreadFactory(group, "test", true),
- null, null, null, null, port2, port2,group);
+ null, null, null, null, 0, port2, port2,group);
ct2.setUseSendQueues(false);
ct2.start();
}
Please sign in to comment.
Something went wrong with that request. Please try again.