#include <LinkLayerInterface.h>
Inheritance diagram for LinkLayerInterface::
Public Methods | |
LinkLayerInterface () | |
Create the Link Layer. More... | |
virtual | ~LinkLayerInterface () |
Destructor. More... | |
int | getNumConnections () |
Returns the current number of open connections. More... | |
bool | isConnected () |
Return true if there is a connection to any other node, false otherwise. More... | |
bool | isConnectedTo (IpAddress ipAddr) |
Check connection table to see if we are connected to specified node. More... | |
Node * | getRandomNeighbor () |
Return a random neighbor from our connection list. More... | |
Node * | getRandomNeighbor (Node *node) |
Return a random neighbor from our connection list, except the one that you pass in. More... | |
bool | getConnection (int index, Node *retVal) |
Get a copy of the node at the specified index in the connection table. More... | |
Node * | getConnection (int index) |
void | registerPacketHandler (PacketHandlerInterface *packetHandler) |
Registers an object to be called whenever a packet is received. More... | |
void | handleEvent (ObservableInterface *observed, int event, void *object) |
This is called by the Catcher object whenever it discovers a new Node. More... | |
int | connect (Node *node) |
Connects to the specified node. More... | |
void | changeListeningPortTo (int port) |
Change the listening port. More... | |
int | sendPacket (NpPacket *packet, Node *node) |
Send a packet to the specified node. More... | |
int | sendPacket (ConnectionPacket *packet) |
Send packet to a random neighbor. More... | |
int | broadcast (NpPacket *packet) |
Send packet to all neighbors. More... | |
int | broadcast (NpPacket *packet, Node *node) |
Send packet to all neighbors but the one specified. More... | |
int | close (Node *) |
Close link to the specified Node. More... | |
virtual void | toStream (std::ostream &out) |
Protected Methods | |
void | listenImpl () |
This function is meant to be started as a pthread. More... | |
void | peerConnectImpl () |
This function is meant to be started as a pthread. More... | |
void | pollAllSocketsImpl (void) |
It will read packets coming in from the Net and then hand them off to the registered handler. More... | |
void | add (ConnectionTableEntry *) |
Add a node to the connection table. More... | |
void | remove (int connTableIndex) |
Remove an entry from the connection table. More... | |
ConnectionTableEntry * | accept () |
Accept handles incoming connect requests. More... | |
void | closeLink (int connTableIndex) |
Close the link to neighbor. More... | |
Static Protected Methods | |
void * | listen (void *) |
This function is meant to be started as a pthread. More... | |
void * | peerConnect (void *) |
This function is meant to be started as a pthread. More... | |
void * | pollAllSockets (void *) |
This function is meant to be started as a pthread. More... | |
Protected Attributes | |
Condition | m_connectionClosed |
Used to signal when a connection is closed. More... | |
Mutex | m_connectionTableLock |
a lock for the connection table. More... | |
vector< ConnectionTableEntry *> | m_connectionTable |
an array of pointers to nodes we have connections to. More... | |
pthread_t | m_listenThreadId |
The thread ID for the listen function. More... | |
pthread_t | m_peerConnectThreadId |
The thread ID for the peerConnect function. More... | |
pthread_t | m_receivePacketThreadId |
Condition | m_newConnection |
Used to signal when we have accepted a new connection. More... | |
Condition | m_nodeAdded |
Used to signal when a new node is added. More... | |
fd_set | m_socketSet |
the set of all current connections. More... | |
int | m_highestFd |
on *UNIX systems, you must provide "select" with the highest descriptor of the three sets you hand in, plus one. This var keeps track of the highest-number descriptor. More... | |
PacketHandlerInterface * | m_packetHandler |
Pointer to packet handler - assigned by the registerHandler function. More... | |
ListenerInterface * | m_connectionListener |
Pointer to object that wants to be informed of node events. More... | |
string | m_state |
state string. More... | |
TRanrotBGenerator | m_randomNumberGenerator |
Each node must take care of itself, but the management of all of them falls to this class.
This class is based on the connection table. The connection table is maintained without any holes. This allows for faster searching and adding, but slower removal because it has to squeeze the array down when one member is removed. This way makes the programming with this array very easy.
I was thinking about using a Reactor design pattern in order to combine accepting connections and reading data. But this allows an attacker to hold up your data flow by spoofing connections. This is why I have separated the listening for new connections from the receiving of data on existing connections.
Definition at line 17 of file LinkLayerInterface.h.
|
Create the Link Layer.
This will start up the following threads:
1) listen: a thread that will listen for connections from other nodes on the default port defined in the Config singleton.
2) peerConnect: actively tries to connect to a random set of peers. The peer list comes from the catcher.
3) receivePacket: reads a packet from any of the connected sockets and passes it to the registered listener. This thread will automatically drop connections out of the connection table that have been severed. Definition at line 40 of file LinkLayerInterface.cpp. |
|
Destructor. Destroys the mutexes and condition variables and the threads.
Definition at line 81 of file LinkLayerInterface.cpp. |
|
Accept handles incoming connect requests. After a connection is accepted, is it treated exactly like all other connections. LLI->listen must be called before this function is called.
Definition at line 391 of file LinkLayerInterface.cpp. Referenced by listenImpl().
|
|
Add a node to the connection table.
Definition at line 606 of file LinkLayerInterface.cpp. Referenced by accept(), and connect().
|
|
Send packet to all neighbors but the one specified.
Definition at line 929 of file LinkLayerInterface.cpp. |
|
Send packet to all neighbors.
Definition at line 913 of file LinkLayerInterface.cpp. Referenced by NetworkLayer::discover(), and NetworkLayer::ping().
|
|
Change the listening port.
Definition at line 528 of file LinkLayerInterface.cpp. |
|
Close link to the specified Node.
Definition at line 870 of file LinkLayerInterface.cpp. |
|
Close the link to neighbor.
Definition at line 889 of file LinkLayerInterface.cpp. Referenced by close(), and pollAllSocketsImpl().
|
|
Connects to the specified node. searches through its connection table looking for holes. If there arent any, add this connection to the end of the list.
Definition at line 448 of file LinkLayerInterface.cpp. Referenced by peerConnectImpl().
|
|
Definition at line 793 of file LinkLayerInterface.cpp. |
|
Get a copy of the node at the specified index in the connection table. You must supply a pointer to an existing node which will be overwritten with the value of the node found at the index. This function will return false if the index is invalid, otherwise it will return true. Definition at line 782 of file LinkLayerInterface.cpp. Referenced by add(), ConnectionManagerCommand::getHtmlInterface(), VisualizerFrame::getInitialNeighborNodes(), pollAllSocketsImpl(), and sendPacket().
|
|
Returns the current number of open connections.
Definition at line 729 of file LinkLayerInterface.cpp. Referenced by SummaryScreenCommand::getHtmlInterface(), ConnectionManagerCommand::getHtmlInterface(), VisualizerFrame::getInitialNeighborNodes(), NetworkLayer::handleConnectPacket(), listenImpl(), and peerConnectImpl().
|
|
Return a random neighbor from our connection list, except the one that you pass in. If we are not connected to any nodes, or only connected to one, this function will return NULL. Definition at line 758 of file LinkLayerInterface.cpp. |
|
Return a random neighbor from our connection list. A neighbor is a node we are currently connected to. Definition at line 740 of file LinkLayerInterface.cpp. Referenced by NetworkLayer::connectForward(), NetworkLayer::handleDiscoveryPacket(), and NetworkLayer::makeVc().
|
|
This is called by the Catcher object whenever it discovers a new Node. This alerts the peerConnect thread that we have a new node. It is that thread that decides what to do with it. Reimplemented from ListenerInterface. Definition at line 903 of file LinkLayerInterface.cpp. |
|
Return true if there is a connection to any other node, false otherwise.
Definition at line 720 of file LinkLayerInterface.cpp. Referenced by ServiceTable::connectService(), and NetworkLayer::makeVc().
|
|
Check connection table to see if we are connected to specified node.
Definition at line 702 of file LinkLayerInterface.cpp. Referenced by accept(), and connect().
|
|
This function is meant to be started as a pthread. This is a wrapper around listenImpl().
Definition at line 326 of file LinkLayerInterface.cpp. |
|
This function is meant to be started as a pthread. This makes the localhost listen for incoming connections on its listeing port defined in selfNode.
Definition at line 340 of file LinkLayerInterface.cpp. Referenced by listen().
|
|
This function is meant to be started as a pthread. It will actively start up connections until it has run out of nodes to connect to or has reached MIN_CONNECTIONS as defined in the config file.
Definition at line 252 of file LinkLayerInterface.cpp. |
|
This function is meant to be started as a pthread. It will actively start up connections until it has run out of nodes to connect to or has reached MIN_CONNECTIONS as defined in the config file.
Definition at line 268 of file LinkLayerInterface.cpp. Referenced by peerConnect().
|
|
This function is meant to be started as a pthread. It is a wrapper for pollAllThreadsImpl. Definition at line 127 of file LinkLayerInterface.cpp. |
|
It will read packets coming in from the Net and then hand them off to the registered handler. Poll all open sockets, read a packet if any have arrived. If a packet is read, this function will return immediately. If no packets are available, this function will block until there is data available. It will also close any sockets that have been disconnected by their peer. The parameters in this function are the return values.
Definition at line 150 of file LinkLayerInterface.cpp. Referenced by pollAllSockets().
|
|
Registers an object to be called whenever a packet is received. Only one packet handler may be registered. Definition at line 562 of file LinkLayerInterface.cpp. Referenced by NetworkLayer::NetworkLayer().
|
|
Remove an entry from the connection table. This automatically closes the connection if it open.
Definition at line 631 of file LinkLayerInterface.cpp. Referenced by closeLink().
|
|
Send packet to a random neighbor. Used for creation of virtual circuits. Definition at line 808 of file LinkLayerInterface.cpp. |
|
Send a packet to the specified node.
Definition at line 839 of file LinkLayerInterface.cpp. Referenced by NetworkLayer::connectForward(), NetworkLayer::connectTerminate(), NetworkLayer::forwardPacket(), NetworkLayer::handleDiscoveryPacket(), NetworkLayer::handleEstablishedPacket(), NetworkLayer::handleImHerePacket(), NetworkLayer::handlePingPacket(), NetworkLayer::makeVc(), and NetworkLayer::send().
|
|
Reimplemented from BasicObject. Definition at line 945 of file LinkLayerInterface.cpp. |
|
Used to signal when a connection is closed.
Definition at line 107 of file LinkLayerInterface.h. |
|
Pointer to object that wants to be informed of node events.
Definition at line 142 of file LinkLayerInterface.h. |
|
an array of pointers to nodes we have connections to.
Definition at line 113 of file LinkLayerInterface.h. |
|
a lock for the connection table.
Definition at line 110 of file LinkLayerInterface.h. |
|
on *UNIX systems, you must provide "select" with the highest descriptor of the three sets you hand in, plus one. This var keeps track of the highest-number descriptor.
Definition at line 136 of file LinkLayerInterface.h. |
|
The thread ID for the listen function.
Definition at line 116 of file LinkLayerInterface.h. |
|
Used to signal when we have accepted a new connection.
Definition at line 125 of file LinkLayerInterface.h. |
|
Used to signal when a new node is added.
Definition at line 128 of file LinkLayerInterface.h. |
|
Pointer to packet handler - assigned by the registerHandler function.
Definition at line 139 of file LinkLayerInterface.h. |
|
The thread ID for the peerConnect function.
Definition at line 119 of file LinkLayerInterface.h. |
|
Definition at line 147 of file LinkLayerInterface.h. |
|
Definition at line 122 of file LinkLayerInterface.h. |
|
the set of all current connections.
Definition at line 131 of file LinkLayerInterface.h. |
|
state string.
Definition at line 145 of file LinkLayerInterface.h. |