Added packet stats

This commit is contained in:
KimLS
2019-03-11 15:24:32 -07:00
parent 675a67b676
commit 67b228a91c
6 changed files with 70 additions and 1 deletions
+9
View File
@@ -30,12 +30,20 @@ public:
uint16 first_eq_opcode;
uint32 first_length; //0=dont check length
};
typedef enum {
MatchNotReady,
MatchSuccessful,
MatchFailed
} MatchState;
struct Stats
{
EQ::Net::DaybreakConnectionStats DaybreakStats;
int RecvCount[_maxEmuOpcode];
int SentCount[_maxEmuOpcode];
};
virtual void QueuePacket(const EQApplicationPacket *p, bool ack_req=true) = 0;
virtual void FastQueuePacket(EQApplicationPacket **p, bool ack_req=true) = 0;
virtual EQApplicationPacket *PopPacket() = 0;
@@ -53,6 +61,7 @@ public:
virtual void SetOpcodeManager(OpcodeManager **opm) = 0;
virtual const EQEmu::versions::ClientVersion ClientVersion() const { return EQEmu::versions::ClientVersion::Unknown; }
virtual std::shared_ptr<EQ::Net::DaybreakConnection> GetRawConnection() const = 0;
virtual Stats GetStats() const = 0;
};
#endif /*EQSTREAMINTF_H_*/
+5
View File
@@ -94,6 +94,11 @@ std::shared_ptr<EQ::Net::DaybreakConnection> EQStreamProxy::GetRawConnection() c
return m_stream->GetRawConnection();
}
EQStreamInterface::Stats EQStreamProxy::GetStats() const
{
return m_stream->GetStats();
}
bool EQStreamProxy::CheckState(EQStreamState state) {
if(m_stream)
return(m_stream->CheckState(state));
+1
View File
@@ -32,6 +32,7 @@ public:
virtual EQStreamState GetState();
virtual void SetOpcodeManager(OpcodeManager **opm);
virtual std::shared_ptr<EQ::Net::DaybreakConnection> GetRawConnection() const;
virtual Stats GetStats() const;
protected:
std::shared_ptr<EQStreamInterface> const m_stream; //we own this stream object.
+28
View File
@@ -67,6 +67,9 @@ void EQ::Net::EQStream::QueuePacket(const EQApplicationPacket *p, bool ack_req)
opcode = p->GetOpcodeBypass();
}
else {
if (m_owner->m_options.track_opcode_stats) {
m_packet_sent_count[p->GetOpcode()]++; //Wont bother with bypass tracking of these since those are rare for testing anyway
}
opcode = (*m_opcode_manager)->EmuToEQ(p->GetOpcode());
}
@@ -116,6 +119,10 @@ EQApplicationPacket *EQ::Net::EQStream::PopPacket() {
}
EmuOpcode emu_op = (*m_opcode_manager)->EQToEmu(opcode);
if (m_owner->m_options.track_opcode_stats) {
m_packet_recv_count[emu_op]++;
}
EQApplicationPacket *ret = new EQApplicationPacket(emu_op, (unsigned char*)p->Data() + m_owner->m_options.opcode_size, p->Length() - m_owner->m_options.opcode_size);
ret->SetProtocolOpcode(opcode);
m_packet_queue.pop_front();
@@ -215,3 +222,24 @@ EQStreamState EQ::Net::EQStream::GetState() {
return CLOSED;
}
}
EQ::Net::EQStream::Stats EQ::Net::EQStream::GetStats() const
{
Stats ret;
ret.DaybreakStats = m_connection->GetStats();
for (int i = 0; i < _maxEmuOpcode; ++i) {
ret.RecvCount[i] = 0;
ret.SentCount[i] = 0;
}
for (auto &s : m_packet_sent_count) {
ret.SentCount[s.first] = s.second;
}
for (auto &r : m_packet_recv_count) {
ret.RecvCount[r.first] = r.second;
}
return ret;
}
+7
View File
@@ -6,6 +6,7 @@
#include "daybreak_connection.h"
#include <vector>
#include <deque>
#include <unordered_map>
namespace EQ
{
@@ -19,6 +20,7 @@ namespace EQ
EQStreamManagerOptions(int port, bool encoded, bool compressed) {
opcode_size = 2;
track_opcode_stats = false;
//World seems to support both compression and xor zone supports one or the others.
//Enforce one or the other in the convienence construct
@@ -35,6 +37,7 @@ namespace EQ
}
int opcode_size;
bool track_opcode_stats;
DaybreakConnectionManagerOptions daybreak_options;
};
@@ -87,11 +90,15 @@ namespace EQ
virtual std::shared_ptr<EQ::Net::DaybreakConnection> GetRawConnection() const {
return m_connection;
}
virtual Stats GetStats() const;
private:
EQStreamManager *m_owner;
std::shared_ptr<DaybreakConnection> m_connection;
OpcodeManager **m_opcode_manager;
std::deque<std::unique_ptr<EQ::Net::Packet>> m_packet_queue;
std::unordered_map<EmuOpcode, int> m_packet_recv_count;
std::unordered_map<EmuOpcode, int> m_packet_sent_count;
friend class EQStreamManager;
};
}