refactoring PICrypt, add PIStreamPackerConfig, delete piclientserver_config

This commit is contained in:
2024-10-18 18:59:20 +03:00
parent 28f3471036
commit 92a0a9356c
16 changed files with 220 additions and 387 deletions

View File

@@ -33,15 +33,17 @@
class PIIODevice;
class PIP_IO_UTILS_EXPORT PIStreamPacker
: public PIObject
, public PIEthUtilBase {
PIOBJECT(PIStreamPacker)
class PIStreamPackerConfig: public PIEthUtilBase {
friend class PIStreamPacker;
public:
//! Contructs packer and try to assign \"dev\"
PIStreamPacker(PIIODevice * dev = 0);
PIStreamPackerConfig() {
crypt_frag = crypt_size = false;
aggressive_optimization = true;
crypt_frag_size = 1 * 1024 * 1024;
max_packet_size = 1400;
packet_sign = 0xAFBE;
}
//! Set maximum size of single packet
void setMaxPacketSize(int max_size) { max_packet_size = max_size; }
@@ -49,17 +51,12 @@ public:
//! Returns maximum size of single packet, default 1400 bytes
int maxPacketSize() const { return max_packet_size; }
//! Set packet sinature
void setPacketSign(ushort sign_) { packet_sign = sign_; }
//! Returns packet sinature, default 0xAFBE
ushort packetSign() const { return packet_sign; }
//! Returns progress of current packet receive in bytes
int receivePacketProgress() const { return packet.size_s(); }
//! Set receive aggressive optimization. If yes then %PIStreamPacker doesn`t
//! check every byte in incoming stream but check only begin of each read()
//! result. Default is \b true.
@@ -68,17 +65,42 @@ public:
//! Returns aggressive optimization
bool aggressiveOptimization() const { return aggressive_optimization; }
bool cryptFragmentationEnabled() const { return crypt_frag; }
void setCryptFragmentationEnabled(bool on) { crypt_frag = on; }
int cryptFragmentationSize() const { return crypt_frag_size; }
void setCryptFragmentationSize(int size_) { crypt_frag_size = size_; }
bool cryptSizeEnabled() const { return crypt_size; }
void setCryptSizeEnabled(bool on);
void setCryptSizeEnabled(bool on) { crypt_size = on; }
//! Get configuration
const PIStreamPackerConfig & configuration() const { return *this; }
PIStreamPackerConfig & configuration() { return *this; }
//! Apply configuration
void setConfiguration(const PIStreamPackerConfig & config) { *this = config; }
private:
bool crypt_frag, crypt_size, aggressive_optimization;
int crypt_frag_size;
ushort packet_sign;
int max_packet_size;
};
class PIP_IO_UTILS_EXPORT PIStreamPacker
: public PIObject
, public PIStreamPackerConfig {
PIOBJECT(PIStreamPacker)
public:
//! Contructs packer and try to assign \"dev\"
PIStreamPacker(PIIODevice * dev = nullptr);
//! Returns progress of current packet receive in bytes
int receivePacketProgress() const { return packet.size_s(); }
void clear();
//! Prepare data for send and raise \a sendRequest() events
void send(const PIByteArray & data);
@@ -130,11 +152,10 @@ protected:
virtual void packetReceived(PIByteArray data) {}
private:
uint sizeCryptedSize();
PIByteArray stream, packet;
bool crypt_frag, crypt_size, aggressive_optimization;
int packet_size, crypt_frag_size;
ushort packet_sign;
int max_packet_size, size_crypted_size;
int packet_size;
mutable PIMutex prog_s_mutex, prog_r_mutex;
};