QXmpp Version: 1.10.0
QXmppStun_p.h
1// SPDX-FileCopyrightText: 2015 Jeremy Lainé <jeremy.laine@m4x.org>
2//
3// SPDX-License-Identifier: LGPL-2.1-or-later
4
5#ifndef QXMPPSTUN_P_H
6#define QXMPPSTUN_P_H
7
8#include "QXmppStun.h"
9
10class QUdpSocket;
11class QTimer;
12
13//
14// W A R N I N G
15// -------------
16//
17// This file is not part of the QXmpp API.
18//
19// This header file may change from version to version without notice,
20// or even be removed.
21//
22// We mean it.
23//
24
25//
26// The QXmppStunTransaction class represents a STUN transaction.
27//
28class QXMPP_EXPORT QXmppStunTransaction : public QXmppLoggable
29{
30 Q_OBJECT
31
32public:
33 QXmppStunTransaction(const QXmppStunMessage &request, QObject *parent);
34 QXmppStunMessage request() const;
35 QXmppStunMessage response() const;
36
37Q_SIGNALS:
38 void finished();
39 void writeStun(const QXmppStunMessage &request);
40
41public Q_SLOTS:
42 void readStun(const QXmppStunMessage &response);
43
44private Q_SLOTS:
45 void retry();
46
47private:
48 QXmppStunMessage m_request;
49 QXmppStunMessage m_response;
50 QTimer *m_retryTimer;
51 int m_tries;
52};
53
54class QXMPP_EXPORT QXmppIceTransport : public QXmppLoggable
55{
56 Q_OBJECT
57
58public:
59 QXmppIceTransport(QObject *parent = nullptr);
60 ~QXmppIceTransport() override;
61
62 virtual QXmppJingleCandidate localCandidate(int component) const = 0;
63 virtual qint64 writeDatagram(const QByteArray &data, const QHostAddress &host, quint16 port) = 0;
64
65public Q_SLOTS:
66 virtual void disconnectFromHost() = 0;
67
68Q_SIGNALS:
70 void datagramReceived(const QByteArray &data, const QHostAddress &host, quint16 port);
71};
72
73//
74// The QXmppTurnAllocation class represents a TURN allocation as defined
75// by RFC 5766 Traversal Using Relays around NAT (TURN).
76//
77class QXMPP_EXPORT QXmppTurnAllocation : public QXmppIceTransport
78{
79 Q_OBJECT
80
81public:
82 enum AllocationState {
83 UnconnectedState,
84 ConnectingState,
85 ConnectedState,
86 ClosingState
87 };
88
89 QXmppTurnAllocation(QObject *parent = nullptr);
90 ~QXmppTurnAllocation() override;
91
92 QHostAddress relayedHost() const;
93 quint16 relayedPort() const;
94 AllocationState state() const;
95
96 void setServer(const QHostAddress &host, quint16 port = 3478);
97 void setUser(const QString &user);
98 void setPassword(const QString &password);
99
100 QXmppJingleCandidate localCandidate(int component) const override;
101 qint64 writeDatagram(const QByteArray &data, const QHostAddress &host, quint16 port) override;
102
103Q_SIGNALS:
105 void connected();
106
108 void disconnected();
109
110public Q_SLOTS:
111 void connectToHost();
112 void disconnectFromHost() override;
113
114private Q_SLOTS:
115 void readyRead();
116 void refresh();
117 void refreshChannels();
118 void transactionFinished();
119 void writeStun(const QXmppStunMessage &message);
120
121private:
122 void handleDatagram(const QByteArray &datagram, const QHostAddress &host, quint16 port);
123 void setState(AllocationState state);
124
125 QUdpSocket *socket;
126 QTimer *m_timer;
127 QTimer *m_channelTimer;
128 QString m_password;
129 QString m_username;
130 QHostAddress m_relayedHost;
131 quint16 m_relayedPort;
132 QHostAddress m_turnHost;
133 quint16 m_turnPort;
134
135 // channels
136 typedef QPair<QHostAddress, quint16> Address;
137 quint16 m_channelNumber;
138 QMap<quint16, Address> m_channels;
139
140 // state
141 quint32 m_lifetime;
142 QByteArray m_key;
143 QString m_realm;
144 QByteArray m_nonce;
145 AllocationState m_state;
146 QList<QXmppStunTransaction *> m_transactions;
147};
148
149//
150// The QXmppUdpTransport class represents a UDP transport.
151//
152class QXMPP_EXPORT QXmppUdpTransport : public QXmppIceTransport
153{
154 Q_OBJECT
155
156public:
157 QXmppUdpTransport(QUdpSocket *socket, QObject *parent = nullptr);
158 ~QXmppUdpTransport() override;
159
160 QXmppJingleCandidate localCandidate(int component) const override;
161 qint64 writeDatagram(const QByteArray &data, const QHostAddress &host, quint16 port) override;
162
163public Q_SLOTS:
164 void disconnectFromHost() override;
165
166private Q_SLOTS:
167 void readyRead();
168
169private:
170 QUdpSocket *m_socket;
171};
172
173#endif
The QXmppJingleCandidate class represents a transport candidate as specified by XEP-0176: Jingle ICE-...
Definition: QXmppJingleData.h:278
The QXmppLoggable class represents a source of logging messages.
Definition: QXmppLogger.h:110