FullyConnectedMesh2 Plugin¶
The FullyConnectedMesh2 plugin manages peer-to-peer mesh networks where every participant connects to every other participant. It handles host determination, connection management, and mesh topology verification.
Basic Usage¶
Setting up a mesh network:
#include "mafianet/FullyConnectedMesh2.h"
MafiaNet::FullyConnectedMesh2 fcm2;
peer->AttachPlugin(&fcm2);
// Set connection credentials (all peers must use same password)
fcm2.SetConnectOnNewRemoteConnection(true, "gamePassword");
// Start the mesh with initial host
fcm2.StartVerifiedJoin(hostGuid);
Handling mesh events:
MafiaNet::Packet* packet;
while ((packet = peer->Receive()) != nullptr) {
switch (packet->data[0]) {
case ID_FCM2_NEW_HOST:
// A new host has been elected
printf("New host: %s\n",
fcm2.GetHostSystem().ToString());
break;
case ID_FCM2_VERIFIED_JOIN_CAPABLE:
// Can join the mesh
fcm2.RespondOnVerifiedJoinCapable(packet, true,
UNASSIGNED_RAKNET_GUID);
break;
case ID_FCM2_VERIFIED_JOIN_ACCEPTED:
printf("Successfully joined mesh\n");
break;
}
peer->DeallocatePacket(packet);
}
Key Features¶
Automatic host migration when host disconnects
Deterministic host election (lowest GUID wins)
Verified join process to prevent partial connections
Connection state synchronization across all peers
NAT punchthrough integration support
Participant list management
Configuration Options¶
SetAutoparticipateConnections()- Auto-add new connections to meshSetConnectOnNewRemoteConnection()- Auto-connect to peers of peersGetHostSystem()- Get current mesh hostGetParticipantCount()- Number of mesh participantsGetVerifiedJoinRequiredProcessingList()- Pending join verifications
See Also¶
NATTypeDetection Plugin - NAT traversal for P2P
NAT Traversal Architecture - Complete NAT solution
RPC4 Plugin - Remote procedure calls in mesh