mail.node
Class Node

java.lang.Object
  extended by mail.node.Node
Direct Known Subclasses:
FriendNode, LocalNode, RemoteNode

public abstract class Node
extends java.lang.Object

This class represents a user in the p2p-net. The user can be local, somewhere else in the net, or not available at all. If the user is not local some methods may take very long to terminate, because the will block until the connection was established and the needed information recieved. So it might be wise to start those methods in an extra thread.

Author:
Arne Müller

Nested Class Summary
protected  class Node.IDComparator
           
protected  class Node.InvertedIDComparator
           
 
Field Summary
protected  CryptEngine crypt
           
 
Constructor Summary
Node()
           
 
Method Summary
abstract  void addNeighbor(Node n)
          add's another neighbor to the node's list of neighbors
 int distance(ID nodeid)
          calculates the distance between this and another node.
 int distance(Node n)
          calculates the distance between this and another node.
 boolean equals(java.lang.Object o)
           
abstract  java.util.ArrayList<Node> getClosest(ID nodeid)
          returns the neighbors of this node sorted by distance.
 CryptEngine getCryptEngine()
           
 ID getID()
          fetches the ID of this node
 java.lang.String getKey()
           
abstract  java.util.Collection<Mail> getMail(ID receiver)
           
abstract  ID getName(NameID nameid)
          fetches the ID that registered the name with the given ID
abstract  java.util.Collection<Node> getNeighbors()
          returns all the neighbors of this Node
abstract  Node getNode(ID id)
           
 int hashCode()
           
protected  void markReachable(Node n)
           
 java.util.Collection<Node> searchClosest(int num, ID target)
           
 ID searchName(NameID nameid)
           
 Node searchNode(ID id)
           
abstract  void store(Mail m)
           
abstract  void storeName(NameID nameid, ID user)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

crypt

protected CryptEngine crypt
Constructor Detail

Node

public Node()
Method Detail

distance

public int distance(Node n)
calculates the distance between this and another node. The distance only expresses information about the ID's of the nodes, not about internet connectivity or other stuff.

Parameters:
n - the node to calculate the distance to
Returns:
the distance
See Also:
ID.distance(ID)

distance

public int distance(ID nodeid)
calculates the distance between this and another node. The distance only expresses information about the ID's of the nodes, not about internet connectivity or other stuff.

Parameters:
n - the node to calculate the distance to
Returns:
the distance
See Also:
ID.distance(ID)

getID

public ID getID()
fetches the ID of this node

Returns:
the ID

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

getClosest

public abstract java.util.ArrayList<Node> getClosest(ID nodeid)
                                              throws RequestFailedException
returns the neighbors of this node sorted by distance. the closest node will be first

Parameters:
nodeid - the id of the node to which distance should be measured to
Returns:
neighbors sorted by distance
Throws:
RequestFailedException

getNeighbors

public abstract java.util.Collection<Node> getNeighbors()
                                                 throws RequestFailedException
returns all the neighbors of this Node

Returns:
Throws:
RequestFailedException

getMail

public abstract java.util.Collection<Mail> getMail(ID receiver)
                                            throws RequestFailedException
Throws:
RequestFailedException

store

public abstract void store(Mail m)
                    throws RequestFailedException
Throws:
RequestFailedException

getNode

public abstract Node getNode(ID id)
                      throws RequestFailedException
Throws:
RequestFailedException

getName

public abstract ID getName(NameID nameid)
                    throws RequestFailedException
fetches the ID that registered the name with the given ID

Parameters:
nameid -
Returns:
Throws:
RequestFailedException

storeName

public abstract void storeName(NameID nameid,
                               ID user)
                        throws RequestFailedException
Throws:
RequestFailedException

addNeighbor

public abstract void addNeighbor(Node n)
                          throws RequestFailedException
add's another neighbor to the node's list of neighbors

Parameters:
n -
Throws:
RequestFailedException

getKey

public java.lang.String getKey()

getCryptEngine

public CryptEngine getCryptEngine()

searchClosest

public java.util.Collection<Node> searchClosest(int num,
                                                ID target)
                                         throws RequestFailedException
Throws:
RequestFailedException

searchNode

public Node searchNode(ID id)

searchName

public ID searchName(NameID nameid)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

markReachable

protected void markReachable(Node n)