diff options
-rw-r--r-- | src/server/net/discoverylistener.cpp | 54 |
1 files changed, 32 insertions, 22 deletions
diff --git a/src/server/net/discoverylistener.cpp b/src/server/net/discoverylistener.cpp index b308a09..f3d7d39 100644 --- a/src/server/net/discoverylistener.cpp +++ b/src/server/net/discoverylistener.cpp @@ -25,6 +25,33 @@ // +++ static ++++ hash ip address +++ + +/***************************************************************************//** + * @brief DiscoveryListener::DiscoveryListener + */ +DiscoveryListener::DiscoveryListener() : + _socket(this), _counterResetPos(0) +{ + if (!_socket.bind(SERVICE_DISCOVERY_PORT)) + qFatal("Could not bind to service discovery port %d", (int)SERVICE_DISCOVERY_PORT); + connect(&_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead())); + for (int i = 0; i < SD_PACKET_TABLE_SIZE; ++i) + _packetCounter[i] = 0; + startTimer((SPAM_MODERATE_AT_ONCE * SPAM_MODERATE_INTERVAL) / SD_PACKET_TABLE_SIZE + 1); +} + +/***************************************************************************//** + * @brief DiscoveryListener::~DiscoveryListener + */ +DiscoveryListener::~DiscoveryListener() +{ +} + +/***************************************************************************//** + * @brief hash + * @param host + * @return + */ static quint16 hash(const QHostAddress& host) { static quint16 seed1 = 0, seed2 = 0; @@ -70,30 +97,13 @@ static quint16 hash(const QHostAddress& host) return result; } -// +++++++++++++++++++++++++++++++++++ - -DiscoveryListener::DiscoveryListener() : - _socket(this), _counterResetPos(0) -{ - if (!_socket.bind(SERVICE_DISCOVERY_PORT)) - qFatal("Could not bind to service discovery port %d", (int)SERVICE_DISCOVERY_PORT); - connect(&_socket, SIGNAL(readyRead()), this, SLOT(onReadyRead())); - for (int i = 0; i < SD_PACKET_TABLE_SIZE; ++i) - _packetCounter[i] = 0; - startTimer((SPAM_MODERATE_AT_ONCE * SPAM_MODERATE_INTERVAL) / SD_PACKET_TABLE_SIZE + 1); -} - -DiscoveryListener::~DiscoveryListener() -{ - // TODO Auto-generated destructor stub -} - /* * Overrides */ -/** - * Decrease packet counters per source IP in our "spam protection" table. +/***************************************************************************//** + * @brief Decrease packet counters per source IP in our "spam protection" table. + * @param event */ void DiscoveryListener::timerEvent(QTimerEvent* event) { @@ -112,8 +122,8 @@ void DiscoveryListener::timerEvent(QTimerEvent* event) * Slots */ -/** - * Incoming UDP packet on service discovery port - handle. +/***************************************************************************//** + * @brief Incoming UDP packet on service discovery port - handle. */ void DiscoveryListener::onReadyRead() { |