@ -14,7 +14,6 @@
# include "common/edac/SHA256.h"
# include "common/network/json/json.h"
# include "common/Log.h"
# include "common/ThreadFunc.h"
# include "common/Utils.h"
# include "network/FNENetwork.h"
# include "network/fne/TagDMRData.h"
@ -206,6 +205,113 @@ void FNENetwork::processNetwork()
}
}
/// <summary>
/// Updates the timer by the passed number of milliseconds.
/// </summary>
/// <param name="ms"></param>
void FNENetwork : : clock ( uint32_t ms )
{
if ( m_status ! = NET_STAT_MST_RUNNING ) {
return ;
}
uint64_t now = std : : chrono : : duration_cast < std : : chrono : : seconds > ( std : : chrono : : system_clock : : now ( ) . time_since_epoch ( ) ) . count ( ) ;
m_maintainenceTimer . clock ( ms ) ;
if ( m_maintainenceTimer . isRunning ( ) & & m_maintainenceTimer . hasExpired ( ) ) {
// check to see if any peers have been quiet (no ping) longer than allowed
std : : vector < uint32_t > peersToRemove = std : : vector < uint32_t > ( ) ;
for ( auto peer : m_peers ) {
uint32_t id = peer . first ;
FNEPeerConnection * connection = peer . second ;
if ( connection ! = nullptr ) {
if ( connection - > connected ( ) ) {
uint64_t dt = connection - > lastPing ( ) + ( m_host - > m_pingTime * m_host - > m_maxMissedPings ) ;
if ( dt < now ) {
LogInfoEx ( LOG_NET , " PEER %u timed out, dt = %u, now = %u " , id , dt , now ) ;
peersToRemove . push_back ( id ) ;
}
}
}
}
// remove any peers
for ( uint32_t peerId : peersToRemove ) {
FNEPeerConnection * connection = m_peers [ peerId ] ;
m_peers . erase ( peerId ) ;
if ( connection ! = nullptr ) {
delete connection ;
}
erasePeerAffiliations ( peerId ) ;
}
// roll the RTP timestamp if no call is in progress
if ( ! m_callInProgress ) {
frame : : RTPHeader : : resetStartTime ( ) ;
m_frameQueue - > clearTimestamps ( ) ;
}
m_maintainenceTimer . start ( ) ;
}
}
/// <summary>
/// Opens connection to the network.
/// </summary>
/// <returns></returns>
bool FNENetwork : : open ( )
{
if ( m_debug )
LogMessage ( LOG_NET , " Opening Network " ) ;
m_status = NET_STAT_MST_RUNNING ;
m_maintainenceTimer . start ( ) ;
m_socket = new udp : : Socket ( m_address , m_port ) ;
// reinitialize the frame queue
if ( m_frameQueue ! = nullptr ) {
delete m_frameQueue ;
m_frameQueue = new FrameQueue ( m_socket , m_peerId , m_debug ) ;
}
bool ret = m_socket - > open ( ) ;
if ( ! ret ) {
m_status = NET_STAT_INVALID ;
}
return ret ;
}
/// <summary>
/// Closes connection to the network.
/// </summary>
void FNENetwork : : close ( )
{
if ( m_debug )
LogMessage ( LOG_NET , " Closing Network " ) ;
if ( m_status = = NET_STAT_MST_RUNNING ) {
uint8_t buffer [ 1U ] ;
: : memset ( buffer , 0x00U , 1U ) ;
for ( auto peer : m_peers ) {
writePeer ( peer . first , { NET_FUNC_MST_CLOSING , NET_SUBFUNC_NOP } , buffer , 1U , ( ushort ) 0U , 0U ) ;
}
}
m_socket - > close ( ) ;
m_maintainenceTimer . stop ( ) ;
m_status = NET_STAT_INVALID ;
}
// ---------------------------------------------------------------------------
// Private Class Members
// ---------------------------------------------------------------------------
/// <summary>
/// Process a data frames from the network.
/// </summary>
@ -776,113 +882,6 @@ void* FNENetwork::threadedNetworkRx(void* arg)
return nullptr ;
}
/// <summary>
/// Updates the timer by the passed number of milliseconds.
/// </summary>
/// <param name="ms"></param>
void FNENetwork : : clock ( uint32_t ms )
{
if ( m_status ! = NET_STAT_MST_RUNNING ) {
return ;
}
uint64_t now = std : : chrono : : duration_cast < std : : chrono : : seconds > ( std : : chrono : : system_clock : : now ( ) . time_since_epoch ( ) ) . count ( ) ;
m_maintainenceTimer . clock ( ms ) ;
if ( m_maintainenceTimer . isRunning ( ) & & m_maintainenceTimer . hasExpired ( ) ) {
// check to see if any peers have been quiet (no ping) longer than allowed
std : : vector < uint32_t > peersToRemove = std : : vector < uint32_t > ( ) ;
for ( auto peer : m_peers ) {
uint32_t id = peer . first ;
FNEPeerConnection * connection = peer . second ;
if ( connection ! = nullptr ) {
if ( connection - > connected ( ) ) {
uint64_t dt = connection - > lastPing ( ) + ( m_host - > m_pingTime * m_host - > m_maxMissedPings ) ;
if ( dt < now ) {
LogInfoEx ( LOG_NET , " PEER %u timed out, dt = %u, now = %u " , id , dt , now ) ;
peersToRemove . push_back ( id ) ;
}
}
}
}
// remove any peers
for ( uint32_t peerId : peersToRemove ) {
FNEPeerConnection * connection = m_peers [ peerId ] ;
m_peers . erase ( peerId ) ;
if ( connection ! = nullptr ) {
delete connection ;
}
erasePeerAffiliations ( peerId ) ;
}
// roll the RTP timestamp if no call is in progress
if ( ! m_callInProgress ) {
frame : : RTPHeader : : resetStartTime ( ) ;
m_frameQueue - > clearTimestamps ( ) ;
}
m_maintainenceTimer . start ( ) ;
}
}
/// <summary>
/// Opens connection to the network.
/// </summary>
/// <returns></returns>
bool FNENetwork : : open ( )
{
if ( m_debug )
LogMessage ( LOG_NET , " Opening Network " ) ;
m_status = NET_STAT_MST_RUNNING ;
m_maintainenceTimer . start ( ) ;
m_socket = new udp : : Socket ( m_address , m_port ) ;
// reinitialize the frame queue
if ( m_frameQueue ! = nullptr ) {
delete m_frameQueue ;
m_frameQueue = new FrameQueue ( m_socket , m_peerId , m_debug ) ;
}
bool ret = m_socket - > open ( ) ;
if ( ! ret ) {
m_status = NET_STAT_INVALID ;
}
return ret ;
}
/// <summary>
/// Closes connection to the network.
/// </summary>
void FNENetwork : : close ( )
{
if ( m_debug )
LogMessage ( LOG_NET , " Closing Network " ) ;
if ( m_status = = NET_STAT_MST_RUNNING ) {
uint8_t buffer [ 1U ] ;
: : memset ( buffer , 0x00U , 1U ) ;
for ( auto peer : m_peers ) {
writePeer ( peer . first , { NET_FUNC_MST_CLOSING , NET_SUBFUNC_NOP } , buffer , 1U , ( ushort ) 0U , 0U ) ;
}
}
m_socket - > close ( ) ;
m_maintainenceTimer . stop ( ) ;
m_status = NET_STAT_INVALID ;
}
// ---------------------------------------------------------------------------
// Private Class Members
// ---------------------------------------------------------------------------
/// <summary>
/// Helper to erase the peer from the peers affiliations list.
/// </summary>