Skip to content

Commit

Permalink
Handle login disconnection, ref #628
Browse files Browse the repository at this point in the history
  • Loading branch information
kaetemi committed Feb 24, 2023
1 parent 3b6ecad commit 4ee3e56
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 37 deletions.
24 changes: 12 additions & 12 deletions ryzom/client/src/network_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -891,13 +891,6 @@ bool CNetworkConnection::update()
}
}

if (m_UseQuic ? (m_QuicConnection.state() == CQuicConnection::Disconnected) : !m_Connection.connected())
{
//if(!ClientCfg.Local)
// nlwarning("CNET[%p]: update() attempted whereas socket is not connected !", this);
return false;
}

try
{
// State automaton
Expand Down Expand Up @@ -975,12 +968,19 @@ bool CNetworkConnection::update()
}
}

if (m_UseQuic && m_QuicConnection.state() == CQuicConnection::Disconnected)
if (m_UseQuic && (m_QuicConnection.state() == CQuicConnection::Disconnected))
{
// Bye
_ConnectionState = Disconnect;
}

if (!m_UseQuic && !m_Connection.connected())
{
//if(!ClientCfg.Local)
// nlwarning("CNET[%p]: update() attempted whereas socket is not connected !", this);
_ConnectionState = Disconnect;
}

//updateBufferizedPackets ();

PacketLossGraph.addOneValue (getMeanPacketLoss ());
Expand Down Expand Up @@ -1230,12 +1230,12 @@ bool CNetworkConnection::stateLogin()
{
sendSystemLogin();
_LatestLoginTime = _UpdateTime;
// On UDP time out the login after 24 attempts (every 300ms, so after 7.2 seconds)
if ((!m_UseQuic) && (m_LoginAttempts > 24))
// Time out the login after 24 attempts (every 300ms, so after 7.2 seconds)
if (m_LoginAttempts > 24)
{
m_LoginAttempts = 0;
disconnect(); // will send disconnection message
nlwarning("CNET[%p]: Too many LOGIN attempts, connection problem", this);
nlwarning("CNET[%p]: Too many LOGIN attempts, connection problem (using %s)", this, m_UseQuic ? "QUIC" : "UDP");
return false; // exit now from loop, don't expect a new state
}
else
Expand Down Expand Up @@ -3123,7 +3123,7 @@ void CNetworkConnection::reset()
_TotalLostPackets = 0;
_ConnectionQuality = false;

m_UseQuic = false;
m_UseQuic = true;

_CurrentSmoothServerTick= 0;
_SSTLastLocalTime= 0;
Expand Down
46 changes: 24 additions & 22 deletions ryzom/client/src/quic_connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,18 +52,20 @@ class CQuicConnectionImpl
Release,
};

CQuicConnectionImpl()
: Api(NULL)
CQuicConnectionImpl(CQuicConnection *self)
: Self(self)
, Api(NULL)
, Registration(NULL)
, Configuration(NULL)
, Connection(NULL)
, DesiredStateChange(NoChange)
, BufferReads(0)
, State(CQuicConnection::Disconnected)
, ReceiveEnable(0)
, ReceiveEnable(0)
{
}

CQuicConnection *Self;
const QUIC_API_TABLE *Api;
HQUIC Registration;
HQUIC Configuration;
Expand Down Expand Up @@ -101,13 +103,16 @@ class CQuicConnectionImpl
void shutdown();
void close();
void release();

/// Received datagram (from quic threads)
void datagramReceived(const uint8 *buffer, uint32 length);
};

CQuicConnection::CQuicConnection()
#ifdef NL_CPP14
: m(std::make_unique<CQuicConnectionImpl>())
: m(std::make_unique<CQuicConnectionImpl>(this))
#else
: m(new CQuicConnectionImpl())
: m(new CQuicConnectionImpl(this))
#endif
{
}
Expand All @@ -121,17 +126,17 @@ CQuicConnection::~CQuicConnection()
void CQuicConnectionImpl::init()
{
CQuicConnectionImpl *const m = this;

if (MsQuic)
{
return;
}

// TestAndSet has acquire semantics, clear has release semantics, so we use clear to flag the events
m->ConnectedFlag.testAndSet();
m->ShuttingDownFlag.testAndSet();
m->ShutdownFlag.testAndSet();

// Open library
QUIC_STATUS status = MsQuicOpenVersion(QUIC_API_VERSION_2, (const void **)&MsQuic);
if (QUIC_FAILED(status))
Expand Down Expand Up @@ -317,7 +322,7 @@ void CQuicConnectionImpl::update()

// Asynchronous release
if (!m->Connection
&& m->DesiredStateChange == CQuicConnectionImpl::Release)
&& m->DesiredStateChange == CQuicConnectionImpl::Release)
{
nlassert(m->State == CQuicConnection::Disconnected);
m->release();
Expand Down Expand Up @@ -371,7 +376,8 @@ void CQuicConnectionImpl::update()
// Shutting down, this is just a limbo state
if (!m->ShuttingDownFlag.testAndSet())
{
if (m->State == CQuicConnection::Connected)
if (m->State == CQuicConnection::Connected
|| m->State == CQuicConnection::Connecting)
{
m->State = CQuicConnection::Disconnecting;
}
Expand Down Expand Up @@ -406,7 +412,7 @@ void CQuicConnectionImpl::release()
CBufFIFO *fifo = &access.value();
fifo->clear();
}

// Close configuration
if (m->Configuration)
{
Expand Down Expand Up @@ -452,8 +458,7 @@ _Function_class_(QUIC_CONNECTION_CALLBACK)
#endif
CQuicConnectionImpl::connectionCallback(HQUIC connection, void *context, QUIC_CONNECTION_EVENT *ev)
{
CQuicConnection *const self = (CQuicConnection *)context;
CQuicConnectionImpl *const m = self->m.get();
CQuicConnectionImpl *const m = (CQuicConnectionImpl *)context;
QUIC_STATUS status = QUIC_STATUS_NOT_SUPPORTED;
switch (ev->Type)
{
Expand Down Expand Up @@ -485,7 +490,7 @@ _Function_class_(QUIC_CONNECTION_CALLBACK)
case QUIC_CONNECTION_EVENT_DATAGRAM_RECEIVED:
nlinfo("Datagram received");
// YES PLEASE
self->datagramReceived(ev->DATAGRAM_RECEIVED.Buffer->Buffer, ev->DATAGRAM_RECEIVED.Buffer->Length);
m->datagramReceived(ev->DATAGRAM_RECEIVED.Buffer->Buffer, ev->DATAGRAM_RECEIVED.Buffer->Length);
status = QUIC_STATUS_SUCCESS;
break;
case QUIC_CONNECTION_EVENT_DATAGRAM_STATE_CHANGED:
Expand Down Expand Up @@ -541,12 +546,12 @@ bool CQuicConnection::receiveDatagram(NLMISC::CBitMemStream &msgin)
{
if (!m->ReceiveEnable)
return false;

int writes = m->BufferWrites;
int reads = m->BufferReads;
if (writes != reads)
{
CFifoAccessor access(&m->Buffer);
CFifoAccessor access(&m->Buffer); // This block is mutex'd now
CBufFIFO *fifo = &access.value();
if (fifo->empty())
{
Expand All @@ -568,9 +573,10 @@ bool CQuicConnection::receiveDatagram(NLMISC::CBitMemStream &msgin)
return false;
}

void CQuicConnection::datagramReceived(const uint8 *buffer, uint32 length)
void CQuicConnectionImpl::datagramReceived(const uint8 *buffer, uint32 length)
{
CFifoAccessor access(&m->Buffer);
CQuicConnectionImpl *const m = this;
CFifoAccessor access(&m->Buffer); // This block is mutex'd now
CBufFIFO *fifo = &access.value();
fifo->push(buffer, length);
++m->BufferWrites;
Expand Down Expand Up @@ -631,10 +637,6 @@ bool CQuicConnection::receiveDatagram(NLMISC::CBitMemStream &msgin)
return false;
}

void CQuicConnection::datagramReceived(const uint8 *buffer, uint32 length)
{
}

#endif

/* end of file */
3 changes: 0 additions & 3 deletions ryzom/client/src/quic_connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,6 @@ class CQuicConnection

/// Internal implementation specific
CUniquePtr<CQuicConnectionImpl> m;

/// Received datagram
void datagramReceived(const uint8 *buffer, uint32 length);
};

#endif /* NL_QUIC_TRANSCEIVER_H */
Expand Down

0 comments on commit 4ee3e56

Please sign in to comment.