57 std::vector<std::string>
data;
63 return [ptr, method](std::vector<std::string> v) {
71 return [ptr, method]() {
81void sendUDP(SOCKET* serverSocket, SIN* addr, IP_Type ipType, std::string message);
118 void send(
const std::string& data, ConnType connType = ConnType::TCP);
150 void addDataCallback(
const std::string& key, std::function<
void(std::vector<std::string>)> callback);
183 std::string
decrypt(
const std::string& cipher);
243 void run(std::stop_token st);
275 std::unordered_map<std::string, std::function<void(std::vector<std::string>)>>
dataRcvCB;
auto createDisconnectionCallback(T *ptr, void(T::*method)())
Template which can be used to create Disconnection callbacks from class' methods.
Definition ClientPP.h:70
void sendUDP(SOCKET *serverSocket, SIN *addr, IP_Type ipType, std::string message)
Function to send an UDP message to a client.
std::string domainNameResolution(std::string domainName)
Wrapper of the resolveDomainName function of NSC, with strings.
auto createDataCallback(T *ptr, void(T::*method)(std::vector< std::string >))
Template which can be used to create DataReceived callbacks from class' methods.
Definition ClientPP.h:62
ClientType
Definition ClientPP.h:33
@ LOCAL
Client-Side.
Definition ClientPP.h:35
@ REMOTE
Server-Side.
Definition ClientPP.h:37
bool isDisconnected
Boolean which is used to stop using the client when kicked.
Definition ClientPP.h:232
void addDisconnectionCallback(std::function< void(void)> callback)
Add a callback for the Disconnection event.
bool haveSecret
Tells if the secret has been computed.
Definition ClientPP.h:254
ClientType type
Information of the client's type REMOTE or LOCAL.
Definition ClientPP.h:222
void addDataCallback(const std::string &key, std::function< void(std::vector< std::string >)> callback)
Add a callback for the DataReceived event.
void setServerPKPath(const std::string &SPKFile)
Set the server's public key for the [LOCAL] client.
int port
Server's port.
Definition ClientPP.h:267
void init()
Init the different informations of the client.
void send(const std::string &data, ConnType connType=ConnType::TCP)
This method can be used by both LOCAL and REMOTE client to exchange with the Server/Clients.
~ClientPP()
Destructor of the ClientPP class.
bool getHaveSecret()
Return the haveSecret boolean value.
Client * clientTCP
TCP client pointer.
Definition ClientPP.h:214
void setSharedSecret(const std::string &PK)
Let you set the public key to compute the shared secret.
void start()
Connect the client and start the run loop.
IP_Type ipType
Session's IP type (IPv4 or IPv6)
Definition ClientPP.h:269
const Client & getClientStruct()
Return a reference to the client structure.
std::shared_ptr< SymmetricCipherInterface > symmetricCipher
Have the information of the symmetricKey used for the communication between the Server and the Client...
Definition ClientPP.h:205
std::string ServerPKFile
Path to the server Public Key file.
Definition ClientPP.h:290
std::string SKFile
Definition ClientPP.h:285
std::string PKFile
Paths to the public and private keys.
Definition ClientPP.h:285
std::vector< std::function< void(void)> > disconnCB
This map register the callback for the Disconnection's events.
Definition ClientPP.h:280
Client * clientUDP
UDP client pointer.
Definition ClientPP.h:217
std::stop_source stopTag
This parameter is used to stop the run loop.
Definition ClientPP.h:237
const std::string & getID()
Return the Client's identity string.
ClientPP(const std::string &address, int port, const std::string &separator, IP_Type ipType=IP_Type::IPv4, bool useCiphering=true)
Constructor of the LOCAL client.
ClientPP(Client clientInfo)
Constructor of the REMOTE client.
std::unordered_map< std::string, std::function< void(std::vector< std::string >)> > dataRcvCB
This map register the callback for the DataReceived's events.
Definition ClientPP.h:275
void setKeysPaths(const std::string &PKFile, const std::string &SKFile)
Set the public and private keys for the [LOCAL] client.
std::unique_ptr< KeyExchangeInterface > kxInterface
Key used for the ECDH symmetricKey exchange.
Definition ClientPP.h:211
std::string decrypt(const std::string &cipher)
Return the decrypted string of the given cipher.
void run(std::stop_token st)
Main loop of the client, it listens to the events and process them.
bool useCiphering
Tells if the client use ciphering.
Definition ClientPP.h:259
void kick()
Kick the client by closing its socket.
void stop()
Stop the client by terminating its run loop and disconnect it from the server.
std::string address
Server's address.
Definition ClientPP.h:265
std::jthread runThread
Run thread.
Definition ClientPP.h:262
std::string ID
String "address:port".
Definition ClientPP.h:227
Structure which hold the Client's Data after an event.
Definition ClientPP.h:43
std::shared_ptr< ClientPP > client
Shared pointer of the client which produced the event (nullptr for UDP).
Definition ClientPP.h:55
EventType type
Type of the event : Connection, Disconnection, DataReceived.
Definition ClientPP.h:45
std::vector< std::string > data
Vector with the string obtained after a split on the separator.
Definition ClientPP.h:57
IP_Type ipType
IP type : IPv4 or IPv6.
Definition ClientPP.h:49
SIN addr
Client's address.
Definition ClientPP.h:53
SOCKET socket
In TCP -> Client's socket; in UDP -> Server's socket.
Definition ClientPP.h:51
ConnType connType
Connection type of this event : TCP or UDP.
Definition ClientPP.h:47