Веб-сайт самохостера Lotigara

summaryrefslogtreecommitdiff
path: root/source/game/StarNetPacketSocket.hpp
diff options
context:
space:
mode:
authorKae <80987908+Novaenia@users.noreply.github.com>2024-03-14 21:41:53 +1100
committerKae <80987908+Novaenia@users.noreply.github.com>2024-03-14 21:41:53 +1100
commit662b83ff92cc2316fb962ff1608359f6d705a5f0 (patch)
treed0e7d15887ed14bd252e6e61888710c8bac2200a /source/game/StarNetPacketSocket.hpp
parent8164e5ae6fa33c9ec2a14f107585a7cbe7fbf813 (diff)
Initial commit of experimental zstd network compression
currently a bit buggy
Diffstat (limited to 'source/game/StarNetPacketSocket.hpp')
-rw-r--r--source/game/StarNetPacketSocket.hpp20
1 files changed, 14 insertions, 6 deletions
diff --git a/source/game/StarNetPacketSocket.hpp b/source/game/StarNetPacketSocket.hpp
index 3530310..dfffec6 100644
--- a/source/game/StarNetPacketSocket.hpp
+++ b/source/game/StarNetPacketSocket.hpp
@@ -4,6 +4,7 @@
#include "StarAtomicSharedPtr.hpp"
#include "StarP2PNetworkingService.hpp"
#include "StarNetPackets.hpp"
+#include "StarZSTDCompression.hpp"
namespace Star {
@@ -24,10 +25,11 @@ class PacketStatCollector {
public:
PacketStatCollector(float calculationWindow = 1.0f);
- void mix(PacketType type, size_t size);
- void mix(HashMap<PacketType, size_t> const& sizes);
+ void mix(size_t size);
+ void mix(PacketType type, size_t size, bool addToTotal = true);
+ void mix(HashMap<PacketType, size_t> const& sizes, bool addToTotal = true);
- // Should always return packet staticstics for the most recent completed
+ // Should always return packet statistics for the most recent completed
// window of time
PacketStats stats() const;
@@ -37,6 +39,7 @@ private:
float m_calculationWindow;
PacketStats m_stats;
Map<PacketType, float> m_unmixed;
+ size_t m_totalBytes;
int64_t m_lastMixTime;
};
@@ -72,10 +75,10 @@ public:
virtual Maybe<PacketStats> incomingStats() const;
virtual Maybe<PacketStats> outgoingStats() const;
- void setLegacy(bool legacy);
- bool legacy() const;
+ virtual void setLegacy(bool legacy);
+ virtual bool legacy() const;
private:
- bool m_legacy = false;
+ bool m_legacy = true;
};
// PacketSocket for local communication.
@@ -127,6 +130,7 @@ public:
Maybe<PacketStats> incomingStats() const override;
Maybe<PacketStats> outgoingStats() const override;
+ void setLegacy(bool legacy) override;
private:
TcpPacketSocket(TcpSocketPtr socket);
@@ -136,6 +140,10 @@ private:
PacketStatCollector m_outgoingStats;
ByteArray m_outputBuffer;
ByteArray m_inputBuffer;
+ bool m_useCompressionStream = false;
+ ByteArray m_compressedBuffer;
+ CompressionStream m_compressionStream;
+ DecompressionStream m_decompressionStream;
};
// Wraps a P2PSocket into a PacketSocket