add PIClientServer::Config, common configuration type for both sides, stream packer and encryption settings

This commit is contained in:
2024-09-13 11:08:32 +03:00
parent 996b7ea403
commit 17b902ebcc
8 changed files with 125 additions and 25 deletions

View File

@@ -25,7 +25,7 @@
#ifndef piclientserver_client_base_H
#define piclientserver_client_base_H
#include "pinetworkaddress.h"
#include "piclientserver_config.h"
#include "pip_client_server_export.h"
#include "pistreampacker.h"
@@ -36,6 +36,7 @@ namespace PIClientServer {
class Server;
class PIP_CLIENT_SERVER_EXPORT ClientBase {
friend class Config;
friend class Server;
NO_COPY_CLASS(ClientBase);
@@ -50,7 +51,7 @@ public:
int write(const void * d, const size_t s);
int write(const PIByteArray & ba) { return write(ba.data(), ba.size()); }
void enableSymmetricEncryption(const PIByteArray & key);
Config & configuration() { return config; }
protected:
virtual void readed(PIByteArray data) {}
@@ -62,6 +63,7 @@ protected:
bool own_tcp = false;
std::atomic_bool can_write = {true};
PIEthernet * tcp = nullptr;
Config config;
private:
void destroy();

View File

@@ -0,0 +1,60 @@
/*! \file piclientserver_config.h
* \ingroup ClientServer
* \~\brief
* \~english
* \~russian
*/
/*
PIP - Platform Independent Primitives
Ivan Pelipenko peri4ko@yandex.ru
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef piclientserver_config_H
#define piclientserver_config_H
#include "pibytearray.h"
#include "pip_client_server_export.h"
namespace PIClientServer {
class Server;
class Client;
class ClientBase;
class PIP_CLIENT_SERVER_EXPORT Config {
friend class Server;
friend class Client;
public:
void setPacketSign(ushort sign);
void setPacketSize(int bytes);
void enableSymmetricEncryption(const PIByteArray & key);
protected:
void apply(ClientBase * client);
PIByteArray crypt_key;
ushort packet_sign = 0xAFBE;
int packet_size = 1400;
private:
};
} // namespace PIClientServer
#endif

View File

@@ -25,6 +25,7 @@
#ifndef piclientserver_server_H
#define piclientserver_server_H
#include "piclientserver_config.h"
#include "pimutex.h"
#include "pinetworkaddress.h"
#include "pip_client_server_export.h"
@@ -55,7 +56,7 @@ public:
void setClientFactory(std::function<ServerClient *()> f) { client_factory = f; }
void enableSymmetricEncryption(const PIByteArray & key);
Config & configuration() { return config; }
private:
void stopServer();
@@ -67,7 +68,7 @@ private:
PIEthernet * tcp_server = nullptr;
PIThread * clean_thread = nullptr;
PIThreadNotifier clean_notifier;
PIByteArray crypt_key;
Config config;
PIVector<ServerClient *> clients;
mutable PIMutex clients_mutex;