HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UT_NetExchange Class Reference

#include <UT_NetMessage.h>

Classes

class  AutoNetworkTimer
 

Public Member Functions

 UT_NetExchange (const UT_StringHolder &trackeraddr, int trackerport, int peer, int npeer, const UT_StringHolder &jobname)
 
 ~UT_NetExchange ()
 
void sendData (int destpeer, const char *data, exint len)
 
void sendData (int destpeer, UT_NetMessage *msg)
 
void sendDone ()
 
bool pumpData (int timeoutms)
 
bool receiveDataLoop (UT_Array< UT_NetMessage * > &completed, int expectedmessages, int timeoutms=100)
 
bool asyncReceiveDataLoop (UT_Array< UT_NetMessage * > &completed, int expectedmessages, int timeoutms=100)
 
bool finishAsyncReceiveDataLoop ()
 Blocks until the asyncReceiveDataLoop completes/errors. More...
 
template<class CallbackType >
bool processDataLoop (UT_Array< UT_NetMessage * > &complist, int expectedmessages, CallbackType callback, int timeoutms=100)
 
bool isErrored () const
 
UT_ValArray< UT_NetMessage * > & completed ()
 
bool gotPeerList () const
 Returns if we have received a peer list from the tracker. More...
 
void setCompressionThreshold (exint threshold_bytes)
 
exint compressionThreshold () const
 
ut_NetPeerDatafindPeer (int peer)
 

Protected Member Functions

void processTrackerMessage (UT_NetMessage *msg)
 
void sendTrackerMessage (const char *msg)
 Assembles a message to the tracker. More...
 
void startNetworkTimer ()
 
void stopNetworkTimer ()
 

Protected Attributes

UT_NetMessagePump myPump
 
int myNPeer
 
int myPeer
 
UT_NetSocketPtr myToSelf
 
UT_StringHolder myTrackerAddr
 
int myTrackerPort
 
bool myGotPeerList
 
bool myError
 
bool myErrorFromTracker
 
UT_Array< ut_NetPeerDatamyPeerList
 
UT_ValArray< UT_NetMessage * > myWaitingForPeers
 
UT_ValArray< UT_NetMessage * > myCompleted
 
UT_StringHolder myJobName
 
UT_StopWatchmyTimer
 We track our elapsed time for printing status. More...
 
int myTimerDelay
 
int myHeartbeat
 
fpreal64 myLastTimerVal
 
exint myCompressionThreshold
 Number of bytes to start compressing at. More...
 

Friends

class AutoNetworkTimer
 

Detailed Description

UT_NetExchange

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. 'P' is used for blosc compressed peer data, it will be uncompressed and revealed to the user as a 'p' data.

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.

Examples:
SIM/GAS_NetVDBSliceExchange.C, and standalone/msgpipe.C.

Definition at line 380 of file UT_NetMessage.h.

Constructor & Destructor Documentation

UT_NetExchange::UT_NetExchange ( const UT_StringHolder trackeraddr,
int  trackerport,
int  peer,
int  npeer,
const UT_StringHolder jobname 
)
UT_NetExchange::~UT_NetExchange ( )

Member Function Documentation

bool UT_NetExchange::asyncReceiveDataLoop ( UT_Array< UT_NetMessage * > &  completed,
int  expectedmessages,
int  timeoutms = 100 
)

Uses a background thread to run the message loop. You should not inspect/alter UT_NetExchange or its owned UT_NetMessages until finished.

UT_ValArray<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 516 of file UT_NetMessage.h.

exint UT_NetExchange::compressionThreshold ( ) const
inline

Definition at line 522 of file UT_NetMessage.h.

ut_NetPeerData* UT_NetExchange::findPeer ( int  peer)
bool UT_NetExchange::finishAsyncReceiveDataLoop ( )

Blocks until the asyncReceiveDataLoop completes/errors.

bool UT_NetExchange::gotPeerList ( ) const
inline

Returns if we have received a peer list from the tracker.

Definition at line 519 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 510 of file UT_NetMessage.h.

template<class CallbackType >
bool UT_NetExchange::processDataLoop ( UT_Array< 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 459 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_Array< 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,
const char *  data,
exint  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::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::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.

void UT_NetExchange::setCompressionThreshold ( exint  threshold_bytes)
inline

Definition at line 521 of file UT_NetMessage.h.

void UT_NetExchange::startNetworkTimer ( )
protected
void UT_NetExchange::stopNetworkTimer ( )
protected

Friends And Related Function Documentation

friend class AutoNetworkTimer
friend

Definition at line 558 of file UT_NetMessage.h.

Member Data Documentation

UT_ValArray<UT_NetMessage *> UT_NetExchange::myCompleted
protected

Definition at line 546 of file UT_NetMessage.h.

exint UT_NetExchange::myCompressionThreshold
protected

Number of bytes to start compressing at.

Definition at line 556 of file UT_NetMessage.h.

bool UT_NetExchange::myError
protected

Definition at line 541 of file UT_NetMessage.h.

bool UT_NetExchange::myErrorFromTracker
protected

Definition at line 542 of file UT_NetMessage.h.

bool UT_NetExchange::myGotPeerList
protected

Definition at line 540 of file UT_NetMessage.h.

int UT_NetExchange::myHeartbeat
protected

Definition at line 552 of file UT_NetMessage.h.

UT_StringHolder UT_NetExchange::myJobName
protected

Definition at line 548 of file UT_NetMessage.h.

fpreal64 UT_NetExchange::myLastTimerVal
protected

Definition at line 553 of file UT_NetMessage.h.

int UT_NetExchange::myNPeer
protected

Definition at line 534 of file UT_NetMessage.h.

int UT_NetExchange::myPeer
protected

Definition at line 534 of file UT_NetMessage.h.

UT_Array<ut_NetPeerData> UT_NetExchange::myPeerList
protected

Definition at line 543 of file UT_NetMessage.h.

UT_NetMessagePump UT_NetExchange::myPump
protected

Definition at line 533 of file UT_NetMessage.h.

UT_StopWatch* UT_NetExchange::myTimer
protected

We track our elapsed time for printing status.

Definition at line 551 of file UT_NetMessage.h.

int UT_NetExchange::myTimerDelay
protected

Definition at line 552 of file UT_NetMessage.h.

UT_NetSocketPtr UT_NetExchange::myToSelf
protected

Definition at line 535 of file UT_NetMessage.h.

UT_StringHolder UT_NetExchange::myTrackerAddr
protected

Definition at line 537 of file UT_NetMessage.h.

int UT_NetExchange::myTrackerPort
protected

Definition at line 538 of file UT_NetMessage.h.

UT_ValArray<UT_NetMessage *> UT_NetExchange::myWaitingForPeers
protected

Definition at line 545 of file UT_NetMessage.h.


The documentation for this class was generated from the following file: