Skip to content

Commit

Permalink
Merge branch 'develop' into darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
za-creature committed Dec 9, 2024
2 parents 36eb61e + f4cef10 commit cc34dd3
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 17 deletions.
4 changes: 3 additions & 1 deletion bindings/dart/lib/client.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ class Subscriptions {
}

void close() {
_sinks.values.forEach((sink) => sink.close());
for (var sink in _sinks.values) {
sink.close();
}
_sinks.clear();
}
}
Expand Down
5 changes: 3 additions & 2 deletions bindings/dart/lib/internal/message_matcher.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'dart:async';
import 'dart:typed_data';
import 'dart:collection';
import 'package:flutter/services.dart';
import 'package:msgpack_dart/msgpack_dart.dart';

import '../client.dart';
Expand Down Expand Up @@ -103,7 +102,9 @@ class MessageMatcher {
_isClosed = true;
_subscriptions.close();
final error = SessionClosed();
_responses.values.forEach((i) => i.completeError(error));
for (var i in _responses.values) {
i.completeError(error);
}
_responses.clear();
}

Expand Down
24 changes: 16 additions & 8 deletions bindings/dart/lib/ouisync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ class Session {

final recvPort = ReceivePort();

if (bindings == null) {
bindings = Bindings.loadDefault();
}
bindings ??= Bindings.loadDefault();

final result = _withPoolSync((pool) => bindings!.session_create(
kind.encode(),
Expand Down Expand Up @@ -92,7 +90,8 @@ class Session {
// native code.
// [channelName] is the name of the MethodChannel to be used, equally named channel
// must be created and set up to listen to the commands in the native code.
static Future<Session> createChanneled(String channelName, [void Function()? onClose]) async {
static Future<Session> createChanneled(String channelName,
[void Function()? onClose]) async {
final client = ChannelClient(channelName, onClose);
await client.initialized;
return Session._(client);
Expand Down Expand Up @@ -238,9 +237,9 @@ class Session {
void closeSync() {
final client = _client;
if (client is DirectClient) {
client.closeSync();
client.closeSync();
} else {
throw "closeSync is currently only implemented for DirectClient";
throw "closeSync is currently only implemented for DirectClient";
}
}
}
Expand Down Expand Up @@ -431,6 +430,15 @@ class Repository {
'credentials': credentials,
});

/// Like `setCredentials` but use the `ShareToken` and reset any values
/// encrypted with local secrets to random values. Currently that is only the
/// writer ID.
Future<void> resetCredentials(ShareToken token) =>
_client.invoke<void>('repository_reset_credentials', {
'repository': _handle,
'token': token.toString(),
});

Future<AccessMode> get accessMode {
return _client
.invoke<int>('repository_access_mode', _handle)
Expand Down Expand Up @@ -937,9 +945,9 @@ class File {
final client = _client;

if (client is DirectClient) {
await client.copyToRawFd(_handle, fd);
await client.copyToRawFd(_handle, fd);
} else {
throw "copyToRawFd is currently implemented only for DirectClient";
throw "copyToRawFd is currently implemented only for DirectClient";
}
}
}
Expand Down
17 changes: 13 additions & 4 deletions ffi/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};
use async_trait::async_trait;
use ouisync_bridge::transport::SessionContext;
use ouisync_lib::{crypto::cipher::SecretKey, PeerAddr};
use ouisync_lib::{crypto::cipher::SecretKey, Credentials, PeerAddr};
use std::{net::SocketAddr, sync::Arc};

#[derive(Clone)]
Expand Down Expand Up @@ -106,9 +106,18 @@ impl ouisync_bridge::transport::Handler for Handler {
Request::RepositorySetCredentials {
repository,
credentials,
} => repository::set_credentials(&self.state, repository, credentials.into())
.await?
.into(),
} => {
let cv: Vec<u8> = credentials.into();
repository::set_credentials(&self.state, repository, Credentials::decode(&cv)?)
.await?
.into()
}
Request::RepositoryResetCredentials { repository, token } => {
let new_credentials = Credentials::with_random_writer_id(token.into_secrets());
repository::set_credentials(&self.state, repository, new_credentials)
.await?
.into()
}
Request::RepositorySetAccessMode {
repository,
access_mode,
Expand Down
4 changes: 4 additions & 0 deletions ffi/src/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ pub(crate) enum Request {
repository: RepositoryHandle,
credentials: Bytes,
},
RepositoryResetCredentials {
repository: RepositoryHandle,
token: ShareToken,
},
RepositoryAccessMode(RepositoryHandle),
RepositorySetAccessMode {
repository: RepositoryHandle,
Expand Down
4 changes: 2 additions & 2 deletions ffi/src/repository.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@ pub(crate) fn credentials(state: &State, handle: RepositoryHandle) -> Result<Vec
pub(crate) async fn set_credentials(
state: &State,
handle: RepositoryHandle,
credentials: Vec<u8>,
credentials: Credentials,
) -> Result<(), Error> {
state
.repositories
.get(handle)?
.repository
.set_credentials(Credentials::decode(&credentials)?)
.set_credentials(credentials)
.await?;

Ok(())
Expand Down

0 comments on commit cc34dd3

Please sign in to comment.