2020-01-28 13:18:38 +01:00
|
|
|
#pragma once
|
|
|
|
#include "../PrivateDefines.h"
|
|
|
|
#include "../../tools/Buffers.h"
|
2020-03-17 21:28:03 +01:00
|
|
|
#include "protocol/Interface.h"
|
|
|
|
#include "protocol/Extra.h"
|
2020-01-28 13:18:38 +01:00
|
|
|
//#include "../net/PacketSender.h"
|
|
|
|
|
|
|
|
namespace tgvoip
|
|
|
|
{
|
|
|
|
class PacketSender;
|
2020-03-17 20:11:27 +01:00
|
|
|
|
|
|
|
struct Packet : public Serializable
|
|
|
|
{
|
|
|
|
public:
|
2020-03-17 21:28:03 +01:00
|
|
|
virtual bool parse(const BufferInputStream &in, int peerVersion) override;
|
|
|
|
virtual bool serialize(BufferOutputStream &out, int peerVersion) override;
|
2020-03-17 20:11:27 +01:00
|
|
|
|
|
|
|
public:
|
|
|
|
enum Flags : uint8_t
|
|
|
|
{
|
|
|
|
Len16 = 1,
|
|
|
|
ExtraFEC = 2,
|
|
|
|
ExtraSignaling = 4,
|
|
|
|
RecvTS = 8
|
|
|
|
};
|
|
|
|
enum EFlags : uint8_t
|
|
|
|
{
|
|
|
|
Fragmented = 1,
|
|
|
|
Keyframe = 2
|
|
|
|
};
|
|
|
|
|
2020-03-16 16:07:13 +01:00
|
|
|
uint32_t seq;
|
|
|
|
uint32_t ackSeq;
|
|
|
|
uint32_t ackMask;
|
|
|
|
|
|
|
|
uint8_t streamId;
|
2020-03-17 20:11:27 +01:00
|
|
|
uint8_t flags = 0;
|
|
|
|
uint8_t eFlags = 0;
|
|
|
|
|
|
|
|
uint32_t recvTS = 0;
|
2020-03-16 16:07:13 +01:00
|
|
|
|
|
|
|
Buffer data;
|
2020-03-17 20:11:27 +01:00
|
|
|
|
2020-03-17 21:28:03 +01:00
|
|
|
Array<Extra> extras;
|
2020-03-17 20:11:27 +01:00
|
|
|
};
|
|
|
|
|
2020-03-17 21:28:03 +01:00
|
|
|
struct PacketLegacy : public Packet
|
2020-03-17 20:11:27 +01:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
bool parse(const BufferInputStream &in, int peerVersion) override;
|
|
|
|
bool serialize(BufferOutputStream &out, int peerVersion) override;
|
|
|
|
|
2020-03-17 21:28:03 +01:00
|
|
|
private:
|
|
|
|
bool parseLegacyLegacyPacket(const BufferInputStream &in, unsigned char &type, uint32_t &ackId, uint32_t &pseq, uint32_t &acks, unsigned char &pflags, size_t &packetInnerLen, int peerVersion);
|
2020-03-17 20:11:27 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
// Legacy stuff
|
2020-01-28 13:18:38 +01:00
|
|
|
struct RecentOutgoingPacket
|
|
|
|
{
|
2020-01-29 15:52:43 +01:00
|
|
|
// For simple NACK reliable resending
|
|
|
|
int64_t endpoint;
|
|
|
|
Buffer data;
|
|
|
|
|
2020-01-28 13:18:38 +01:00
|
|
|
uint32_t seq;
|
|
|
|
uint16_t id; // for group calls only
|
|
|
|
double sendTime;
|
|
|
|
double ackTime;
|
|
|
|
double rttTime;
|
|
|
|
uint8_t type;
|
|
|
|
uint32_t size;
|
|
|
|
PacketSender *sender;
|
|
|
|
bool lost;
|
|
|
|
};
|
|
|
|
struct UnacknowledgedExtraData
|
|
|
|
{
|
|
|
|
unsigned char type;
|
|
|
|
Buffer data;
|
|
|
|
uint32_t firstContainingSeq;
|
|
|
|
};
|
|
|
|
struct ReliableOutgoingPacket
|
|
|
|
{
|
|
|
|
Buffer data;
|
|
|
|
unsigned char type;
|
|
|
|
HistoricBuffer<uint32_t, 16> seqs;
|
|
|
|
double firstSentTime;
|
|
|
|
double lastSentTime;
|
|
|
|
double retryInterval;
|
|
|
|
double timeout;
|
|
|
|
uint8_t tries;
|
|
|
|
};
|
|
|
|
struct PendingOutgoingPacket
|
|
|
|
{
|
|
|
|
PendingOutgoingPacket(uint32_t seq_, uint8_t type_, size_t len_, Buffer &&data_, int64_t endpoint_)
|
|
|
|
: seq(seq_),
|
|
|
|
type(type_),
|
|
|
|
len(len_),
|
|
|
|
data(std::move(data_)),
|
|
|
|
endpoint(endpoint_)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
PendingOutgoingPacket(PendingOutgoingPacket &&other)
|
|
|
|
: seq(other.seq),
|
|
|
|
type(other.type),
|
|
|
|
len(other.len),
|
|
|
|
data(std::move(other.data)),
|
|
|
|
endpoint(other.endpoint)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
PendingOutgoingPacket &operator=(PendingOutgoingPacket &&other)
|
|
|
|
{
|
|
|
|
if (this != &other)
|
|
|
|
{
|
|
|
|
seq = other.seq;
|
|
|
|
type = other.type;
|
|
|
|
len = other.len;
|
|
|
|
data = std::move(other.data);
|
|
|
|
endpoint = other.endpoint;
|
|
|
|
}
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
TGVOIP_DISALLOW_COPY_AND_ASSIGN(PendingOutgoingPacket);
|
|
|
|
uint32_t seq;
|
|
|
|
uint8_t type;
|
|
|
|
size_t len;
|
|
|
|
Buffer data;
|
|
|
|
int64_t endpoint;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
struct DebugLoggedPacket
|
|
|
|
{
|
|
|
|
int32_t seq;
|
|
|
|
double timestamp;
|
|
|
|
int32_t length;
|
|
|
|
};
|
|
|
|
*/
|
|
|
|
} // namespace tgvoip
|