chat: invite-ссылки с несколькими адресами + ncd-адреса узлов (join)
This commit is contained in:
1 parent
d88dccfa19
commit
481872d5db
24 files changed
+517
-114
No files matched your search
@@ -82,14 +82,14 @@ InviteData decodeInviteLink(const QString& link) {
|
||||
int off = 0;
|
||||
|
||||
uint8_t ver = data[off++];
|
||||
if (ver != INVITE_LINK_VERSION && ver != 0x02) {
|
||||
if (ver != INVITE_LINK_VERSION && ver != 0x02 && ver != 0x01) {
|
||||
d.error = QStringLiteral("unsupported version 0x%1").arg(ver, 2, 16, QLatin1Char('0'));
|
||||
GUI_ERROR("decodeInviteLink: unsupported version %d", ver);
|
||||
return d;
|
||||
}
|
||||
|
||||
/* v2: password field before channel_id */
|
||||
if (ver == 0x02) {
|
||||
/* v2/v3: password field before channel_id */
|
||||
if (ver == 0x02 || ver == INVITE_LINK_VERSION) {
|
||||
if (off >= len) {
|
||||
d.error = QStringLiteral("truncated at pass_len");
|
||||
return d;
|
||||
@@ -127,6 +127,23 @@ InviteData decodeInviteLink(const QString& link) {
|
||||
jk = (jk << 8) | data[off++];
|
||||
d.joinKey = jk;
|
||||
|
||||
/* v3: reality-блок (node-global параметры) */
|
||||
if (ver == INVITE_LINK_VERSION) {
|
||||
if (off >= len) { d.error = QStringLiteral("truncated at reality"); return d; }
|
||||
if (data[off++] != 0) {
|
||||
if (off + 8 + 32 + 3 + 1 > len) { d.error = QStringLiteral("truncated at reality params"); return d; }
|
||||
d.reality.shortId = QByteArray(reinterpret_cast<const char*>(data + off), 8); off += 8;
|
||||
d.reality.serverPubkey = QByteArray(reinterpret_cast<const char*>(data + off), 32); off += 32;
|
||||
d.reality.version = QByteArray(reinterpret_cast<const char*>(data + off), 3); off += 3;
|
||||
uint8_t snlen = data[off++];
|
||||
if (snlen > INVITE_SNAME_MAX - 1) snlen = INVITE_SNAME_MAX - 1;
|
||||
if (off + snlen > len) { d.error = QStringLiteral("truncated at reality server_name"); return d; }
|
||||
d.reality.serverName = QString::fromUtf8(reinterpret_cast<const char*>(data + off), snlen);
|
||||
off += snlen;
|
||||
d.reality.has = true;
|
||||
}
|
||||
}
|
||||
|
||||
bool firstBlock = true;
|
||||
while (off + 1 <= len) {
|
||||
uint8_t header = data[off++];
|
||||
@@ -169,3 +186,25 @@ InviteData decodeInviteLink(const QString& link) {
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
QByteArray serializeInviteAddrs(const InviteData& d) {
|
||||
QByteArray buf;
|
||||
buf.append(static_cast<char>(d.reality.has ? 1 : 0));
|
||||
if (d.reality.has) {
|
||||
buf.append(d.reality.shortId.leftJustified(8, '\0', true));
|
||||
buf.append(d.reality.serverPubkey.leftJustified(32, '\0', true));
|
||||
buf.append(d.reality.version.leftJustified(3, '\0', true));
|
||||
QByteArray sn = d.reality.serverName.toUtf8().left(INVITE_SNAME_MAX - 1);
|
||||
buf.append(static_cast<char>(sn.size()));
|
||||
buf.append(sn);
|
||||
}
|
||||
for (const auto& a : d.addrs) {
|
||||
buf.append(static_cast<char>(a.family));
|
||||
buf.append(static_cast<char>(a.socketId));
|
||||
buf.append(static_cast<char>(a.proto));
|
||||
buf.append(a.address);
|
||||
buf.append(static_cast<char>((a.port >> 8) & 0xFF));
|
||||
buf.append(static_cast<char>(a.port & 0xFF));
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
Reference in new issue
Block a user