RakNet  4.0
Public Member Functions | Protected Attributes | List of all members
RakNet::FullyConnectedMesh2 Class Reference

Fully connected mesh plugin, revision 2. More...

#include <FullyConnectedMesh2.h>

Inheritance diagram for RakNet::FullyConnectedMesh2:
RakNet::PluginInterface2

Public Member Functions

void SetConnectOnNewRemoteConnection (bool attemptConnection, RakNet::RakString pw)
 
RakNetGUID GetConnectedHost (void) const
 The connected host is whichever system we are connected to that has been running the longest.
 
RakNetGUID GetHostSystem (void) const
 
bool IsHostSystem (void) const
 
void GetHostOrder (DataStructures::List< RakNetGUID > &hostList)
 
bool IsConnectedHost (void) const
 
void SetAutoparticipateConnections (bool b)
 Automatically add new connections to the fully connected mesh. Each remote system that you want to check should be added as a participant, either through SetAutoparticipateConnections() or by calling this function.
 
void ResetHostCalculation (void)
 
void AddParticipant (RakNetGUID rakNetGuid)
 if SetAutoparticipateConnections() is called with false, then you need to use AddParticipant before these systems will be added to the mesh FullyConnectedMesh2 will track who is the who host among a fully connected mesh of participants Each remote system that you want to check should be added as a participant, either through SetAutoparticipateConnections() or by calling this function
 
void GetParticipantList (DataStructures::List< RakNetGUID > &participantList)
 
bool HasParticipant (RakNetGUID participantGuid)
 Returns if a participant is in the participant list.
 
void ConnectToRemoteNewIncomingConnections (Packet *packet)
 
void Clear (void)
 Clear all memory and reset everything.
 
virtual void StartVerifiedJoin (RakNetGUID client)
 Notify the client of GetParticipantList() in order to connect to each of those systems until the mesh has been completed.
 
virtual void RespondOnVerifiedJoinCapable (Packet *packet, bool accept, BitStream *additionalData)
 On ID_FCM2_VERIFIED_JOIN_CAPABLE , accept or reject the new connection.
 
virtual void GetVerifiedJoinRequiredProcessingList (RakNetGUID host, DataStructures::List< SystemAddress > &addresses, DataStructures::List< RakNetGUID > &guids)
 On ID_FCM2_VERIFIED_JOIN_START, read the SystemAddress and RakNetGUID values of each system to connect to.
 
virtual void GetVerifiedJoinAcceptedAdditionalData (Packet *packet, bool *thisSystemAccepted, DataStructures::List< RakNetGUID > &systemsAccepted, BitStream *additionalData)
 On ID_FCM2_VERIFIED_JOIN_ACCEPTED, read additional data passed to RespondOnVerifiedJoinCapable()
 
virtual void GetVerifiedJoinRejectedAdditionalData (Packet *packet, BitStream *additionalData)
 On ID_FCM2_VERIFIED_JOIN_REJECTED, read additional data passed to RespondOnVerifiedJoinCapable()
 
virtual PluginReceiveResult OnReceive (Packet *packet)
 
virtual void OnRakPeerStartup (void)
 Called when RakPeer is initialized.
 
virtual void OnAttach (void)
 Called when the interface is attached.
 
virtual void OnRakPeerShutdown (void)
 Called when RakPeer is shutdown.
 
virtual void OnClosedConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, PI2_LostConnectionReason lostConnectionReason)
 
virtual void OnNewConnection (const SystemAddress &systemAddress, RakNetGUID rakNetGUID, bool isIncoming)
 
virtual void OnFailedConnectionAttempt (Packet *packet, PI2_FailedConnectionAttemptReason failedConnectionAttemptReason)
 
- Public Member Functions inherited from RakNet::PluginInterface2
virtual void OnDetach (void)
 Called when the interface is detached.
 
virtual void Update (void)
 Update is called every time a packet is checked for .
 
virtual bool UsesReliabilityLayer (void) const
 
virtual void OnDirectSocketSend (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
 
virtual void OnDirectSocketReceive (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
 
virtual void OnReliabilityLayerNotification (const char *errorMessage, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress, bool isError)
 
virtual void OnInternalPacket (InternalPacket *internalPacket, unsigned frameNumber, SystemAddress remoteSystemAddress, RakNet::TimeMS time, int isSend)
 
virtual void OnAck (unsigned int messageNumber, SystemAddress remoteSystemAddress, RakNet::TimeMS time)
 
virtual void OnPushBackPacket (const char *data, const BitSize_t bitsUsed, SystemAddress remoteSystemAddress)
 

Protected Attributes

DataStructures::List
< FCM2Participant > 
fcm2ParticipantList
 List of systems we know the FCM2Guid for.
 

Detailed Description

Fully connected mesh plugin, revision 2.

This will connect RakPeer to all connecting peers, and all peers the connecting peer knows about.
It will also calculate which system has been running longest, to find out who should be host, if you need one system to act as a host

Precondition
You must also install the ConnectionGraph2 plugin in order to use SetConnectOnNewRemoteConnection()

Member Function Documentation

void RakNet::FullyConnectedMesh2::AddParticipant ( RakNetGUID  rakNetGuid)

if SetAutoparticipateConnections() is called with false, then you need to use AddParticipant before these systems will be added to the mesh FullyConnectedMesh2 will track who is the who host among a fully connected mesh of participants Each remote system that you want to check should be added as a participant, either through SetAutoparticipateConnections() or by calling this function

Parameters
[in]participantThe new participant
See Also
StartVerifiedJoin()
void RakNet::FullyConnectedMesh2::ConnectToRemoteNewIncomingConnections ( Packet packet)

Connect to all systems from ID_REMOTE_NEW_INCOMING_CONNECTION You can call this if SetConnectOnNewRemoteConnection is false

Parameters
[in]packetThe packet containing ID_REMOTE_NEW_INCOMING_CONNECTION
[in]connectionPasswordPassword passed to RakPeerInterface::Connect()
[in]connectionPasswordLengthPassword length passed to RakPeerInterface::Connect()
RakNetGUID RakNet::FullyConnectedMesh2::GetConnectedHost ( void  ) const

The connected host is whichever system we are connected to that has been running the longest.

Will return UNASSIGNED_RAKNET_GUID if we are not connected to anyone, or if we are connected and are calculating the host If includeCalculating is true, will return the estimated calculated host as long as the calculation is nearly complete includeCalculating should be true if you are taking action based on another system becoming host, because not all host calculations may complete at the exact same time

See Also
ConnectionGraph2::GetLowestAveragePingSystem() . If you need one system in the peer to peer group to relay data, have the host call this function after host migration, and use that system
Returns
System address of whichever system is host.
void RakNet::FullyConnectedMesh2::GetHostOrder ( DataStructures::List< RakNetGUID > &  hostList)

Get the list of connected systems, from oldest connected to newest This is also the order that the hosts will be chosen in

RakNetGUID RakNet::FullyConnectedMesh2::GetHostSystem ( void  ) const
Returns
System address of whichever system is host. Always returns something, even though it may be our own system.
void RakNet::FullyConnectedMesh2::GetParticipantList ( DataStructures::List< RakNetGUID > &  participantList)

Get the participants added with AddParticipant()

Parameters
[out]participantListParticipants added with AddParticipant();
virtual void RakNet::FullyConnectedMesh2::GetVerifiedJoinAcceptedAdditionalData ( Packet packet,
bool *  thisSystemAccepted,
DataStructures::List< RakNetGUID > &  systemsAccepted,
BitStream additionalData 
)
virtual

On ID_FCM2_VERIFIED_JOIN_ACCEPTED, read additional data passed to RespondOnVerifiedJoinCapable()

bool thisSystemAccepted;
RakNet::BitStream additionalData;
fullyConnectedMesh->GetVerifiedJoinAcceptedAdditionalData(packet, &thisSystemAccepted, systemsAccepted, &additionalData);
Parameters
[in]packetPacket containing the ID_FCM2_VERIFIED_JOIN_ACCEPTED message
[out]thisSystemAcceptedIf true, it was this instance of RakPeerInterface that was accepted. If false, this is notification for another system
[out]systemsAcceptedWhich system(s) were added with AddParticipant(). If thisSystemAccepted is false, this list will only have length 1
[out]additionalDataadditionalData parameter passed to RespondOnVerifiedJoinCapable()
virtual void RakNet::FullyConnectedMesh2::GetVerifiedJoinRejectedAdditionalData ( Packet packet,
BitStream additionalData 
)
virtual

On ID_FCM2_VERIFIED_JOIN_REJECTED, read additional data passed to RespondOnVerifiedJoinCapable()

This does not automatically close the connection. The following code will do so:

rakPeer[i]->CloseConnection(packet->guid, true);
Parameters
[in]packetPacket containing the ID_FCM2_VERIFIED_JOIN_REJECTED message
[out]additionalDataadditionalData parameter passed to RespondOnVerifiedJoinCapable().
virtual void RakNet::FullyConnectedMesh2::GetVerifiedJoinRequiredProcessingList ( RakNetGUID  host,
DataStructures::List< SystemAddress > &  addresses,
DataStructures::List< RakNetGUID > &  guids 
)
virtual

On ID_FCM2_VERIFIED_JOIN_START, read the SystemAddress and RakNetGUID values of each system to connect to.

fullyConnectedMesh->GetVerifiedJoinRequiredProcessingList(packet->guid, addresses, guids);
for (unsigned int i=0; i < addresses.Size(); i++)
rakPeer[i]->Connect(addresses[i].ToString(false), addresses[i].GetPort(), 0, 0);
Parameters
[in]hostWhich system sent ID_FCM2_VERIFIED_JOIN_START
[out]addressesSystemAddress values of systems to connect to. List has the same number and order as guids
[out]guidsRakNetGUID values of systems to connect to. List has the same number and order as guids
bool RakNet::FullyConnectedMesh2::HasParticipant ( RakNetGUID  participantGuid)

Returns if a participant is in the participant list.

Parameters
[in]RakNetGUIDof the participant to query
Returns
True if in the list
bool RakNet::FullyConnectedMesh2::IsConnectedHost ( void  ) const
Parameters
[in]includeCalculatingIf true, and we are currently calculating a new host, return the new host if the calculation is nearly complete
Returns
If our system is host
bool RakNet::FullyConnectedMesh2::IsHostSystem ( void  ) const
Returns
If our system is host
virtual void RakNet::FullyConnectedMesh2::OnClosedConnection ( const SystemAddress systemAddress,
RakNetGUID  rakNetGUID,
PI2_LostConnectionReason  lostConnectionReason 
)
virtual

Called when a connection is dropped because the user called RakPeer::CloseConnection() for a particular system

Parameters
[in]systemAddressThe system whose connection was closed
[in]rakNetGuidThe guid of the specified system
[in]lostConnectionReasonHow the connection was closed: manually, connection lost, or notification of disconnection

Reimplemented from RakNet::PluginInterface2.

virtual void RakNet::FullyConnectedMesh2::OnFailedConnectionAttempt ( Packet packet,
PI2_FailedConnectionAttemptReason  failedConnectionAttemptReason 
)
virtual

Called when a connection attempt fails

Parameters
[in]packetPacket to be returned to the user
[in]failedConnectionReasonWhy the connection failed

Reimplemented from RakNet::PluginInterface2.

virtual void RakNet::FullyConnectedMesh2::OnNewConnection ( const SystemAddress systemAddress,
RakNetGUID  rakNetGUID,
bool  isIncoming 
)
virtual

Called when we got a new connection

Parameters
[in]systemAddressAddress of the new connection
[in]rakNetGuidThe guid of the specified system
[in]isIncomingIf true, this is ID_NEW_INCOMING_CONNECTION, or the equivalent

Reimplemented from RakNet::PluginInterface2.

virtual PluginReceiveResult RakNet::FullyConnectedMesh2::OnReceive ( Packet packet)
virtual

OnReceive is called for every packet.

Parameters
[in]packetthe packet that is being returned to the user
Returns
True to allow the game and other plugins to get this message, false to absorb it

Reimplemented from RakNet::PluginInterface2.

void RakNet::FullyConnectedMesh2::ResetHostCalculation ( void  )

Clear our own host order, and recalculate as if we had just reconnected Call this to reset the running time of the host just before joining/creating a game room for networking

virtual void RakNet::FullyConnectedMesh2::RespondOnVerifiedJoinCapable ( Packet packet,
bool  accept,
BitStream additionalData 
)
virtual

On ID_FCM2_VERIFIED_JOIN_CAPABLE , accept or reject the new connection.

fullyConnectedMesh->RespondOnVerifiedJoinCapable(packet, true, 0);
Parameters
[in]packetThe system that sent ID_FCM2_VERIFIED_JOIN_CAPABLE. Based on , ID_FCM2_VERIFIED_JOIN_ACCEPTED or ID_FCM2_VERIFIED_JOIN_REJECTED will be sent in reply
[in]acceptTrue to accept, and thereby automatically call AddParticipant() on all systems on the mesh. False to reject, and call CloseConnection() to all mesh systems on the target
[in]additionalDataAny additional data you want to add to the ID_FCM2_VERIFIED_JOIN_ACCEPTED or ID_FCM2_VERIFIED_JOIN_REJECTED messages
void RakNet::FullyConnectedMesh2::SetAutoparticipateConnections ( bool  b)

Automatically add new connections to the fully connected mesh. Each remote system that you want to check should be added as a participant, either through SetAutoparticipateConnections() or by calling this function.

Defaults to true.

Parameters
[in]bAs stated
void RakNet::FullyConnectedMesh2::SetConnectOnNewRemoteConnection ( bool  attemptConnection,
RakNet::RakString  pw 
)

When the message ID_REMOTE_NEW_INCOMING_CONNECTION arrives, we try to connect to that system If attemptConnection is false, you can manually connect to all systems listed in ID_REMOTE_NEW_INCOMING_CONNECTION with ConnectToRemoteNewIncomingConnections()

Note
This will not work on any console. It will also not work if NAT punchthrough is needed. Generally, this should be false and you should connect manually. It is here for legacy reasons.
Parameters
[in]attemptConnectionIf true, we try to connect to any systems we are notified about with ID_REMOTE_NEW_INCOMING_CONNECTION, which comes from the ConnectionGraph2 plugin. Defaults to true.
[in]pwThe password to use to connect with. Only used if attemptConnection is true
virtual void RakNet::FullyConnectedMesh2::StartVerifiedJoin ( RakNetGUID  client)
virtual

Notify the client of GetParticipantList() in order to connect to each of those systems until the mesh has been completed.

In the simple case of forming a peer to peer mesh:

  1. AddParticipant() is called on the host whenever you get a new connection
  2. The host sends all participants to the new client
  3. The client connects to the participant list

However, the above steps assumes connections to all systems in the mesh always complete. When there is a risk of failure, such as if relying on NATPunchthroughClient, you may not want to call AddParticipant() until are connections have completed to all other particpants StartVerifiedJoin() can manage the overhead of the negotiation involved so the programmer only has to deal with overall success or failure

Processing:

  1. Send the RakNetGUID and SystemAddress values of GetParticipantList() to the client with ID_FCM2_VERIFIED_JOIN_START
  2. The client, on ID_FCM2_VERIFIED_JOIN_START, can execute NatPunchthroughClient::OpenNAT() (optional), followed by RakPeerInterface::Connect() if punchthrough success, for each system returned from GetVerifiedJoinRequiredProcessingList()
  3. After all participants in step 2 have connected, failed to connect, or failed NatPunchthrough, the client automatically sends the results to the server.
  4. The server compares the results of the operations in step 2 with the values from GetParticpantList(). 4A. If the client failed to connect to a current participant, return ID_FCM2_VERIFIED_JOIN_FAILED to the client. CloseConnection() is automatically called on the client for the failed participants. 4B. If AddParticipant() was called between steps 1 and 4, go back to step 1, transmitting new participants. 4C. If the client successfully connected to all participants, the server gets ID_FCM2_VERIFIED_JOIN_CAPABLE. The server programmer, on the same frame, should execute RespondOnVerifiedJoinCapable() to either accept or reject the client.
  5. If the client got ID_FCM2_VERIFIED_JOIN_ACCEPTED, AddParticipant() is automatically called for each system in the mesh.
  6. If the client got ID_FCM2_VERIFIED_JOIN_REJECTED, CloseConnection() is automatically called for each system in the mesh. The connection is NOT automatically closed to the original host that sent StartVerifiedJoin().
  7. If the client's connection to the server was lost before getting ID_FCM2_VERIFIED_JOIN_ACCEPTED or ID_FCM2_VERIFIED_JOIN_REJECTED, return to the programmer ID_FCM2_VERIFIED_JOIN_FAILED and call RakPeerInterface::CloseConnection()
Parameters
[in]clientThe system to send ID_FCM2_VERIFIED_JOIN_START to

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