aboutsummaryrefslogtreecommitdiffstats
path: root/src/coap/qcoapclient.cpp
blob: 21af3e24f8ef85d04fbc2b76fec529d6b74353c0 (plain)
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
/****************************************************************************
**
** Copyright (C) 2017 Witekio.
** Copyright (C) 2018 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the QtCoap module.
**
** $QT_BEGIN_LICENSE:GPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 or (at your option) any later version
** approved by the KDE Free Qt Foundation. The licenses are as published by
** the Free Software Foundation and appearing in the file LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/

#include "qcoapclient_p.h"
#include "qcoapprotocol_p.h"
#include "qcoapreply.h"
#include "qcoapdiscoveryreply.h"
#include "qcoapnamespace.h"
#include "qcoapsecurityconfiguration.h"
#include "qcoapqudpconnection_p.h"
#include <QtCore/qiodevice.h>
#include <QtCore/qurl.h>
#include <QtCore/qloggingcategory.h>
#include <QtNetwork/qudpsocket.h>

QT_BEGIN_NAMESPACE

Q_LOGGING_CATEGORY(lcCoapClient, "qt.coap.client")

QCoapClientPrivate::QCoapClientPrivate(QCoapProtocol *protocol, QCoapConnection *connection)
    : protocol(protocol)
    , connection(connection)
    , workerThread(new QThread)
{
    protocol->moveToThread(workerThread);
    connection->moveToThread(workerThread);
    workerThread->start();
}

QCoapClientPrivate::~QCoapClientPrivate()
{
    workerThread->quit();
    workerThread->wait();
    delete workerThread;
    delete protocol;
    delete connection;
}

/*!
    \class QCoapClient
    \inmodule QtCoap

    \brief The QCoapClient class allows the application to
    send CoAP requests and receive replies.

    \reentrant

    The QCoapClient class contains signals that get triggered when the
    reply of a sent request has arrived.

    The application can use a QCoapClient to send requests over a CoAP
    network. It provides functions for standard requests: each returns a QCoapReply object,
    to which the response data shall be delivered; this can be read when the finished()
    signal arrives.

    A simple request can be sent with:
    \code
        QCoapClient *client = new QCoapClient(this);
        connect(client, &QCoapClient::finished, this, &TestClass::slotFinished);
        client->get(QCoapRequest(Qurl("coap://coap.me/test")));
    \endcode

    \note After processing of the request has finished, it is the responsibility
    of the user to delete the QCoapReply object at an appropriate time. Do not
    directly delete it inside the slot connected to finished(). You can use the
    deleteLater() function.

    You can also use an \e observe request. This can be used as above, or more
    conveniently with the QCoapReply::notified() signal:
    \code
        QCoapRequest request = QCoapRequest(Qurl("coap://coap.me/obs"));
        QCoapReply *reply = client->observe(request);
        connect(reply, &QCoapReply::notified, this, &TestClass::slotNotified);
    \endcode

    And the observation can be cancelled with:
    \code
        client->cancelObserve(reply);
    \endcode

    When a reply arrives, the QCoapClient emits a finished() signal.

    \note For a discovery request, the returned object is a QCoapDiscoveryReply.
    It can be used the same way as a QCoapReply but contains also a list of
    resources.

    \sa QCoapRequest, QCoapReply, QCoapDiscoveryReply
*/

/*!
    \fn void QCoapClient::finished(QCoapReply *reply)

    This signal is emitted along with the \l QCoapReply::finished() signal
    whenever a CoAP reply is received, after either a success or an error.
    The \a reply parameter will contain a pointer to the reply that has just
    been received.

    \sa error(), QCoapReply::finished(), QCoapReply::error()
*/

/*!
    \fn void QCoapClient::responseToMulticastReceived(QCoapReply *reply,
                                                      const QCoapMessage &message,
                                                      const QHostAddress &sender)

    This signal is emitted when a unicast response to a multicast request
    arrives. The \a reply parameter contains a pointer to the reply that has just
    been received, \a message contains the payload and the message details,
    and \a sender contains the sender address.

    \sa error(), QCoapReply::finished(), QCoapReply::error()
*/

/*!
    \fn void QCoapClient::error(QCoapReply *reply, QtCoap::Error error)

    This signal is emitted whenever an error occurs. The \a reply parameter
    can be \nullptr if the error is not related to a specific QCoapReply. The
    \a error parameter contains the error code.

    \sa finished(), QCoapReply::error(), QCoapReply::finished()
*/

/*!
    Constructs a QCoapClient object for the given \a securityMode and
    sets \a parent as the parent object.

    The default for \a securityMode is SecurityMode::NoSec, which
    disables security.

    This connects using a QCoapQUdpConnection; to use a custom transport,
    sub-class QCoapConnection and pass an instance to one of the other
    constructors.
*/
QCoapClient::QCoapClient(QtCoap::SecurityMode securityMode, QObject *parent) :
    QCoapClient(new QCoapProtocol, new QCoapQUdpConnection(securityMode), parent)
{
}

/*!
    Constructs a QCoapClient object with the given \a connection and
    sets \a parent as the parent object.
*/
QCoapClient::QCoapClient(QCoapConnection *connection, QObject *parent) :
    QCoapClient(new QCoapProtocol, connection, parent)
{
}

/*!
    Base constructor, taking the \a protocol, \a connection, and \a parent
    as arguments.
*/
QCoapClient::QCoapClient(QCoapProtocol *protocol, QCoapConnection *connection, QObject *parent) :
    QObject(*new QCoapClientPrivate(protocol, connection), parent)
{
    Q_D(QCoapClient);

    qRegisterMetaType<QCoapReply *>();
    qRegisterMetaType<QCoapMessage>();
    qRegisterMetaType<QPointer<QCoapReply>>();
    qRegisterMetaType<QPointer<QCoapDiscoveryReply>>();
    qRegisterMetaType<QCoapConnection *>();
    qRegisterMetaType<QtCoap::Error>();
    qRegisterMetaType<QtCoap::ResponseCode>();
    qRegisterMetaType<QtCoap::Method>();
    qRegisterMetaType<QtCoap::SecurityMode>();
    qRegisterMetaType<QtCoap::MulticastGroup>();
    // Requires a name, as this is a typedef
    qRegisterMetaType<QCoapToken>("QCoapToken");
    qRegisterMetaType<QCoapMessageId>("QCoapMessageId");
    qRegisterMetaType<QAbstractSocket::SocketOption>();

    connect(d->connection, &QCoapConnection::readyRead, d->protocol,
            [this](const QByteArray &data, const QHostAddress &sender) {
                    Q_D(QCoapClient);
                    d->protocol->d_func()->onFrameReceived(data, sender);
            });
    connect(d->connection, &QCoapConnection::error, d->protocol,
            [this](QAbstractSocket::SocketError socketError) {
                    Q_D(QCoapClient);
                    d->protocol->d_func()->onConnectionError(socketError);
            });

    connect(d->protocol, &QCoapProtocol::finished,
            this, &QCoapClient::finished);
    connect(d->protocol, &QCoapProtocol::responseToMulticastReceived,
            this, &QCoapClient::responseToMulticastReceived);
    connect(d->protocol, &QCoapProtocol::error,
            this, &QCoapClient::error);
}

/*!
    Destroys the QCoapClient object and frees up any
    resources. Note that QCoapReply objects that are returned from
    this class have the QCoapClient set as their parents, which means that
    they will be deleted along with it.
*/
QCoapClient::~QCoapClient()
{
    qDeleteAll(findChildren<QCoapReply *>(QString(), Qt::FindDirectChildrenOnly));
}

/*!
    Sends the \a request using the GET method and returns a new QCoapReply object.

    \sa post(), put(), deleteResource(), observe(), discover()
*/
QCoapReply *QCoapClient::get(const QCoapRequest &request)
{
    Q_D(QCoapClient);

    QCoapRequest copyRequest(request, QtCoap::Method::Get);
    copyRequest.adjustUrl(d->connection->isSecure());

    return d->sendRequest(copyRequest);
}

/*!
    \overload

    Sends a GET request to \a url and returns a new QCoapReply object.

    \sa post(), put(), deleteResource(), observe(), discover()
*/
QCoapReply *QCoapClient::get(const QUrl &url)
{
    QCoapRequest request(url);
    return get(request);
}

/*!
    Sends the \a request using the PUT method and returns a new QCoapReply
    object. Uses \a data as the payload for this request.

    \sa get(), post(), deleteResource(), observe(), discover()
*/
QCoapReply *QCoapClient::put(const QCoapRequest &request, const QByteArray &data)
{
    Q_D(QCoapClient);

    QCoapRequest copyRequest(request, QtCoap::Method::Put);
    copyRequest.setPayload(data);
    copyRequest.adjustUrl(d->connection->isSecure());

    return d->sendRequest(copyRequest);
}

/*!
    \overload

    Sends the \a request using the PUT method and returns a new QCoapReply
    object. Uses \a device content as the payload for this request.
    A null device is treated as empty content.

    \note The device has to be open and readable before calling this function.

    \sa get(), post(), deleteResource(), observe(), discover()
*/
QCoapReply *QCoapClient::put(const QCoapRequest &request, QIODevice *device)
{
    return put(request, device ? device->readAll() : QByteArray());
}

/*!
    \overload

    Sends a PUT request to \a url and returns a new QCoapReply object.
    Uses \a data as the payload for this request.

    \sa get(), post(), deleteResource(), observe(), discover()
*/
QCoapReply *QCoapClient::put(const QUrl &url, const QByteArray &data)
{
    return put(QCoapRequest(url), data);
}

/*!
    Sends the \a request using the POST method and returns a new QCoapReply
    object. Uses \a data as the payload for this request.

    \sa get(), put(), deleteResource(), observe(), discover()
*/
QCoapReply *QCoapClient::post(const QCoapRequest &request, const QByteArray &data)
{
    Q_D(QCoapClient);

    QCoapRequest copyRequest(request, QtCoap::Method::Post);
    copyRequest.setPayload(data);
    copyRequest.adjustUrl(d->connection->isSecure());

    return d->sendRequest(copyRequest);
}

/*!
    \overload

    Sends the \a request using the POST method and returns a new QCoapReply
    object. Uses \a device content as the payload for this request.
    A null device is treated as empty content.

    \note The device has to be open and readable before calling this function.

    \sa get(), put(), deleteResource(), observe(), discover()
*/
QCoapReply *QCoapClient::post(const QCoapRequest &request, QIODevice *device)
{
    if (!device)
        return nullptr;

    return post(request, device->readAll());
}

/*!
    \overload

    Sends a POST request to \a url and returns a new QCoapReply object.
    Uses \a data as the payload for this request.

    \sa get(), put(), deleteResource(), observe(), discover()
*/
QCoapReply *QCoapClient::post(const QUrl &url, const QByteArray &data)
{
    return post(QCoapRequest(url), data);
}

/*!
    Sends the \a request using the DELETE method and returns a new QCoapReply
    object.

    \sa get(), put(), post(), observe(), discover()
 */
QCoapReply *QCoapClient::deleteResource(const QCoapRequest &request)
{
    Q_D(QCoapClient);

    QCoapRequest copyRequest(request, QtCoap::Method::Delete);
    copyRequest.adjustUrl(d->connection->isSecure());

    return d->sendRequest(copyRequest);
}

/*!
    \overload

    Sends a DELETE request to the target \a url.

    \sa get(), put(), post(), observe(), discover()
 */
QCoapReply *QCoapClient::deleteResource(const QUrl &url)
{
    return deleteResource(QCoapRequest(url));
}

/*!
    \overload

    Discovers the resources available at the endpoints which have joined
    the \a group at the given \a port. Returns a new QCoapDiscoveryReply
    object which emits the \l QCoapDiscoveryReply::discovered() signal whenever
    a response arrives. The \a group is one of the CoAP multicast group addresses
    and defaults to QtCoap::AllCoapNodesIPv4.

    Discovery path defaults to "/.well-known/core", but can be changed
    by passing a different path to \a discoveryPath. Discovery is described in
    \l{https://tools.ietf.org/html/rfc6690#section-1.2.1}{RFC 6690}.

    \sa get(), post(), put(), deleteResource(), observe()
*/
QCoapDiscoveryReply *QCoapClient::discover(QtCoap::MulticastGroup group, int port,
                                           const QString &discoveryPath)
{
    Q_D(QCoapClient);

    QString base;
    switch (group) {
    case QtCoap::MulticastGroup::AllCoapNodesIPv4:
        base = QStringLiteral("224.0.1.187");
        break;
    case QtCoap::MulticastGroup::AllCoapNodesIPv6LinkLocal:
        base = QStringLiteral("ff02::fd");
        break;
    case QtCoap::MulticastGroup::AllCoapNodesIPv6SiteLocal:
        base = QStringLiteral("ff05::fd");
        break;
    }

    QUrl discoveryUrl;
    discoveryUrl.setHost(base);
    discoveryUrl.setPath(discoveryPath);
    discoveryUrl.setPort(port);

    QCoapRequest request(discoveryUrl);
    request.setMethod(QtCoap::Method::Get);
    request.adjustUrl(d->connection->isSecure());

    return d->sendDiscovery(request);
}

/*!
    Discovers the resources available at the given \a url and returns
    a new QCoapDiscoveryReply object which emits the
    \l QCoapDiscoveryReply::discovered() signal whenever the response
    arrives.

    Discovery path defaults to "/.well-known/core", but can be changed
    by passing a different path to \a discoveryPath. Discovery is described in
    \l{https://tools.ietf.org/html/rfc6690#section-1.2.1}{RFC 6690}.

    \sa get(), post(), put(), deleteResource(), observe()
*/
QCoapDiscoveryReply *QCoapClient::discover(const QUrl &url, const QString &discoveryPath)
{
    Q_D(QCoapClient);

    QUrl discoveryUrl(url);
    discoveryUrl.setPath(url.path() + discoveryPath);

    QCoapRequest request(discoveryUrl);
    request.setMethod(QtCoap::Method::Get);
    request.adjustUrl(d->connection->isSecure());

    return d->sendDiscovery(request);
}

/*!
    Sends a request to observe the target \a request and returns
    a new QCoapReply object which emits the \l QCoapReply::notified()
    signal whenever a new notification arrives.

    \sa cancelObserve(), get(), post(), put(), deleteResource(), discover()
*/
QCoapReply *QCoapClient::observe(const QCoapRequest &request)
{
    QCoapRequest copyRequest(request, QtCoap::Method::Get);
    copyRequest.enableObserve();

    return get(copyRequest);
}

/*!
    \overload

    Sends a request to observe the target \a url and returns
    a new QCoapReply object which emits the \l QCoapReply::notified()
    signal whenever a new notification arrives.

    \sa cancelObserve(), get(), post(), put(), deleteResource(), discover()
*/
QCoapReply *QCoapClient::observe(const QUrl &url)
{
    return observe(QCoapRequest(url));
}

/*!
    \overload

    Cancels the observation of a resource using the reply returned by the
    observe() method.

    \sa observe()
*/
void QCoapClient::cancelObserve(QCoapReply *notifiedReply)
{
    Q_D(QCoapClient);
    QMetaObject::invokeMethod(d->protocol, "cancelObserve",
                              Q_ARG(QPointer<QCoapReply>, QPointer<QCoapReply>(notifiedReply)));
}

/*!
    \overload

    Cancels the observation of a resource identified by the \a url.

    \sa observe()
*/
void QCoapClient::cancelObserve(const QUrl &url)
{
    Q_D(QCoapClient);
    const auto adjustedUrl = QCoapRequest::adjustedUrl(url, d->connection->isSecure());
    QMetaObject::invokeMethod(d->protocol, "cancelObserve", Q_ARG(QUrl, adjustedUrl));
}

/*!
    Closes the open sockets and connections to free the transport.
*/
void QCoapClient::disconnect()
{
    Q_D(QCoapClient);
    QMetaObject::invokeMethod(d->connection, "disconnect", Qt::QueuedConnection);
}

/*!
    \internal

    Sends the CoAP \a request to its own URL and returns a new QCoapReply
    object.
*/
QCoapReply *QCoapClientPrivate::sendRequest(const QCoapRequest &request)
{
    Q_Q(QCoapClient);

    // Prepare the reply
    QCoapReply *reply = new QCoapReply(request, q);

    if (!send(reply)) {
        delete reply;
        return nullptr;
    }

    return reply;
}

/*!
    \internal

    Sends the CoAP \a request to its own URL and returns a
    new QCoapDiscoveryReply object.
*/
QCoapDiscoveryReply *QCoapClientPrivate::sendDiscovery(const QCoapRequest &request)
{
    Q_Q(QCoapClient);

    // Prepare the reply
    QCoapDiscoveryReply *reply = new QCoapDiscoveryReply(request, q);

    if (!send(reply)) {
        delete reply;
        return nullptr;
    }

    return reply;
}

/*!
    \internal

    Connect to the reply and use the protocol to send it.
*/
bool QCoapClientPrivate::send(QCoapReply *reply)
{
    const auto scheme = connection->isSecure() ? QLatin1String("coaps") : QLatin1String("coap");
    if (reply->request().url().scheme() != scheme) {
        qCWarning(lcCoapClient, "Failed to send request, URL has an incorrect scheme.");
        return false;
    }

    if (!QCoapRequest::isUrlValid(reply->request().url())) {
        qCWarning(lcCoapClient, "Failed to send request for an invalid URL.");
        return false;
    }

    // According to https://tools.ietf.org/html/rfc7252#section-8.1,
    // multicast requests MUST be Non-confirmable.
    if (QHostAddress(reply->url().host()).isMulticast()
            && reply->request().type() == QCoapMessage::MessageType::Confirmable) {
        qCWarning(lcCoapClient, "Failed to send request, "
                                "multicast requests must be non-confirmable.");
        return false;
    }

    QMetaObject::invokeMethod(protocol, "sendRequest", Qt::QueuedConnection,
                              Q_ARG(QPointer<QCoapReply>, QPointer<QCoapReply>(reply)),
                              Q_ARG(QCoapConnection *, connection));

    return true;
}

/*!
    Sets the security configuration parameters from \a configuration.
    Configuration will be ignored if the QtCoap::NoSec mode is used.

    \note This method must be called before the handshake starts.
*/
void QCoapClient::setSecurityConfiguration(const QCoapSecurityConfiguration &configuration)
{
    Q_D(QCoapClient);

    QMetaObject::invokeMethod(d->connection, "setSecurityConfiguration", Qt::QueuedConnection,
                              Q_ARG(QCoapSecurityConfiguration, configuration));
}

/*!
    Sets the maximum block size used by the protocol to \a blockSize
    when sending requests and receiving replies. The block size must be
    a power of two.

    \sa QCoapProtocol::setBlockSize()
*/
void QCoapClient::setBlockSize(quint16 blockSize)
{
    Q_D(QCoapClient);

    QMetaObject::invokeMethod(d->protocol, "setBlockSize", Qt::QueuedConnection,
                              Q_ARG(quint16, blockSize));
}

/*!
    Sets the QUdpSocket socket \a option to \a value.
*/
void QCoapClient::setSocketOption(QAbstractSocket::SocketOption option, const QVariant &value)
{
    Q_D(QCoapClient);

    QMetaObject::invokeMethod(d->connection, "setSocketOption", Qt::QueuedConnection,
                              Q_ARG(QAbstractSocket::SocketOption, option),
                              Q_ARG(QVariant, value));
}

/*!
    Sets the \c MAX_SERVER_RESPONSE_DELAY value to \a responseDelay in milliseconds.
    The default is 250 seconds.

    As defined in \l {RFC 7390 - Section 2.5}, \c MAX_SERVER_RESPONSE_DELAY is the expected
    maximum response delay over all servers that the client can send a multicast request to.
*/
void QCoapClient::setMaxServerResponseDelay(uint responseDelay)
{
    Q_D(QCoapClient);
    QMetaObject::invokeMethod(d->protocol, "setMaxServerResponseDelay", Qt::QueuedConnection,
                              Q_ARG(uint, responseDelay));
}

/*!
    Sets the \c ACK_TIMEOUT value defined in \l {RFC 7252 - Section 4.2} to
    \a ackTimeout in milliseconds. The default is 2000 ms.

    This timeout only applies to confirmable messages. The actual timeout for
    reliable transmissions is a random value between \c ACK_TIMEOUT and
    \c {ACK_TIMEOUT * ACK_RANDOM_FACTOR}.

    \sa setAckRandomFactor()
*/
void QCoapClient::setAckTimeout(uint ackTimeout)
{
    Q_D(QCoapClient);
    QMetaObject::invokeMethod(d->protocol, "setAckTimeout", Qt::QueuedConnection,
                              Q_ARG(uint, ackTimeout));
}

/*!
    Sets the \c ACK_RANDOM_FACTOR value defined in \l {RFC 7252 - Section 4.2},
    to \a ackRandomFactor. This value should be greater than or equal to 1.
    The default is 1.5.

    \sa setAckTimeout()
*/
void QCoapClient::setAckRandomFactor(double ackRandomFactor)
{
    Q_D(QCoapClient);
    QMetaObject::invokeMethod(d->protocol, "setAckRandomFactor", Qt::QueuedConnection,
                              Q_ARG(double, ackRandomFactor));
}

/*!
    Sets the \c MAX_RETRANSMIT value defined in \l {RFC 7252 - Section 4.2}
    to \a maxRetransmit. This value should be less than or equal to 25.
    The default is 4.
*/
void QCoapClient::setMaxRetransmit(uint maxRetransmit)
{
    Q_D(QCoapClient);
    QMetaObject::invokeMethod(d->protocol, "setMaxRetransmit", Qt::QueuedConnection,
                              Q_ARG(uint, maxRetransmit));
}

QT_END_NAMESPACE