PoC conference call creation.
This commit is contained in:
@@ -12,20 +12,77 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include <tde2e/td/e2e/e2e_api.h>
|
||||
|
||||
namespace TdE2E {
|
||||
namespace {
|
||||
|
||||
CallState CreateCallState() {
|
||||
constexpr auto kPermissionAdd = 1;
|
||||
constexpr auto kPermissionRemove = 2;
|
||||
|
||||
[[nodiscard]] tde2e_api::Slice Slice(const QByteArray &data) {
|
||||
return {
|
||||
data.constData(),
|
||||
std::string_view::size_type(data.size())
|
||||
};
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Call::Call(UserId myUserId)
|
||||
: _myUserId(myUserId) {
|
||||
const auto id = tde2e_api::key_generate_temporary_private_key();
|
||||
Assert(id.is_ok());
|
||||
const auto key = tde2e_api::key_to_public_key(id.value());
|
||||
_myKeyId = { .v = uint64(id.value()) };
|
||||
|
||||
const auto key = tde2e_api::key_to_public_key(_myKeyId.v);
|
||||
Assert(key.is_ok());
|
||||
Assert(key.value().size() == sizeof(_myKey));
|
||||
memcpy(&_myKey, key.value().data(), sizeof(_myKey));
|
||||
}
|
||||
|
||||
auto result = CallState{
|
||||
.myKeyId = PrivateKeyId{ .v = uint64(id.value()) },
|
||||
PublicKey Call::myKey() const {
|
||||
return _myKey;
|
||||
}
|
||||
|
||||
Block Call::makeZeroBlock() const {
|
||||
const auto publicKeyView = std::string_view{
|
||||
reinterpret_cast<const char*>(&_myKey),
|
||||
sizeof(_myKey),
|
||||
};
|
||||
Assert(key.value().size() == sizeof(result.myKey));
|
||||
memcpy(&result.myKey, key.value().data(), 32);
|
||||
const auto publicKeyId = tde2e_api::key_from_public_key(publicKeyView);
|
||||
Assert(publicKeyId.is_ok());
|
||||
|
||||
return result;
|
||||
const auto myKeyId = std::int64_t(_myKeyId.v);
|
||||
const auto result = tde2e_api::call_create_zero_block(myKeyId, {
|
||||
.height = 0,
|
||||
.participants = { {
|
||||
.user_id = std::int64_t(_myUserId.v),
|
||||
.public_key_id = publicKeyId.value(),
|
||||
.permissions = kPermissionAdd | kPermissionRemove,
|
||||
} },
|
||||
});
|
||||
Assert(result.is_ok());
|
||||
|
||||
return {
|
||||
.data = QByteArray::fromStdString(result.value()),
|
||||
};
|
||||
}
|
||||
|
||||
void Call::create(const Block &last) {
|
||||
tde2e_api::call_create(std::int64_t(_myKeyId.v), Slice(last.data));
|
||||
}
|
||||
|
||||
Call::ApplyResult Call::apply(const Block &block) {
|
||||
const auto result = tde2e_api::call_apply_block(
|
||||
std::int64_t(_id.v),
|
||||
Slice(block.data));
|
||||
|
||||
if (!result.is_ok()) {
|
||||
const auto error = result.error();
|
||||
(void)error;
|
||||
}
|
||||
|
||||
return result.is_ok()
|
||||
? ApplyResult::Success
|
||||
: ApplyResult::BlockSkipped;
|
||||
}
|
||||
|
||||
} // namespace TdE2E
|
||||
|
||||
@@ -11,10 +11,18 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
|
||||
namespace TdE2E {
|
||||
|
||||
struct UserId {
|
||||
uint64 v = 0;
|
||||
};
|
||||
|
||||
struct PrivateKeyId {
|
||||
uint64 v = 0;
|
||||
};
|
||||
|
||||
struct CallId {
|
||||
uint64 v = 0;
|
||||
};
|
||||
|
||||
struct PublicKey {
|
||||
uint64 a = 0;
|
||||
uint64 b = 0;
|
||||
@@ -23,15 +31,36 @@ struct PublicKey {
|
||||
};
|
||||
|
||||
struct ParticipantState {
|
||||
uint64 id = 0;
|
||||
UserId id;
|
||||
PublicKey key;
|
||||
};
|
||||
|
||||
struct CallState {
|
||||
PrivateKeyId myKeyId;
|
||||
PublicKey myKey;
|
||||
struct Block {
|
||||
QByteArray data;
|
||||
};
|
||||
|
||||
[[nodiscard]] CallState CreateCallState();
|
||||
class Call final {
|
||||
public:
|
||||
explicit Call(UserId myUserId);
|
||||
|
||||
[[nodiscard]] PublicKey myKey() const;
|
||||
|
||||
[[nodiscard]] Block makeZeroBlock() const;
|
||||
|
||||
void create(const Block &last);
|
||||
|
||||
enum class ApplyResult {
|
||||
Success,
|
||||
BlockSkipped
|
||||
};
|
||||
[[nodiscard]] ApplyResult apply(const Block &block);
|
||||
|
||||
private:
|
||||
CallId _id;
|
||||
UserId _myUserId;
|
||||
PrivateKeyId _myKeyId;
|
||||
PublicKey _myKey;
|
||||
|
||||
};
|
||||
|
||||
} // namespace TdE2E
|
||||
|
||||
27
Telegram/SourceFiles/tde2e/tde2e_integration.cpp
Normal file
27
Telegram/SourceFiles/tde2e/tde2e_integration.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "tde2e/tde2e_integration.h"
|
||||
|
||||
#include "data/data_user.h"
|
||||
#include "tde2e/tde2e_api.h"
|
||||
|
||||
namespace TdE2E {
|
||||
|
||||
UserId MakeUserId(not_null<UserData*> user) {
|
||||
return MakeUserId(peerToUser(user->id));
|
||||
}
|
||||
|
||||
UserId MakeUserId(::UserId id) {
|
||||
return { .v = id.bare };
|
||||
}
|
||||
|
||||
MTPint256 PublicKeyToMTP(const PublicKey &key) {
|
||||
return MTP_int256(MTP_int128(key.a, key.b), MTP_int128(key.c, key.d));
|
||||
}
|
||||
|
||||
} // namespace TdE2E
|
||||
20
Telegram/SourceFiles/tde2e/tde2e_integration.h
Normal file
20
Telegram/SourceFiles/tde2e/tde2e_integration.h
Normal file
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
namespace TdE2E {
|
||||
|
||||
struct UserId;
|
||||
struct PublicKey;
|
||||
|
||||
[[nodiscard]] UserId MakeUserId(not_null<UserData*> user);
|
||||
[[nodiscard]] UserId MakeUserId(::UserId id);
|
||||
|
||||
[[nodiscard]] MTPint256 PublicKeyToMTP(const PublicKey &key);
|
||||
|
||||
} // namespace TdE2E
|
||||
Reference in New Issue
Block a user