#include <UT_NetMessage.h>
Public Member Functions | |
| UT_NetExchange (const char *trackeraddr, int trackerport, int peer, int npeer, const char *jobname) | |
| virtual | ~UT_NetExchange () |
| void | sendData (int destpeer, const char *data, int len) |
| void | sendData (int destpeer, UT_NetMessage *msg) |
| void | sendDone () |
| bool | pumpData (int timeoutms) |
| bool | receiveDataLoop (UT_PtrArray< UT_NetMessage * > &completed, int expectedmessages, int timeoutms=100) |
| template<class CallbackType > | |
| bool | processDataLoop (UT_PtrArray< UT_NetMessage * > &complist, int expectedmessages, CallbackType callback, int timeoutms=100) |
| bool | isErrored () const |
| UT_PtrArray< UT_NetMessage * > & | completed () |
| bool | gotPeerList () const |
| Returns if we have received a peer list from the tracker. | |
Protected Member Functions | |
| ut_NetPeerData * | findPeer (int peer) |
| void | processTrackerMessage (UT_NetMessage *msg) |
| void | sendTrackerMessage (const char *msg) |
| Assembles a message to the tracker. | |
Protected Attributes | |
| UT_NetMessagePump | myPump |
| int | myNPeer |
| int | myPeer |
| UT_NetSocket * | myToSelf |
| UT_String | myTrackerAddr |
| int | myTrackerPort |
| bool | myGotPeerList |
| bool | myError |
| bool | myErrorFromTracker |
| UT_RefArray< ut_NetPeerData > | myPeerList |
| UT_PtrArray< UT_NetMessage * > | myWaitingForPeers |
| UT_PtrArray< UT_NetMessage * > | myCompleted |
| UT_String | myJobName |
| UT_StopWatch * | myTimer |
| We track our elapsed time for printing status. | |
| int | myTimerDelay |
| int | myHeartbeat |
| fpreal64 | myLastTimerVal |
Uses a tracker to exchange data between peers. The tracker handles peer discovery and synchronization. A unique jobname is used to allow multiple net exchanges to use the same tracker.
EXTERNAL PROTOCOL:
UT_NetMessages accepted or returned from this have an 8 byte header. The fields are filled out for you on a sendData() and can be queried to determine the message source when pulling completed messages from the result list.
The first byte is the message type. If it is 'p', it is peer data. Users of UT_NetExchange should only see these messages as the other are internal tracker messages.
extractInt16(4): Destination peer # extractInt16(6): Source peer #
Anything 8 and after is user data.
INTERNAL PROTOCOL:
From the tracker:
Message of type 'b' is a barrier value. The 32 bit network byte order barrier value starts at offset 1.
Message type of 'c' is a peer list. A space delimited list of address port peer triples is present, one for each peer.
Message type of 'd' is a done flag. It informs that all the peers have reported done to the tracker.
Message type of 'e' is an error. One of the peers reported an error to the tracker that got broadcast back.
To the tracker:
Messages to the tracker all have the format command port peer npeer jobname
port is the listen port used by this peer. peer is the peer number npeer is the number of peers jobname is the name of the current job
command is one of: acquire: A peer is logging on to this jobname. done: A peer has all the data it cares about from the netexchange. error: A peer has encountered a fatal network error and wants a clean shutdown. barrierset: Establish a barrier, the current value is peer. barrierwait: Will recevie a done message when the peer value is reached or exceeded by the named barrier.
Definition at line 325 of file UT_NetMessage.h.
| UT_NetExchange::UT_NetExchange | ( | const char * | trackeraddr, | |
| int | trackerport, | |||
| int | peer, | |||
| int | npeer, | |||
| const char * | jobname | |||
| ) |
| virtual UT_NetExchange::~UT_NetExchange | ( | ) | [virtual] |
| UT_PtrArray<UT_NetMessage *>& UT_NetExchange::completed | ( | ) | [inline] |
Same semantics as UT_NetMessagePump. Stores all the messages that have successfully arrived. This first 8 bytes of theses messages is the header with which you can extract the source peer of the message.
Definition at line 439 of file UT_NetMessage.h.
| ut_NetPeerData* UT_NetExchange::findPeer | ( | int | peer | ) | [protected] |
| bool UT_NetExchange::gotPeerList | ( | ) | const [inline] |
Returns if we have received a peer list from the tracker.
Definition at line 442 of file UT_NetMessage.h.
| bool UT_NetExchange::isErrored | ( | ) | const [inline] |
The net exchange goes into an error state when the connection the tracker sends an error message. peer-to-peer errors are dealt with by sending the tracker an error message which is supposed to broadcast the error back to all the peers. Error recovery can thus be effected provided it is the tracker that stays up.
Definition at line 433 of file UT_NetMessage.h.
| bool UT_NetExchange::processDataLoop | ( | UT_PtrArray< UT_NetMessage * > & | complist, | |
| int | expectedmessages, | |||
| CallbackType | callback, | |||
| int | timeoutms = 100 | |||
| ) | [inline] |
Pumps the message pump until we have received the expected number of data messages and the tracker reports us as done. The messages in the completed array must be deleted by the caller. UT_Interrupt is used to interrupt this. true if everything finished properly, false if there was an interrupt or error.
The callback processes any message with a 'r' as the 8th byte. Final messages (which do not get further processed) should have 'd' as the 8th byte - they will be added to the completed list and count to the expectedmessages. It should be a function object taking two parameters, UT_NetExchange * and UT_NetMessage *.
UT_Interrupt is used to interrupt this. true if everything finished properly, false if there was an interrupt or error.
Definition at line 381 of file UT_NetMessage.h.
| void UT_NetExchange::processTrackerMessage | ( | UT_NetMessage * | msg | ) | [protected] |
| bool UT_NetExchange::pumpData | ( | int | timeoutms | ) |
Returns true until the tracker notifies us that all of the peers have invoked sendDone() or an error occurs.
| bool UT_NetExchange::receiveDataLoop | ( | UT_PtrArray< UT_NetMessage * > & | completed, | |
| int | expectedmessages, | |||
| int | timeoutms = 100 | |||
| ) |
Pumps the message pump until we have received the expected number of messages and the tracker reports us as done. The messages in the completed array must be deleted by the caller. UT_Interrupt is used to interrupt this. true if everything finished properly, false if there was an interrupt or error.
| void UT_NetExchange::sendData | ( | int | destpeer, | |
| UT_NetMessage * | msg | |||
| ) |
Gains ownership of the message. The message must have an 8 byte header reserved for the net exchange protocol. The rest of the data in the net message is unaffected.
| void UT_NetExchange::sendData | ( | int | destpeer, | |
| const char * | data, | |||
| int | len | |||
| ) |
Posts the data to be sent to the specific destination machine. The data will be copied into an internal buffer. Note that destpeer could be this, in which case we'll just have effected a very slow copy.
| void UT_NetExchange::sendDone | ( | ) |
Flags this peer as done. You should still process the pump until interrupted or completed, however, as the other peers may not yet be done. Likewise, you may still continue to get new requests from other peers.
| void UT_NetExchange::sendTrackerMessage | ( | const char * | msg | ) | [protected] |
Assembles a message to the tracker.
UT_PtrArray<UT_NetMessage *> UT_NetExchange::myCompleted [protected] |
Definition at line 464 of file UT_NetMessage.h.
bool UT_NetExchange::myError [protected] |
Definition at line 459 of file UT_NetMessage.h.
bool UT_NetExchange::myErrorFromTracker [protected] |
Definition at line 460 of file UT_NetMessage.h.
bool UT_NetExchange::myGotPeerList [protected] |
Definition at line 458 of file UT_NetMessage.h.
int UT_NetExchange::myHeartbeat [protected] |
Definition at line 470 of file UT_NetMessage.h.
UT_String UT_NetExchange::myJobName [protected] |
Definition at line 466 of file UT_NetMessage.h.
fpreal64 UT_NetExchange::myLastTimerVal [protected] |
Definition at line 471 of file UT_NetMessage.h.
int UT_NetExchange::myNPeer [protected] |
Definition at line 452 of file UT_NetMessage.h.
int UT_NetExchange::myPeer [protected] |
Definition at line 452 of file UT_NetMessage.h.
UT_RefArray<ut_NetPeerData> UT_NetExchange::myPeerList [protected] |
Definition at line 461 of file UT_NetMessage.h.
UT_NetMessagePump UT_NetExchange::myPump [protected] |
Definition at line 451 of file UT_NetMessage.h.
UT_StopWatch* UT_NetExchange::myTimer [protected] |
int UT_NetExchange::myTimerDelay [protected] |
Definition at line 470 of file UT_NetMessage.h.
UT_NetSocket* UT_NetExchange::myToSelf [protected] |
Definition at line 453 of file UT_NetMessage.h.
UT_String UT_NetExchange::myTrackerAddr [protected] |
Definition at line 455 of file UT_NetMessage.h.
int UT_NetExchange::myTrackerPort [protected] |
Definition at line 456 of file UT_NetMessage.h.
UT_PtrArray<UT_NetMessage *> UT_NetExchange::myWaitingForPeers [protected] |
Definition at line 463 of file UT_NetMessage.h.
1.5.9