summaryrefslogtreecommitdiffstats
path: root/src/server/net/discoverylistener.h
blob: 47a42953889d61d67120f92a87e4e8041b84c9ba (plain) (blame)
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
/*
 * discoverylistener.h
 *
 *  Created on: 25.01.2013
 *      Author: sr
 */

#ifndef DISCOVERYLISTENER_H_
#define DISCOVERYLISTENER_H_

#include <QObject>
#include <QUdpSocket>
#include "../../shared/networkmessage.h"

#define SD_PACKET_TABLE_SIZE 20000

class QTimerEvent;

class DiscoveryListener : public QObject
{
	Q_OBJECT

private:
	QUdpSocket _socket;
	NetworkMessage _packet;
	int _counterResetPos{};

	quint8 _packetCounter[SD_PACKET_TABLE_SIZE]{}; // count packets per source address to ignore spammers

protected:
	void timerEvent(QTimerEvent* event) override;

public:
	explicit DiscoveryListener(QObject *parent);
	~DiscoveryListener() override;

private slots:
	void onReadyRead();

};

#endif /* DISCOVERYLISTENER_H_ */