mirror of
https://github.com/nostar/urfd.git
synced 2026-11-08 04:19:39 +00:00
dht support for interlinking
This commit is contained in:
1 parent
1ed0ab2971
commit
d11128df3a
9 files changed
+66
-232
No files matched your search
@@ -1,49 +0,0 @@
|
||||
// Copyright © 2015 Jean-Luc. All rights reserved.
|
||||
|
||||
// urfd -- The universal reflector
|
||||
// Copyright © 2021 Thomas A. Early N7TAE
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
|
||||
#include "Notification.h"
|
||||
|
||||
class CNotificationQueue
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
CNotificationQueue() {}
|
||||
|
||||
// destructor
|
||||
~CNotificationQueue() {}
|
||||
|
||||
// lock
|
||||
void Lock() { m_Mutex.lock(); }
|
||||
void Unlock() { m_Mutex.unlock(); }
|
||||
|
||||
// pass thru
|
||||
CNotification front() { return queue.front(); }
|
||||
void pop() { queue.pop(); }
|
||||
void push(CNotification note) { queue.push(note); }
|
||||
bool empty() const { return queue.empty(); }
|
||||
|
||||
protected:
|
||||
// data
|
||||
std::mutex m_Mutex;
|
||||
std::queue<CNotification> queue;
|
||||
};
|
||||
@@ -38,8 +38,8 @@ public:
|
||||
CInterlinkMapItem(const char *addr, const char *mods, uint16_t port);
|
||||
|
||||
// Update things
|
||||
void UpdateIP(bool IPv6NotConfigured);
|
||||
#ifndef NO_DHT
|
||||
void UpdateIP(bool IPv6NotConfigured);
|
||||
void UpdateItem(const std::string &cmods, const std::string &ipv4, const std::string &ipv6, uint16_t port, const std::string &tcmods);
|
||||
#endif
|
||||
|
||||
@@ -69,6 +69,6 @@ private:
|
||||
|
||||
#ifndef NO_DHT
|
||||
bool m_Updated;
|
||||
std::string m_CMods, m_IPv4, m_IPv6, m_TCMods;
|
||||
std::string m_CMods, m_TCMods, m_IPv4, m_IPv6;
|
||||
#endif
|
||||
};
|
||||
@@ -1,37 +0,0 @@
|
||||
// Copyright © 2015 Jean-Luc. All rights reserved.
|
||||
|
||||
// urfd -- The universal reflector
|
||||
// Copyright © 2021 Thomas A. Early N7TAE
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
#include "Notification.h"
|
||||
|
||||
CNotification::CNotification()
|
||||
{
|
||||
// init variables
|
||||
m_iId = NOTIFICATION_NONE;
|
||||
}
|
||||
|
||||
CNotification::CNotification(int iId)
|
||||
{
|
||||
m_iId = iId;
|
||||
}
|
||||
|
||||
CNotification::CNotification(int iId, const CCallsign &Callsign)
|
||||
{
|
||||
m_iId = iId;
|
||||
m_Callsign = Callsign;
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright © 2015 Jean-Luc. All rights reserved.
|
||||
|
||||
// urfd -- The universal reflector
|
||||
// Copyright © 2021 Thomas A. Early N7TAE
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Callsign.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Id
|
||||
#define NOTIFICATION_NONE 0
|
||||
#define NOTIFICATION_CLIENTS 1
|
||||
#define NOTIFICATION_USERS 2
|
||||
#define NOTIFICATION_STREAM_OPEN 3
|
||||
#define NOTIFICATION_STREAM_CLOSE 4
|
||||
#define NOTIFICATION_PEERS 5
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// class
|
||||
|
||||
class CNotification
|
||||
{
|
||||
public:
|
||||
// constructor
|
||||
CNotification();
|
||||
CNotification(int);
|
||||
CNotification(int, const CCallsign &);
|
||||
|
||||
// get
|
||||
int GetId(void) const { return m_iId; }
|
||||
const CCallsign &GetCallsign(void) const { return m_Callsign; }
|
||||
|
||||
protected:
|
||||
// data
|
||||
int m_iId;
|
||||
CCallsign m_Callsign;
|
||||
|
||||
};
|
||||
@@ -1,49 +0,0 @@
|
||||
// Copyright © 2015 Jean-Luc. All rights reserved.
|
||||
|
||||
// urfd -- The universal reflector
|
||||
// Copyright © 2021 Thomas A. Early N7TAE
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <queue>
|
||||
#include <mutex>
|
||||
|
||||
#include "Notification.h"
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// class
|
||||
|
||||
class CNotificationQueue
|
||||
{
|
||||
public:
|
||||
// lock
|
||||
void Lock() { m_Mutex.lock(); }
|
||||
void Unlock() { m_Mutex.unlock(); }
|
||||
|
||||
// pass thru
|
||||
CNotification front() { return queue.front(); }
|
||||
void pop() { queue.pop(); }
|
||||
void push(CNotification note) { queue.push(note); }
|
||||
bool empty() const { return queue.empty(); }
|
||||
|
||||
protected:
|
||||
// data
|
||||
std::mutex m_Mutex;
|
||||
std::queue<CNotification> queue;
|
||||
};
|
||||
+16
-32
@@ -236,7 +236,7 @@ std::shared_ptr<CPacketStream> CReflector::OpenStream(std::unique_ptr<CDvHeaderP
|
||||
stream->Push(std::move(DvHeader));
|
||||
|
||||
// notify
|
||||
OnStreamOpen(stream->GetUserCallsign());
|
||||
//OnStreamOpen(stream->GetUserCallsign());
|
||||
|
||||
}
|
||||
return stream;
|
||||
@@ -264,7 +264,7 @@ void CReflector::CloseStream(std::shared_ptr<CPacketStream> stream)
|
||||
client->NotAMaster();
|
||||
|
||||
// notify
|
||||
OnStreamClose(stream->GetUserCallsign());
|
||||
//OnStreamClose(stream->GetUserCallsign());
|
||||
|
||||
std::cout << "Closing stream of module " << GetStreamModule(stream) << std::endl;
|
||||
}
|
||||
@@ -381,48 +381,32 @@ void CReflector::XmlReportThread()
|
||||
|
||||
void CReflector::OnPeersChanged(void)
|
||||
{
|
||||
CNotification notification(NOTIFICATION_PEERS);
|
||||
|
||||
m_Notifications.Lock();
|
||||
m_Notifications.push(notification);
|
||||
m_Notifications.Unlock();
|
||||
#ifndef NO_DHT
|
||||
PutDHTPeers();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CReflector::OnClientsChanged(void)
|
||||
{
|
||||
CNotification notification(NOTIFICATION_CLIENTS);
|
||||
|
||||
m_Notifications.Lock();
|
||||
m_Notifications.push(notification);
|
||||
m_Notifications.Unlock();
|
||||
#ifndef NO_DHT
|
||||
PutDHTClients();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CReflector::OnUsersChanged(void)
|
||||
{
|
||||
CNotification notification(NOTIFICATION_USERS);
|
||||
|
||||
m_Notifications.Lock();
|
||||
m_Notifications.push(notification);
|
||||
m_Notifications.Unlock();
|
||||
#ifndef NO_DHT
|
||||
PutDHTUsers();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CReflector::OnStreamOpen(const CCallsign &callsign)
|
||||
{
|
||||
CNotification notification(NOTIFICATION_STREAM_OPEN, callsign);
|
||||
// void CReflector::OnStreamOpen(const CCallsign &callsign)
|
||||
// {
|
||||
// }
|
||||
|
||||
m_Notifications.Lock();
|
||||
m_Notifications.push(notification);
|
||||
m_Notifications.Unlock();
|
||||
}
|
||||
// void CReflector::OnStreamClose(const CCallsign &callsign)
|
||||
// {
|
||||
|
||||
void CReflector::OnStreamClose(const CCallsign &callsign)
|
||||
{
|
||||
CNotification notification(NOTIFICATION_STREAM_CLOSE, callsign);
|
||||
|
||||
m_Notifications.Lock();
|
||||
m_Notifications.push(notification);
|
||||
m_Notifications.Unlock();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////////
|
||||
// modules & queues
|
||||
|
||||
@@ -25,7 +25,6 @@
|
||||
#include "Peers.h"
|
||||
#include "Protocols.h"
|
||||
#include "PacketStream.h"
|
||||
#include "NotificationQueue.h"
|
||||
|
||||
#ifndef NO_DHT
|
||||
#include "urfd-dht-values.h"
|
||||
@@ -80,8 +79,8 @@ public:
|
||||
void OnPeersChanged(void);
|
||||
void OnClientsChanged(void);
|
||||
void OnUsersChanged(void);
|
||||
void OnStreamOpen(const CCallsign &);
|
||||
void OnStreamClose(const CCallsign &);
|
||||
// void OnStreamOpen(const CCallsign &);
|
||||
// void OnStreamClose(const CCallsign &);
|
||||
|
||||
#ifndef NO_DHT
|
||||
// Publish DHT
|
||||
@@ -124,9 +123,6 @@ protected:
|
||||
std::unordered_map<char, std::future<void>> m_RouterFuture;
|
||||
std::future<void> m_XmlReportFuture;
|
||||
|
||||
// notifications
|
||||
CNotificationQueue m_Notifications;
|
||||
|
||||
#ifndef NO_DHT
|
||||
// Distributed Hash Table
|
||||
dht::DhtRunner node;
|
||||
|
||||
@@ -314,10 +314,49 @@ void CURFProtocol::HandlePeerLinks(void)
|
||||
const auto cs = it->first;
|
||||
if ((0 == cs.substr(0, 3).compare("URF")) && (nullptr==peers->FindPeer(CCallsign(cs), EProtocol::urf)))
|
||||
{
|
||||
// send connect packet to re-initiate peer link
|
||||
EncodeConnectPacket(&buffer, it->second.GetModules().c_str());
|
||||
Send(buffer, it->second.GetIp(), it->second.GetPort());
|
||||
std::cout << "Sending connect packet to URF peer " << cs << " @ " << it->second.GetIp() << " for modules " << it->second.GetModules() << std::endl;
|
||||
#ifndef NO_DHT
|
||||
it->second.UpdateIP(g_Configure.GetString(g_Keys.ip.ipv6address).empty());
|
||||
if (it->second.GetIp().IsSet())
|
||||
{
|
||||
bool ok = true;
|
||||
// does everything match up?
|
||||
for (const auto c : it->second.GetModules())
|
||||
{
|
||||
if (std::string::npos == g_Configure.GetString(g_Keys.modules.modules).find(c))
|
||||
{ // is the local module not config'ed?
|
||||
ok = false;
|
||||
std::cerr << "This reflector has no module '" << c << "', so it can't interlink with " << it->first << std::endl;
|
||||
}
|
||||
else if (it->second.UsesDHT())
|
||||
{
|
||||
if (std::string::npos == it->second.GetCMods().find(c))
|
||||
{ // the remote module not config'ed!
|
||||
ok = false;
|
||||
std::cerr << it->first << " has no module '" << c << "'" << std::endl;
|
||||
}
|
||||
else if ((std::string::npos == it->second.GetTCMods().find(c)) != (std::string::npos == g_Configure.GetString(g_Keys.modules.tcmodules).find(c)))
|
||||
{ // are the transcoding states on both sides mismatched?
|
||||
ok = false;
|
||||
std::cerr << "The encryption states for module '" << c << "' don't match for this reflector and " << it->first << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ok)
|
||||
{
|
||||
|
||||
#endif
|
||||
// send connect packet to re-initiate peer link
|
||||
EncodeConnectPacket(&buffer, it->second.GetModules().c_str());
|
||||
Send(buffer, it->second.GetIp(), it->second.GetPort());
|
||||
std::cout << "Sending connect packet to URF peer " << cs << " @ " << it->second.GetIp() << " for modules " << it->second.GetModules() << std::endl;
|
||||
#ifndef NO_DHT
|
||||
}
|
||||
}
|
||||
else // m_Ip is not set!
|
||||
{
|
||||
g_Reflector.GetDHTConfig(it->first);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -85,5 +85,8 @@ bool CVersion::operator <(const CVersion &v) const
|
||||
std::ostream &operator <<(std::ostream &os, const CVersion &v)
|
||||
{
|
||||
os << v.GetMajor() << '.' << v.GetMinor() << '.' << v.GetRevision();
|
||||
#ifndef NO_DHT
|
||||
os << "-dht";
|
||||
#endif
|
||||
return os;
|
||||
};
|
||||
Reference in new issue
Block a user