Skip to content

Commit

Permalink
Fix missing message type on FS in fifo, need to keep track of outgoin…
Browse files Browse the repository at this point in the history
…g datagram buffers (todo), connection works, ingame ui keeps saying Probing on both UDP and QUIC (known bug), ref #628
  • Loading branch information
kaetemi committed Feb 24, 2023
1 parent 8852792 commit f20e74f
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 14 deletions.
1 change: 1 addition & 0 deletions nel/include/nel/misc/buf_fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class CBufFIFO

/// Concate and push 'buffer1' and buffer2 in the head of the FIFO. The goal is to avoid a copy
void push (const std::vector<uint8> &buffer1, const std::vector<uint8> &buffer2);
void push (const uint8 *buffer1, uint32 size1, const uint8 *buffer2, uint32 size2);

/// Get the buffer in the tail of the FIFO and put it in 'buffer'
void front (std::vector<uint8> &buffer);
Expand Down
13 changes: 9 additions & 4 deletions nel/src/misc/buf_fifo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,18 +120,23 @@ void CBufFIFO::push (const uint8 *buffer, uint32 s)
}

void CBufFIFO::push(const std::vector<uint8> &buffer1, const std::vector<uint8> &buffer2)
{
push(&buffer1[0], buffer1.size(), &buffer2[0], buffer2.size());
}

void CBufFIFO::push(const uint8 *buffer1, uint32 size1, const uint8 *buffer2, uint32 size2)
{
#if STAT_FIFO
TTicks before = CTime::getPerformanceTime();
#endif

TFifoSize s = (TFifoSize)(buffer1.size() + buffer2.size());
TFifoSize s = (TFifoSize)(size1 + size2);

#if DEBUG_FIFO
nldebug("%p push2(%d)", this, s);
#endif

nlassert((buffer1.size() + buffer2.size ()) > 0 && (buffer1.size() + buffer2.size ()) < pow(2.0, static_cast<double>(sizeof(TFifoSize)*8)));
nlassert((size1 + size2) > 0 && (size1 + size2) < pow(2.0, static_cast<double>(sizeof(TFifoSize)*8)));

// avoid too big fifo
if (this->size() > 10000000)
Expand All @@ -157,8 +162,8 @@ void CBufFIFO::push(const std::vector<uint8> &buffer1, const std::vector<uint8>
_Head += sizeof(TFifoSize);

// store the block itself
CFastMem::memcpy(_Head, &(buffer1[0]), buffer1.size());
CFastMem::memcpy(_Head + buffer1.size(), &(buffer2[0]), buffer2.size());
CFastMem::memcpy(_Head, &(buffer1[0]), size1);
CFastMem::memcpy(_Head + size1, &(buffer2[0]), size2);
_Head += s;

_Empty = false;
Expand Down
2 changes: 2 additions & 0 deletions ryzom/client/src/network_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,6 +1231,7 @@ bool CNetworkConnection::stateLogin()
sendSystemLogin();
_LatestLoginTime = _UpdateTime;
// Time out the login after 24 attempts (every 300ms, so after 7.2 seconds)
#if 1 // Disable login timeout here when debugging login messages
if (m_LoginAttempts > 24)
{
m_LoginAttempts = 0;
Expand All @@ -1239,6 +1240,7 @@ bool CNetworkConnection::stateLogin()
return false; // exit now from loop, don't expect a new state
}
else
#endif
{
++m_LoginAttempts;
}
Expand Down
12 changes: 7 additions & 5 deletions ryzom/client/src/quic_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -532,12 +532,14 @@ _Function_class_(QUIC_CONNECTION_CALLBACK)

bool CQuicConnection::sendDatagram(const uint8 *buffer, uint32 size)
{
if (m->Connection && size <= m->MaxSendLength)
if (m->Connection && m->State && CQuicConnection::Connected && size <= m->MaxSendLength.load())
{
QUIC_BUFFER buf;
buf.Buffer = (uint8 *)buffer;
buf.Length = size;
QUIC_STATUS status = MsQuic->DatagramSend(m->Connection, &buf, 1, QUIC_SEND_FLAG_NONE, this);
QUIC_BUFFER *buf = new QUIC_BUFFER(); // wow leak :)
uint8 *copy = new uint8[size];
memcpy(copy, buffer, size);
buf->Buffer = copy; // (uint8 *)buffer;
buf->Length = size;
QUIC_STATUS status = MsQuic->DatagramSend(m->Connection, buf, 1, QUIC_SEND_FLAG_NONE, this);
if (QUIC_FAILED(status))
{
nlwarning("DatagramSend failed with %d", status);
Expand Down
14 changes: 9 additions & 5 deletions ryzom/server/src/frontend_service/quic_transceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,9 @@ void CQuicTransceiver::datagramReceived(CQuicUserContext *user, const uint8 *buf
// Locked block
{
CAtomicFlagLockYield lock(m->BufferMutex);
m->Buffer->push(buffer, length);
static const uint8 userEvent = TReceivedMessage::User;
static_assert(MsgHeaderSize == sizeof(userEvent));
m->Buffer->push(&userEvent, MsgHeaderSize, buffer, length);
m->Buffer->push((uint8 *)&user, sizeof(user)); // Pointer
}
}
Expand All @@ -510,10 +512,12 @@ NLMISC::CBufFIFO *CQuicTransceiver::swapWriteQueue(NLMISC::CBufFIFO *writeQueue)

void CQuicTransceiver::sendDatagram(CQuicUserContext *user, const uint8 *buffer, uint32 size)
{
QUIC_BUFFER buf;
buf.Buffer = (uint8 *)buffer;
buf.Length = size;
QUIC_STATUS status = MsQuic->DatagramSend((HQUIC)user->Connection, &buf, 1, QUIC_SEND_FLAG_NONE, (void *)user);
QUIC_BUFFER *buf = new QUIC_BUFFER(); // wow leak :)
uint8 *copy = new uint8[size];
memcpy(copy, buffer, size);
buf->Buffer = copy; // (uint8 *)buffer;
buf->Length = size;
QUIC_STATUS status = MsQuic->DatagramSend((HQUIC)user->Connection, buf, 1, QUIC_SEND_FLAG_NONE, (void *)user);
if (QUIC_FAILED(status))
{
nlwarning("MsQuic->ConnectionSendDatagram failed with status %d", status);
Expand Down

0 comments on commit f20e74f

Please sign in to comment.