Skip to content

Commit

Permalink
Fix memory reference error in NatPunchthroughServer and Integer overf…
Browse files Browse the repository at this point in the history
…low when 2GB data is transfered continuously. Issue SLikeSoft#39
  • Loading branch information
exuvo committed Aug 30, 2022
1 parent d6e1470 commit c24e428
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Source/include/slikenet/CCRakNetSlidingWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class CCRakNetSlidingWindow
/// Update over time
void Update(CCTimeType curTime, bool hasDataToSendOrResend);

int GetRetransmissionBandwidth(CCTimeType curTime, CCTimeType timeSinceLastTick, uint32_t unacknowledgedBytes, bool isContinuousSend);
int GetTransmissionBandwidth(CCTimeType curTime, CCTimeType timeSinceLastTick, uint32_t unacknowledgedBytes, bool isContinuousSend);
int64_t GetRetransmissionBandwidth(CCTimeType curTime, CCTimeType timeSinceLastTick, uint64_t unacknowledgedBytes, bool isContinuousSend);
int64_t GetTransmissionBandwidth(CCTimeType curTime, CCTimeType timeSinceLastTick, uint64_t unacknowledgedBytes, bool isContinuousSend);

/// Acks do not have to be sent immediately. Instead, they can be buffered up such that groups of acks are sent at a time
/// This reduces overall bandwidth usage
Expand Down
2 changes: 1 addition & 1 deletion Source/include/slikenet/ReliabilityLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ class ReliabilityLayer//<ReliabilityLayer>
#endif


uint32_t unacknowledgedBytes;
uint64_t unacknowledgedBytes;

bool ResendBufferOverflow(void) const;
void ValidateResendList(void) const;
Expand Down
1 change: 1 addition & 0 deletions Source/include/slikenet/defineoverrides.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#define __GET_TIME_64BIT 0
#define USE_SLIDING_WINDOW_CONGESTION_CONTROL 1
// Randomly fails with: Socket failed test send
//#define RAKNET_SUPPORT_IPV6 1
#define RAKSTRING_TYPE_IS_UNICODE 0
#define RAKPEER_USER_THREADED 0
Expand Down
8 changes: 4 additions & 4 deletions Source/src/CCRakNetSlidingWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,22 @@ void CCRakNetSlidingWindow::Update(CCTimeType curTime, bool hasDataToSendOrResen
(void) hasDataToSendOrResend;
}
// ----------------------------------------------------------------------------------------------------------------------------
int CCRakNetSlidingWindow::GetRetransmissionBandwidth(CCTimeType curTime, CCTimeType timeSinceLastTick, uint32_t unacknowledgedBytes, bool isContinuousSend) {
int64_t CCRakNetSlidingWindow::GetRetransmissionBandwidth(CCTimeType curTime, CCTimeType timeSinceLastTick, uint64_t unacknowledgedBytes, bool isContinuousSend) {
(void) curTime;
(void) isContinuousSend;
(void) timeSinceLastTick;

return unacknowledgedBytes;
}
// ----------------------------------------------------------------------------------------------------------------------------
int CCRakNetSlidingWindow::GetTransmissionBandwidth(CCTimeType curTime, CCTimeType timeSinceLastTick, uint32_t unacknowledgedBytes, bool isContinuousSend) {
int64_t CCRakNetSlidingWindow::GetTransmissionBandwidth(CCTimeType curTime, CCTimeType timeSinceLastTick, uint64_t unacknowledgedBytes, bool isContinuousSend) {
(void) curTime;
(void) timeSinceLastTick;

_isContinuousSend=isContinuousSend;

if (unacknowledgedBytes<=cwnd)
return (int) (cwnd-unacknowledgedBytes);
if (unacknowledgedBytes <= cwnd)
return (int64_t) (cwnd - unacknowledgedBytes);
else
return 0;
}
Expand Down
5 changes: 4 additions & 1 deletion Source/src/NatPunchthroughServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,10 @@ void NatPunchthroughServer::OnClosedConnection(const SystemAddress &systemAddres
if (connectionAttempt->attemptPhase==ConnectionAttempt::NAT_ATTEMPT_PHASE_GETTING_RECENT_PORTS)
{
otherUser->isReady=true;
freedUpInProgressUsers.Insert(otherUser, _FILE_AND_LINE_ );

if (connectionAttempt->sender != user || connectionAttempt->recipient != user) {
freedUpInProgressUsers.Insert(otherUser, _FILE_AND_LINE_ );
}
}

otherUser->DeleteConnectionAttempt(connectionAttempt);
Expand Down
4 changes: 2 additions & 2 deletions Source/src/ReliabilityLayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1956,8 +1956,8 @@ void ReliabilityLayer::UpdateInternal( RakNetSocket2 *s, SystemAddress &systemAd
dhf.hasBAndAS=false;
ResetPacketsAndDatagrams();

int transmissionBandwidth = congestionManager.GetTransmissionBandwidth(time, timeSinceLastTick, unacknowledgedBytes,dhf.isContinuousSend);
int retransmissionBandwidth = congestionManager.GetRetransmissionBandwidth(time, timeSinceLastTick, unacknowledgedBytes,dhf.isContinuousSend);
int64_t transmissionBandwidth = congestionManager.GetTransmissionBandwidth(time, timeSinceLastTick, unacknowledgedBytes,dhf.isContinuousSend);
int64_t retransmissionBandwidth = congestionManager.GetRetransmissionBandwidth(time, timeSinceLastTick, unacknowledgedBytes,dhf.isContinuousSend);
if (retransmissionBandwidth>0 || transmissionBandwidth>0)
{
statistics.isLimitedByCongestionControl=false;
Expand Down

0 comments on commit c24e428

Please sign in to comment.