Title: JXTA e Relay
1JXTA e Relay
- Realizzazione di una Jxta Chat
2Peer
- Definizione
- Secondo la filosofia JXTA tutto ciò che è
collegabile in rete, può diventare un Peer - Es
- Host, Cellulari, Router,
3Virtual Network
4Introduzione
JXTA Virtual Network
Protocolli
Peer
Super Peer
Edge Peer
Randevouz
Relay
5Relay
Firewall
Peer
Peer
- Problem
- How should a host beyond Firewall become a Peer
? - Solution
- Using a Relay
Relay
Peer
Peer
Peer
6Case 1 Outgoing Connection
- Protected Peer connects first to external Peer
- Nice Firewall allows outgoing TCP connections
- Strict Firewall allows only HTTP connections for
using WWW service
Peer
TCP stable
Peer
HTTP request
Peer
HTTP answer
For each request only one answer is allowed
7Case 2 Incoming Connection
Peer
- External Peer tries to connect to protected Peer
- Firewall blocks the packets
Blocked
Peer
8Using Realy
PeerB
- Using a Relay
- 1) PeerA connects to Relay (TCP or HTTP it
dipends on what firewall allows) - 2) PeerB connects to Relay and leave its message
for PeerA - 3) Relay routes the connection request to PeerA
that connects to PeerB (TCP or HTTP it dipends on
what firewall allows)
2
3
Relay
1
PeerA
Relay keeps the msg until PeerA isnt ready to
retrive it
9Dimostration
- TCP 160.78.28.2362057 160.78.28.2339701
ESTABLISHED - This line has been taken from a netstat na
logfile
Its a stable TCP connection
- Protected Peer IP - Random port means this
peer has started the connection
- - Free Peer IP
- Fixed port means
- this peer has recived
- the connection request
10Services
Randevouz
It keeps PipeAdv in cache
- Discovery Service
- Pipe Service
Pipe
DiscoveryService. Publish(PipeAdv)
PipeService.Create
DHT Chosen Randevouz
Server Peer
Randevouz
Pipe Advertisement
11Services
Randevouz
- Discovery Service
- Pipe Service
Relay should use a Randevouz
DHT Chosen Randevouz
Relay
DiscoveryService. query
Relay should act as Randevouz Himself and calc
DHT
Client Peer
Randevouz
12Query responses
Randevouz
- Asynchronous mechanism for query results
Relay
Client Peer
Query response
13Opening Pipe
Pipe
Relay
Access to remote pipe
Client Peer
Server Peer
Pipe Adv
14Implementation
Relay
- Usually its Server Peer to start the connection
toward client, but in this case its viceversa,
only this way the firewall allows it
Blocked
Server Peer
Client Peer
TCP Connection Implements the JXTA Pipe
15Problem Privileges of JVM
- Standard JVM
- java MyClass
- No Restrictions
- JXTA requires privileges to open files,
- It works ok with this JVM
Standard JVM
OK
JXTA
File
File
File
16Problem Privileges of JVM
- JVM Browser Plugin
- Many Restrictions for Security Reasons
- JXTA requires privileges to open files,
- It doesnt work
Plugin JVM
Noooo
JXTA
File
File
File
17Solution Engine, Applet, RMI
ENGINE
APPLET
Plugin JVM
Standard JVM
RMI
Applet
JXTA
Browser
File
File
File
18Engine
- Module running JXTA
- Runs in the Standard JVM with no restrictions
- It does the Real Work
- It passes results up to the Applet
- It acts as Console
Engine Code
DiscoveryService PipeService
JXTA
19Applet
Browser
Applet
- Runs in the restricted JVM Browser Plugin
- Its only task is to recive data from the engine
and show them on the browser
RMI
Restrictions
No Restriction
Engine Code
20RMI
- RMI Remote Method Invocation
- It allows data exchange between 2 different
contexts - Automatic Data Marshaling
21Interface Definition
- To invoke Remote Methods its needed an Interface
that defines Remote Methods Name, Parameters, - public interface MyPipeServer extends Remote
-
- public void addTempMsgListener() throws
RemoteException -
One of my Remote Methods It must be declared that
throws RemoteException
My remote Interface must extend Remote (defined
by RMI)
22Interface Implementation
- Remote Interface must be implemented by a class
extending UnicastRemoteObject - public class MyPipeServerImpl extends
UnicastRemoteObject implements MyPipeServer
- UnicastRemoteObject has this characteristics
- Gives the illusion that the RemoteObject is local
- Provides comunication between 2 sides with TCP
- Provides a protocol for invocation, params and
results
23Registration
- Once created an instance of the
RemoteUnicastObject it has to be registered in
the RMI Registry - Once Registered in RMI Registry it can be
accessed from any other context - Naming.rebind(myapp.RMIHost myapp.RMIPort
myapp.RMIServerName, myapp)
Name my object is registered with in the registry
24Accessing a Remote Object
- A Remote Object is used by its Remote Interface
- It can taken querying the RMI Registry
- tMsgListener (TempMsgListener)
Naming.lookup(RMIHost RMIPort RMIClientName)
Remote Interface for the Remote Object
Name the object is registered with in the
registry
Interface to use locally to invoke The Remote
Object
25Whats RMI Registry ?
- Its an executable
- Opens a TCP Port and waits for registrations or
lookups query - Its the bridge between the 2 contexts
- Server Where the Remote Object Implementation
stays - Client Where the Remote Interface is used