-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathinterlink.cpp
More file actions
116 lines (104 loc) · 3.66 KB
/
interlink.cpp
File metadata and controls
116 lines (104 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//
// ccallsignlistitem.cpp
// mrefd
//
// Created by Jean-Luc Deltombe (LX3JL) on 31/01/2016.
// Copyright © 2015 Jean-Luc Deltombe (LX3JL). All rights reserved.
// Copyright © 2025 Thomas A. Early N7TAE
//
// ----------------------------------------------------------------------------
// This file is part of mrefd.
//
// 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
// with this software. If not, see <http://www.gnu.org/licenses/>.
// ----------------------------------------------------------------------------
#include <string.h>
#include "configure.h"
#include "interlink.h"
#include "reflector.h"
extern CConfigure g_CFG;
////////////////////////////////////////////////////////////////////////////////////////
// constructor
#ifndef NO_DHT
CInterlink::CInterlink(const std::string &cs, const std::string &mods) : m_UsingDHT(true), m_reqMods(mods), m_Callsign(cs)
{
}
#endif
CInterlink::CInterlink(const std::string &cs, const std::string &mods, const std::string &addr, uint16_t port, bool islegacy) : m_UsingDHT(false), m_reqMods(mods), m_Callsign(cs)
{
if (g_CFG.IsIPv4Address(addr))
UpdateItem(mods, "", addr, "", port, islegacy);
else if (g_CFG.IsIPv6Address(addr))
UpdateItem(mods, "", "", addr, port, islegacy);
else
std::cerr << "ERROR: '" << addr << "' is not a valid internet address!" << std::endl;
}
////////////////////////////////////////////////////////////////////////////////////////
// compare
void CInterlink::UpdateItem(const std::string &mods, const std::string &emods, const std::string &ipv4, const std::string &ipv6, uint16_t port, bool islegacy)
{
m_IsNotLegacy = not islegacy; // this is the gatekeeper for sending packets to a reflector
bool isbad = false;
for (const auto m : m_reqMods)
{
if (std::string::npos == mods.find(m))
{
std::cerr << "ERROR: Requested module '" << m << " is not in " << m_Callsign.GetCS() << std::endl;
isbad = true;
}
}
if (isbad)
return;
CReflMods reqrm(m_reqMods, emods); // make the request
// checkout the modules first
if (not reqrm.IsIn(g_CFG.GetRefMods(), m_UsingDHT, m_Callsign.GetCS()))
{
return;
}
// now the other stuff
if (m_IPv4.compare(ipv4))
{
m_IPv4.assign(ipv4);
}
if (m_IPv6.compare(ipv6))
{
m_IPv6.assign(ipv6);
}
if (m_Port != port)
{
m_Port = port;
}
if (g_CFG.GetIPv6BindAddr().empty()) // this reflector is IPv4 only
{
if (m_IPv4.empty())
std::cout << "ERROR: " << m_Callsign.GetCS() << " doesn't have an IPv4 address and this reflector is IPv4 only" << std::endl;
else
m_Ip.Initialize(AF_INET, m_Port, m_IPv4.c_str());
}
else if (g_CFG.GetIPv4BindAddr().empty()) // this reflector is IPv6 only
{
if (m_IPv6.empty())
std::cout << "ERROR: " << m_Callsign.GetCS() << "doesn't have an IPv6 addess and this reflector is IPv6 only" << std::endl;
else
m_Ip.Initialize(AF_INET6, m_Port, m_IPv6.c_str());
}
else // this reflector is dual stack
{
if (not m_IPv6.empty())
m_Ip.Initialize(AF_INET6, m_Port, m_IPv6.c_str());
else if (not m_IPv4.empty())
m_Ip.Initialize(AF_INET, m_Port, m_IPv4.c_str());
else
std::cerr << "ERROR: Could not find an IP address for " << m_Callsign << std::endl;
}
}