mirror of
https://github.com/danog/libtgvoip.git
synced 2024-11-30 04:39:03 +01:00
Update
This commit is contained in:
parent
2eaf6d8e98
commit
49bb662a56
@ -19,7 +19,7 @@ controller/audio/OpusDecoder.cpp \
|
|||||||
controller/audio/OpusEncoder.cpp \
|
controller/audio/OpusEncoder.cpp \
|
||||||
controller/net/PacketReassembler.cpp \
|
controller/net/PacketReassembler.cpp \
|
||||||
controller/net/PacketSender.cpp \
|
controller/net/PacketSender.cpp \
|
||||||
controller/protocol/Ack.cpp \
|
controller/protocol/PacketManager.cpp \
|
||||||
VoIPGroupController.cpp \
|
VoIPGroupController.cpp \
|
||||||
VoIPServerConfig.cpp \
|
VoIPServerConfig.cpp \
|
||||||
audio/AudioIO.cpp \
|
audio/AudioIO.cpp \
|
||||||
|
32
Makefile.in
32
Makefile.in
@ -817,9 +817,10 @@ am__libtgvoip_la_SOURCES_DIST = TgVoip.cpp VoIPController.cpp \
|
|||||||
controller/audio/OpusDecoder.cpp \
|
controller/audio/OpusDecoder.cpp \
|
||||||
controller/audio/OpusEncoder.cpp \
|
controller/audio/OpusEncoder.cpp \
|
||||||
controller/net/PacketReassembler.cpp \
|
controller/net/PacketReassembler.cpp \
|
||||||
controller/net/PacketSender.cpp controller/protocol/Ack.cpp \
|
controller/net/PacketSender.cpp \
|
||||||
VoIPGroupController.cpp VoIPServerConfig.cpp audio/AudioIO.cpp \
|
controller/protocol/PacketManager.cpp VoIPGroupController.cpp \
|
||||||
audio/AudioInput.cpp audio/AudioOutput.cpp audio/Resampler.cpp \
|
VoIPServerConfig.cpp audio/AudioIO.cpp audio/AudioInput.cpp \
|
||||||
|
audio/AudioOutput.cpp audio/Resampler.cpp \
|
||||||
audio/AudioInputTester.cpp os/posix/NetworkSocketPosix.cpp \
|
audio/AudioInputTester.cpp os/posix/NetworkSocketPosix.cpp \
|
||||||
video/VideoSource.cpp video/VideoRenderer.cpp \
|
video/VideoSource.cpp video/VideoRenderer.cpp \
|
||||||
video/VideoPacketSender.cpp video/VideoFEC.cpp \
|
video/VideoPacketSender.cpp video/VideoFEC.cpp \
|
||||||
@ -1757,9 +1758,10 @@ am__objects_12 = TgVoip.lo VoIPController.lo tools/Buffers.lo \
|
|||||||
controller/audio/OpusDecoder.lo \
|
controller/audio/OpusDecoder.lo \
|
||||||
controller/audio/OpusEncoder.lo \
|
controller/audio/OpusEncoder.lo \
|
||||||
controller/net/PacketReassembler.lo \
|
controller/net/PacketReassembler.lo \
|
||||||
controller/net/PacketSender.lo controller/protocol/Ack.lo \
|
controller/net/PacketSender.lo \
|
||||||
VoIPGroupController.lo VoIPServerConfig.lo audio/AudioIO.lo \
|
controller/protocol/PacketManager.lo VoIPGroupController.lo \
|
||||||
audio/AudioInput.lo audio/AudioOutput.lo audio/Resampler.lo \
|
VoIPServerConfig.lo audio/AudioIO.lo audio/AudioInput.lo \
|
||||||
|
audio/AudioOutput.lo audio/Resampler.lo \
|
||||||
audio/AudioInputTester.lo os/posix/NetworkSocketPosix.lo \
|
audio/AudioInputTester.lo os/posix/NetworkSocketPosix.lo \
|
||||||
video/VideoSource.lo video/VideoRenderer.lo \
|
video/VideoSource.lo video/VideoRenderer.lo \
|
||||||
video/VideoPacketSender.lo video/VideoFEC.lo \
|
video/VideoPacketSender.lo video/VideoFEC.lo \
|
||||||
@ -2073,7 +2075,7 @@ am__depfiles_remade = ./$(DEPDIR)/TgVoip.Plo \
|
|||||||
controller/net/$(DEPDIR)/NetworkSocket.Plo \
|
controller/net/$(DEPDIR)/NetworkSocket.Plo \
|
||||||
controller/net/$(DEPDIR)/PacketReassembler.Plo \
|
controller/net/$(DEPDIR)/PacketReassembler.Plo \
|
||||||
controller/net/$(DEPDIR)/PacketSender.Plo \
|
controller/net/$(DEPDIR)/PacketSender.Plo \
|
||||||
controller/protocol/$(DEPDIR)/Ack.Plo \
|
controller/protocol/$(DEPDIR)/PacketManager.Plo \
|
||||||
os/darwin/$(DEPDIR)/AudioInputAudioUnit.Plo \
|
os/darwin/$(DEPDIR)/AudioInputAudioUnit.Plo \
|
||||||
os/darwin/$(DEPDIR)/AudioInputAudioUnitOSX.Plo \
|
os/darwin/$(DEPDIR)/AudioInputAudioUnitOSX.Plo \
|
||||||
os/darwin/$(DEPDIR)/AudioOutputAudioUnit.Plo \
|
os/darwin/$(DEPDIR)/AudioOutputAudioUnit.Plo \
|
||||||
@ -2390,9 +2392,10 @@ SRC = TgVoip.cpp VoIPController.cpp tools/Buffers.cpp \
|
|||||||
controller/audio/OpusDecoder.cpp \
|
controller/audio/OpusDecoder.cpp \
|
||||||
controller/audio/OpusEncoder.cpp \
|
controller/audio/OpusEncoder.cpp \
|
||||||
controller/net/PacketReassembler.cpp \
|
controller/net/PacketReassembler.cpp \
|
||||||
controller/net/PacketSender.cpp controller/protocol/Ack.cpp \
|
controller/net/PacketSender.cpp \
|
||||||
VoIPGroupController.cpp VoIPServerConfig.cpp audio/AudioIO.cpp \
|
controller/protocol/PacketManager.cpp VoIPGroupController.cpp \
|
||||||
audio/AudioInput.cpp audio/AudioOutput.cpp audio/Resampler.cpp \
|
VoIPServerConfig.cpp audio/AudioIO.cpp audio/AudioInput.cpp \
|
||||||
|
audio/AudioOutput.cpp audio/Resampler.cpp \
|
||||||
audio/AudioInputTester.cpp os/posix/NetworkSocketPosix.cpp \
|
audio/AudioInputTester.cpp os/posix/NetworkSocketPosix.cpp \
|
||||||
video/VideoSource.cpp video/VideoRenderer.cpp \
|
video/VideoSource.cpp video/VideoRenderer.cpp \
|
||||||
video/VideoPacketSender.cpp video/VideoFEC.cpp \
|
video/VideoPacketSender.cpp video/VideoFEC.cpp \
|
||||||
@ -2564,7 +2567,8 @@ controller/protocol/$(am__dirstamp):
|
|||||||
controller/protocol/$(DEPDIR)/$(am__dirstamp):
|
controller/protocol/$(DEPDIR)/$(am__dirstamp):
|
||||||
@$(MKDIR_P) controller/protocol/$(DEPDIR)
|
@$(MKDIR_P) controller/protocol/$(DEPDIR)
|
||||||
@: > controller/protocol/$(DEPDIR)/$(am__dirstamp)
|
@: > controller/protocol/$(DEPDIR)/$(am__dirstamp)
|
||||||
controller/protocol/Ack.lo: controller/protocol/$(am__dirstamp) \
|
controller/protocol/PacketManager.lo: \
|
||||||
|
controller/protocol/$(am__dirstamp) \
|
||||||
controller/protocol/$(DEPDIR)/$(am__dirstamp)
|
controller/protocol/$(DEPDIR)/$(am__dirstamp)
|
||||||
audio/$(am__dirstamp):
|
audio/$(am__dirstamp):
|
||||||
@$(MKDIR_P) audio
|
@$(MKDIR_P) audio
|
||||||
@ -4033,7 +4037,7 @@ distclean-compile:
|
|||||||
@AMDEP_TRUE@@am__include@ @am__quote@controller/net/$(DEPDIR)/NetworkSocket.Plo@am__quote@ # am--include-marker
|
@AMDEP_TRUE@@am__include@ @am__quote@controller/net/$(DEPDIR)/NetworkSocket.Plo@am__quote@ # am--include-marker
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@controller/net/$(DEPDIR)/PacketReassembler.Plo@am__quote@ # am--include-marker
|
@AMDEP_TRUE@@am__include@ @am__quote@controller/net/$(DEPDIR)/PacketReassembler.Plo@am__quote@ # am--include-marker
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@controller/net/$(DEPDIR)/PacketSender.Plo@am__quote@ # am--include-marker
|
@AMDEP_TRUE@@am__include@ @am__quote@controller/net/$(DEPDIR)/PacketSender.Plo@am__quote@ # am--include-marker
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@controller/protocol/$(DEPDIR)/Ack.Plo@am__quote@ # am--include-marker
|
@AMDEP_TRUE@@am__include@ @am__quote@controller/protocol/$(DEPDIR)/PacketManager.Plo@am__quote@ # am--include-marker
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@os/darwin/$(DEPDIR)/AudioInputAudioUnit.Plo@am__quote@ # am--include-marker
|
@AMDEP_TRUE@@am__include@ @am__quote@os/darwin/$(DEPDIR)/AudioInputAudioUnit.Plo@am__quote@ # am--include-marker
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@os/darwin/$(DEPDIR)/AudioInputAudioUnitOSX.Plo@am__quote@ # am--include-marker
|
@AMDEP_TRUE@@am__include@ @am__quote@os/darwin/$(DEPDIR)/AudioInputAudioUnitOSX.Plo@am__quote@ # am--include-marker
|
||||||
@AMDEP_TRUE@@am__include@ @am__quote@os/darwin/$(DEPDIR)/AudioOutputAudioUnit.Plo@am__quote@ # am--include-marker
|
@AMDEP_TRUE@@am__include@ @am__quote@os/darwin/$(DEPDIR)/AudioOutputAudioUnit.Plo@am__quote@ # am--include-marker
|
||||||
@ -4923,7 +4927,7 @@ distclean: distclean-am
|
|||||||
-rm -f controller/net/$(DEPDIR)/NetworkSocket.Plo
|
-rm -f controller/net/$(DEPDIR)/NetworkSocket.Plo
|
||||||
-rm -f controller/net/$(DEPDIR)/PacketReassembler.Plo
|
-rm -f controller/net/$(DEPDIR)/PacketReassembler.Plo
|
||||||
-rm -f controller/net/$(DEPDIR)/PacketSender.Plo
|
-rm -f controller/net/$(DEPDIR)/PacketSender.Plo
|
||||||
-rm -f controller/protocol/$(DEPDIR)/Ack.Plo
|
-rm -f controller/protocol/$(DEPDIR)/PacketManager.Plo
|
||||||
-rm -f os/darwin/$(DEPDIR)/AudioInputAudioUnit.Plo
|
-rm -f os/darwin/$(DEPDIR)/AudioInputAudioUnit.Plo
|
||||||
-rm -f os/darwin/$(DEPDIR)/AudioInputAudioUnitOSX.Plo
|
-rm -f os/darwin/$(DEPDIR)/AudioInputAudioUnitOSX.Plo
|
||||||
-rm -f os/darwin/$(DEPDIR)/AudioOutputAudioUnit.Plo
|
-rm -f os/darwin/$(DEPDIR)/AudioOutputAudioUnit.Plo
|
||||||
@ -5293,7 +5297,7 @@ maintainer-clean: maintainer-clean-am
|
|||||||
-rm -f controller/net/$(DEPDIR)/NetworkSocket.Plo
|
-rm -f controller/net/$(DEPDIR)/NetworkSocket.Plo
|
||||||
-rm -f controller/net/$(DEPDIR)/PacketReassembler.Plo
|
-rm -f controller/net/$(DEPDIR)/PacketReassembler.Plo
|
||||||
-rm -f controller/net/$(DEPDIR)/PacketSender.Plo
|
-rm -f controller/net/$(DEPDIR)/PacketSender.Plo
|
||||||
-rm -f controller/protocol/$(DEPDIR)/Ack.Plo
|
-rm -f controller/protocol/$(DEPDIR)/PacketManager.Plo
|
||||||
-rm -f os/darwin/$(DEPDIR)/AudioInputAudioUnit.Plo
|
-rm -f os/darwin/$(DEPDIR)/AudioInputAudioUnit.Plo
|
||||||
-rm -f os/darwin/$(DEPDIR)/AudioInputAudioUnitOSX.Plo
|
-rm -f os/darwin/$(DEPDIR)/AudioInputAudioUnitOSX.Plo
|
||||||
-rm -f os/darwin/$(DEPDIR)/AudioOutputAudioUnit.Plo
|
-rm -f os/darwin/$(DEPDIR)/AudioOutputAudioUnit.Plo
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "controller/controller/Init.cpp"
|
#include "controller/controller/Init.cpp"
|
||||||
#include "controller/controller/Crypto.cpp"
|
#include "controller/controller/Crypto.cpp"
|
||||||
#include "controller/controller/Time.cpp"
|
#include "controller/controller/Time.cpp"
|
||||||
|
#include "controller/controller/Streams.cpp"
|
||||||
#include "controller/media/Audio.cpp"
|
#include "controller/media/Audio.cpp"
|
||||||
#include "controller/media/Video.cpp"
|
#include "controller/media/Video.cpp"
|
||||||
#include "controller/protocol/Bandwidth.cpp"
|
#include "controller/protocol/Bandwidth.cpp"
|
||||||
|
@ -38,7 +38,7 @@
|
|||||||
#include "controller/audio/OpusEncoder.h"
|
#include "controller/audio/OpusEncoder.h"
|
||||||
#include "controller/audio/EchoCanceller.h"
|
#include "controller/audio/EchoCanceller.h"
|
||||||
#include "controller/net/CongestionControl.h"
|
#include "controller/net/CongestionControl.h"
|
||||||
#include "controller/protocol/Ack.h"
|
#include "controller/protocol/PacketManager.h"
|
||||||
#include "controller/protocol/PacketStructs.h"
|
#include "controller/protocol/PacketStructs.h"
|
||||||
#include "tools/Buffers.h"
|
#include "tools/Buffers.h"
|
||||||
#include "controller/net/PacketReassembler.h"
|
#include "controller/net/PacketReassembler.h"
|
||||||
@ -138,7 +138,7 @@ struct CellularCarrierInfo
|
|||||||
|
|
||||||
class PacketSender;
|
class PacketSender;
|
||||||
|
|
||||||
class VoIPController : Ack
|
class VoIPController : PacketManager
|
||||||
{
|
{
|
||||||
friend class VoIPGroupController;
|
friend class VoIPGroupController;
|
||||||
friend class PacketSender;
|
friend class PacketSender;
|
||||||
@ -400,7 +400,7 @@ public:
|
|||||||
STREAM_TYPE_VIDEO
|
STREAM_TYPE_VIDEO
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Stream : Ack
|
struct Stream : PacketManager
|
||||||
{
|
{
|
||||||
int32_t userID;
|
int32_t userID;
|
||||||
uint8_t id;
|
uint8_t id;
|
||||||
|
@ -123,18 +123,6 @@ enum ProtocolVersions
|
|||||||
#define MSC_STACK_FALLBACK(a, b) (a)
|
#define MSC_STACK_FALLBACK(a, b) (a)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SEQ_MAX 0xFFFFFFFF
|
|
||||||
|
|
||||||
inline bool seqgt(uint32_t s1, uint32_t s2)
|
|
||||||
{
|
|
||||||
return ((s1 > s2) && (s1 - s2 <= SEQ_MAX / 2)) || ((s1 < s2) && (s2 - s1 > SEQ_MAX / 2));
|
|
||||||
}
|
|
||||||
|
|
||||||
inline bool seqgte(uint32_t s1, uint32_t s2)
|
|
||||||
{
|
|
||||||
return s1 == s2 || seqgt(s1, s2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#define NEED_RATE_FLAG_SHITTY_INTERNET_MODE 1
|
#define NEED_RATE_FLAG_SHITTY_INTERNET_MODE 1
|
||||||
#define NEED_RATE_FLAG_UDP_NA 2
|
#define NEED_RATE_FLAG_UDP_NA 2
|
||||||
#define NEED_RATE_FLAG_UDP_BAD 4
|
#define NEED_RATE_FLAG_UDP_BAD 4
|
||||||
|
@ -26,7 +26,7 @@ void VoIPController::InitializeTimers()
|
|||||||
<< GetCurrentTime() - connectionInitTime
|
<< GetCurrentTime() - connectionInitTime
|
||||||
<< endpoints.at(currentEndpoint).rtts[0]
|
<< endpoints.at(currentEndpoint).rtts[0]
|
||||||
<< lastRemoteSeq
|
<< lastRemoteSeq
|
||||||
<< (uint32_t)seq
|
<< (uint32_t)getLocalSeq()
|
||||||
<< peerAcks[0]
|
<< peerAcks[0]
|
||||||
<< recvLossCount
|
<< recvLossCount
|
||||||
<< conctl.GetSendLossCount()
|
<< conctl.GetSendLossCount()
|
||||||
|
@ -452,7 +452,7 @@ string VoIPController::GetDebugLog()
|
|||||||
{"tcp_used", useTCP},
|
{"tcp_used", useTCP},
|
||||||
{"p2p_type", p2pType},
|
{"p2p_type", p2pType},
|
||||||
{"packet_stats", json11::Json::object{
|
{"packet_stats", json11::Json::object{
|
||||||
{"out", (int)seq},
|
{"out", (int)getLocalSeq()},
|
||||||
{"in", (int)packetsReceived},
|
{"in", (int)packetsReceived},
|
||||||
{"lost_out", (int)conctl.GetSendLossCount()},
|
{"lost_out", (int)conctl.GetSendLossCount()},
|
||||||
{"lost_in", (int)recvLossCount}}},
|
{"lost_in", (int)recvLossCount}}},
|
||||||
|
27
controller/controller/Streams.cpp
Normal file
27
controller/controller/Streams.cpp
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#include "../PrivateDefines.cpp"
|
||||||
|
|
||||||
|
using namespace tgvoip;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
|
||||||
|
shared_ptr<VoIPController::Stream> VoIPController::GetStreamByType(StreamType type, bool outgoing)
|
||||||
|
{
|
||||||
|
for (shared_ptr<Stream> &ss : (outgoing ? outgoingStreams : incomingStreams))
|
||||||
|
{
|
||||||
|
if (ss->type == type)
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
|
shared_ptr<Stream> s;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
shared_ptr<VoIPController::Stream> VoIPController::GetStreamByID(unsigned char id, bool outgoing)
|
||||||
|
{
|
||||||
|
for (shared_ptr<Stream> &ss : (outgoing ? outgoingStreams : incomingStreams))
|
||||||
|
{
|
||||||
|
if (ss->id == id)
|
||||||
|
return ss;
|
||||||
|
}
|
||||||
|
shared_ptr<Stream> s;
|
||||||
|
return s;
|
||||||
|
}
|
51
controller/net/PacketSender.cpp
Normal file
51
controller/net/PacketSender.cpp
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
#include "PacketSender.h"
|
||||||
|
|
||||||
|
using namespace tgvoip;
|
||||||
|
|
||||||
|
void PacketSender::SendExtra(Buffer &data, unsigned char type)
|
||||||
|
{
|
||||||
|
controller->SendExtra(data, type);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacketSender::IncrementUnsentStreamPackets()
|
||||||
|
{
|
||||||
|
controller->unsentStreamPackets++;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t PacketSender::SendPacket(PendingOutgoingPacket pkt)
|
||||||
|
{
|
||||||
|
uint32_t seq = controller->nextLocalSeq();
|
||||||
|
pkt.seq = seq;
|
||||||
|
controller->SendOrEnqueuePacket(std::move(pkt), true, this);
|
||||||
|
return seq;
|
||||||
|
}
|
||||||
|
|
||||||
|
double PacketSender::GetConnectionInitTime()
|
||||||
|
{
|
||||||
|
return controller->connectionInitTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
const HistoricBuffer<double, 32> &PacketSender::RTTHistory() const
|
||||||
|
{
|
||||||
|
return controller->rttHistory;
|
||||||
|
}
|
||||||
|
|
||||||
|
MessageThread &PacketSender::GetMessageThread()
|
||||||
|
{
|
||||||
|
return controller->messageThread;
|
||||||
|
}
|
||||||
|
|
||||||
|
const VoIPController::ProtocolInfo &PacketSender::GetProtocolInfo() const
|
||||||
|
{
|
||||||
|
return controller->protocolInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
void PacketSender::SendStreamFlags(VoIPController::Stream &stm)
|
||||||
|
{
|
||||||
|
controller->SendStreamFlags(stm);
|
||||||
|
}
|
||||||
|
|
||||||
|
const VoIPController::Config &PacketSender::GetConfig() const
|
||||||
|
{
|
||||||
|
return controller->config;
|
||||||
|
}
|
@ -1,13 +1,12 @@
|
|||||||
#include "Ack.h"
|
#include "PacketManager.h"
|
||||||
#include "../PrivateDefines.h"
|
|
||||||
#include "../../tools/logging.h"
|
#include "../../tools/logging.h"
|
||||||
|
|
||||||
using namespace tgvoip;
|
using namespace tgvoip;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Ack::Ack() : recentIncomingSeqs(MAX_RECENT_PACKETS) {}
|
PacketManager::PacketManager() : recentIncomingSeqs(MAX_RECENT_PACKETS) {}
|
||||||
|
|
||||||
void Ack::ackLocal(uint32_t ackId, uint32_t mask)
|
void PacketManager::ackLocal(uint32_t ackId, uint32_t mask)
|
||||||
{
|
{
|
||||||
peerAcks[0] = ackId;
|
peerAcks[0] = ackId;
|
||||||
for (unsigned int i = 1; i <= 32; i++)
|
for (unsigned int i = 1; i <= 32; i++)
|
||||||
@ -15,7 +14,7 @@ void Ack::ackLocal(uint32_t ackId, uint32_t mask)
|
|||||||
peerAcks[i] = (mask >> (32 - i)) & 1 ? ackId - i : 0;
|
peerAcks[i] = (mask >> (32 - i)) & 1 ? ackId - i : 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bool Ack::wasLocalAcked(uint32_t seq)
|
bool PacketManager::wasLocalAcked(uint32_t seq)
|
||||||
{
|
{
|
||||||
if (seqgt(seq, peerAcks[0]))
|
if (seqgt(seq, peerAcks[0]))
|
||||||
return false;
|
return false;
|
||||||
@ -29,7 +28,7 @@ bool Ack::wasLocalAcked(uint32_t seq)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Ack::ackRemoteSeq(uint32_t ackId)
|
bool PacketManager::ackRemoteSeq(uint32_t ackId)
|
||||||
{
|
{
|
||||||
// Duplicate and moving window check
|
// Duplicate and moving window check
|
||||||
if (seqgt(ackId, lastRemoteSeq - MAX_RECENT_PACKETS))
|
if (seqgt(ackId, lastRemoteSeq - MAX_RECENT_PACKETS))
|
||||||
@ -52,7 +51,7 @@ bool Ack::ackRemoteSeq(uint32_t ackId)
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
uint32_t Ack::getRemoteAckMask()
|
uint32_t PacketManager::getRemoteAckMask()
|
||||||
{
|
{
|
||||||
uint32_t acks = 0;
|
uint32_t acks = 0;
|
||||||
uint32_t distance;
|
uint32_t distance;
|
@ -1,15 +1,27 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include "../PrivateDefines.h"
|
|
||||||
#include "PacketStructs.h"
|
#include "PacketStructs.h"
|
||||||
|
|
||||||
namespace tgvoip
|
namespace tgvoip
|
||||||
{
|
{
|
||||||
// Local and remote packet history management
|
|
||||||
struct Ack
|
#define SEQ_MAX 0xFFFFFFFF
|
||||||
|
|
||||||
|
inline bool seqgt(uint32_t s1, uint32_t s2)
|
||||||
{
|
{
|
||||||
Ack();
|
return ((s1 > s2) && (s1 - s2 <= SEQ_MAX / 2)) || ((s1 < s2) && (s2 - s1 > SEQ_MAX / 2));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool seqgte(uint32_t s1, uint32_t s2)
|
||||||
|
{
|
||||||
|
return s1 == s2 || seqgt(s1, s2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Local and remote packet history management
|
||||||
|
struct PacketManager
|
||||||
|
{
|
||||||
|
PacketManager();
|
||||||
|
|
||||||
/* Local seqno ack */
|
/* Local seqno ack */
|
||||||
// Ack specified local seq + up to 32 seqs ago, specified by mask
|
// Ack specified local seq + up to 32 seqs ago, specified by mask
|
||||||
@ -24,9 +36,17 @@ struct Ack
|
|||||||
return seq++;
|
return seq++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get current local seqno
|
||||||
|
inline uint32_t getLocalSeq()
|
||||||
|
{
|
||||||
|
return seq;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
// Stream-specific local seqno
|
// Stream-specific local seqno
|
||||||
std::atomic<uint32_t> seq = ATOMIC_VAR_INIT(1);
|
std::atomic<uint32_t> seq = ATOMIC_VAR_INIT(1);
|
||||||
|
|
||||||
|
public:
|
||||||
// Recent ougoing packets
|
// Recent ougoing packets
|
||||||
std::vector<RecentOutgoingPacket> recentOutgoingPackets;
|
std::vector<RecentOutgoingPacket> recentOutgoingPackets;
|
||||||
|
|
84
controller/protocol/PacketStructs.h
Normal file
84
controller/protocol/PacketStructs.h
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "../PrivateDefines.h"
|
||||||
|
#include "../../tools/Buffers.h"
|
||||||
|
//#include "../net/PacketSender.h"
|
||||||
|
|
||||||
|
namespace tgvoip
|
||||||
|
{
|
||||||
|
class PacketSender;
|
||||||
|
struct RecentOutgoingPacket
|
||||||
|
{
|
||||||
|
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
|
Loading…
Reference in New Issue
Block a user