![]() |
Diarkis C++Client Library API Document
|
Base class that wraps the IDiarkisP2P class for easy use of P2P functionality. More...
#include <DiarkisP2PBase.h>
Public Member Functions | |
DiarkisP2PBase () | |
DiarkisP2PBase constructor. More... | |
virtual | ~DiarkisP2PBase () |
DiarkisP2PBase destructor. More... | |
virtual void | SetupP2P (const std::shared_ptr< IDiarkisUdp > &udp, const std::shared_ptr< LoggerFactory > &loggerFactory, const char *uid) |
Set up DirectMessage with UDP protocol. More... | |
virtual void | ConnectClient (const char *uid, const char **address, size_t addressCount, size_t timeoutInMilliseconds=5000, bool bBuffering=true) |
Attempts to make a P2P connection to the specified user ID. More... | |
virtual void | ConnectClient (const std::string &uid, const std::vector< std::string > &address, size_t timeoutInMilliseconds=5000, bool bBuffering=true) |
Same as ConnectClient() More... | |
virtual void | SetEncryptionKeys (bool bEncryption, const uint8_t *key, size_t keySize, const uint8_t *iv, size_t ivSize, const uint8_t *mkey, size_t mkeySize) |
Set the encryption key. More... | |
virtual void | SetEncryptionKeys (bool bEncryption, const std::vector< uint8_t > &key, const std::vector< uint8_t > &iv, const std::vector< uint8_t > &mkey) |
Same as SetEncryptionKeys() More... | |
virtual uint16_t | SendUnicast (const uint8_t *payload, size_t payloadSize, RudpType type, const char *uid) |
Sends a message to one peer. More... | |
virtual uint16_t | SendUnicast (const uint8_t *payload, size_t payloadSize, RudpType type, const std::string &uid) |
Same as SendUnicast() More... | |
virtual uint16_t | SendUnicast (const std::vector< uint8_t > &payload, RudpType type, const std::string &uid) |
Same as SendUnicast() More... | |
virtual uint16_t | SendMulticast (const uint8_t *payload, size_t payloadSize, RudpType type, const char **uids, size_t uidsLen) |
Sends a message to multiple peers. More... | |
virtual uint16_t | SendMulticast (const uint8_t *payload, size_t payloadSize, RudpType type, const std::vector< std::string > &uid) |
Same as SendMulticast() More... | |
virtual uint16_t | SendMulticast (const std::vector< uint8_t > &payload, RudpType type, const std::vector< std::string > &uid) |
Same as SendMulticast() More... | |
virtual uint16_t | SendBroadcast (const uint8_t *payload, size_t payloadSize, RudpType type) |
Sends a message to all peers. More... | |
virtual uint16_t | SendBroadcast (const std::vector< uint8_t > &payload, RudpType type) |
Same as SendBroadcast() More... | |
void | Disconnect () |
Disconnects the P2P connection to all peers. More... | |
bool | Disconnect (const char *uid) |
Disconnect P2P connection with the specified user. More... | |
void | Update () |
Function to update the status of the connection and other information. Must be called periodically. More... | |
void | SetSchedulerAddNotifyEvent (std::function< void()> notifyEventFunc) |
Sets the process to be called when a P2P-related event is added to the scheduler. More... | |
uint16_t | GetConnectedNum () |
Get the number of peers connected by P2P. More... | |
void | GetPeerUids (Diarkis::StdVector< Diarkis::StdString > &output) |
Get the user id of peers connected by P2P. More... | |
Protected Member Functions | |
virtual void | OnP2PReady (const DiarkisReadyEventArgs &args) |
Callback event called when a P2P connection succeeds. More... | |
virtual void | OnP2PFail (const DiarkisFailEventArgs &args) |
Callback event called when a hole punch fails. More... | |
virtual void | OnP2PDisconnect (const DiarkisP2PDisconnectEventArgs &args) |
Callback event called when a P2P connection is disconnected. More... | |
virtual void | OnP2PMessage (const DiarkisMessageEventArgs &args) |
Callback event called when a message is received by P2P. More... | |
virtual void | OnP2PException (const DiarkisExceptionEventArgs &args) |
Callback event called when sending or receiving fails in P2P. More... | |
void | RegisterPeer (const Diarkis::StdString &uid, const std::shared_ptr< Peer > &p2p) |
Register an IDiarkisP2P instance. More... | |
uint64_t | UnregisterPeer (const Diarkis::StdString &uid) |
Unregister an IDiarkisP2P instance. More... | |
Protected Attributes | |
Diarkis::StdUnorderedMap< Diarkis::StdString, std::shared_ptr< Peer > > | p2pList_ |
List of P2P connections. key:UID, value:pointer to IDiarkisP2P. More... | |
std::recursive_mutex | p2pListMutex_ |
P2P list Mutex. More... | |
std::shared_ptr< IDiarkisUdp > | udp_ |
Pointer to the IDiarkisUdp class. More... | |
std::shared_ptr< LoggerFactory > | loggerFactory_ |
Pointer to logger class. More... | |
std::shared_ptr< IDiarkisLogger > | logger_ |
Pointer to logger class. More... | |
std::function< void()> | schedulerAddNotifyEventFunc_ |
Callback function called when P2P-related events are added. More... | |
Diarkis::StdString | ownGlobalAddress_ |
My Global IP address. More... | |
Diarkis::StdString | myUid_ |
My user ID. More... | |
Base class that wraps the IDiarkisP2P class for easy use of P2P functionality.
DiarkisP2PBase::DiarkisP2PBase | ( | ) |
DiarkisP2PBase constructor.
|
virtual |
|
virtual |
Set up DirectMessage with UDP protocol.
Register loggers and callback functions.
[in] | udp | Pointer to IDiarkisUdp class |
[in] | loggerFactory | Pointer to logger class |
[in] | uid | Your user ID |
|
virtual |
Attempts to make a P2P connection to the specified user ID.
If the connection successes, a callback event registered with GetReadyEvent() (e.g. OnP2PReady) will be triggered.
If the connection fails, a callback event registered with GetFailEvent() (e.g. OnP2PFail) will be triggered.
[in] | uid | Your user ID |
[in] | address | List of endpoints to connect to |
[in] | addressCount | Length of the address |
[in] | timeoutInMilliseconds | Timeout time for hole punch |
[in] | bBuffering | Whether buffering is performed when sending or receiving packets |
|
virtual |
|
virtual |
Set the encryption key.
[in] | bEncryption | Whether to encrypt or not |
[in] | key | Encryption key |
[in] | keySize | Length of the key |
[in] | iv | Initialization vector |
[in] | ivSize | Length of the iv |
[in] | mkey | Message authentication code |
[in] | mkeySize | Length of the mkey |
|
virtual |
|
virtual |
Sends a message to one peer.
When a message is received A callback event (e.g. OnP2PMessage) registered with GetMessageEvent() is triggered.
[in] | payload | Data to be sent |
[in] | payloadSize | Length of the payload |
[in] | type | RUDP type to be used |
[in] | uid | User ID of the peer to which the data is sent |
|
virtual |
|
virtual |
|
virtual |
Sends a message to multiple peers.
When a message is received A callback event (e.g. OnP2PMessage) registered with GetMessageEvent() is triggered.
[in] | payload | Data to be sent |
[in] | payloadSize | Length of the payload |
[in] | type | RUDP type to be used |
[in] | uids | List of user ID of the peer to which the data is sent |
[in] | uidsLen | Length of the uids |
|
virtual |
|
virtual |
|
virtual |
Sends a message to all peers.
When a message is received A callback event (e.g. OnP2PMessage) registered with GetMessageEvent() is triggered.
[in] | payload | Data to be sent |
[in] | payloadSize | Length of the payload |
[in] | type | RUDP type to be used |
|
virtual |
void DiarkisP2PBase::Disconnect | ( | ) |
Disconnects the P2P connection to all peers.
Callback events registered with GetDisconnectEvent() (e.g. OnP2PDisconnect) will be triggered for disconnected peers.
bool DiarkisP2PBase::Disconnect | ( | const char * | uid | ) |
Disconnect P2P connection with the specified user.
Callback events registered with GetDisconnectEvent() (e.g. OnP2PDisconnect) will be triggered.
[in] | uid | User ID of the user to disconnect. |
void DiarkisP2PBase::Update | ( | ) |
Function to update the status of the connection and other information. Must be called periodically.
void DiarkisP2PBase::SetSchedulerAddNotifyEvent | ( | std::function< void()> | notifyEventFunc | ) |
Sets the process to be called when a P2P-related event is added to the scheduler.
uint16_t DiarkisP2PBase::GetConnectedNum | ( | ) |
Get the number of peers connected by P2P.
void DiarkisP2PBase::GetPeerUids | ( | Diarkis::StdVector< Diarkis::StdString > & | output | ) |
Get the user id of peers connected by P2P.
|
protectedvirtual |
Callback event called when a P2P connection succeeds.
|
protectedvirtual |
Callback event called when a hole punch fails.
Triggered when a hole punch is not completed within the specified time.
|
protectedvirtual |
Callback event called when a P2P connection is disconnected.
|
protectedvirtual |
Callback event called when a message is received by P2P.
|
protectedvirtual |
Callback event called when sending or receiving fails in P2P.
It is triggered when the socket is closed and no transmission or reception is possible.
|
protected |
Register an IDiarkisP2P instance.
[in] | uid | UID of the peer |
[in] | p2p | Pointer to IDiarkisP2P instance |
|
protected |
Unregister an IDiarkisP2P instance.
[in] | uid | UID of the peer |
|
protected |
List of P2P connections. key:UID, value:pointer to IDiarkisP2P.
|
protected |
P2P list Mutex.
|
protected |
Pointer to the IDiarkisUdp class.
|
protected |
Pointer to logger class.
|
protected |
Pointer to logger class.
|
protected |
Callback function called when P2P-related events are added.
|
protected |
My Global IP address.
|
protected |
My user ID.