From 293682d62b425bb3dce9c6a119eb52a4053de6e2 Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Sun, 17 Dec 2017 22:44:05 +0000 Subject: [PATCH] Add blocking mechanism for UDP message destinations and enforce for pskreporter addresses git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@8338 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- MessageClient.cpp | 39 +++++++++++++++++++++++++++++++-------- MessageClient.hpp | 4 ++++ psk_reporter.cpp | 9 ++++++--- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/MessageClient.cpp b/MessageClient.cpp index 87de8c678..80a14fe75 100644 --- a/MessageClient.cpp +++ b/MessageClient.cpp @@ -1,6 +1,8 @@ #include "MessageClient.hpp" #include +#include +#include #include #include @@ -76,6 +78,7 @@ public: QHostAddress server_; quint32 schema_; QTimer * heartbeat_timer_; + std::vector blocked_addresses_; // hold messages sent before host lookup completes asynchronously QQueue pending_messages_; @@ -93,15 +96,24 @@ void MessageClient::impl::host_info_results (QHostInfo host_info) } else if (host_info.addresses ().size ()) { - server_ = host_info.addresses ()[0]; - - // send initial heartbeat which allows schema negotiation - heartbeat (); - - // clear any backlog - while (pending_messages_.size ()) + auto server = host_info.addresses ()[0]; + if (blocked_addresses_.end () == std::find (blocked_addresses_.begin (), blocked_addresses_.end (), server)) { - send_message (pending_messages_.dequeue ()); + server_ = server; + + // send initial heartbeat which allows schema negotiation + heartbeat (); + + // clear any backlog + while (pending_messages_.size ()) + { + send_message (pending_messages_.dequeue ()); + } + } + else + { + Q_EMIT self_->error ("UDP server blocked, please try another"); + pending_messages_.clear (); // discard } } } @@ -349,6 +361,17 @@ void MessageClient::send_raw_datagram (QByteArray const& message, QHostAddress c } } +void MessageClient::add_blocked_destination (QHostAddress const& a) +{ + m_->blocked_addresses_.push_back (a); + if (a == m_->server_) + { + m_->server_.clear (); + Q_EMIT error ("UDP server blocked, please try another"); + m_->pending_messages_.clear (); // discard + } +} + void MessageClient::status_update (Frequency f, QString const& mode, QString const& dx_call , QString const& report, QString const& tx_mode , bool tx_enabled, bool transmitting, bool decoding diff --git a/MessageClient.hpp b/MessageClient.hpp index 048b1a28f..6cb3ea87f 100644 --- a/MessageClient.hpp +++ b/MessageClient.hpp @@ -69,6 +69,10 @@ public: // UDP messaging if desired Q_SLOT void send_raw_datagram (QByteArray const&, QHostAddress const& dest_address, port_type dest_port); + // disallowed message destination (does not block datagrams sent + // with send_raw_datagram() above) + Q_SLOT void add_blocked_destination (QHostAddress const&); + // this signal is emitted if the server sends us a reply, the only // reply supported is reply to a prior CQ or QRZ message Q_SIGNAL void reply (QTime, qint32 snr, float delta_time, quint32 delta_frequency, QString const& mode diff --git a/psk_reporter.cpp b/psk_reporter.cpp index 38d10417a..6a4a73a22 100644 --- a/psk_reporter.cpp +++ b/psk_reporter.cpp @@ -119,8 +119,11 @@ void PSK_Reporter::dnsLookupResult(QHostInfo info) { if (!info.addresses().isEmpty()) { m_pskReporterAddress = info.addresses().at(0); -// qDebug() << "PSK Reporter IP: " << m_pskReporterAddress; + // qDebug() << "PSK Reporter IP: " << m_pskReporterAddress; + + // deal with miss-configured settings that attempt to set a + // Pskreporter Internet address for the WSJT-X UDP protocol + // server address + m_messageClient->add_blocked_destination (m_pskReporterAddress); } } - -