|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object core.EventNotifier network.NetworkNotifier network.Network
This is the the only class that any other layer of our project should care about.
To use it, have a class implement the NetworkListener interface and pass an instance
of that class to the constructor (probably this
). We do this so there
is a NetworkListener listening before we start the Server.
Field Summary | |
static java.lang.String |
CACHE_MAX_SIZE
|
static java.lang.String |
LOCALHOST
|
static java.lang.String |
MAX_NEIGHBORS
|
static java.lang.String |
MIN_NEIGHBORS
|
static int |
NUM_PORTS
The number of ports to listen on |
static int |
PORT
The first port for this app, avail range: 32636-32765 |
static int |
PORT_INC
The next port to check |
Constructor Summary | |
Network(java.lang.String ownVirtualAddress,
Prefs prefs,
java.util.Vector channelListeners)
Create a new Network with no neighbors and a server that listens for connections. |
Method Summary | |
void |
addIPs(java.lang.String addresses)
Add the given string of IPs to the IPCache |
boolean |
addNeighbor(java.net.Socket socket,
boolean transferKey)
Add a neighbor. |
boolean |
addNeighbor(java.lang.String address)
Add a neighbor. |
void |
addNeighbors()
Try to fill the neighbor list. |
void |
addRoute(java.lang.String fromVirtualAddress,
Neighbor neighbor)
|
void |
broadcast(Packet packet,
Neighbor fromNeighbor)
Broadcasts packet to all neighbors. |
void |
cancelTimer()
Stop the maintainence daemon. |
boolean |
contains(java.lang.String ip)
|
java.lang.String |
getLocalIP()
|
int |
getMinNeighbors()
|
java.util.Collection |
getNeighbors()
Returns a Collection of neighbors connected to. |
int |
getNumNeighbors()
Get the number of connected neighbors. |
java.lang.String |
getOwnVirtualAddress()
|
Prefs |
getPrefs()
|
java.util.Hashtable |
getVirtualAddressToPacketID()
|
void |
printChannelList(java.lang.String from)
Print channel list associated with from address |
void |
reloadServers()
loads server ips into cache again. |
void |
removeNeighbor(Neighbor neighbor,
java.lang.String caller)
Remove the neighbor with the given address from the list of neighbors. |
void |
sendIPs(Neighbor neighbor,
int numRequested)
Send the IPs of our neighbors to the requesting neighbor |
void |
sendMessage(Message message)
Send the TextMessage message. |
void |
sendPacket(XMLPacket packet,
Neighbor fromNeighbor)
Send the Packet. |
void |
sendPacketToNeighbor(Packet packet,
Neighbor neighbor)
|
void |
stop()
Stop the network. |
Methods inherited from class network.NetworkNotifier |
fireMessageReceived, fireNeighborConnected |
Methods inherited from class core.EventNotifier |
addListener, removeListener |
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String LOCALHOST
public static final java.lang.String MIN_NEIGHBORS
public static final java.lang.String CACHE_MAX_SIZE
public static final java.lang.String MAX_NEIGHBORS
public static final int PORT
public static final int PORT_INC
public static final int NUM_PORTS
Constructor Detail |
public Network(java.lang.String ownVirtualAddress, Prefs prefs, java.util.Vector channelListeners)
ownVirtualAddress
- Our virtual address.prefs
- Our preferences.channelListeners
- Method Detail |
public void addNeighbors()
public boolean addNeighbor(java.lang.String address)
address
- The IP address or hostname of the neighbor.public boolean addNeighbor(java.net.Socket socket, boolean transferKey)
socket
- The Socket for communicating with the neighbor.transferKey
- Whether we need to send the Cipher
public void addRoute(java.lang.String fromVirtualAddress, Neighbor neighbor)
public void removeNeighbor(Neighbor neighbor, java.lang.String caller)
neighbor
- The address of the neighbor to be removed.public void sendMessage(Message message)
message
- The TextMessage to be sent.public void sendPacket(XMLPacket packet, Neighbor fromNeighbor)
packet
- The Packet to be sent.fromNeighbor
- The neighbor the packet is from.public void broadcast(Packet packet, Neighbor fromNeighbor)
packet
- The packet to be broadcasted.fromNeighbor
- The neighbor the packet is from.public void sendPacketToNeighbor(Packet packet, Neighbor neighbor)
public java.util.Collection getNeighbors()
public void stop()
public java.lang.String getOwnVirtualAddress()
public void printChannelList(java.lang.String from)
from
- public int getNumNeighbors()
public void sendIPs(Neighbor neighbor, int numRequested)
neighbor
- The neighbor requesting the IPs.numRequested
- The number of IPs requested.public void addIPs(java.lang.String addresses)
addresses
- The string of IPs separated by white spacepublic boolean contains(java.lang.String ip)
ip
- the ip address of the neighbor.
public void reloadServers()
public int getMinNeighbors()
public void cancelTimer()
public java.lang.String getLocalIP()
public Prefs getPrefs()
public java.util.Hashtable getVirtualAddressToPacketID()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |