Skip to content

Commit

Permalink
Work in progrogress on improving datachannel file transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Apr 18, 2024
1 parent 0437105 commit 6c00bc7
Show file tree
Hide file tree
Showing 19 changed files with 171 additions and 190 deletions.
2 changes: 1 addition & 1 deletion src/irisnet/noncore/icelocaltransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ private slots:
QByteArray buf = sock->readDatagram(from);
if (buf.isEmpty()) // it's weird we ever came here, but should relax static analyzer
break;
qDebug("got packet from %s", qPrintable(from));
// qDebug("got packet from %s", qPrintable(from));
if (from == stunBindAddr || from == stunRelayAddr) {
bool haveData = processIncomingStun(buf, from, &dg);

Expand Down
10 changes: 10 additions & 0 deletions src/xmpp/xmpp-core/protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

using namespace XMPP;

#ifdef XMPP_TEST
// printArray
//
// This function prints out an array of bytes as latin characters, converting
Expand All @@ -52,6 +53,7 @@ static QString printArray(const QByteArray &a)
}
return s;
}
#endif

// firstChildElement
//
Expand Down Expand Up @@ -787,13 +789,17 @@ void CoreProtocol::stringSend(const QString &s)
{
#ifdef XMPP_TEST
TD::outgoingTag(s);
#else
Q_UNUSED(s)
#endif
}

void CoreProtocol::stringRecv(const QString &s)
{
#ifdef XMPP_TEST
TD::incomingTag(s);
#else
Q_UNUSED(s)
#endif
}

Expand Down Expand Up @@ -848,13 +854,17 @@ void CoreProtocol::elementSend(const QDomElement &e)
{
#ifdef XMPP_TEST
TD::outgoingXml(e);
#else
Q_UNUSED(e)
#endif
}

void CoreProtocol::elementRecv(const QDomElement &e)
{
#ifdef XMPP_TEST
TD::incomingXml(e);
#else
Q_UNUSED(e)
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion src/xmpp/xmpp-im/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ void Client::streamReadyRead()
debug(QString("Client: incoming: [\n%1]\n").arg(out));
emit xmlIncoming(out);

QDomElement x = s.element(); // oldStyleNS(s.element());
QDomElement x = s.element();
distribute(x);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/xmpp/xmpp-im/jingle-connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ namespace XMPP { namespace Jingle {

bool Connection::hasPendingDatagrams() const { return false; }

NetworkDatagram Connection::readDatagram(qint64 maxSize)
QNetworkDatagram Connection::readDatagram(qint64 maxSize)
{
qCritical("Calling unimplemented function receiveDatagram");
Q_UNUSED(maxSize)
return NetworkDatagram();
return QNetworkDatagram();
}

bool Connection::writeDatagram(const NetworkDatagram &)
bool Connection::writeDatagram(const QNetworkDatagram &)
{
qCritical("Calling unimplemented function sendDatagram");
return false;
Expand Down
28 changes: 2 additions & 26 deletions src/xmpp/xmpp-im/jingle-connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,41 +28,17 @@
#include "iris/bytestream.h"
#include "jingle.h"

#if QT_VERSION >= QT_VERSION_CHECK(5, 8, 0)
#include <QNetworkDatagram>
#else
#include <QHostAddress>
#endif

namespace XMPP { namespace Jingle {
#if QT_VERSION < QT_VERSION_CHECK(5, 8, 0)
// stub implementation
class NetworkDatagram {
public:
bool _valid = false;
QByteArray _data;
inline NetworkDatagram(const QByteArray &data, const QHostAddress &destinationAddress = QHostAddress(),
quint16 port = 0) : _valid(true), _data(data)
{
Q_UNUSED(destinationAddress);
Q_UNUSED(port)
}
inline NetworkDatagram() { }

inline bool isValid() const { return _valid; }
inline QByteArray data() const { return _data; }
};
#else
typedef QNetworkDatagram NetworkDatagram;
#endif

class Connection : public ByteStream {
Q_OBJECT
public:
using Ptr = QSharedPointer<Connection>; // will be shared between transport and application
virtual bool hasPendingDatagrams() const;
virtual NetworkDatagram readDatagram(qint64 maxSize = -1);
virtual bool writeDatagram(const NetworkDatagram &data);
virtual QNetworkDatagram readDatagram(qint64 maxSize = -1);
virtual bool writeDatagram(const QNetworkDatagram &data);
virtual size_t blockSize() const;
virtual int component() const;
virtual TransportFeatures features() const = 0;
Expand Down
58 changes: 24 additions & 34 deletions src/xmpp/xmpp-im/jingle-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,16 @@ QDomElement Range::toXml(QDomDocument *doc) const
//----------------------------------------------------------------------------
class File::Private : public QSharedData {
public:
bool rangeSupported = false;
bool hasSize = false;
QDateTime date;
QString mediaType;
QString name;
QString desc;
std::uint64_t size = 0;
Range range;
QList<Hash> hashes;
Thumbnail thumbnail;
QByteArray amplitudes;
bool rangeSupported = false;
QDateTime date;
QString mediaType;
QString name;
QString desc;
std::optional<std::uint64_t> size = 0;
Range range;
QList<Hash> hashes;
Thumbnail thumbnail;
QByteArray amplitudes;
};

File::File() { }
Expand All @@ -92,17 +91,16 @@ File::File(const File &other) : d(other.d) { }

File::File(const QDomElement &file)
{
QDateTime date;
QString mediaType;
QString name;
QString desc;
std::uint64_t size = 0;
bool rangeSupported = false;
bool hasSize = false;
Range range;
QList<Hash> hashes;
Thumbnail thumbnail;
QByteArray amplitudes;
QDateTime date;
QString mediaType;
QString name;
QString desc;
std::optional<std::uint64_t> size = 0;
bool rangeSupported = false;
Range range;
QList<Hash> hashes;
Thumbnail thumbnail;
QByteArray amplitudes;

bool ok;

Expand All @@ -125,7 +123,6 @@ File::File(const QDomElement &file)
if (!ok) {
return;
}
hasSize = true;

} else if (ce.tagName() == RANGE_TAG) {
if (ce.hasAttribute(QLatin1String("offset"))) {
Expand Down Expand Up @@ -188,7 +185,6 @@ File::File(const QDomElement &file)
p->desc = desc;
p->size = size;
p->rangeSupported = rangeSupported;
p->hasSize = hasSize;
p->range = range;
p->hashes = hashes;
p->thumbnail = thumbnail;
Expand Down Expand Up @@ -218,8 +214,8 @@ QDomElement File::toXml(QDomDocument *doc) const
if (d->name.size()) {
el.appendChild(XMLHelper::textTag(*doc, NAME_TAG, d->name));
}
if (d->hasSize) {
el.appendChild(XMLHelper::textTag(*doc, SIZE_TAG, qint64(d->size)));
if (d->size) {
el.appendChild(XMLHelper::textTag(*doc, SIZE_TAG, qint64(*d->size)));
}
if (d->rangeSupported || d->range.isValid()) {
el.appendChild(d->range.toXml(doc));
Expand Down Expand Up @@ -261,8 +257,6 @@ bool File::hasComputedHashes() const
return false;
}

bool File::hasSize() const { return d->hasSize; }

QDateTime File::date() const { return d ? d->date : QDateTime(); }

QString File::description() const { return d ? d->desc : QString(); }
Expand Down Expand Up @@ -298,7 +292,7 @@ QString File::mediaType() const { return d ? d->mediaType : QString(); }

QString File::name() const { return d ? d->name : QString(); }

std::uint64_t File::size() const { return d ? d->size : 0; }
std::optional<std::uint64_t> File::size() const { return d ? d->size : std::optional<std::uint64_t> {}; }

Range File::range() const { return d ? d->range : Range(); }

Expand All @@ -318,11 +312,7 @@ void File::setMediaType(const QString &mediaType) { ensureD()->mediaType = media

void File::setName(const QString &name) { ensureD()->name = name; }

void File::setSize(std::uint64_t size)
{
ensureD()->size = size;
d->hasSize = true;
}
void File::setSize(std::uint64_t size) { ensureD()->size = size; }

void File::setRange(const Range &range)
{
Expand Down
33 changes: 16 additions & 17 deletions src/xmpp/xmpp-im/jingle-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@

namespace XMPP::Jingle::FileTransfer {
struct Range {
std::int64_t offset = 0;
std::int64_t length = 0; // 0 - from offset to the end of the file
QList<Hash> hashes;
std::uint64_t offset = 0; // 0 - default value from spec even when not set.
std::uint64_t length = 0; // 0 - from offset to the end of the file
QList<Hash> hashes;

inline Range() { }
inline Range(std::int64_t offset, std::int64_t length) : offset(offset), length(length) { }
inline bool isValid() const { return hashes.size() || offset || length; }
inline Range(std::uint64_t offset, std::uint64_t length) : offset(offset), length(length) { }
inline bool isValid() const { return offset || length; }
inline operator bool() const { return isValid(); }
QDomElement toXml(QDomDocument *doc) const;
};
Expand All @@ -50,19 +50,18 @@ class File {
QDomElement toXml(QDomDocument *doc) const;
bool merge(const File &other);
bool hasComputedHashes() const;
bool hasSize() const;

QDateTime date() const;
QString description() const;
QList<Hash> hashes() const;
QList<Hash> computedHashes() const;
Hash hash(Hash::Type t = Hash::Unknown) const;
QString mediaType() const;
QString name() const;
uint64_t size() const;
Range range() const;
Thumbnail thumbnail() const;
QByteArray amplitudes() const;
QDateTime date() const;
QString description() const;
QList<Hash> hashes() const;
QList<Hash> computedHashes() const;
Hash hash(Hash::Type t = Hash::Unknown) const;
QString mediaType() const;
QString name() const;
std::optional<std::uint64_t> size() const;
Range range() const;
Thumbnail thumbnail() const;
QByteArray amplitudes() const;

void setDate(const QDateTime &date);
void setDescription(const QString &desc);
Expand Down
Loading

0 comments on commit 6c00bc7

Please sign in to comment.