Skip to main content

Configuring relay peers and connecting peers to connect through Firewall

1 reply [Last post]
desaipremal
Offline
Joined: 2008-07-03
Points: 0

Hi,

I have been spending a number of days trying to configure the Relay Peer and the so that connecting peers can communicate with each other when they have a firewall between them. I have had absolutely no luck so far, despite trying so many different configuration options and reading so many related threads in this forum.

Unfortunately, Jxta's documentation does not cover this real life scenario in detail for people's understanding. And lot of their APIs are poorly documented. NO jxta book so far (including the recent book Practical Jxta) has detailed example with the Relay Peer and Firewall Communication). Lots of talk and no walk.

Anybody's help on this issue will be very much appreciated. The problem description and the code excerpts follow:

I am using JxSe tutorial's example of having a JxtaSocket Client setup a connection with a JxtaSocket Server (which is placed behind the firewall) to talk. The firewall permits incoming and outgoing communication on Port 80 only. After having all the three peers configured to communicate through the firewall and run, I cannot say right now if there is communication between the Socket Client and Relay Peer or if there's any ongoing communication between the SocketServer and the Relay Peer. There are no logs in the FINEST mode. The socket Client does not make a connection yet with the Socket Server. By the way, the Relay Peer is running outside the firewall.

Any help will be highly appreciated.

Here's how the RELAY PEER is Configured:
package com.weblayers.firewall;

public class RelayPeer {

private transient NetworkManager manager = null;

private transient PeerGroup netPeerGroup = null;
private transient PipeAdvertisement pipeAdv;

public RelayPeer(boolean waitForRendezvous) {
try {
System.setProperty("net.jxta.logging.Logging", "FINEST");
System.setProperty("net.jxta.level", "FINEST");
manager = new NetworkManager
(NetworkManager.ConfigMode.RENDEZVOUS_RELAY, "Rendezvous", new
File(new File(".cache"), "Rendezvous").toURI());
NetworkConfigurator myConfigurator = manager.getConfigurator();

myConfigurator.setName("Relay Peer");
myConfigurator.setDescription("Private Relay");
myConfigurator.setUseMulticast(true);
myConfigurator.setMode(NetworkConfigurator.RDV_SERVER +
NetworkConfigurator.RELAY_SERVER);

myConfigurator.setUseOnlyRelaySeeds(true);
myConfigurator.setUseOnlyRendezvousSeeds(true);

// Relay Server is has a LAN IP. It is running on a LAN
// It will be polled by a Jxta Peer running Socket Server on another
// machine that has a personal firewall.
myConfigurator.setHttpInterfaceAddress("192.168.200.14");
myConfigurator.setHttpEnabled(true);
myConfigurator.setHttpPort(80);
myConfigurator.setHttpIncoming(true);
myConfigurator.setHttpOutgoing(true);

myConfigurator.setRelayMaxClients(100);

System.out.println(this.getClass().getName() + " Peer ID = " +
myConfigurator.getPeerID());
myConfigurator.save();
manager.startNetwork();
} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}

netPeerGroup = manager.getNetPeerGroup();
if (waitForRendezvous) {
manager.waitForRendezvousConnection(0);
}

}

public void run() {
while (true) {
try {
Thread.sleep(10000);
}catch(InterruptedException io) {

}
System.out.println(this.getClass().getName() + "Woke up and now going back to sleep. Hopefully, I will unite the connecting Peers one day");
}
}

public static void main(String[] args) throws Exception {
RelayPeer b = new RelayPeer(false);
b.run();
}
}
----------------------------------------------------------
Connecting Peer#1 (Socket Clientwhich is sitting outside the firewall)
Here's is the code excerpt of the Socket Client's configuration set in
its constructor:

manager = new NetworkManager
(NetworkManager.ConfigMode.ADHOC, "SocketClient",
new File(new File(".cache"), "SocketClient").toURI());
NetworkConfigurator myConfigurator = manager.getConfigurator();

String seedName = "http://192.168.200.14:80";
URI localSeedingRendezVousURI = URI.create(seedName);
myConfigurator.addSeedRelay(localSeedingRendezVousURI);
myConfigurator.setTcpEnabled(true);
myConfigurator.setTcpIncoming(true);
myConfigurator.setTcpOutgoing(true);

myConfigurator.setHttpInterfaceAddress("192.168.200.14");
myConfigurator.setHttpEnabled(true);
myConfigurator.setHttpIncoming(true);
myConfigurator.setHttpOutgoing(true);

System.out.println(this.getClass().getName() + " Peer ID = " +
myConfigurator.getPeerID());
myConfigurator.save();
manager.setUseDefaultSeeds(false);
manager.startNetwork();

} catch (Exception e) {
e.printStackTrace();
System.exit(-1);
}

----------------------------------------------------------
Connecting Peer#2 (Socket Server which is sitting behind the firewall)
Here's is the code excerpt of the Socket Server's configuration set in
its constructor:

NetworkManager manager = new NetworkManager
(NetworkManager.ConfigMode.ADHOC, "SocketServer",
new File(new File(".cache"), "SocketServer").toURI());
NetworkConfigurator myConfigurator = manager.getConfigurator();

String seedName = "http://192.168.200.14:80";
URI localSeedingRendezVousURI = URI.create(seedName);
myConfigurator.addSeedRelay(localSeedingRendezVousURI);

myConfigurator.setTcpEnabled(true);
myConfigurator.setTcpIncoming(true);
myConfigurator.setTcpOutgoing(true);

myConfigurator.setHttpInterfaceAddress("192.168.200.20");
myConfigurator.setHttpEnabled(true);
myConfigurator.setHttpIncoming(true);
myConfigurator.setHttpOutgoing(true);

System.out.println(this.getClass().getName() + " Peer ID = " +
myConfigurator.getPeerID());
myConfigurator.save();

manager.startNetwork();
netPeerGroup = manager.getNetPeerGroup();

Once again, any help will be highly appreciated.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
desaipremal
Offline
Joined: 2008-07-03
Points: 0

Eureka! Works like a charm now.

While tracing the Jxta source code, I noticed that it would disabled just when the mode was ADHOC. Then on reviewing the peer types I realized that ADHOC peers have minimal configuration and do not connect to relays or rendezvous peers.

I changed the type of each of the connecting peers from ADHOC to EDGE and it worked!

FYI....