16 #include <nn/pia/session/session_Definitions.h>
17 #include <nn/pia/session/session_Types.h>
19 #include <nn/pia/common/common_AsyncContext.h>
20 #include <nn/pia/common/common_SignatureSetting.h>
22 #include <nn/pia/transport/transport_Station.h>
31 class MonitoringDataSender;
43 class StationConnectionInfo;
44 class StationProtocol;
45 class ConnectStationJob;
46 class DisconnectStationJob;
47 class ProcessConnectionRequestJob;
48 class MissingStationHandler;
50 class BandwidthCheckProtocol;
67 class ProcessJoinRequestJob;
68 class ProcessUpdateMeshJob;
70 class ProcessDestroyMeshJob;
71 class ProcessHostMigrationJob;
72 class LeaveWithHostMigrationJob;
73 class SignatureSettingStorage;
74 class RelayRouteManageJob;
75 class KickoutManageJob;
77 class SyncClockProtocol;
78 class MeshEventListener;
91 class Mesh :
public common::RootObject
93 friend class CreateMeshJob;
94 friend class JoinMeshJob;
95 friend class LeaveMeshJob;
96 friend class ProcessJoinRequestJob;
97 friend class ProcessUpdateMeshJob;
98 friend class DestroyMeshJob;
99 friend class ProcessDestroyMeshJob;
100 friend class ProcessHostMigrationJob;
101 friend class LeaveWithHostMigrationJob;
102 friend class KickoutManageJob;
103 friend class MeshProtocol;
104 friend class MeshEventListener;
116 transport::NetworkFactory* pNetworkFactory;
124 struct StartupSetting
129 isHostMigrationEnabled(true),
132 isPlayersCountedAsParticipants(true),
133 pCryptoSetting(NULL),
134 signatureSetting(common::SignatureSetting::NoSignature),
136 bitRateCheckPacketSize(0),
137 bitRateMeasuringSpan(1000),
138 isBitRateCheckSkipped(false),
140 isAddRecentPlayRecordEnabled(true)
144 uint32_t maxSilenceTime;
145 uint32_t keepAliveSendingInterval;
146 bool isHostMigrationEnabled;
147 const transport::Station::PlayerInfo* pPlayerInfo;
148 uint8_t playerInfoSize;
149 bool isPlayersCountedAsParticipants;
150 const common::CryptoSetting* pCryptoSetting;
151 common::SignatureSetting signatureSetting;
152 int32_t uplinkBitRateLowerLimit;
153 uint32_t bitRateCheckPacketSize;
154 int32_t bitRateMeasuringSpan;
155 bool isBitRateCheckSkipped;
156 const transport::Station::IdentificationToken* pToken;
157 bool isAddRecentPlayRecordEnabled;
165 DebugSetting(
bool argIsRelayEmulationEnabled =
false,
bool argIsCheckMaxSilenceTimeEnabled =
true)
166 : isRelayEmulationEnabled(argIsRelayEmulationEnabled),
167 isCheckMaxSilenceTimeEnabled(argIsCheckMaxSilenceTimeEnabled)
170 bool isRelayEmulationEnabled;
171 bool isCheckMaxSilenceTimeEnabled;
192 DisconnectReason_UnknownReason = 0,
193 DisconnectReason_NotYetCommunicated,
194 DisconnectReason_OperationOfOwn,
195 DisconnectReason_OperationOfOther,
196 DisconnectReason_KickoutByUser,
197 DisconnectReason_KickoutBySystem,
198 DisconnectReason_InconsistentInfo,
199 DisconnectReason_MigrationFail,
200 DisconnectReason_ExternalFactor,
201 DisconnectReason_MigrationFatalError
212 EmulationType_None = 0,
225 EventType_EventLeave,
226 EventType_EventHostChanged,
227 EventType_EventMigrationFail,
228 EventType_EventStartHostMigration
240 typedef void (*MeshEventCallback)(EventType eventType,
StationId id);
253 typedef bool (*JoiningMeshApprovalCallback)(
const transport::Station::IdentificationToken* pRequesterToken);
261 typedef uint8_t (*CheckHostCandidateRankingCallback)(
StationIndex targetId,
bool isHost);
265 typedef uint32_t (*GetSessionIdCallback)();
292 static Result CreateInstance(
const session::Mesh::Setting& setting);
298 static void DestroyInstance();
309 static Mesh* GetInstance()
390 Result Startup(Mesh::StartupSetting& startupSetting);
436 Result CreateMesh(common::AsyncContext* pAsyncContext);
455 Result CreateMeshAsync();
466 bool IsCreateMeshCompleted();
481 Result GetCreateMeshResult();
505 Result DestroyMesh(common::AsyncContext* pAsyncContext);
526 Result DestroyMeshAsync();
537 bool IsDestroyMeshCompleted();
550 Result GetDestroyMeshResult();
573 Result LeaveMeshWithHostMigration(common::AsyncContext* pAsyncContext);
595 Result LeaveMeshWithHostMigrationAsync();
606 bool IsLeaveMeshWithHostMigrationCompleted();
619 Result GetLeaveMeshWithHostMigrationResult();
628 uint8_t CheckApprovalJoin(transport::Station* pTargetStation);
675 Result JoinMesh(
const transport::StationConnectionInfo& stationConnectionInfo, common::AsyncContext* pAsyncContext);
697 Result JoinMeshAsync(
const transport::StationConnectionInfo& stationConnectionInfo);
708 bool IsJoinMeshCompleted();
739 Result GetJoinMeshResult();
754 Result CancelJoinMeshAsync();
774 Result LeaveMesh(common::AsyncContext* pAsyncContext);
792 Result LeaveMeshAsync();
803 bool IsLeaveMeshCompleted();
816 Result GetLeaveMeshResult();
857 uint16_t GetStationNum()
const;
903 bool IsValidStationId(
StationId id)
const;
924 uint32_t GetValidStationIndexBitmap()
const;
937 Result CheckConnectionError()
const;
956 bool IsBitRateCheckCompleted()
const;
975 Result GetUplinkBitRate(int32_t* pBps);
1002 void RegisterMeshEventCallback(MeshEventCallback callback);
1010 void UnregisterMeshEventCallback();
1028 void RegisterJoiningMeshApprovalCallback(JoiningMeshApprovalCallback callback);
1036 void UnregisterJoiningMeshApprovalCallback();
1052 Result RegisterCheckHostCandidateRankingCallback(CheckHostCandidateRankingCallback callback);
1060 void UnregisterCheckHostCandidateRankingCallback();
1065 void RegisterEventListener(MeshEventListener* pEventListener);
1066 void UnregisterEventListener();
1068 void RegisterGetSessionIdCallback(GetSessionIdCallback callback);
1069 void UnregisterGetSessionIdCallback();
1085 MeshProtocol* GetMeshProtocol();
1094 transport::StationProtocol* GetStationProtocol();
1117 int64_t GetTime()
const;
1126 void SetSyncClockPulseInterval(int32_t interval);
1135 int32_t GetSyncClockPulseInterval()
const;
1163 Result SetMaxNumOfRelayRoutesAssignedToStation(uint16_t num);
1181 Result SetMaxRtt(uint16_t rtt);
1243 void ResetRelayEmulation();
1256 void SetHostMigrationStarted(
bool val);
1264 bool IsHostMigrationStarted();
1268 ProcessHostMigrationJob* GetProcessHostMigrationJobPtr();
1269 KickoutManageJob* GetKickoutManageJobPtr();
1270 ProcessDestroyMeshJob* GetProcessDestroyMeshJobPtr();
1271 void SetFatalError(DisconnectReason reason);
1272 ProcessUpdateMeshJob* GetProcessUpdateMeshJobPtr();
1274 const SignatureSettingStorage* GetSignatureSettingStorage()
const;
1275 static Result SetDebugSettingForInternal(
const DebugSetting& debugSetting);
1276 void NotifyLeaveStationAddress(
const common::StationAddress& leftStationAddress);
1289 void TraceStationConnectionInfoList(uint64_t flag);
1292 bool IsHostMigrationEnabled()
const;
1293 HostMigrationMode GetHostMigrationMode()
const;
1294 int GetJoinMeshSequence()
const;
1295 int GetHostMigrationSequence()
const;
1296 void SetSkipCleanupReport(
bool isSkip);
1297 void SetSkipReport(
bool isSkip);
1298 void SendReport(uint8_t type);
1299 void SetupSendReport();
1300 bool IsProcessedAtMeshBegin()
const;
1301 bool IsProcessingLeaveMesh()
const;
1302 bool IsProcessingHostMigration()
const;
1303 State GetMeshState()
const;
1304 int32_t GetProcessUpdateMeshJobStepSequence()
const;
1305 uint8_t GetLocalPlayerCount()
const;
1306 bool IsPlayersCountedAsParticipants()
const;
1307 bool IsRecentPlayRecordEnabled()
const;
1308 bool IsMultiPlayerEnabled()
const;
1309 Result CheckPlayerInfo(
const transport::Station::PlayerInfo& playerInfo)
const;
1310 Result CheckPlayerInfoSetting(
const transport::Station::PlayerInfo* pPlayerInfo, uint8_t playerInfoSize)
const;
1311 void CleanupMonitoringBeginData();
1312 common::MonitoringDataSender* GetMonitoringDataSender();
1314 transport::BandwidthCheckProtocol* GetBandwidthCheckProtocol();
1315 bool IsBandwidthCheckProtocolSetupParamValid(int32_t uplinkBitRateLowerLimit, uint32_t bitRateCheckPacketSize, int32_t bitRateMeasuringSpan)
const;
1322 void SetDenyJoinRequestByInvalidState(
bool isDeny);
1329 void SetDenyJoinRequestBySessionIsFull(
bool isFull);
1337 virtual void Trace(uint64_t flag)
const;
1345 static Mesh* s_pMesh;
1346 static DebugSetting s_DebugSetting;
1347 static Result setDebugSettingImpl(
const DebugSetting& debugSetting);
1354 Mesh(
const session::Mesh::Setting& setting);
1375 Mesh& operator=(
const Mesh&);
1378 Result
Initialize(
const session::Mesh::Setting& setting,
bool isRelayEmulationEnabled);
1380 Result SetupLocalPlayerInfo();
1381 Result SetupProtocols();
1383 void CleanupStatus();
1386 void CleanupStationsJobs();
1394 void ResetStationIndexUsage();
1397 void SetMeshStartTime(common::Time startTime);
1400 bool IsMeshStartTimeValid()
const;
1403 common::TimeSpan CalcDiffWithMeshStartTime(common::Time target)
const;
1405 void ProcessingAtMeshBegin();
1406 void ProcessingAtMeshEnd(DisconnectReason reason);
1407 void ProcessingAtEndHM();
1408 void MonitoringProcess(DisconnectReason reason, uint8_t type);
1410 void AddPlayHistory(transport::Station* pTargetStation, transport::Station::PlayerInfo* pLocalPlayerInfo, uint32_t localPlayerInfoSize);
1412 enum AsyncProcessingName
1414 AsyncProcessingName_Nothing = 0,
1415 AsyncProcessingName_CreateSession,
1416 AsyncProcessingName_DestroySession,
1417 AsyncProcessingName_LeaveSessionWithHm,
1418 AsyncProcessingName_JoinSession,
1419 AsyncProcessingName_LeaveSession
1422 void ResetInternalAsyncState();
1423 bool IsAsyncProcessCompleted(AsyncProcessingName processingName);
1424 Result GetAsyncProcessResult(AsyncProcessingName processingName);
1425 Result CancelAsyncProcess(AsyncProcessingName processingName);
1427 Result JoinMeshCore(
const transport::StationConnectionInfo& stationConnectionInfo, common::AsyncContext* pAsyncContext);
1429 void SetMeshState(State meshState);
1430 void NoticeMeshEvent(EventType eventType,
StationIndex idx);
1432 CreateMeshJob* m_pCreateMeshJob;
1433 JoinMeshJob* m_pJoinMeshJob;
1434 LeaveMeshJob* m_pLeaveMeshJob;
1435 ProcessJoinRequestJob* m_pProcessJoinRequestJob;
1436 ProcessUpdateMeshJob* m_pProcessUpdateMeshJob;
1437 DestroyMeshJob* m_pDestroyMeshJob;
1438 ProcessDestroyMeshJob* m_pProcessDestroyMeshJob;
1439 ProcessHostMigrationJob* m_pProcessHostMigrationJob;
1440 LeaveWithHostMigrationJob* m_pLeaveWithHostMigrationJob;
1441 SignatureSettingStorage* m_pSignatureSettingStorage;
1442 RelayRouteManageJob* m_pRelayRouteManageJob;
1443 KickoutManageJob* m_pKickoutManageJob;
1444 transport::MissingStationHandler* m_pMissingStationHandler;
1446 MeshEventCallback m_MeshEventCallback;
1447 JoiningMeshApprovalCallback m_JoiningMeshApprovalCallback;
1448 CheckHostCandidateRankingCallback m_CheckHostCandidateRankingCallback;
1449 GetSessionIdCallback m_GetSessionIdCallback;
1451 uint32_t m_MeshProtocolHandle;
1452 MeshProtocol* m_pMeshProtocol;
1453 transport::StationProtocol* m_pStationProtocol;
1455 uint32_t m_BandwidthCheckProtocolHandle;
1456 transport::BandwidthCheckProtocol* m_pBandwidthCheckProtocol;
1458 uint16_t m_StationMax;
1459 bool m_IsApprovalJoin;
1466 HostMigrationMode m_HostMigrationMode;
1470 bool m_IsHostMigrationEnabled;
1471 bool m_IsServerRequired;
1472 bool m_IsRecentPlayRecordEnabled;
1473 bool m_IsMultiplayerEnabled;
1475 uint32_t m_StationIndexFlagsForJoinResponseComplete;
1476 uint32_t m_StationIndexUsedFlags;
1477 uint32_t m_UpdateCount;
1481 uint32_t m_SyncClockProtocolHandle;
1483 common::Time m_MeshStartTime;
1484 bool m_MeshStartTimeValidFlag;
1488 bool m_HostMigrationStartFlag;
1490 bool m_AutoAddRecentPlayRecord;
1492 common::MonitoringDataSender* m_pMonitoringDataSender;
1494 common::AsyncContext m_InternalContext;
1495 AsyncProcessingName m_CurrentAsyncProcessingName;
1497 MeshEventListener* m_pMeshEventListener;
1499 bool m_IsSkipSendingReport;
1500 bool m_IsSkipCleanupReport;
1502 bool m_IsPlayersCountedAsParticipants;
1503 uint8_t m_LocalPlayerCount;
1505 uint32_t m_ExpectedFirstUpdateCount;
1506 bool m_IsReceivedUpdateCount;
1508 bool m_SetDenyJoinRequestByInvalidState;
1509 bool m_SetDenyJoinRequestBySessionIsFull;
1512 uint8_t m_ValidPlayerInfoNum;