10#define PROTOCOL_ID 0x4f457403
12#define MAX_UDP_PEERS 65535
30#define BASE_HEADER_SIZE 7
31#define CHANNEL_COUNT 3
66#define ORIGINAL_HEADER_SIZE 1
97#define RELIABLE_HEADER_SIZE 3
98#define SEQNUM_INITIAL 65500
99#define SEQNUM_MAX 65535
131 u16 window_start = next;
132 u16 window_end = ( next + window_size ) % (
SEQNUM_MAX+1);
134 if (window_start < window_end) {
135 return ((seqnum >= window_start) && (seqnum < window_end));
139 return ((seqnum < window_end) || (seqnum >= window_start));
144 float value = (curtime - lasttime) / 1000.0f;
207 u32 protocol_id,
session_t sender_peer_id, u8 channel);
257 std::vector<ConstSharedPtr<BufferedPacket>>
getResend(
float timeout, u32 max_packets);
295 std::map<u16, IncomingSplitPacket*>
m_buf;
354#define MAX_RELIABLE_WINDOW_SIZE 0x8000
355#define MAX_RELIABLE_WINDOW_SIZE_SEND 2048
357#define START_RELIABLE_WINDOW_SIZE 64
359#define MIN_RELIABLE_WINDOW_SIZE 32
475 unsigned int max_packet_size)
override;
485 bool reliable)
override;
487 bool isTimedOut(
float timeout, std::string &reason)
override;
497 unsigned int max_packet_size,
498 unsigned int maxtransfer);
516 unsigned int max_packet_size);
#define DISABLE_CLASS_COPY(C)
Definition basic_macros.h:26
#define MYMIN(a, b)
Definition basic_macros.h:9
#define MYMAX(a, b)
Definition basic_macros.h:11
Definition exceptions.h:12
Definition networkpacket.h:14
Definition internal.h:362
void UpdateBytesLost(unsigned int bytes)
Definition impl.cpp:700
u16 getOutgoingSequenceNumber(bool &successful)
Definition impl.cpp:633
u16 m_window_size
Definition internal.h:432
unsigned int current_packet_loss
Definition internal.h:439
void UpdatePacketTooLateCounter()
Definition impl.cpp:713
float getAvgLossRateKB()
Definition internal.h:418
u16 readNextIncomingSeqNum()
Definition impl.cpp:608
float getCurrentLossRateKB()
Definition internal.h:406
float cur_incoming_kbps
Definition internal.h:451
void UpdateTimers(float dtime)
Definition impl.cpp:719
u16 getWindowSize() const
Definition internal.h:423
u16 next_outgoing_split_seqnum
Definition internal.h:437
unsigned int current_packet_too_late
Definition internal.h:440
float bpm_counter
Definition internal.h:456
float avg_incoming_kbps
Definition internal.h:452
float getMaxLossRateKB()
Definition internal.h:408
unsigned int current_packet_successful
Definition internal.h:441
float max_kbps
Definition internal.h:447
float max_incoming_kbps
Definition internal.h:450
float getAvgIncomingRateKB()
Definition internal.h:420
ReliablePacketBuffer outgoing_reliables_sent
Definition internal.h:380
float getAvgDownloadRateKB()
Definition internal.h:416
std::deque< ConnectionCommandPtr > queued_commands
Definition internal.h:386
float getMaxIncomingRateKB()
Definition internal.h:413
void UpdateBytesSent(unsigned int bytes, unsigned int packages=1)
Definition impl.cpp:688
float avg_kbps_lost
Definition internal.h:455
u16 incNextIncomingSeqNum()
Definition impl.cpp:614
bool putBackSequenceNumber(u16)
Definition impl.cpp:678
void UpdateBytesReceived(unsigned int bytes)
Definition impl.cpp:695
ReliablePacketBuffer incoming_reliables
Definition internal.h:377
float packet_loss_counter
Definition internal.h:442
u16 readNextSplitSeqNum()
Definition impl.cpp:622
float max_kbps_lost
Definition internal.h:453
u16 next_incoming_seqnum
Definition internal.h:434
unsigned int current_bytes_transfered
Definition internal.h:444
float avg_kbps
Definition internal.h:449
void setWindowSize(long size)
Definition internal.h:425
IncomingSplitBuffer incoming_splits
Definition internal.h:388
unsigned int current_bytes_lost
Definition internal.h:446
void UpdatePacketLossCounter(unsigned int count)
Definition impl.cpp:707
float getCurrentDownloadRateKB()
Definition internal.h:401
std::mutex m_internal_mutex
Definition internal.h:431
float getMaxDownloadRateKB()
Definition internal.h:403
float getCurrentIncomingRateKB()
Definition internal.h:411
void setNextSplitSeqNum(u16 seqnum)
Definition impl.cpp:627
float cur_kbps
Definition internal.h:448
std::queue< BufferedPacketPtr > queued_reliables
Definition internal.h:383
u16 next_outgoing_seqnum
Definition internal.h:436
unsigned int current_bytes_received
Definition internal.h:445
u16 readOutgoingSequenceNumber()
Definition impl.cpp:672
float cur_kbps_lost
Definition internal.h:454
unsigned int rate_samples
Definition internal.h:458
Definition internal.h:169
IncomingDataCorruption(const char *s)
Definition internal.h:171
Definition internal.h:281
std::mutex m_map_mutex
Definition internal.h:297
std::map< u16, IncomingSplitPacket * > m_buf
Definition internal.h:295
SharedBuffer< u8 > insert(BufferedPacketPtr &p_ptr, bool reliable)
Definition impl.cpp:438
void removeUnreliableTimedOuts(float dtime, float timeout)
Definition impl.cpp:505
~IncomingSplitBuffer()
Definition impl.cpp:430
Definition internal.h:151
NotFoundException(const char *s)
Definition internal.h:153
Address address
Definition impl.h:184
std::mutex m_exclusive_access_mutex
Definition impl.h:177
Definition internal.h:163
ProcessedQueued(const char *s)
Definition internal.h:165
Definition internal.h:157
ProcessedSilentlyException(const char *s)
Definition internal.h:159
Definition internal.h:246
void incrementTimeouts(float dtime)
Definition impl.cpp:340
std::list< BufferedPacketPtr >::iterator FindResult
Definition internal.h:265
u16 m_oldest_non_answered_ack
Definition internal.h:271
BufferedPacketPtr popSeqnum(u16 seqnum)
Definition impl.cpp:215
u32 size()
Definition impl.cpp:174
std::vector< ConstSharedPtr< BufferedPacket > > getResend(float timeout, u32 max_packets)
Definition impl.cpp:361
std::mutex m_list_mutex
Definition internal.h:273
BufferedPacketPtr popFirst()
Definition impl.cpp:198
bool empty()
Definition impl.cpp:168
std::list< BufferedPacketPtr > m_list
Definition internal.h:269
void print()
Definition impl.cpp:157
u32 getTimedOuts(float timeout)
Definition impl.cpp:349
void insert(BufferedPacketPtr &p_ptr, u16 next_expected)
Definition impl.cpp:236
FindResult findPacketNoLock(u16 seqnum)
Definition impl.cpp:180
bool getFirstSeqnum(u16 &result)
Definition impl.cpp:189
Definition internal.h:463
bool processReliableSendCommand(ConnectionCommandPtr &c_ptr, unsigned int max_packet_size)
Definition impl.cpp:1051
void setNextSplitSequenceNumber(u8 channel, u16 seqnum) override
Definition impl.cpp:1192
void RunCommandQueues(unsigned int max_packet_size, unsigned int maxtransfer)
Definition impl.cpp:1154
void reportRTT(float rtt) override
Definition impl.cpp:981
bool isTimedOut(float timeout, std::string &reason) override
Definition impl.cpp:963
void PutReliableSendCommand(ConnectionCommandPtr &c, unsigned int max_packet_size) override
Definition impl.cpp:1020
UDPPeer(session_t id, const Address &address, Connection *connection)
Definition impl.cpp:956
bool m_pending_disconnect
Definition internal.h:509
Channel channels[CHANNEL_COUNT]
Definition internal.h:508
float resend_timeout
Definition internal.h:512
virtual const Address & getAddress() const override
Definition internal.h:477
u16 getNextSplitSequenceNumber(u8 channel) override
Definition impl.cpp:1186
virtual ~UDPPeer()=default
void setResendTimeout(float timeout)
Definition internal.h:503
float getResendTimeout()
Definition internal.h:500
bool Ping(float dtime, SharedBuffer< u8 > &data) override
Definition impl.cpp:1006
SharedBuffer< u8 > addSplitPacket(u8 channel, BufferedPacketPtr &toadd, bool reliable) override
Definition impl.cpp:1198
#define PEER_ID_INEXISTENT
Definition constants.h:19
#define MAX_RELIABLE_WINDOW_SIZE_SEND
Definition internal.h:355
#define SEQNUM_MAX
Definition internal.h:99
#define CHANNEL_COUNT
Definition internal.h:31
ControlType
Definition internal.h:51
@ CONTROLTYPE_PING
Definition internal.h:54
@ CONTROLTYPE_ACK
Definition internal.h:52
@ CONTROLTYPE_DISCO
Definition internal.h:55
@ CONTROLTYPE_SET_PEER_ID
Definition internal.h:53
#define MIN_RELIABLE_WINDOW_SIZE
Definition internal.h:359
#define SEQNUM_INITIAL
Definition internal.h:98
std::lock_guard< std::mutex > MutexAutoLock
Definition mutex_auto_lock.h:31
bool seqnum_in_window(u16 seqnum, u16 next, u16 window_size)
Definition internal.h:129
SharedBuffer< u8 > makeReliablePacket(const SharedBuffer< u8 > &data, u16 seqnum)
Definition impl.cpp:139
PacketType
Definition internal.h:105
@ PACKET_TYPE_CONTROL
Definition internal.h:106
@ PACKET_TYPE_RELIABLE
Definition internal.h:109
@ PACKET_TYPE_MAX
Definition internal.h:110
@ PACKET_TYPE_SPLIT
Definition internal.h:108
@ PACKET_TYPE_ORIGINAL
Definition internal.h:107
void makeAutoSplitPacket(const SharedBuffer< u8 > &data, u32 chunksize_max, u16 &split_seqnum, std::list< SharedBuffer< u8 > > *list)
Definition impl.cpp:125
ConnectionCommandType
Definition internal.h:300
@ CONNCMD_RESEND_ONE
Definition internal.h:310
@ CONNCMD_CONNECT
Definition internal.h:303
@ CONNCMD_SEND
Definition internal.h:306
@ CONNCMD_SERVE
Definition internal.h:302
@ CONNCMD_DISCONNECT_PEER
Definition internal.h:305
@ CONNCMD_SEND_TO_ALL
Definition internal.h:307
@ CONNCMD_NONE
Definition internal.h:301
@ CONCMD_CREATE_PEER
Definition internal.h:309
@ CONNCMD_DISCONNECT
Definition internal.h:304
@ CONCMD_ACK
Definition internal.h:308
std::shared_ptr< BufferedPacket > BufferedPacketPtr
Definition impl.h:90
float CALC_DTIME(u64 lasttime, u64 curtime)
Definition internal.h:142
std::shared_ptr< ConnectionCommand > ConnectionCommandPtr
Definition impl.h:87
BufferedPacketPtr makePacket(const Address &address, const SharedBuffer< u8 > &data, u32 protocol_id, session_t sender_peer_id, u8 channel)
Definition impl.cpp:56
bool seqnum_higher(u16 totest, u16 base)
Definition internal.h:113
u16 session_t
Definition networkprotocol.h:22
#define rangelim(d, min, max)
Definition numeric.h:18
Definition internal.h:180
u8 * data
Definition internal.h:193
Address address
Definition internal.h:197
size_t size() const
Definition internal.h:191
u64 absolute_send_time
Definition internal.h:196
unsigned int resend_count
Definition internal.h:198
float time
Definition internal.h:194
std::vector< u8 > m_data
Definition internal.h:201
u16 getSeqnum() const
Definition impl.cpp:48
float totaltime
Definition internal.h:195
BufferedPacket(u32 a_size)
Definition internal.h:181
Definition internal.h:315
static ConnectionCommandPtr connect(Address address)
Definition impl.cpp:544
static ConnectionCommandPtr ack(session_t peer_id, u8 channelnum, const Buffer< u8 > &data)
Definition impl.cpp:583
static ConnectionCommandPtr create(ConnectionCommandType type)
Definition impl.cpp:532
static ConnectionCommandPtr disconnect_peer(session_t peer_id)
Definition impl.cpp:556
u8 channelnum
Definition internal.h:319
static ConnectionCommandPtr createPeer(session_t peer_id, const Buffer< u8 > &data)
Definition impl.cpp:593
Buffer< u8 > data
Definition internal.h:320
Address address
Definition internal.h:317
bool reliable
Definition internal.h:321
ConnectionCommand(ConnectionCommandType type_)
Definition internal.h:336
static ConnectionCommandPtr disconnect()
Definition impl.cpp:551
bool raw
Definition internal.h:322
static ConnectionCommandPtr send(session_t peer_id, u8 channelnum, NetworkPacket *pkt, bool reliable)
Definition impl.cpp:572
session_t peer_id
Definition internal.h:318
const ConnectionCommandType type
Definition internal.h:316
static ConnectionCommandPtr resend_one(session_t peer_id)
Definition impl.cpp:563
DISABLE_CLASS_COPY(ConnectionCommand)
static ConnectionCommandPtr serve(Address address)
Definition impl.cpp:537
Definition internal.h:218
u32 chunk_count
Definition internal.h:225
bool allReceived() const
Definition internal.h:228
SharedBuffer< u8 > reassemble()
Definition impl.cpp:404
IncomingSplitPacket(u32 cc, bool r)
Definition internal.h:219
IncomingSplitPacket()=delete
bool reliable
Definition internal.h:226
bool insert(u32 chunk_num, SharedBuffer< u8 > &chunkdata)
Definition impl.cpp:388
std::map< u16, SharedBuffer< u8 > > chunks
Definition internal.h:237
float time
Definition internal.h:224