|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectmail.communication.Communicator
mail.communication.inet.InetCommunicator
public class InetCommunicator
Field Summary | |
---|---|
private java.util.Collection<InetAddress> |
addr
this communicators address |
private java.io.File |
basedir
directory in which comm-properties are stored |
static int |
BOOT_TIMEOUT
|
private java.util.Properties |
bootstrap
|
private static java.lang.String |
BOOTSTRAP_ADDR
|
static int |
CONNECTION_TIMEOUT
the time after which a connection is considered dead. |
(package private) java.util.Hashtable<InetAddress,java.lang.Long> |
connections
map of connections to their last response time |
private javax.xml.parsers.DocumentBuilderFactory |
docfactory
used to build the XML documents needed to send packages |
(package private) boolean |
ip_answer
indicates if this communicators ip address was updated |
private LocalNode |
local
the local node this communicator is attached to |
private static int |
MAX_BOOTSTRAP_TRIES
|
static int |
PING_INTERVAL
the interval PING packages get send to neighbor nodes, to keep the UDP connection alive, because if the UDP connection collapse it might be hard to rebuild it (UDP hole punching) |
(package private) java.util.Hashtable<InetAddress,java.util.Vector<UDP>> |
received
contains received, unfinished packets |
(package private) java.util.Hashtable<InetAddress,java.lang.Integer> |
responses
list of received elementar response packets |
private java.util.Properties |
settings
|
private static java.lang.String |
SETTINGS
|
private java.net.DatagramSocket |
socket
the socket all packets are send and received with. |
static int |
TIMEOUT
If TIMEOUT ms have passed after an request, the package is believed of have gotten lost |
private javax.xml.transform.TransformerFactory |
transFactory
used to transform XML documents into OutputStreams |
(package private) java.util.Hashtable<Node,InetAddress> |
useableAddresses
maps Nodes to InetAddresses of the Node, that work |
Constructor Summary | |
---|---|
InetCommunicator()
creates a new InetCommunicator. |
|
InetCommunicator(java.io.File basedir)
|
|
InetCommunicator(int port)
creates a new InetCommunicator. |
Method Summary | |
---|---|
void |
attachNode(LocalNode l)
|
void |
bootstrap()
|
void |
close()
|
private boolean |
connectionEstablished(InetAddress address)
looks up the time, when the last package was received. |
private void |
establishConnection(InetAddress address)
establishes a connection. |
void |
findMyAddress(Address apeer)
|
java.util.Collection<Address> |
getAddress()
returns the Address this Communicator uses to send Packets |
javax.xml.parsers.DocumentBuilder |
getDocumentBuilder()
|
boolean |
isOpen()
|
boolean |
open()
|
void |
open(int port)
|
InetAddress |
parseAddress(java.lang.String addr)
|
private void |
print_debug(org.w3c.dom.Document d)
print a Document to System.out. |
private void |
punch_hole(InetAddress action)
sends PING packets to punch a UDP hole into the NAT router this peer is hidden behind |
private void |
receivePackage(java.io.InputStream in,
InetAddress sender)
builds a CPackage out of the InputStream. |
private void |
request_hole_punch(InetAddress action,
InetAddress sender)
sends a node a request to punch a UDP hole for another node |
private void |
reset(InetAddress address,
int reply)
resets the specified entry at adress in the response list |
void |
run()
this methods listens for Packets send to this peer and handles them appropriately. |
void |
sendPackage(CPackage p,
Address to)
|
void |
sendPackage(CPackage p,
RemoteNode to)
|
private void |
startConnectionHolder()
starts the mechanism to keep UDP connections alive. |
private int |
waitForEcho(InetAddress address)
waits until any reply came from address. |
private int |
waitForEcho(InetAddress address,
int reply)
waits until the specified reply came from address. |
void |
write(org.w3c.dom.Document d,
java.io.File out)
|
Methods inherited from class mail.communication.Communicator |
---|
getReplyList |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final java.lang.String BOOTSTRAP_ADDR
private static final java.lang.String SETTINGS
private static final int MAX_BOOTSTRAP_TRIES
private java.io.File basedir
private java.util.Properties bootstrap
private java.util.Properties settings
public static final int BOOT_TIMEOUT
public static final int TIMEOUT
public static final int PING_INTERVAL
public static final int CONNECTION_TIMEOUT
private LocalNode local
private java.util.Collection<InetAddress> addr
private javax.xml.parsers.DocumentBuilderFactory docfactory
private javax.xml.transform.TransformerFactory transFactory
private java.net.DatagramSocket socket
java.util.Hashtable<InetAddress,java.util.Vector<UDP>> received
java.util.Hashtable<InetAddress,java.lang.Integer> responses
java.util.Hashtable<InetAddress,java.lang.Long> connections
java.util.Hashtable<Node,InetAddress> useableAddresses
boolean ip_answer
Constructor Detail |
---|
public InetCommunicator()
public InetCommunicator(java.io.File basedir)
public InetCommunicator(int port) throws java.io.IOException
java.io.IOException
Method Detail |
---|
public boolean open() throws java.io.IOException
java.io.IOException
public void bootstrap() throws BootstrapException
BootstrapException
public boolean isOpen()
isOpen
in class Communicator
public void open(int port) throws java.io.IOException
java.io.IOException
public void close()
close
in class Communicator
public void attachNode(LocalNode l)
attachNode
in class Communicator
public java.util.Collection<Address> getAddress()
Communicator
getAddress
in class Communicator
public void findMyAddress(Address apeer) throws java.io.IOException
findMyAddress
in class Communicator
java.io.IOException
public javax.xml.parsers.DocumentBuilder getDocumentBuilder()
getDocumentBuilder
in class Communicator
public InetAddress parseAddress(java.lang.String addr) throws IncompatibleAddressException
parseAddress
in class Communicator
IncompatibleAddressException
private void print_debug(org.w3c.dom.Document d)
d
- the document to printpublic void write(org.w3c.dom.Document d, java.io.File out) throws javax.xml.transform.TransformerException, java.io.IOException
write
in class Communicator
javax.xml.transform.TransformerException
java.io.IOException
private void startConnectionHolder()
private boolean connectionEstablished(InetAddress address)
address
- the address the connection belongs to
private void establishConnection(InetAddress address) throws UDP.UDPException, java.io.IOException
address
- the address to connect to
java.io.IOException
- if no connection could be established
UDP.UDPException
private int waitForEcho(InetAddress address)
address
- the address to listen at
UDP.NO_REPLY
, if TIMEOUT ms no message cameprivate int waitForEcho(InetAddress address, int reply)
address
- the Address to listen atreply
- the reply to wait for
UDP.NO_REPLY
, if TIMEOUT ms no reply cameprivate void reset(InetAddress address, int reply)
address
- the address to resetreply
- the reply to reset at the addressprivate void punch_hole(InetAddress action)
action
- the address to enable the communication toprivate void request_hole_punch(InetAddress action, InetAddress sender)
action
- the node to send the request tosender
- the node to punch the UDP hole forpublic void run()
receivePackage(InputStream, InetAddress)
is executed
run
in interface java.lang.Runnable
private void receivePackage(java.io.InputStream in, InetAddress sender)
in
- the InputStream containing the datasender
- the address of the sender of the package (might not be usable if the sender used tor)public void sendPackage(CPackage p, RemoteNode to) throws IncompatibleAddressException, NotReachableException, PackageBuildException
sendPackage
in class Communicator
IncompatibleAddressException
NotReachableException
PackageBuildException
public void sendPackage(CPackage p, Address to) throws IncompatibleAddressException, java.io.IOException, PackageBuildException
sendPackage
in class Communicator
IncompatibleAddressException
java.io.IOException
PackageBuildException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |