network connection base class.
|
Adaptive Protocol |
Functions and state for the adaptive rate protocol.
TNL's adaptive rate uses rate control algorithms similar to TCP/IP's.
There are a few state variables here that aren't documented.
|
void | setIsAdaptive () |
| Enables the adaptive protocol.
|
void | setFixedRateParameters (U32 minPacketSendPeriod, U32 minPacketRecvPeriod, U32 maxSendBandwidth, U32 maxRecvBandwidth) |
| sets the fixed rate send and receive data sizes, and sets the connection to not behave as an adaptive rate connection
|
bool | isAdaptive () |
| Query the adaptive status of the connection.
|
virtual bool | isDataToTransmit () |
| Returns true if this connection has data to transmit.
|
F32 | cwnd |
F32 | ssthresh |
U32 | mLastSeqRecvdAck |
U32 | mLastAckTime |
Public Types |
enum | TerminationReason {
ReasonTimedOut,
ReasonFailedConnectHandshake,
ReasonRemoteHostRejectedConnection,
ReasonRemoteDisconnectPacket,
ReasonDuplicateConnectionAttempt,
ReasonSelfDisconnect,
ReasonError
} |
enum | NetConnectionTypeFlags {
ConnectionToServer = BIT(0),
ConnectionToClient = BIT(1),
ConnectionAdaptive = BIT(2),
ConnectionRemoteAdaptive = BIT(3)
} |
| Flags specifying the type of the connection instance. More...
|
enum | NetConnectionState {
NotConnected = 0,
AwaitingChallengeResponse,
SendingPunchPackets,
ComputingPuzzleSolution,
AwaitingConnectResponse,
ConnectTimedOut,
ConnectRejected,
Connected,
Disconnected,
TimedOut,
StateCount
} |
| Connection state flags for a NetConnection instance. More...
|
Public Member Functions |
| NetConnection () |
| ~NetConnection () |
U32 | getNextSendSequence () |
| Returns the next send sequence that will be sent by this side.
|
U32 | getLastSendSequence () |
| Returns the sequence of the last packet sent by this connection, or the current packet's send sequence if called from within writePacket().
|
void | setInitialRecvSequence (U32 sequence) |
| Sets the initial sequence number of packets read from the remote host.
|
U32 | getInitialRecvSequence () |
| Returns the initial sequence number of packets sent from the remote host.
|
U32 | getInitialSendSequence () |
| Returns the initial sequence number of packets sent to the remote host.
|
void | connect (NetInterface *connectionInterface, const Address &address, bool requestKeyExchange=false, bool requestCertificate=false) |
| Connect to a server through a given network interface.
|
bool | connectLocal (NetInterface *connectionInterface, NetInterface *localServerInterface) |
| Connects to a server interface within the same process.
|
void | connectArranged (NetInterface *connectionInterface, const Vector< Address > &possibleAddresses, Nonce &myNonce, Nonce &remoteNonce, ByteBufferPtr sharedSecret, bool isInitiator, bool requestsKeyExchange=false, bool requestsCertificate=false) |
| Connects to a remote host that is also connecting to this connection (negotiated by a third party).
|
void | disconnect (const char *reason) |
| Sends a disconnect packet to notify the remote host that this side is terminating the connection for the specified reason.
|
bool | windowFull () |
| Returns true if the packet send window is full and no more data packets can be sent.
|
ConnectionParameters & | getConnectionParameters () |
bool | isInitiator () |
| returns true if this object initiated the connection with the remote host
|
void | setRemoteConnectionObject (NetConnection *connection) |
NetConnection * | getRemoteConnectionObject () |
void | setInterface (NetInterface *myInterface) |
| Sets the NetInterface this NetConnection will communicate through.
|
NetInterface * | getInterface () |
| Returns the NetInterface this connection communicates through.
|
void | setSymmetricCipher (SymmetricCipher *theCipher) |
| Sets the SymmetricCipher this NetConnection will use for encryption.
|
virtual NetClassGroup | getNetClassGroup () const |
| Returns the class group of objects that can be transmitted over this NetConnection.
|
void | setPingTimeouts (U32 msPerPing, U32 pingRetryCount) |
| Sets the ping/timeout characteristics for a fixed-rate connection. Total timeout is msPerPing * pingRetryCount.
|
void | setSimulatedNetParams (F32 packetLoss, U32 latency) |
| Simulates a network situation with a percentage random packet loss and a connection one way latency as specified.
|
void | setIsConnectionToServer () |
| Specifies that this NetConnection instance is a connection to a "server.".
|
bool | isConnectionToServer () |
| Returns true if this is a connection to a "server.".
|
void | setIsConnectionToClient () |
| Specifies that this NetConnection instance is a connection to a "client.".
|
bool | isConnectionToClient () |
| Returns true if this is a connection to a "client.".
|
bool | isLocalConnection () |
| Returns true if the remote side of this connection is a NetConnection instance in on the same host.
|
bool | isNetworkConnection () |
| Returns true if the remote side if this connection is on a remote host.
|
F32 | getRoundTripTime () |
| Returns the running average packet round trip time.
|
F32 | getOneWayTime () |
| Returns have of the average of the round trip packet time.
|
const Address & | getNetAddress () |
| Returns the remote address of the host we're connected or trying to connect to.
|
const char * | getNetAddressString () const |
| Returns the remote address in string form.
|
void | setNetAddress (const Address &address) |
| Sets the address of the remote host we want to connect to.
|
NetError | sendPacket (BitStream *stream) |
| Sends a packet that was written into a BitStream to the remote host, or the mRemoteConnection on this host.
|
bool | checkTimeout (U32 time) |
| Checks to see if the connection has timed out, possibly sending a ping packet to the remote host. Returns true if the connection timed out.
|
void | checkPacketSend (bool force, U32 currentTime) |
| Checks to see if a packet should be sent at the currentTime to the remote host.
|
void | setConnectionState (NetConnectionState state) |
| Sets the current connection state of this NetConnection.
|
NetConnectionState | getConnectionState () |
| Gets the current connection state of this NetConnection.
|
bool | isEstablished () |
| Returns true if the connection handshaking has completed successfully.
|
void | setTranslatesStrings () |
| Enables string tag translation on this connection.
|
Static Public Member Functions |
char * | getErrorBuffer () |
| returns the current error buffer
|
void | setLastError (const char *fmt,...) |
| Sets an error string and notifies the currently processing connection that it should terminate.
|
Data Fields |
U32 | mConnectSendCount |
| Number of challenge or connect requests sent to the remote host.
|
U32 | mConnectLastSendTime |
| The send time of the last challenge or connect request.
|
NetConnectionState | mConnectionState |
| Current state of this NetConnection.
|
Protected Member Functions |
virtual void | onConnectTerminated (TerminationReason reason, const char *rejectionString) |
| Called when a pending connection is terminated.
|
virtual void | onConnectionTerminated (TerminationReason, const char *errorDisconnectString) |
| Called when this established connection is terminated for any reason.
|
virtual void | onConnectionEstablished () |
| Called when the connection is successfully established with the remote host.
|
virtual bool | validateCertficate (Certificate *theCertificate, bool isInitiator) |
| validates that the given certificate is a valid certificate for this connection.
|
virtual bool | validatePublicKey (AsymmetricKey *theKey, bool isInitiator) |
| Validates that the given public key is valid for this connection.
|
virtual void | writeConnectRequest (BitStream *stream) |
| Fills the connect request packet with additional custom data (from a subclass).
|
virtual bool | readConnectRequest (BitStream *stream, const char **errorString) |
| Called after this connection instance is created on a non-initiating host (server).
|
virtual void | writeConnectAccept (BitStream *stream) |
| Writes any data needed to start the connection on the accept packet.
|
virtual bool | readConnectAccept (BitStream *stream, const char **errorString) |
| Reads out the extra data read by writeConnectAccept and returns true if it is processed properly.
|
virtual void | readPacket (BitStream *bstream) |
| Called to read a subclass's packet data from the packet.
|
virtual void | prepareWritePacket () |
| Called to prepare the connection for packet writing.
|
virtual void | writePacket (BitStream *bstream, PacketNotify *note) |
| Called to write a subclass's packet data into the packet.
|
virtual void | packetReceived (PacketNotify *note) |
| Called when the packet associated with the specified notify is known to have been received by the remote host.
|
virtual void | packetDropped (PacketNotify *note) |
| Called when the packet associated with the specified notify is known to have been not received by the remote host.
|
virtual PacketNotify * | allocNotify () |
| Allocates a data record to track data sent on an individual packet.
|
void | readRawPacket (BitStream *bstream) |
| Reads a raw packet from a BitStream, as dispatched from NetInterface.
|
void | writeRawPacket (BitStream *bstream, NetPacketType packetType) |
| Writes a full packet of the specified type into the BitStream.
|
void | writePacketHeader (BitStream *bstream, NetPacketType packetType) |
| Writes the notify protocol's packet header into the BitStream.
|
bool | readPacketHeader (BitStream *bstream) |
| Reads a notify protocol packet header from the BitStream and returns true if it was a data packet that needs more processing.
|
void | writePacketRateInfo (BitStream *bstream, PacketNotify *note) |
| Writes any packet send rate change information into the packet.
|
void | readPacketRateInfo (BitStream *bstream) |
| Reads any packet send rate information requests from the packet.
|
void | sendPingPacket () |
| Sends a ping packet to the remote host, to determine if it is still alive and what its packet window status is.
|
void | sendAckPacket () |
| Sends an ack packet to the remote host, in response to receiving a ping packet.
|
void | handleNotify (U32 sequence, bool recvd) |
| Dispatches a notify when a packet is ACK'd or NACK'd.
|
void | keepAlive () |
| Called when a packet is received to stop any timeout action in progress.
|
void | clearAllPacketNotifies () |
| Clears out the pending notify list.
|
PacketNotify * | getCurrentWritePacketNotify () |
| Returns the notify structure for the current packet write, or last written packet.
|
Protected Attributes |
PacketNotify * | mNotifyQueueHead |
| Linked list of structures representing the data in sent packets.
|
PacketNotify * | mNotifyQueueTail |
| Tail of the notify queue linked list. New packets are added to the end of the tail.
|
SafePtr< NetConnection > | mRemoteConnection |
| Safe pointer to a short-circuit remote connection on the same host.
|
ConnectionParameters | mConnectionParameters |
SafePtr< NetInterface > | mInterface |
| The NetInterface of which this NetConnection is a member.
|
RefPtr< SymmetricCipher > | mSymmetricCipher |
| The helper object that performs symmetric encryption on packets.
|
Static Protected Attributes |
char | mErrorBuffer [256] |
| String buffer that errors are written into.
|
Private Types |
typedef Object | Parent |
enum | HeaderConstants {
MaxPacketWindowSizeShift = 5,
MaxPacketWindowSize = (1 << MaxPacketWindowSizeShift),
PacketWindowMask = MaxPacketWindowSize - 1,
MaxAckMaskSize = 1 << (MaxPacketWindowSizeShift - 5),
MaxAckByteCount = MaxAckMaskSize << 2,
SequenceNumberBitSize = 11,
SequenceNumberWindowSize = (1 << SequenceNumberBitSize),
SequenceNumberMask = -SequenceNumberWindowSize,
AckSequenceNumberBitSize = 10,
AckSequenceNumberWindowSize = (1 << AckSequenceNumberBitSize),
AckSequenceNumberMask = -AckSequenceNumberWindowSize,
PacketHeaderBitSize = 3 + AckSequenceNumberBitSize + SequenceNumberBitSize,
PacketHeaderByteSize = (PacketHeaderBitSize + 7) >> 3,
PacketHeaderPadBits = (PacketHeaderByteSize << 3) - PacketHeaderBitSize,
MessageSignatureBytes = 5
} |
| Constants controlling the data representation of each packet header. More...
|
enum | NetPacketType {
DataPacket,
PingPacket,
AckPacket,
InvalidPacketType
} |
| Two-bit identifier for each connected packet. More...
|
enum | DefaultPingConstants {
AdaptiveInitialPingTimeout = 60000,
AdaptivePingRetryCount = 4,
DefaultPingTimeout = 5000,
DefaultPingRetryCount = 10,
AdaptiveUnackedSentPingTimeout = 3000
} |
| Constants controlling the behavior of pings and timeouts. More...
|
enum | RateDefaults {
DefaultFixedBandwidth = 2500,
DefaultFixedSendPeriod = 96,
MaxFixedBandwidth = 65535,
MaxFixedSendPeriod = 2047
} |
Private Member Functions |
bool | hasUnackedSentPackets () |
| Returns true if this connection has sent packets that have not yet been acked by the remote host.
|
void | computeNegotiatedRate () |
| Called internally when the local or remote rate changes.
|
Private Attributes |
U32 | mLastPacketRecvTime |
| Time of the receipt of the last data packet.
|
U32 | mLastSeqRecvdAtSend [MaxPacketWindowSize] |
| The sequence number of the last packet received from the remote host when we sent the packet with sequence X & PacketWindowMask.
|
U32 | mLastSeqRecvd |
| The sequence number of the most recently received packet from the remote host.
|
U32 | mHighestAckedSeq |
| The highest sequence number the remote side has acknowledged.
|
U32 | mLastSendSeq |
| The sequence number of the last packet sent.
|
U32 | mAckMask [MaxAckMaskSize] |
| long string of bits, each acking a packet sent by the remote host
|
U32 | mLastRecvAckAck |
| The highest sequence this side knows the other side has received an ACK or NACK for.
|
U32 | mInitialSendSeq |
| The first mLastSendSeq for this side of the connection.
|
U32 | mInitialRecvSeq |
| The first mLastSeqRecvd (the first mLastSendSeq for the remote host).
|
U32 | mHighestAckedSendTime |
| The send time of the highest packet sequence acked by the remote host.
|
U32 | mPingTimeout |
| Milliseconds to wait before sending a ping packet.
|
U32 | mPingRetryCount |
| Number of unacknowledged pings to send before timing out.
|
BitSet32 | mTypeFlags |
| Flags describing the type of connection this is, OR'd from NetConnectionTypeFlags.
|
U32 | mLastUpdateTime |
| The last time a packet was sent from this instance.
|
F32 | mRoundTripTime |
| Running average round trip time.
|
U32 | mSendDelayCredit |
| Metric to help compensate for irregularities on fixed rate packet sends.
|
U32 | mSimulatedLatency |
| Amount of additional time this connection delays its packet sends to simulate latency in the connection.
|
F32 | mSimulatedPacketLoss |
| Function to simulate packet loss on a network.
|
NetRate | mLocalRate |
| Current communications rate negotiated for this connection.
|
NetRate | mRemoteRate |
| Maximum allowable communications rate for this connection.
|
bool | mLocalRateChanged |
| Set to true when the local connection's rate has changed.
|
U32 | mCurrentPacketSendSize |
| Current size of each packet sent to the remote host.
|
U32 | mCurrentPacketSendPeriod |
| Millisecond delay between sent packets.
|
Address | mNetAddress |
| The network address of the host this instance is connected to.
|
U32 | mPingSendCount |
| Number of unacknowledged ping packets sent to the remote host.
|
U32 | mLastPingSendTime |
| Last time a ping packet was sent from this connection.
|
ConnectionStringTable * | mStringTable |
| Helper for managing translation between global NetStringTable ids to local ids for this connection.
|
Friends |
class | NetInterface |
class | ConnectionStringTable |