remove obsolete c++ files

threads
Gernot Kranz 2 weeks ago
parent d138c084fa
commit 8b7d3fbd9a
  1. 286
      src/pEpTransportUDP.cc
  2. 96
      src/pEpTransportUDP.hh

@ -1,286 +0,0 @@
#include "pEpTransportUDP.hh"
#include <pEp/pEpLog.hh>
#include <pEp/map_asn1.h>
#include <pEp/mime.h>
#include <pEp/Adapter.hh> //what for?
using namespace pEp::peptox;
using namespace pEp::peptox::protocol;
pEp::Transport::Config::~Config() {}
namespace pEp {
namespace UDP {
pEpTransportUDP::ConfigUDP::ConfigUDP(const std::string &userfile) : userfile{ userfile } {}
// ----------------------------------------------------------------------------------------
bool pEpTransportUDP::log_enabled{ false };
pEpTransportUDP::pEpTransportUDP(PEP_transport_id id) :
id{ id },
// peptox{ nullptr },
// peptox_callbacks{ nullptr },
rx_queue{},
cb_incomming_message_registered{ false },
cb_statuschange_registered{ false },
cb_sendto_result_registered{ false },
cb_statuschange{ nullptr },
cb_incomming_message{ nullptr },
cb_sendto_result{ nullptr }
{
pEpLogClass("called");
}
void pEpTransportUDP::configure(const Config &config)
{
pEpLogClass("called");
if (allCallbacksRegistered()) {
if (ConfigUDP *cfg = dynamic_cast<ConfigUDP *>(const_cast<Config *>(&config))) {
// peptox = std::make_unique<pEpTox>(cfg->userfile);
// peptox_callbacks = std::make_unique<pEpToxCB>(*this);
// peptox->set_callbacks(*peptox_callbacks);
} else {
throw ConfigError("configure(): object has to be of type ConfigUDP");
}
} else {
throw ConfigError("configure(): all callbacks need to be register first");
}
}
void pEpTransportUDP::startup()
{
pEpLogClass("called");
throwInvalidState();
// Find out address&port (maybe move to startup()?)
struct ifaddrs *ifa;
int udp_status;
udp_status = getifaddrs(*ifap);
while(ifa.ifa_broadaddr == NULL) ifa=ifa.next;
// prepare socket (move to startup()??)
socki = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
if (socki == -1) {
/* if socket failed to initialize, exit */
// TODO: figure out sensible TSCs
return(PEP_tsc_udp_cannot_create_socket);
}
udp_status = connect(socki,ifa.broadaddr,sizeof(ifa.broadaddr));
}
void pEpTransportUDP::shutdown()
{
pEpLogClass("called");
throwInvalidState();
close(socki);
}
void pEpTransportUDP::sendto(::message *msg)
{
pEpLogClass("called");
throwInvalidState();
if (msg == nullptr) {
throw std::runtime_error("sendto(): invalid message - null");
}
if (msg->id == nullptr) {
throw std::runtime_error("sendto(): invalid message - msg.id is null");
}
std::string msg_id{ std::string(msg->id) };
// TODO: how/where to handle mutlicast/duplicating of msg? Yes, the encrypted msg needs to be duplicated here.
// With UDP broadcast, we can skip this whole recipient validation
if (msg->to == nullptr) {
throw std::runtime_error("sendto(): invalid message - msg.to is null");
}
if (msg->to->ident == nullptr) {
throw std::runtime_error("sendto(): invalid message - msg.to.ident is null");
}
if (msg->to->ident->address == nullptr) {
throw std::runtime_error("sendto(): invalid message - msg.to.ident.address is null");
}
string addr{ std::string(msg->to->ident->address) };
//////////////
// Find out address&port (moved to startup())
// prepare socket (moved to startup())
// Prepare message as ASN1
// TODO: we only need Sync attachment
ASN1Message_t *asn1_msg;
asn1_msg = ASN1Message_from_message(*msg, NULL, 1, 0);
// write to socket
udp_status = write(sock, asn1_msg.longmsg, strlen(asn1_msg.longmsg));
// close socket (moved to shutdown())
/////////////
}
::message *pEpTransportUDP::recvnext()
{
pEpLogClass("called");
throwInvalidState();
::message *msg_pep = nullptr;
if (rx_queue.empty()) {
throw TransportError(PEP_tsc_rx_queue_underrun);
} else {
// // pEpTox-Message
// MessageRX &msg_rce = rx_queue.front();
// std::string payload{ msg_rce.payload.begin(), msg_rce.payload.end() };
// // MIME-Decode
// ::message *msg;
// bool has_possible_pEp_msg;
// ::PEP_STATUS status = ::mime_decode_message(
// payload.c_str(),
// payload.size(),
// &msg,
// &has_possible_pEp_msg);
// throw_status(status);
// if (msg == nullptr) {
// rx_queue.pop_front();
// throw std::runtime_error("recvnext(): invalid message received.");
// }
// msg_pep = msg;
// rx_queue.pop_front();
}
return msg_pep;
}
PEP_transport_id pEpTransportUDP::get_id()
{
return id;
}
std::string pEpTransportUDP::own_address()
{
throwInvalidState();
// return peptox->own_address().hex();
}
bool pEpTransportUDP::shortmsg_supported()
{
return true;
}
bool pEpTransportUDP::longmsg_supported()
{
return true;
}
bool pEpTransportUDP::longmsg_formatted_supported()
{
return true;
}
PEP_text_format pEpTransportUDP::native_text_format()
{
return PEP_text_format_html;
}
//Register callbacks
void pEpTransportUDP::signal_statuschange(CBStatusChange handler)
{
pEpLogClass("called");
if (!handler) {
throw std::runtime_error("invalid handler");
}
cb_statuschange = handler;
cb_statuschange_registered = true;
}
void pEpTransportUDP::signal_sendto_result(CBSendToResult handler)
{
pEpLogClass("called");
if (!handler) {
throw std::runtime_error("invalid handler");
}
cb_sendto_result = handler;
cb_sendto_result_registered = true;
}
void pEpTransportUDP::signal_incoming_message(CBIncomminMessage handler)
{
pEpLogClass("called");
if (!handler) {
throw std::runtime_error("invalid handler");
}
cb_incomming_message = handler;
cb_incomming_message_registered = true;
}
// -----------------------------------------------------------------------------------------
// private
bool pEpTransportUDP::allCallbacksRegistered()
{
return cb_incomming_message_registered && cb_sendto_result_registered &&
cb_statuschange_registered;
}
// private
void pEpTransportUDP::throwInvalidState()
{
if (peptox == nullptr) {
throw TransportError(PEP_tsc_no_config);
}
}
// pEpTox Callbacks-------------------------------------------------------------------------
pEpToxCB::pEpToxCB(pEpTransportUDP &rce) : rce{ rce } {}
void pEpToxCB::cb_connection_status(bool online)
{
CallbacksDefault::cb_connection_status(online);
if (online) {
PEP_transport_status_code status{ PEP_tsc_connection_up };
rce.cb_statuschange(rce.id, status);
} else {
PEP_transport_status_code status{ PEP_tsc_connection_down };
rce.cb_statuschange(rce.id, status);
}
}
void pEpToxCB::cb_message_status(const std::string &message_id, MessageStatusTX status)
{
CallbacksDefault::cb_message_status(message_id, status);
PEP_transport_status_code status_rce{};
if (status == MessageStatusTX::QUEUED) {
// No equivalent
}
if (status == MessageStatusTX::SENT_INCOMPLETE) {
status_rce = PEP_tsc_message_on_the_way;
}
if (status == MessageStatusTX::SENT_COMPLETE) {
// No equivalent, delivered but not confirmed
}
if (status == MessageStatusTX::CONFIRMED) {
status_rce = PEP_tsc_message_delivered;
}
if (status == MessageStatusTX::TIMEOUT) {
status_rce = PEP_tsc_could_not_deliver_giving_up;
}
rce.cb_sendto_result(rce.id, message_id, status_rce);
}
void pEpToxCB::cb_message_incomming(toxcore::Address from, unsigned char channel_nr)
{
CallbacksDefault::cb_message_incomming(from, channel_nr);
// would be a new TSC message incomming (relevant for BIG messages)
}
void pEpToxCB::cb_message_received(const peptox::MessageRX &msg)
{
CallbacksDefault::cb_message_received(msg);
rce.rx_queue.emplace_back(msg);
// TODO: THIS IS WRONG: Which TSC pleaese?
rce.cb_incomming_message(rce.id, PEP_tsc_ready);
}
} // namespace UDP
} // namespace pEp

@ -1,96 +0,0 @@
#ifndef PEPUDPTRANSPORT_HH
#define PEPUDPTRANSPORT_HH
#include <pEp/transport.hh>
#include <exception>
#include <string>
#include <functional>
#include <pEp/pEpLog.hh>
namespace pEp {
namespace UDP {
class pEpTransportUDP : public Transport {
// friend pEpToxCB;
public:
class ConfigUDP : public Config {
public:
explicit ConfigUDP(const std::string& userfile);
std::string userfile;
};
explicit pEpTransportUDP(PEP_transport_id id);
// Non-copyable
pEpTransportUDP(const pEpTransportUDP&) = delete;
pEpTransportUDP(const pEpTransportUDP&&) = delete;
pEpTransportUDP& operator=(const pEpTransportUDP&) = delete;
pEpTransportUDP& operator=(const pEpTransportUDP&&) = delete;
// register callbacks
void signal_statuschange(CBStatusChange handler) override;
void signal_sendto_result(CBSendToResult handler) override;
void signal_incoming_message(CBIncomminMessage handler) override;
void configure(const Config& config) override;
void startup() override;
void shutdown() override;
void sendto(::message* msg) override;
::message* recvnext() override;
PEP_transport_id get_id() override;
bool shortmsg_supported() override;
bool longmsg_supported() override;
bool longmsg_formatted_supported() override;
PEP_text_format native_text_format() override;
// pEpTransportUDP specific functions
std::string own_address();
// logger
static bool log_enabled;
Adapter::pEpLog::pEpLogger logger{ "pEpTransportUDP", log_enabled };
virtual ~pEpTransportUDP() = default;
private:
PEP_transport_id id;
// The registered callback functions
CBStatusChange cb_statuschange;
CBSendToResult cb_sendto_result;
CBIncomminMessage cb_incomming_message;
bool cb_statuschange_registered;
bool cb_sendto_result_registered;
bool cb_incomming_message_registered;
// std::unique_ptr<peptox::pEpTox> peptox;
// std::unique_ptr<pEpToxCB> peptox_callbacks;
std::deque<peptox::MessageRX> rx_queue;
bool allCallbacksRegistered();
void throwInvalidState();
Adapter::pEpLog::pEpLogger& m4gic_logger_n4me = logger;
int socki;
};
// class pEpToxCB : public peptox::CallbacksDefault {
// public:
// explicit pEpToxCB(pEpTransportUDP& rce);
// void cb_connection_status(bool online);
// void cb_message_status(const std::string& message_id, peptox::MessageStatusTX status);
// void cb_message_incomming(toxcore::Address from, unsigned char channel_nr);
// void cb_message_received(const peptox::MessageRX& msg);
// private:
// pEpTransportUDP& rce;
// };
} // namespace UDP
} // namespace pEp
#endif // PEPUDPTRANSPORT_HH
Loading…
Cancel
Save