|
|
|
|
@ -4,6 +4,7 @@
|
|
|
|
|
//
|
|
|
|
|
// Created by Jean-Luc Deltombe (LX3JL) on 10/12/2016.
|
|
|
|
|
// Copyright © 2016 Jean-Luc Deltombe (LX3JL). All rights reserved.
|
|
|
|
|
// Copyright © 2020 Thomas A. Early, N7TAE
|
|
|
|
|
//
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
// This file is part of xlxd.
|
|
|
|
|
@ -48,7 +49,7 @@ CPeers::~CPeers()
|
|
|
|
|
delete m_Peers[i];
|
|
|
|
|
}
|
|
|
|
|
m_Peers.clear();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
m_Mutex.unlock();
|
|
|
|
|
}
|
|
|
|
|
@ -73,7 +74,7 @@ void CPeers::AddPeer(CPeer *peer)
|
|
|
|
|
//std::cout << "Adding existing peer " << peer->GetCallsign() << " at " << peer->GetIp() << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// if not, append to the vector
|
|
|
|
|
if ( !found )
|
|
|
|
|
{
|
|
|
|
|
@ -89,12 +90,12 @@ void CPeers::AddPeer(CPeer *peer)
|
|
|
|
|
// and append all peer's client to reflector client list
|
|
|
|
|
// it is double lock safe to lock Clients list after Peers list
|
|
|
|
|
CClients *clients = g_Reflector.GetClients();
|
|
|
|
|
for ( int i = 0; i < peer->GetNbClients(); i++ )
|
|
|
|
|
for ( auto cit=peer->cbegin(); cit!=peer->cend(); cit++ )
|
|
|
|
|
{
|
|
|
|
|
clients->AddClient(peer->GetClient(i));
|
|
|
|
|
clients->AddClient(*cit);
|
|
|
|
|
}
|
|
|
|
|
g_Reflector.ReleaseClients();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// notify
|
|
|
|
|
g_Reflector.OnPeersChanged();
|
|
|
|
|
}
|
|
|
|
|
@ -115,15 +116,15 @@ void CPeers::RemovePeer(CPeer *peer)
|
|
|
|
|
// remove all clients from reflector client list
|
|
|
|
|
// it is double lock safe to lock Clients list after Peers list
|
|
|
|
|
CClients *clients = g_Reflector.GetClients();
|
|
|
|
|
for ( int i = 0; i < peer->GetNbClients(); i++ )
|
|
|
|
|
for ( auto cit=peer->begin(); cit!=peer->end(); cit++ )
|
|
|
|
|
{
|
|
|
|
|
// this also delete the client object
|
|
|
|
|
clients->RemoveClient(peer->GetClient(i));
|
|
|
|
|
clients->RemoveClient(*cit);
|
|
|
|
|
}
|
|
|
|
|
// so clear it then
|
|
|
|
|
m_Peers[i]->ClearClients();
|
|
|
|
|
g_Reflector.ReleaseClients();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// remove it
|
|
|
|
|
std::cout << "Peer " << m_Peers[i]->GetCallsign() << " at " << m_Peers[i]->GetIp()
|
|
|
|
|
<< " removed" << std::endl;
|
|
|
|
|
@ -155,7 +156,7 @@ CPeer *CPeers::GetPeer(int i)
|
|
|
|
|
CPeer *CPeers::FindPeer(const CIp &Ip, int Protocol)
|
|
|
|
|
{
|
|
|
|
|
CPeer *peer = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// find peer
|
|
|
|
|
for ( int i = 0; (i < m_Peers.size()) && (peer == NULL); i++ )
|
|
|
|
|
{
|
|
|
|
|
@ -164,7 +165,7 @@ CPeer *CPeers::FindPeer(const CIp &Ip, int Protocol)
|
|
|
|
|
peer = m_Peers[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// done
|
|
|
|
|
return peer;
|
|
|
|
|
}
|
|
|
|
|
@ -172,7 +173,7 @@ CPeer *CPeers::FindPeer(const CIp &Ip, int Protocol)
|
|
|
|
|
CPeer *CPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip, int Protocol)
|
|
|
|
|
{
|
|
|
|
|
CPeer *peer = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// find peer
|
|
|
|
|
for ( int i = 0; (i < m_Peers.size()) && (peer == NULL); i++ )
|
|
|
|
|
{
|
|
|
|
|
@ -183,7 +184,7 @@ CPeer *CPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip, int Protocol)
|
|
|
|
|
peer = m_Peers[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// done
|
|
|
|
|
return peer;
|
|
|
|
|
}
|
|
|
|
|
@ -191,7 +192,7 @@ CPeer *CPeers::FindPeer(const CCallsign &Callsign, const CIp &Ip, int Protocol)
|
|
|
|
|
CPeer *CPeers::FindPeer(const CCallsign &Callsign, int Protocol)
|
|
|
|
|
{
|
|
|
|
|
CPeer *peer = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// find peer
|
|
|
|
|
for ( int i = 0; (i < m_Peers.size()) && (peer == NULL); i++ )
|
|
|
|
|
{
|
|
|
|
|
@ -201,7 +202,7 @@ CPeer *CPeers::FindPeer(const CCallsign &Callsign, int Protocol)
|
|
|
|
|
peer = m_Peers[i];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// done
|
|
|
|
|
return peer;
|
|
|
|
|
}
|
|
|
|
|
@ -213,7 +214,7 @@ CPeer *CPeers::FindPeer(const CCallsign &Callsign, int Protocol)
|
|
|
|
|
CPeer *CPeers::FindNextPeer(int Protocol, int *index)
|
|
|
|
|
{
|
|
|
|
|
CPeer *peer = NULL;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// find next peer
|
|
|
|
|
bool found = false;
|
|
|
|
|
for ( int i = *index+1; (i < m_Peers.size()) && !found; i++ )
|
|
|
|
|
@ -227,4 +228,3 @@ CPeer *CPeers::FindNextPeer(int Protocol, int *index)
|
|
|
|
|
}
|
|
|
|
|
return peer;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|