Network Class Reference
#include <Network.h>
Inherits NetworkInterface.

Classes | |
| class | ConverterToV1_0a4 |
Public Member Functions | |
| Network () | |
| virtual | ~Network () |
| virtual bool | loadConfig (std::string configFile) |
| virtual void | cleanup () |
| virtual bool | connect (std::string nodeName) |
| virtual int | sizeRecvList (uint8_t channelId=0) |
| virtual NetMessage * | peek (uint8_t channelId=0) |
| virtual NetMessage * | pop (uint8_t channelId=0) |
| virtual void | popAll (uint8_t channelId, std::vector< NetMessage * > *dst) |
| virtual void | sendMessageTCP (NetMessage *msg, uint8_t channelId=0) |
| virtual void | sendMessageUDP (NetMessage *msg, uint8_t channelId=0) |
| virtual void | sendMessageTCPTo (NetMessage *msg, uint8_t channelId, unsigned userId) |
| virtual void | sendMessageUDPTo (NetMessage *msg, uint8_t channelId, unsigned userId) |
| virtual void | sendTransformation (TransformationData &trans, TransformationPipe *pipe, bool useTCP) |
| virtual void | sendEvent (Event *event) |
| virtual void | flush () |
| virtual std::string | getName () |
| virtual int | getNumberOfParticipants () |
| virtual NetworkIdentification | getLocalIdentification () |
Protected Member Functions | |
| bool | init (uint16_t portTCP, uint16_t portUDP, std::string ipAddress="") |
| void | sendMessageToGroup (NetMessage *msg, uint8_t channelId, std::vector< NetworkIdentification > *destinationList, bool useTCP) |
| bool | quickConnect (UserNetworkIdentification *id) |
| bool | handShake (OSG::StreamSocket *socket, UserNetworkIdentification *id, bool quickConnect=false) |
| bool | handleNormalConnect (OSG::StreamSocket *socket, UserNetworkIdentification *otherID) |
| bool | handleQuickConnect (OSG::StreamSocket *socket) |
| void | encodeId (NetMessage *msg, UserNetworkIdentification *id, bool putFirst=false) |
| void | decodeId (UserNetworkIdentification *id, NetMessage *msg) |
| int | decodeMessageToIDs (NetMessage *msg, UserNetworkIdentification **ids) |
| decodeId | |
| bool | checkConnection () |
| void | connectionDone () |
| bool | checkClientConnected (NetworkIdentification *id) |
| int | sendPrioritizedMessage (NetMessage *msg) |
| void | addClientsToMessage (NetMessage *msg) |
| std::string | dumpNetworkIdentification (NetworkIdentification *netId) |
| void | dumpConnection (SocketListEntry *con) |
| void | handleLostConnections () |
| void | setLocalIPAddress (OSG::StreamSocket *socket) |
| void | checkSocketAndSendListConsistency (SocketListEntry *sockets, int entries) |
| void | splitDestination (std::string destination, std::string &ipAddress, int &port) |
| bool | alreadyConnected () |
| bool | initializeConnectionRequest () |
| void | finalizeConnectionRequest () |
| void | addConnectionToNetwork (OSG::StreamSocket *socket, UserNetworkIdentification &otherID) |
Static Protected Member Functions | |
| static void | sendNetMessage (OSG::Socket *socket, NetMessage *msg) |
| static void | receiveNetMessage (OSG::Socket *socket, NetMessage *dst) |
| static void | sendNetMessageTo (OSG::DgramSocket *socket, OSG::SocketAddress dst, NetMessage *msg) |
| static void | receiveNetMessageFrom (OSG::DgramSocket *socket, OSG::SocketAddress *src, NetMessage *dst) |
| static bool | IDequalsID (NetworkIdentification *i1, NetworkIdentification *i2) |
Protected Attributes | |
| std::map< uint32_t, NetworkIdentification > | mapUserToNetworkId |
| std::deque< SendListEntry * > | sendListTCP |
| std::deque< NetMessage * > * | recvList [256] |
| std::vector< SocketListEntry * > | socketList |
| std::deque< SendListEntry * > | sendListUDP |
| bool | connectionLocalAllowed |
| bool | connectionGlobalAllowed |
| bool | isInitialized |
| bool | connectCalled |
| OSG::Lock * | socketListLock |
| OSG::Lock * | connectionDisconnectionLock |
| OSG::Lock * | recvListLock |
| OSG::Lock * | sendListLock |
| OSG::DgramSocket | socketUDP |
| NetworkIdentification | myId |
| OSG::Thread * | sendRecvThread |
| OSG::Thread * | serverThread |
| SocketListEntry * | newSocketListEntry |
| SendReceiveThread * | sendRecvObj |
| SyncPipe< NetworkIdentification * > | killedSocketsPipe |
Static Protected Attributes | |
| static const uint32_t | normalMsgTag = 0 |
| static const uint32_t | connectionRequestTag = 1 |
| static const uint32_t | connectionRequestOkTag = 2 |
| static const uint32_t | connectionRequestDenyTag = 3 |
| static const uint32_t | quickConnectTag = 4 |
| static const uint32_t | connectionRequestDoneTag = 5 |
| static const uint32_t | quickConnectFailedTag = 6 |
| static const uint32_t | quickConnectOkTag = 7 |
Static Private Attributes | |
| static XmlConfigurationLoader | xmlConfigLoader |
Friends | |
| class | ServerThread |
| class | SendReceiveThread |
| class | SendListEntry |
Constructor & Destructor Documentation
| Network::Network | ( | ) |
Constructor initializes Network Module.
| Network::~Network | ( | ) | [virtual] |
Empty destructor
Member Function Documentation
| void Network::addClientsToMessage | ( | NetMessage * | msg | ) | [protected] |
This method adds the IDs of every connected client to the passed message.
- Parameters:
-
msg message, where to put the IDs to
| void Network::addConnectionToNetwork | ( | OSG::StreamSocket * | socket, | |
| UserNetworkIdentification & | otherID | |||
| ) | [protected] |
- Todo:
- check if we don't get threading-problems since this method is called from ServerThread too!!!
| bool Network::alreadyConnected | ( | ) | [protected] |
| bool Network::checkClientConnected | ( | NetworkIdentification * | id | ) | [protected] |
This method checks, if a client with the passed NetworkIdentification is already connected to the local machine.
- Parameters:
-
id NetworkIdentification for check
- Returns:
- true, if a client with matching ID is already connected
| bool Network::checkConnection | ( | ) | [protected] |
This method checks, if the a client is allowed to connect. For this it first checks locally, if already another client tries to connect to the network. If not, it sends a prioritizedMsg to all partners with the connectionRequestTag and waits for the answers of all partners. If every partner accepts the connection request the message returns true.
- Returns:
- true, if the client is allowed to connect
| void Network::checkSocketAndSendListConsistency | ( | SocketListEntry * | sockets, | |
| int | entries | |||
| ) | [protected] |
| void Network::cleanup | ( | ) | [virtual] |
Cleans up the network module. runs flush implicitily! message which are still in the queue will not be discarded!
Implements NetworkInterface.
| bool Network::connect | ( | std::string | nodeName | ) | [virtual] |
This method establishes the connection to a network. For this it first checks, if there is already a connection to another computer, and returns false if so, because joining 2 subnets is not supported. It then tries to open a socket to the computer with the passed IP-address and returns false if the socket-connection couldn't be established. The method then reads the local IP-address from the open socket and stores it in the local NetworkIdentification myId in class Network. Afterwards the handShake-method is called and if the handShake worked fine the connection is entered in the socketList.
- Parameters:
-
nodeName <ip>:<port> of machine to connect to
- Returns:
- true, if connection worked
Implements NetworkInterface.
| void Network::connectionDone | ( | ) | [protected] |
This method sends a message to all partners for finalizing the connection request of a client, so that everyone can accept new connections of other clients again.
| void Network::decodeId | ( | UserNetworkIdentification * | id, | |
| NetMessage * | msg | |||
| ) | [protected] |
| int Network::decodeMessageToIDs | ( | NetMessage * | msg, | |
| UserNetworkIdentification ** | ids | |||
| ) | [protected] |
decodeId
| void Network::dumpConnection | ( | SocketListEntry * | con | ) | [protected] |
| std::string Network::dumpNetworkIdentification | ( | NetworkIdentification * | netId | ) | [protected] |
| void Network::encodeId | ( | NetMessage * | msg, | |
| UserNetworkIdentification * | id, | |||
| bool | putFirst = false | |||
| ) | [protected] |
| void Network::finalizeConnectionRequest | ( | ) | [protected] |
| void Network::flush | ( | ) | [virtual] |
blocks current thread until all messages are sent
Implements NetworkInterface.
| NetworkIdentification Network::getLocalIdentification | ( | ) | [virtual] |
Implements NetworkInterface.
| std::string Network::getName | ( | ) | [virtual] |
Returns the name of the module.
Implements NetworkInterface.
| int Network::getNumberOfParticipants | ( | ) | [virtual] |
DEPRECATED. Needed by the Transformation Manager during initialization (runFirst()). I hope we can get rid of it soon!
- Returns:
- returns the number of users in the network (not including the local user)
Implements NetworkInterface.
| void Network::handleLostConnections | ( | ) | [protected] |
Polls killedSocketsPipe and invokes onConnectionClosed() for each lost connection
- Todo:
- implement this
| bool Network::handleNormalConnect | ( | OSG::StreamSocket * | socket, | |
| UserNetworkIdentification * | otherID | |||
| ) | [protected] |
| bool Network::handleQuickConnect | ( | OSG::StreamSocket * | socket | ) | [protected] |
| bool Network::handShake | ( | OSG::StreamSocket * | socket, | |
| UserNetworkIdentification * | id, | |||
| bool | quickConnect = false | |||
| ) | [protected] |
This method makes the handshake between the local computer and the parnter to check, if the local computer is allowed or is able to connect to the network. For this it first sends the type of the connection (quick or normal). Then the method distinguishes between a quick-connection or a normal connection. If the connection type is a quick connection, the method receives an answer from the server if the connection is ok and returns true if so. If it is a normal connection the method receives a message from the partner and first decodes the message-tag to see if the connection is allowed. If the connection is allowed the method decodes the partners ID and the IDs of all members connected to the partner from the message. It then tries to establish a quick-connection to all connected members of the client. If everything went fine the method sends back a message to it's partner that the connection is done.
- Parameters:
-
socket the socket to the partner to connect with otherID the partner's ID decoded from the first message of the partner quick for distinction beween quick-connect and normal connect
- Returns:
- true, if the connection is established
| bool Network::IDequalsID | ( | NetworkIdentification * | i1, | |
| NetworkIdentification * | i2 | |||
| ) | [static, protected] |
This method checks, if two NetworkIdentifications are equal
- Parameters:
-
i1,i2 NetworkIdentifications to compare
- Returns:
- true, if ipAddress, TCP-port and processId are the same
| bool Network::init | ( | uint16_t | portTCP, | |
| uint16_t | portUDP, | |||
| std::string | ipAddress = "" | |||
| ) | [protected] |
Initializes the network module.
- Returns:
- true on success, false on failure (most likely because tcp port is already in use)
- Parameters:
-
portTCP tcp server port for incoming tcp connections portUDP port which receives udp messages
| bool Network::initializeConnectionRequest | ( | ) | [protected] |
| bool Network::loadConfig | ( | std::string | configFile | ) | [virtual] |
Loads the configuration of the module from the passed config-file. It currently reads the ports for UDP and TCP from the file and calls the init-method.
Implements ModuleInterface.
| NetMessage * Network::peek | ( | uint8_t | channelId = 0 |
) | [virtual] |
This method returns a pointer to the first Message in the receiveList.
- Returns:
- pointer to first message in receiveList
Implements NetworkInterface.
| NetMessage * Network::pop | ( | uint8_t | channelId = 0 |
) | [virtual] |
This method pops the first message from the receiveList.
- Returns:
- first message in receiveList
Implements NetworkInterface.
| void Network::popAll | ( | uint8_t | channelId, | |
| std::vector< NetMessage * > * | dst | |||
| ) | [virtual] |
Implements NetworkInterface.
| bool Network::quickConnect | ( | UserNetworkIdentification * | id | ) | [protected] |
This method is for connecting to all other members of the network when the connection to the first member is established. While connecting to the network the connection partner sends back a list of all other members in the network (see handShake). To avoid checking, if the new client is allowed to connect (since this was already done by the ServerThread of the first partner) this message just establishes the connection without a long handShake. For this it tries to open a socket to the computer with the passed NetworkIdentification and then calls the handShake-method with a parameter set for the quick-connection. If the handShake worked the new connection is added to the socketList.
- Parameters:
-
id NetworkIdentification of the partner to connect to
- Returns:
- true, if quick-connection worked
| void Network::receiveNetMessage | ( | OSG::Socket * | socket, | |
| NetMessage * | dst | |||
| ) | [static, protected] |
| void Network::receiveNetMessageFrom | ( | OSG::DgramSocket * | socket, | |
| OSG::SocketAddress * | src, | |||
| NetMessage * | dst | |||
| ) | [static, protected] |
| void Network::sendEvent | ( | Event * | event | ) | [virtual] |
encodes a Event into NetMessage and transmitts it via TCP checks event->visibilityLevel for int "destinationUserId". If not set the event will be broadcasted otherwise it will be send to userid referenced to by that key
Implements NetworkInterface.
| void Network::sendMessageTCP | ( | NetMessage * | msg, | |
| uint8_t | channelId = 0 | |||
| ) | [virtual] |
Implements NetworkInterface.
| void Network::sendMessageTCPTo | ( | NetMessage * | msg, | |
| uint8_t | channelId, | |||
| unsigned | userId | |||
| ) | [virtual] |
Implements NetworkInterface.
| void Network::sendMessageToGroup | ( | NetMessage * | msg, | |
| uint8_t | channelId, | |||
| std::vector< NetworkIdentification > * | destinationList, | |||
| bool | useTCP | |||
| ) | [protected] |
this method is used internally to handle all sendMessageXXX() tasks
- Parameters:
-
destinationList NULL means broadcast to all available connections
| void Network::sendMessageUDP | ( | NetMessage * | msg, | |
| uint8_t | channelId = 0 | |||
| ) | [virtual] |
Implements NetworkInterface.
| void Network::sendMessageUDPTo | ( | NetMessage * | msg, | |
| uint8_t | channelId, | |||
| unsigned | userId | |||
| ) | [virtual] |
Implements NetworkInterface.
| void Network::sendNetMessage | ( | OSG::Socket * | socket, | |
| NetMessage * | msg | |||
| ) | [static, protected] |
| void Network::sendNetMessageTo | ( | OSG::DgramSocket * | socket, | |
| OSG::SocketAddress | dst, | |||
| NetMessage * | msg | |||
| ) | [static, protected] |
| int Network::sendPrioritizedMessage | ( | NetMessage * | msg | ) | [protected] |
This method sends a prioritizedMsg, which is needed e.g. for connections. A prioritized message bypasses the message queues.
- Parameters:
-
message message to send
- Returns:
- number of clients to which the message will be sent
| void Network::sendTransformation | ( | TransformationData & | trans, | |
| TransformationPipe * | pipe, | |||
| bool | useTCP | |||
| ) | [virtual] |
a NetMessage with the following layout will be transmitted:
struct MSGCONTENT { uint32_t pipeOwnerUserId; uint64_t pipeId; uint32_t[14] contentOfTrans; // see addTransformationToBinaryMsg() (SystemCore/DataTypes.cpp) };
The message is expected to be addressed to the channel TRANSFORMATION_MANAGER_ID
- Parameters:
-
useTCP is intended to serve as hint
Implements NetworkInterface.
| void Network::setLocalIPAddress | ( | OSG::StreamSocket * | socket | ) | [protected] |
- Todo:
- check if myId should be locked because of multiple threads
| int Network::sizeRecvList | ( | uint8_t | channelId = 0 |
) | [virtual] |
This method returns the number of messages waiting in the receiveList.
- Returns:
- number of messages waiting in receiveList
Implements NetworkInterface.
| void Network::splitDestination | ( | std::string | destination, | |
| std::string & | ipAddress, | |||
| int & | port | |||
| ) | [protected] |
Friends And Related Function Documentation
friend class SendListEntry [friend] |
friend class SendReceiveThread [friend] |
friend class ServerThread [friend] |
Member Data Documentation
bool Network::connectCalled [protected] |
OSG::Lock* Network::connectionDisconnectionLock [protected] |
bool Network::connectionGlobalAllowed [protected] |
bool Network::connectionLocalAllowed [protected] |
const uint32_t Network::connectionRequestDenyTag = 3 [static, protected] |
const uint32_t Network::connectionRequestDoneTag = 5 [static, protected] |
const uint32_t Network::connectionRequestOkTag = 2 [static, protected] |
const uint32_t Network::connectionRequestTag = 1 [static, protected] |
bool Network::isInitialized [protected] |
SyncPipe<NetworkIdentification*> Network::killedSocketsPipe [protected] |
std::map<uint32_t, NetworkIdentification> Network::mapUserToNetworkId [protected] |
NetworkIdentification Network::myId [protected] |
SocketListEntry* Network::newSocketListEntry [protected] |
const uint32_t Network::normalMsgTag = 0 [static, protected] |
const uint32_t Network::quickConnectFailedTag = 6 [static, protected] |
const uint32_t Network::quickConnectOkTag = 7 [static, protected] |
const uint32_t Network::quickConnectTag = 4 [static, protected] |
std::deque<NetMessage*>* Network::recvList[256] [protected] |
OSG::Lock* Network::recvListLock [protected] |
OSG::Lock* Network::sendListLock [protected] |
std::deque<SendListEntry*> Network::sendListTCP [protected] |
std::deque<SendListEntry*> Network::sendListUDP [protected] |
SendReceiveThread* Network::sendRecvObj [protected] |
OSG::Thread* Network::sendRecvThread [protected] |
OSG::Thread* Network::serverThread [protected] |
std::vector<SocketListEntry*> Network::socketList [protected] |
OSG::Lock* Network::socketListLock [protected] |
OSG::DgramSocket Network::socketUDP [protected] |
XmlConfigurationLoader Network::xmlConfigLoader [static, private] |
The documentation for this class was generated from the following files:
- src/inVRs/Modules/Network/Network.h
- src/inVRs/Modules/Network/Network.cpp
Generated on Wed Oct 20 16:11:58 2010 for inVRs by
1.5.8