Skip to content

Commit

Permalink
simplify ffi
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Sep 4, 2023
1 parent bdf1add commit a41627b
Show file tree
Hide file tree
Showing 10 changed files with 289 additions and 354 deletions.
167 changes: 73 additions & 94 deletions livekit-ffi/protocol/e2ee.proto
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ syntax = "proto3";
package livekit.proto;
option csharp_namespace = "LiveKit.Proto";

// TODO(theomonnom): Should FrameCryptor be stateful on the client side and have their own handle?

enum EncryptionType {
None = 0;
Gcm = 1;
Custom = 2;
NONE = 0;
GCM = 1;
CUSTOM = 2;
}

message FrameCryptor {
string participant_identity = 1;
string track_sid = 2;
int32 key_index = 3;
bool enabled = 4;
}

message KeyProviderOptions {
Expand All @@ -30,12 +39,12 @@ message KeyProviderOptions {
bytes uncrypted_magic_bytes = 4;
}

message E2EEOptions {
message E2eeOptions {
EncryptionType encryption_type = 1;
KeyProviderOptions key_provider_options = 2;
}

enum E2EEState {
enum E2eeState {
NEW = 0;
OK = 1;
ENCRYPTION_FAILED = 2;
Expand All @@ -45,130 +54,100 @@ enum E2EEState {
INTERNAL_ERROR = 6;
}

message E2EEManagerSetEnabledRequest {
uint64 room_handle = 1;
bool enabled = 2;
}

message E2EEManagerSetEnabledResponse {
}

message E2EEManagerGetFrameCryptorsRequest {
uint64 room_handle = 1;
}

message FrameCryptor {
string participant_id = 1;
EncryptionType encryption_type = 2;
int32 key_index = 3;
bool enabled = 4;
message E2eeManagerSetEnabledRequest {
bool enabled = 1;
}
message E2eeManagerSetEnabledResponse {}

message E2EEManagerGetFrameCryptorsResponse {
message E2eeManagerGetFrameCryptorsRequest {}
message E2eeManagerGetFrameCryptorsResponse {
repeated FrameCryptor frame_cryptors = 1;
}

message FrameCryptorSetEnabledRequest {
uint64 room_handle = 1;
string participant_id = 2;
string participant_identity = 1;
string track_sid = 2;
bool enabled = 3;
}

message FrameCryptorSetEnabledResponse {
}
message FrameCryptorSetEnabledResponse { }

message FrameCryptorSetKeyIndexRequest {
uint64 room_handle = 1;
string participant_id = 2;
string participant_identity = 1;
string track_sid = 2;
int32 key_index = 3;
}
message FrameCryptorSetKeyIndexResponse { }

message FrameCryptorSetKeyIndexResponse {
}

message KeyProviderSetSharedKeyRequest {
uint64 room_handle = 1;
string shared_key = 2;
int32 key_index = 3;
message SetSharedKeyRequest {
bytes shared_key = 1;
int32 key_index = 2;
}
message SetSharedKeyResponse { }

message KeyProviderSetSharedKeyResponse {
message RachetSharedKeyRequest {
int32 key_index = 1;
}

message KeyProviderRachetSharedKeyRequest {
uint64 room_handle = 1;
int32 key_index = 2;
message RachetSharedKeyResponse {
optional bytes new_key = 1;
}

message KeyProviderRachetSharedKeyResponse {
bytes new_key = 2;
message GetSharedKeyRequest {
int32 key_index = 1;
}

message KeyProviderExportSharedKeyRequest {
uint64 room_handle = 1;
int32 key_index = 2;
message GetSharedKeyResponse {
optional bytes key = 1;
}

message KeyProviderExportSharedKeyResponse {
message SetKeyRequest {
string participant_identity = 1;
bytes key = 2;
int32 key_index = 3;
}
message SetKeyResponse {}

message KeyProviderSetKeyRequest {
uint64 room_handle = 1;
string participant_id = 2;
string key = 3;
int32 key_index = 4;
message RachetKeyRequest {
string participant_identity = 1;
int32 key_index = 2;
}

message KeyProviderSetKeyResponse {
message RachetKeyResponse {
optional bytes new_key = 1;
}

message KeyProviderRachetKeyRequest {
uint64 room_handle = 1;
string participant_id = 2;
int32 key_index = 3;
message GetKeyRequest {
string participant_identity = 1;
int32 key_index = 2;
}

message KeyProviderRachetKeyResponse {
bytes new_key = 2;
message GetKeyResponse {
optional bytes key = 1;
}

message KeyProviderExportKeyRequest {
message E2eeRequest {
uint64 room_handle = 1;
string participant_id = 2;
int32 key_index = 3;
}

message KeyProviderExportKeyResponse {
bytes key = 2;
}

message E2EERequest {
oneof message {
E2EEManagerSetEnabledRequest e2ee_manager_set_enabled = 1;
E2EEManagerGetFrameCryptorsRequest e2ee_manager_get_frame_cryptors = 2;
FrameCryptorSetEnabledRequest frame_cryptor_set_enabled = 3;
FrameCryptorSetKeyIndexRequest frame_cryptor_set_key_index = 4;
KeyProviderSetSharedKeyRequest key_provider_set_shared_key = 5;
KeyProviderRachetSharedKeyRequest key_provider_rachet_shared_key = 6;
KeyProviderExportSharedKeyRequest key_provider_export_shared_key = 7;
KeyProviderSetKeyRequest key_provider_set_key = 8;
KeyProviderRachetKeyRequest key_provider_rachet_key = 9;
KeyProviderExportKeyRequest key_provider_export_key = 10;
E2eeManagerSetEnabledRequest manager_set_enabled = 2;
E2eeManagerGetFrameCryptorsRequest manager_get_frame_cryptors = 3;
FrameCryptorSetEnabledRequest cryptor_set_enabled = 4;
FrameCryptorSetKeyIndexRequest cryptor_set_key_index = 5;
SetSharedKeyRequest set_shared_key = 6;
RachetSharedKeyRequest rachet_shared_key = 7;
GetSharedKeyRequest get_shared_key = 8;
SetKeyRequest set_key = 9;
RachetKeyRequest rachet_key = 10;
GetKeyRequest get_key = 11;
}
}

message E2EEResponse {
message E2eeResponse {
oneof message {
E2EEManagerSetEnabledResponse e2ee_manager_set_enabled = 1;
E2EEManagerGetFrameCryptorsResponse e2ee_manager_get_frame_cryptors = 2;
FrameCryptorSetEnabledResponse frame_cryptor_set_enabled = 3;
FrameCryptorSetKeyIndexResponse frame_cryptor_set_key_index = 4;
KeyProviderSetSharedKeyResponse key_provider_set_shared_key = 5;
KeyProviderRachetSharedKeyResponse key_provider_rachet_shared_key = 6;
KeyProviderExportSharedKeyResponse key_provider_export_shared_key = 7;
KeyProviderSetKeyResponse key_provider_set_key = 8;
KeyProviderRachetKeyResponse key_provider_rachet_key = 9;
KeyProviderExportKeyResponse key_provider_export_key = 10;
E2eeManagerSetEnabledResponse manager_set_enabled = 1;
E2eeManagerGetFrameCryptorsResponse manager_get_frame_cryptors = 2;
FrameCryptorSetEnabledResponse cryptor_set_enabled = 3;
FrameCryptorSetKeyIndexResponse cryptor_set_key_index = 4;
SetSharedKeyResponse set_shared_key = 5;
RachetSharedKeyResponse rachet_shared_key = 6;
GetSharedKeyResponse get_shared_key = 7;
SetKeyResponse set_key = 8;
RachetKeyResponse rachet_key = 9;
GetKeyResponse get_key = 10;
}
}
4 changes: 2 additions & 2 deletions livekit-ffi/protocol/ffi.proto
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ message FfiRequest {
CaptureAudioFrameRequest capture_audio_frame = 20;
NewAudioResamplerRequest new_audio_resampler = 21;
RemixAndResampleRequest remix_and_resample = 22;
E2EERequest e2ee = 23;
E2eeRequest e2ee = 23;
}
}

Expand Down Expand Up @@ -121,7 +121,7 @@ message FfiResponse {
CaptureAudioFrameResponse capture_audio_frame = 20;
NewAudioResamplerResponse new_audio_resampler = 21;
RemixAndResampleResponse remix_and_resample = 22;
E2EEResponse e2ee = 23;
E2eeResponse e2ee = 23;
}
}

Expand Down
12 changes: 5 additions & 7 deletions livekit-ffi/protocol/room.proto
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ message RoomOptions {
bool auto_subscribe = 1;
bool adaptive_stream = 2;
bool dynacast = 3;
optional E2EEOptions e2ee_options = 4;
optional E2eeOptions e2ee = 4;
}

//
Expand Down Expand Up @@ -190,7 +190,7 @@ message RoomEvent {
Disconnected disconnected = 18;
Reconnecting reconnecting = 19;
Reconnected reconnected = 20;
E2EEStateChanged e2ee_state_changed = 21;
E2eeStateChanged e2ee_state_changed = 21;
}
}

Expand Down Expand Up @@ -260,11 +260,9 @@ message TrackUnmuted {
string track_sid = 2;
}

message E2EEStateChanged {
string participant_sid = 1;
string track_sid = 2;
string participant_id = 3;
E2EEState state = 4;
message E2eeStateChanged {
string participant_sid = 1; // Using sid instead of identity for ffi communication
E2eeState state = 2;
}

message ActiveSpeakersChanged { repeated string participant_sids = 1; }
Expand Down
1 change: 1 addition & 0 deletions livekit-ffi/protocol/track.proto
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ message TrackPublicationInfo {
string mime_type = 8;
bool muted = 9;
bool remote = 10;
EncryptionType encryption_type = 11;
}

message OwnedTrackPublication {
Expand Down
12 changes: 3 additions & 9 deletions livekit-ffi/src/conversion/room.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl From<ConnectionState> for proto::ConnectionState {
}
}

impl From<proto::EncryptionType> for EncryptionType {
impl From<proto::EncryptionType> for EncryptionType {
fn from(value: proto::EncryptionType) -> Self {
match value {
proto::EncryptionType::None => Self::None,
Expand All @@ -52,7 +52,6 @@ impl From<proto::EncryptionType> for EncryptionType {
impl From<proto::KeyProviderOptions> for KeyProviderOptions {
fn from(value: proto::KeyProviderOptions) -> Self {
Self {
shared_key: value.shared_key,
ratchet_window_size: value.ratchet_window_size,
ratchet_salt: value.ratchet_salt,
uncrypted_magic_bytes: value.uncrypted_magic_bytes,
Expand All @@ -64,9 +63,7 @@ impl From<proto::E2eeOptions> for E2EEOptions {
fn from(value: proto::E2eeOptions) -> Self {
Self {
encryption_type: value.encryption_type().into(),
key_provider: BaseKeyProvider::new(
value.key_provider_options.unwrap().into(),
),
key_provider: BaseKeyProvider::new(value.key_provider_options.unwrap().into()),
}
}
}
Expand All @@ -77,10 +74,7 @@ impl From<proto::RoomOptions> for RoomOptions {
adaptive_stream: value.adaptive_stream,
auto_subscribe: value.auto_subscribe,
dynacast: value.dynacast,
e2ee_options: match value.e2ee_options {
Some(opts) => Some(opts.into()),
None => None,
},
e2ee: value.e2ee.map(Into::into),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion livekit-ffi/src/conversion/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl From<&FfiPublication> for proto::TrackPublicationInfo {
simulcasted: publication.simulcasted(),
muted: publication.is_muted(),
remote: publication.is_remote(),
encryption_type: publication.encryption_type() as i32,
encryption_type: publication.encryption_type().into(),
}
}
}
Expand Down
Loading

0 comments on commit a41627b

Please sign in to comment.