doc/xmlrpc-doc/book
doc/help/book
doc/help/help.pdf
+dist
#include "radius.h"
-#include "server.h"
#include "radproto/error.h"
-
#include "stg/common.h"
-#include <boost/asio.hpp>
-#include <string>
#include <iterator>
#include <iostream>
{
}
-int RADIUS::Run(std::stop_token token)
-{
- SetRunning(true);
-
- try
- {
- boost::asio::io_service ioService;
- Server server(ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries());
- ioService.run();
- }
- catch (const std::exception& e)
- {
- m_errorStr = "Exception in RADIUS::Run(): " + std::string(e.what());
- m_logger("Exception in RADIUS:: Run(): %s", e.what());
- printfd(__FILE__, "Exception in RADIUS:: Run(). Message: '%s'\n", e.what());
- }
-
- SetRunning(false);
- return 0;
-}
-
int RADIUS::ParseSettings()
{
auto ret = m_radSettings.ParseSettings(m_settings);
m_thread.request_stop();
+ if (m_server)
+ m_server->stop();
+
m_thread.join();
return 0;
}
const std::lock_guard lock(m_mutex);
m_running = val;
}
+
+int RADIUS::Run(std::stop_token token)
+{
+ SetRunning(true);
+
+ try
+ {
+ if (!m_server)
+ m_server = std::make_unique<Server>(m_ioService, m_radSettings.GetSecret(), m_radSettings.GetPort(), m_radSettings.GetDictionaries(), std::move(token), m_logger);
+ m_ioService.run();
+ }
+ catch (const std::exception& e)
+ {
+ m_errorStr = "Exception in RADIUS::Run(): " + std::string(e.what());
+ m_logger("Exception in RADIUS:: Run(): %s", e.what());
+ printfd(__FILE__, "Exception in RADIUS:: Run(). Message: '%s'\n", e.what());
+ }
+
+ SetRunning(false);
+ return 0;
+}
#include "stg/module_settings.h"
#include "stg/subscriptions.h"
#include "stg/logger.h"
+#include "server.h"
+#include <boost/asio.hpp>
#include <string>
+#include <memory>
#include <mutex>
#include <jthread.hpp>
#include <cstdint> //uint8_t, uint32_t
private:
std::mutex m_mutex;
+ boost::asio::io_service m_ioService;
int Run(std::stop_token token);
mutable std::string m_errorStr;
std::jthread m_thread;
PluginLogger m_logger;
+
+ std::unique_ptr<Server> m_server;
};
}
#include "server.h"
#include "radproto/packet_codes.h"
+#include "stg/common.h"
+#include <cstring>
#include <functional>
-#include <iostream>
using STG::Server;
using boost::system::error_code;
-Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath)
+Server::Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger)
: m_radius(io_service, secret, port),
- m_dictionaries(filePath)
+ m_dictionaries(filePath),
+ m_token(std::move(token)),
+ m_logger(logger)
+{
+ start();
+}
+
+void Server::start()
{
startReceive();
}
+void Server::stop()
+{
+ error_code ec;
+ m_radius.close(ec);
+}
+
void Server::startReceive()
{
m_radius.asyncReceive([this](const auto& error, const auto& packet, const boost::asio::ip::udp::endpoint& source){ handleReceive(error, packet, source); });
void Server::handleSend(const error_code& ec)
{
- if (ec)
- std::cout << "Error asyncSend: " << ec.message() << "\n";
+ if (m_token.stop_requested())
+ return;
+ if (ec)
+ {
+ m_logger("Error asyncSend: %s", ec.message().c_str());
+ printfd(__FILE__, "Error asyncSend: '%s'\n", ec.message().c_str());
+ }
startReceive();
}
void Server::handleReceive(const error_code& error, const std::optional<RadProto::Packet>& packet, const boost::asio::ip::udp::endpoint& source)
{
+ if (m_token.stop_requested())
+ return;
+
if (error)
{
- std::cout << "Error asyncReceive: " << error.message() << "\n";
- return;
+ m_logger("Error asyncReceive: %s", error.message().c_str());
+ printfd(__FILE__, "Error asyncReceive: '%s'\n", error.message().c_str());
}
if (packet == std::nullopt)
{
- std::cout << "Error asyncReceive: the request packet is missing\n";
+ m_logger("Error asyncReceive: the request packet is missing\n");
+ printfd(__FILE__, "Error asyncReceive: the request packet is missing\n");
return;
}
- else
- {
- m_radius.asyncSend(makeResponse(*packet), source, [this](const auto& ec){ handleSend(ec); });
- }
+ m_radius.asyncSend(makeResponse(*packet), source, [this](const auto& ec){ handleSend(ec); });
}
#include "radproto/socket.h"
#include "radproto/packet.h"
#include "radproto/dictionaries.h"
+#include "stg/logger.h"
#include <boost/asio.hpp>
+#include <stop_token.hpp>
#include <optional>
#include <cstdint> //uint8_t, uint32_t
class Server
{
public:
- Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath);
-
+ Server(boost::asio::io_service& io_service, const std::string& secret, uint16_t port, const std::string& filePath, std::stop_token token, PluginLogger& logger);
+ void stop();
private:
RadProto::Packet makeResponse(const RadProto::Packet& request);
void handleReceive(const boost::system::error_code& error, const std::optional<RadProto::Packet>& packet, const boost::asio::ip::udp::endpoint& source);
void handleSend(const boost::system::error_code& ec);
+ void start();
void startReceive();
RadProto::Socket m_radius;
RadProto::Dictionaries m_dictionaries;
+ std::stop_token m_token;
+
+ PluginLogger& m_logger;
};
}