ouisync.session
Session API: connects to a running Ouisync service's local control socket.
Includes the bindgen-generated data types, Request/Response tagged unions
and Session/Repository/File API classes, plus the parts bindgen doesn't
generate: connect/close, and the streaming endpoints (handled by hand in
every other binding too).
1"""Session API: connects to a running Ouisync service's local control socket. 2 3Includes the bindgen-generated data types, `Request`/`Response` tagged unions 4and `Session`/`Repository`/`File` API classes, plus the parts bindgen doesn't 5generate: connect/close, and the streaming endpoints (handled by hand in 6every other binding too).""" 7 8import inspect 9import typing 10 11from ._generated import api as _api 12from ._generated.api import * 13from .client import Client as _Client 14from .state_monitor import MonitorId 15 16 17async def connect(config_dir) -> Session: 18 client = await _Client.connect(config_dir) 19 return Session(client) 20 21 22async def close(session: Session): 23 await session._client.close() 24 25 26async def subscribe_to_network_events(session: Session) -> typing.AsyncIterator[NetworkEvent]: 27 async for response in session._client.subscribe(Request_SessionSubscribeToNetwork()): 28 if isinstance(response, Response_NetworkEvent): 29 yield response.value 30 elif isinstance(response, Response_Unit): 31 yield NetworkEvent.PEER_SET_CHANGE 32 33# Re-export everything from the generated api module. 34_all = [] 35 36for name, member in inspect.getmembers(_api): 37 if not inspect.isclass(member): 38 continue 39 40 # Don't re-export private clases 41 if name.startswith('_'): 42 continue 43 44 # Don't re-export "handle" classes as they are used only internally by the API classes (which 45 # are re-exported). 46 if name.endswith('Handle'): 47 continue 48 49 _all.append(name) 50 51# Re-export handwritten classes 52_all.append('MonitorId') 53 54__all__ = _all
122class AccessChange: 123 """How to change access to a repository.""" 124 _variants: ClassVar[dict[str, type]] = {}
How to change access to a repository.
133@dataclass 134class AccessChange_Disable(AccessChange): 135 """Disable access""" 136 _tag: ClassVar[str] = "Disable" 137 _shape: ClassVar[str] = "unit"
Disable access
126@dataclass 127class AccessChange_Enable(AccessChange): 128 """Enable read or write access, optionally with local secret""" 129 _tag: ClassVar[str] = "Enable" 130 _shape: ClassVar[str] = "unnamed" 131 value: SetLocalSecret | None
Enable read or write access, optionally with local secret
54class AccessMode(IntEnum): 55 """Access mode of a repository.""" 56 BLIND = 0 57 """Repository is neither readable not writtable (but can still be synced).""" 58 READ = 1 59 """Repository is readable but not writtable.""" 60 WRITE = 2 61 """Repository is both readable and writable."""
Access mode of a repository.
Repository is neither readable not writtable (but can still be synced).
553@dataclass 554class DirectoryEntry: 555 _shape: ClassVar[str] = "named" 556 name: str 557 entry_type: EntryType 558 version_hash: bytes
Type of filesystem entry.
263class ErrorCode(IntEnum): 264 OK = 0 265 """No error""" 266 PERMISSION_DENIED = 1 267 """Insuficient permission to perform the intended operation""" 268 INVALID_INPUT = 2 269 """Invalid input parameter""" 270 INVALID_DATA = 3 271 """Invalid data (e.g., malformed incoming message, config file, etc...)""" 272 ALREADY_EXISTS = 4 273 """Entry already exists""" 274 NOT_FOUND = 5 275 """Entry not found""" 276 AMBIGUOUS = 6 277 """Multiple matching entries found""" 278 UNSUPPORTED = 8 279 """The indended operation is not supported""" 280 INTERRUPTED = 9 281 """The operation was interrupted""" 282 CONNECTION_REFUSED = 1025 283 """Failed to establish connection to the server""" 284 CONNECTION_ABORTED = 1026 285 """Connection aborted by the server""" 286 TRANSPORT_ERROR = 1027 287 """Failed to send or receive message""" 288 LISTENER_BIND_ERROR = 1028 289 """Listener failed to bind to the specified address""" 290 LISTENER_ACCEPT_ERROR = 1029 291 """Listener failed to accept client connection""" 292 STORE_ERROR = 2049 293 """Operation on the internal repository store failed""" 294 IS_DIRECTORY = 2050 295 """Entry was expected to not be a directory but it is""" 296 NOT_DIRECTORY = 2051 297 """Entry was expected to be a directory but it isn't""" 298 DIRECTORY_NOT_EMPTY = 2052 299 """Directory was expected to be empty but it isn't""" 300 RESOURCE_BUSY = 2053 301 """File or directory is busy""" 302 SNAPSHOT_NOT_FOUND = 2054 303 """Snapshot no longer exists (e.g., because it has been replaced by a newer one)""" 304 RUNTIME_INITIALIZE_ERROR = 4097 305 """Failed to initialize runtime""" 306 CONFIG_ERROR = 4099 307 """Failed to read from or write into the config file""" 308 TLS_CERTIFICATES_NOT_FOUND = 4100 309 """TLS certificated not found""" 310 TLS_CERTIFICATES_INVALID = 4101 311 """TLS certificates failed to load""" 312 TLS_KEYS_NOT_FOUND = 4102 313 """TLS keys not found""" 314 TLS_CONFIG_ERROR = 4103 315 """Failed to create TLS config""" 316 VFS_DRIVER_INSTALL_ERROR = 4104 317 """Failed to install virtual filesystem driver""" 318 VFS_OTHER_ERROR = 4105 319 """Unspecified virtual filesystem error""" 320 SERVICE_ALREADY_RUNNING = 4106 321 """Another instance of the service is already running""" 322 STORE_DIR_UNSPECIFIED = 4107 323 """Store directory is not specified""" 324 MOUNT_DIR_UNSPECIFIED = 4108 325 """Mount directory is not specified""" 326 OTHER = 65535 327 """Unspecified error"""
Insuficient permission to perform the intended operation
Invalid data (e.g., malformed incoming message, config file, etc...)
Failed to establish connection to the server
Listener failed to bind to the specified address
Listener failed to accept client connection
Directory was expected to be empty but it isn't
Snapshot no longer exists (e.g., because it has been replaced by a newer one)
TLS certificated not found
TLS certificates failed to load
Failed to install virtual filesystem driver
Another instance of the service is already running
3425class File: 3426 def __init__(self, client: Client, handle: FileHandle): 3427 """@private""" 3428 self._client = client 3429 self._handle = handle 3430 3431 async def close( 3432 self, 3433 ): 3434 """Closes the file.""" 3435 request = Request_FileClose( 3436 self._handle, 3437 ) 3438 response = await self._client.invoke(request) 3439 if isinstance(response, Response_Unit): 3440 return 3441 raise UnexpectedResponse() 3442 3443 async def flush( 3444 self, 3445 ): 3446 """Flushes any pending writes to the file.""" 3447 request = Request_FileFlush( 3448 self._handle, 3449 ) 3450 response = await self._client.invoke(request) 3451 if isinstance(response, Response_Unit): 3452 return 3453 raise UnexpectedResponse() 3454 3455 async def get_length( 3456 self, 3457 ) -> int: 3458 """Returns the length of the file in bytes""" 3459 request = Request_FileGetLength( 3460 self._handle, 3461 ) 3462 response = await self._client.invoke(request) 3463 if isinstance(response, Response_U64): 3464 return response.value 3465 raise UnexpectedResponse() 3466 3467 async def get_progress( 3468 self, 3469 ) -> int: 3470 """ 3471 Returns the sync progress of this file, that is, the total byte size of all the blocks of 3472 this file that's already been downloaded. 3473 3474 Note that Ouisync downloads the blocks in random order, so until the file's been completely 3475 downloaded, the already downloaded blocks are not guaranteed to continuous (there might be 3476 gaps). 3477 """ 3478 request = Request_FileGetProgress( 3479 self._handle, 3480 ) 3481 response = await self._client.invoke(request) 3482 if isinstance(response, Response_U64): 3483 return response.value 3484 raise UnexpectedResponse() 3485 3486 async def read( 3487 self, 3488 *, 3489 offset: int, 3490 size: int, 3491 ) -> bytes: 3492 """Reads `size` bytes from the file starting at `offset` bytes from the beginning of the file.""" 3493 request = Request_FileRead( 3494 self._handle, 3495 offset, 3496 size, 3497 ) 3498 response = await self._client.invoke(request) 3499 if isinstance(response, Response_Bytes): 3500 return response.value 3501 raise UnexpectedResponse() 3502 3503 async def truncate( 3504 self, 3505 *, 3506 len: int, 3507 ): 3508 """Truncates the file to the given length.""" 3509 request = Request_FileTruncate( 3510 self._handle, 3511 len, 3512 ) 3513 response = await self._client.invoke(request) 3514 if isinstance(response, Response_Unit): 3515 return 3516 raise UnexpectedResponse() 3517 3518 async def write( 3519 self, 3520 *, 3521 offset: int, 3522 data: bytes, 3523 ): 3524 """Writes the data to the file at the given offset.""" 3525 request = Request_FileWrite( 3526 self._handle, 3527 offset, 3528 data, 3529 ) 3530 response = await self._client.invoke(request) 3531 if isinstance(response, Response_Unit): 3532 return 3533 raise UnexpectedResponse()
3431 async def close( 3432 self, 3433 ): 3434 """Closes the file.""" 3435 request = Request_FileClose( 3436 self._handle, 3437 ) 3438 response = await self._client.invoke(request) 3439 if isinstance(response, Response_Unit): 3440 return 3441 raise UnexpectedResponse()
Closes the file.
3443 async def flush( 3444 self, 3445 ): 3446 """Flushes any pending writes to the file.""" 3447 request = Request_FileFlush( 3448 self._handle, 3449 ) 3450 response = await self._client.invoke(request) 3451 if isinstance(response, Response_Unit): 3452 return 3453 raise UnexpectedResponse()
Flushes any pending writes to the file.
3455 async def get_length( 3456 self, 3457 ) -> int: 3458 """Returns the length of the file in bytes""" 3459 request = Request_FileGetLength( 3460 self._handle, 3461 ) 3462 response = await self._client.invoke(request) 3463 if isinstance(response, Response_U64): 3464 return response.value 3465 raise UnexpectedResponse()
Returns the length of the file in bytes
3467 async def get_progress( 3468 self, 3469 ) -> int: 3470 """ 3471 Returns the sync progress of this file, that is, the total byte size of all the blocks of 3472 this file that's already been downloaded. 3473 3474 Note that Ouisync downloads the blocks in random order, so until the file's been completely 3475 downloaded, the already downloaded blocks are not guaranteed to continuous (there might be 3476 gaps). 3477 """ 3478 request = Request_FileGetProgress( 3479 self._handle, 3480 ) 3481 response = await self._client.invoke(request) 3482 if isinstance(response, Response_U64): 3483 return response.value 3484 raise UnexpectedResponse()
Returns the sync progress of this file, that is, the total byte size of all the blocks of this file that's already been downloaded.
Note that Ouisync downloads the blocks in random order, so until the file's been completely downloaded, the already downloaded blocks are not guaranteed to continuous (there might be gaps).
3486 async def read( 3487 self, 3488 *, 3489 offset: int, 3490 size: int, 3491 ) -> bytes: 3492 """Reads `size` bytes from the file starting at `offset` bytes from the beginning of the file.""" 3493 request = Request_FileRead( 3494 self._handle, 3495 offset, 3496 size, 3497 ) 3498 response = await self._client.invoke(request) 3499 if isinstance(response, Response_Bytes): 3500 return response.value 3501 raise UnexpectedResponse()
Reads size bytes from the file starting at offset bytes from the beginning of the file.
3503 async def truncate( 3504 self, 3505 *, 3506 len: int, 3507 ): 3508 """Truncates the file to the given length.""" 3509 request = Request_FileTruncate( 3510 self._handle, 3511 len, 3512 ) 3513 response = await self._client.invoke(request) 3514 if isinstance(response, Response_Unit): 3515 return 3516 raise UnexpectedResponse()
Truncates the file to the given length.
3518 async def write( 3519 self, 3520 *, 3521 offset: int, 3522 data: bytes, 3523 ): 3524 """Writes the data to the file at the given offset.""" 3525 request = Request_FileWrite( 3526 self._handle, 3527 offset, 3528 data, 3529 ) 3530 response = await self._client.invoke(request) 3531 if isinstance(response, Response_Unit): 3532 return 3533 raise UnexpectedResponse()
Writes the data to the file at the given offset.
234@dataclass 235class JointSnapshot: 236 """ 237 Identifies a set of snapshots, one per branch, to read a repository from. Reading at a joint 238 snapshot (see [Repository::open_directory_at](crate::Repository::open_directory_at)) gives a 239 consistent view of the repository even when it's changing in the meantime, and never falls 240 back to older snapshots when some blocks are missing: such reads fail instead. 241 242 It's an opaque token. Equal tokens identify the same snapshots. 243 """ 244 _shape: ClassVar[str] = "unnamed" 245 value: bytes
Identifies a set of snapshots, one per branch, to read a repository from. Reading at a joint snapshot (see Repository::open_directory_at) gives a consistent view of the repository even when it's changing in the meantime, and never falls back to older snapshots when some blocks are missing: such reads fail instead.
It's an opaque token. Equal tokens identify the same snapshots.
63class LocalSecret: 64 """Type of secret to unlock a repository.""" 65 _variants: ClassVar[dict[str, type]] = {}
Type of secret to unlock a repository.
67@dataclass 68class LocalSecret_Password(LocalSecret): 69 """Password provided by the user""" 70 _tag: ClassVar[str] = "Password" 71 _shape: ClassVar[str] = "unnamed" 72 value: Password
Password provided by the user
74@dataclass 75class LocalSecret_SecretKey(LocalSecret): 76 """Secret key generated by secure means (e.g., crypto-secure RNG, KDF, ...)""" 77 _tag: ClassVar[str] = "SecretKey" 78 _shape: ClassVar[str] = "unnamed" 79 value: SecretKey
Secret key generated by secure means (e.g., crypto-secure RNG, KDF, ...)
537@dataclass 538class MetadataEdit: 539 """Edit of a single metadata entry.""" 540 _shape: ClassVar[str] = "named" 541 key: str 542 old_value: str | None 543 new_value: str | None
Edit of a single metadata entry.
258class NatBehavior(IntEnum): 259 ENDPOINT_INDEPENDENT = 0 260 ADDRESS_DEPENDENT = 1 261 ADDRESS_AND_PORT_DEPENDENT = 2
545@dataclass 546class NetworkDefaults: 547 """Default network parameters""" 548 _shape: ClassVar[str] = "named" 549 bind: list[str] 550 port_forwarding_enabled: bool 551 local_discovery_enabled: bool
Default network parameters
149class NetworkEvent(IntEnum): 150 """Network notification event.""" 151 PROTOCOL_VERSION_MISMATCH = 0 152 """ 153 A peer has appeared with higher protocol version than us. Probably means we are using 154 outdated library. This event can be used to notify the user that they should update the app. 155 """ 156 PEER_SET_CHANGE = 1 157 """The set of known peers has changed (e.g., a new peer has been discovered)"""
Network notification event.
A peer has appeared with higher protocol version than us. Probably means we are using outdated library. This event can be used to notify the user that they should update the app.
The set of known peers has changed (e.g., a new peer has been discovered)
3536class NetworkSocket: 3537 def __init__(self, client: Client, handle: NetworkSocketHandle): 3538 """@private""" 3539 self._client = client 3540 self._handle = handle 3541 3542 async def close( 3543 self, 3544 ): 3545 request = Request_NetworkSocketClose( 3546 self._handle, 3547 ) 3548 response = await self._client.invoke(request) 3549 if isinstance(response, Response_Unit): 3550 return 3551 raise UnexpectedResponse() 3552 3553 async def recv_from( 3554 self, 3555 *, 3556 len: int, 3557 ) -> Datagram: 3558 request = Request_NetworkSocketRecvFrom( 3559 self._handle, 3560 len, 3561 ) 3562 response = await self._client.invoke(request) 3563 if isinstance(response, Response_Datagram): 3564 return response.value 3565 raise UnexpectedResponse() 3566 3567 async def send_to( 3568 self, 3569 *, 3570 data: bytes, 3571 addr: str, 3572 ) -> int: 3573 request = Request_NetworkSocketSendTo( 3574 self._handle, 3575 data, 3576 addr, 3577 ) 3578 response = await self._client.invoke(request) 3579 if isinstance(response, Response_U64): 3580 return response.value 3581 raise UnexpectedResponse()
3553 async def recv_from( 3554 self, 3555 *, 3556 len: int, 3557 ) -> Datagram: 3558 request = Request_NetworkSocketRecvFrom( 3559 self._handle, 3560 len, 3561 ) 3562 response = await self._client.invoke(request) 3563 if isinstance(response, Response_Datagram): 3564 return response.value 3565 raise UnexpectedResponse()
3567 async def send_to( 3568 self, 3569 *, 3570 data: bytes, 3571 addr: str, 3572 ) -> int: 3573 request = Request_NetworkSocketSendTo( 3574 self._handle, 3575 data, 3576 addr, 3577 ) 3578 response = await self._client.invoke(request) 3579 if isinstance(response, Response_U64): 3580 return response.value 3581 raise UnexpectedResponse()
3584class NetworkStream: 3585 def __init__(self, client: Client, handle: NetworkStreamHandle): 3586 """@private""" 3587 self._client = client 3588 self._handle = handle 3589 3590 async def close( 3591 self, 3592 ): 3593 """Gracefully closes the given raw byte stream.""" 3594 request = Request_NetworkStreamClose( 3595 self._handle, 3596 ) 3597 response = await self._client.invoke(request) 3598 if isinstance(response, Response_Unit): 3599 return 3600 raise UnexpectedResponse() 3601 3602 async def read_exact( 3603 self, 3604 *, 3605 len: int, 3606 ) -> bytes: 3607 """Reads exactly the given number of bytes from the given raw byte stream.""" 3608 request = Request_NetworkStreamReadExact( 3609 self._handle, 3610 len, 3611 ) 3612 response = await self._client.invoke(request) 3613 if isinstance(response, Response_Bytes): 3614 return response.value 3615 raise UnexpectedResponse() 3616 3617 async def write_all( 3618 self, 3619 *, 3620 buf: bytes, 3621 ): 3622 """Writes the whole buffer to the given raw byte stream.""" 3623 request = Request_NetworkStreamWriteAll( 3624 self._handle, 3625 buf, 3626 ) 3627 response = await self._client.invoke(request) 3628 if isinstance(response, Response_Unit): 3629 return 3630 raise UnexpectedResponse()
3590 async def close( 3591 self, 3592 ): 3593 """Gracefully closes the given raw byte stream.""" 3594 request = Request_NetworkStreamClose( 3595 self._handle, 3596 ) 3597 response = await self._client.invoke(request) 3598 if isinstance(response, Response_Unit): 3599 return 3600 raise UnexpectedResponse()
Gracefully closes the given raw byte stream.
3602 async def read_exact( 3603 self, 3604 *, 3605 len: int, 3606 ) -> bytes: 3607 """Reads exactly the given number of bytes from the given raw byte stream.""" 3608 request = Request_NetworkStreamReadExact( 3609 self._handle, 3610 len, 3611 ) 3612 response = await self._client.invoke(request) 3613 if isinstance(response, Response_Bytes): 3614 return response.value 3615 raise UnexpectedResponse()
Reads exactly the given number of bytes from the given raw byte stream.
3617 async def write_all( 3618 self, 3619 *, 3620 buf: bytes, 3621 ): 3622 """Writes the whole buffer to the given raw byte stream.""" 3623 request = Request_NetworkStreamWriteAll( 3624 self._handle, 3625 buf, 3626 ) 3627 response = await self._client.invoke(request) 3628 if isinstance(response, Response_Unit): 3629 return 3630 raise UnexpectedResponse()
Writes the whole buffer to the given raw byte stream.
329class OuisyncError(Exception): 330 def __init__(self, code: ErrorCode, message: str | None = None, sources: list[str] | None = None): 331 self.code = code 332 self.message = message 333 self.sources = sources or [] 334 super().__init__(message or str(code))
Common base class for all non-exit exceptions.
351class OuisyncError_AlreadyExists(OuisyncError): 352 """Entry already exists""" 353 def __init__(self, message: str | None = None, sources: list[str] | None = None): 354 super().__init__(ErrorCode.ALREADY_EXISTS, message, sources)
Entry already exists
361class OuisyncError_Ambiguous(OuisyncError): 362 """Multiple matching entries found""" 363 def __init__(self, message: str | None = None, sources: list[str] | None = None): 364 super().__init__(ErrorCode.AMBIGUOUS, message, sources)
Multiple matching entries found
436class OuisyncError_ConfigError(OuisyncError): 437 """Failed to read from or write into the config file""" 438 def __init__(self, message: str | None = None, sources: list[str] | None = None): 439 super().__init__(ErrorCode.CONFIG_ERROR, message, sources)
Failed to read from or write into the config file
381class OuisyncError_ConnectionAborted(OuisyncError): 382 """Connection aborted by the server""" 383 def __init__(self, message: str | None = None, sources: list[str] | None = None): 384 super().__init__(ErrorCode.CONNECTION_ABORTED, message, sources)
Connection aborted by the server
376class OuisyncError_ConnectionRefused(OuisyncError): 377 """Failed to establish connection to the server""" 378 def __init__(self, message: str | None = None, sources: list[str] | None = None): 379 super().__init__(ErrorCode.CONNECTION_REFUSED, message, sources)
Failed to establish connection to the server
416class OuisyncError_DirectoryNotEmpty(OuisyncError): 417 """Directory was expected to be empty but it isn't""" 418 def __init__(self, message: str | None = None, sources: list[str] | None = None): 419 super().__init__(ErrorCode.DIRECTORY_NOT_EMPTY, message, sources)
Directory was expected to be empty but it isn't
371class OuisyncError_Interrupted(OuisyncError): 372 """The operation was interrupted""" 373 def __init__(self, message: str | None = None, sources: list[str] | None = None): 374 super().__init__(ErrorCode.INTERRUPTED, message, sources)
The operation was interrupted
346class OuisyncError_InvalidData(OuisyncError): 347 """Invalid data (e.g., malformed incoming message, config file, etc...)""" 348 def __init__(self, message: str | None = None, sources: list[str] | None = None): 349 super().__init__(ErrorCode.INVALID_DATA, message, sources)
Invalid data (e.g., malformed incoming message, config file, etc...)
341class OuisyncError_InvalidInput(OuisyncError): 342 """Invalid input parameter""" 343 def __init__(self, message: str | None = None, sources: list[str] | None = None): 344 super().__init__(ErrorCode.INVALID_INPUT, message, sources)
Invalid input parameter
406class OuisyncError_IsDirectory(OuisyncError): 407 """Entry was expected to not be a directory but it is""" 408 def __init__(self, message: str | None = None, sources: list[str] | None = None): 409 super().__init__(ErrorCode.IS_DIRECTORY, message, sources)
Entry was expected to not be a directory but it is
396class OuisyncError_ListenerAcceptError(OuisyncError): 397 """Listener failed to accept client connection""" 398 def __init__(self, message: str | None = None, sources: list[str] | None = None): 399 super().__init__(ErrorCode.LISTENER_ACCEPT_ERROR, message, sources)
Listener failed to accept client connection
391class OuisyncError_ListenerBindError(OuisyncError): 392 """Listener failed to bind to the specified address""" 393 def __init__(self, message: str | None = None, sources: list[str] | None = None): 394 super().__init__(ErrorCode.LISTENER_BIND_ERROR, message, sources)
Listener failed to bind to the specified address
481class OuisyncError_MountDirUnspecified(OuisyncError): 482 """Mount directory is not specified""" 483 def __init__(self, message: str | None = None, sources: list[str] | None = None): 484 super().__init__(ErrorCode.MOUNT_DIR_UNSPECIFIED, message, sources)
Mount directory is not specified
411class OuisyncError_NotDirectory(OuisyncError): 412 """Entry was expected to be a directory but it isn't""" 413 def __init__(self, message: str | None = None, sources: list[str] | None = None): 414 super().__init__(ErrorCode.NOT_DIRECTORY, message, sources)
Entry was expected to be a directory but it isn't
356class OuisyncError_NotFound(OuisyncError): 357 """Entry not found""" 358 def __init__(self, message: str | None = None, sources: list[str] | None = None): 359 super().__init__(ErrorCode.NOT_FOUND, message, sources)
Entry not found
336class OuisyncError_PermissionDenied(OuisyncError): 337 """Insuficient permission to perform the intended operation""" 338 def __init__(self, message: str | None = None, sources: list[str] | None = None): 339 super().__init__(ErrorCode.PERMISSION_DENIED, message, sources)
Insuficient permission to perform the intended operation
421class OuisyncError_ResourceBusy(OuisyncError): 422 """File or directory is busy""" 423 def __init__(self, message: str | None = None, sources: list[str] | None = None): 424 super().__init__(ErrorCode.RESOURCE_BUSY, message, sources)
File or directory is busy
431class OuisyncError_RuntimeInitializeError(OuisyncError): 432 """Failed to initialize runtime""" 433 def __init__(self, message: str | None = None, sources: list[str] | None = None): 434 super().__init__(ErrorCode.RUNTIME_INITIALIZE_ERROR, message, sources)
Failed to initialize runtime
471class OuisyncError_ServiceAlreadyRunning(OuisyncError): 472 """Another instance of the service is already running""" 473 def __init__(self, message: str | None = None, sources: list[str] | None = None): 474 super().__init__(ErrorCode.SERVICE_ALREADY_RUNNING, message, sources)
Another instance of the service is already running
426class OuisyncError_SnapshotNotFound(OuisyncError): 427 """Snapshot no longer exists (e.g., because it has been replaced by a newer one)""" 428 def __init__(self, message: str | None = None, sources: list[str] | None = None): 429 super().__init__(ErrorCode.SNAPSHOT_NOT_FOUND, message, sources)
Snapshot no longer exists (e.g., because it has been replaced by a newer one)
476class OuisyncError_StoreDirUnspecified(OuisyncError): 477 """Store directory is not specified""" 478 def __init__(self, message: str | None = None, sources: list[str] | None = None): 479 super().__init__(ErrorCode.STORE_DIR_UNSPECIFIED, message, sources)
Store directory is not specified
401class OuisyncError_StoreError(OuisyncError): 402 """Operation on the internal repository store failed""" 403 def __init__(self, message: str | None = None, sources: list[str] | None = None): 404 super().__init__(ErrorCode.STORE_ERROR, message, sources)
Operation on the internal repository store failed
446class OuisyncError_TlsCertificatesInvalid(OuisyncError): 447 """TLS certificates failed to load""" 448 def __init__(self, message: str | None = None, sources: list[str] | None = None): 449 super().__init__(ErrorCode.TLS_CERTIFICATES_INVALID, message, sources)
TLS certificates failed to load
441class OuisyncError_TlsCertificatesNotFound(OuisyncError): 442 """TLS certificated not found""" 443 def __init__(self, message: str | None = None, sources: list[str] | None = None): 444 super().__init__(ErrorCode.TLS_CERTIFICATES_NOT_FOUND, message, sources)
TLS certificated not found
456class OuisyncError_TlsConfigError(OuisyncError): 457 """Failed to create TLS config""" 458 def __init__(self, message: str | None = None, sources: list[str] | None = None): 459 super().__init__(ErrorCode.TLS_CONFIG_ERROR, message, sources)
Failed to create TLS config
451class OuisyncError_TlsKeysNotFound(OuisyncError): 452 """TLS keys not found""" 453 def __init__(self, message: str | None = None, sources: list[str] | None = None): 454 super().__init__(ErrorCode.TLS_KEYS_NOT_FOUND, message, sources)
TLS keys not found
386class OuisyncError_TransportError(OuisyncError): 387 """Failed to send or receive message""" 388 def __init__(self, message: str | None = None, sources: list[str] | None = None): 389 super().__init__(ErrorCode.TRANSPORT_ERROR, message, sources)
Failed to send or receive message
366class OuisyncError_Unsupported(OuisyncError): 367 """The indended operation is not supported""" 368 def __init__(self, message: str | None = None, sources: list[str] | None = None): 369 super().__init__(ErrorCode.UNSUPPORTED, message, sources)
The indended operation is not supported
461class OuisyncError_VfsDriverInstallError(OuisyncError): 462 """Failed to install virtual filesystem driver""" 463 def __init__(self, message: str | None = None, sources: list[str] | None = None): 464 super().__init__(ErrorCode.VFS_DRIVER_INSTALL_ERROR, message, sources)
Failed to install virtual filesystem driver
466class OuisyncError_VfsOtherError(OuisyncError): 467 """Unspecified virtual filesystem error""" 468 def __init__(self, message: str | None = None, sources: list[str] | None = None): 469 super().__init__(ErrorCode.VFS_OTHER_ERROR, message, sources)
Unspecified virtual filesystem error
32@dataclass 33class Password: 34 """ 35 A simple wrapper over String to avoid certain kinds of attack. For more elaboration please see 36 the documentation for the SecretKey structure. 37 """ 38 _shape: ClassVar[str] = "unnamed" 39 value: str 40 def __repr__(self) -> str: 41 return f"{type(self).__name__}(******)"
A simple wrapper over String to avoid certain kinds of attack. For more elaboration please see the documentation for the SecretKey structure.
159@dataclass 160class PeerInfo: 161 """Information about a peer.""" 162 _shape: ClassVar[str] = "named" 163 addr: str 164 source: PeerSource 165 state: PeerState 166 stats: Stats
Information about a peer.
168class PeerSource(IntEnum): 169 """How was the peer discovered.""" 170 USER_PROVIDED = 0 171 """Explicitly added by the user.""" 172 LISTENER = 1 173 """Peer connected to us.""" 174 LOCAL_DISCOVERY = 2 175 """Discovered on the Local Discovery.""" 176 DHT = 3 177 """Discovered on the DHT.""" 178 PEER_EXCHANGE = 4 179 """Discovered on the Peer Exchange."""
How was the peer discovered.
199@dataclass 200class PeerState_Active(PeerState): 201 _tag: ClassVar[str] = "Active" 202 _shape: ClassVar[str] = "named" 203 id: PublicRuntimeId 204 since: typing.Any
227@dataclass 228class Progress: 229 """Progress of a task.""" 230 _shape: ClassVar[str] = "named" 231 value: int 232 total: int
Progress of a task.
560@dataclass 561class QuotaInfo: 562 _shape: ClassVar[str] = "named" 563 quota: StorageSize | None 564 size: StorageSize
2681class Repository: 2682 def __init__(self, client: Client, handle: RepositoryHandle): 2683 """@private""" 2684 self._client = client 2685 self._handle = handle 2686 2687 async def close( 2688 self, 2689 ): 2690 """Closes the repository.""" 2691 request = Request_RepositoryClose( 2692 self._handle, 2693 ) 2694 response = await self._client.invoke(request) 2695 if isinstance(response, Response_Unit): 2696 return 2697 raise UnexpectedResponse() 2698 2699 async def create_directory( 2700 self, 2701 *, 2702 path: str, 2703 ): 2704 """Creates a new directory at the given path in the repository.""" 2705 request = Request_RepositoryCreateDirectory( 2706 self._handle, 2707 path, 2708 ) 2709 response = await self._client.invoke(request) 2710 if isinstance(response, Response_Unit): 2711 return 2712 raise UnexpectedResponse() 2713 2714 async def create_file( 2715 self, 2716 *, 2717 path: str, 2718 ) -> File: 2719 """Creates a new file at the given path in the repository.""" 2720 request = Request_RepositoryCreateFile( 2721 self._handle, 2722 path, 2723 ) 2724 response = await self._client.invoke(request) 2725 if isinstance(response, Response_File): 2726 return File(self._client, response.value) 2727 raise UnexpectedResponse() 2728 2729 async def create_mirror( 2730 self, 2731 *, 2732 host: str, 2733 ): 2734 """ 2735 Creates mirror of this repository on the given cache server host. 2736 2737 Cache servers relay traffic between Ouisync peers and also temporarily store data. They are 2738 useful when direct P2P connection fails (e.g. due to restrictive NAT) and also to allow 2739 syncing when the peers are not online at the same time (they still need to be online within 2740 ~24 hours of each other). 2741 2742 Requires the repository to be opened in write mode. 2743 """ 2744 request = Request_RepositoryCreateMirror( 2745 self._handle, 2746 host, 2747 ) 2748 response = await self._client.invoke(request) 2749 if isinstance(response, Response_Unit): 2750 return 2751 raise UnexpectedResponse() 2752 2753 async def delete( 2754 self, 2755 ): 2756 """Delete the repository""" 2757 request = Request_RepositoryDelete( 2758 self._handle, 2759 ) 2760 response = await self._client.invoke(request) 2761 if isinstance(response, Response_Unit): 2762 return 2763 raise UnexpectedResponse() 2764 2765 async def delete_mirror( 2766 self, 2767 *, 2768 host: str, 2769 ): 2770 """ 2771 Deletes mirror of this repository from the given cache server host. 2772 2773 Requires the repository to be opened in write mode. 2774 """ 2775 request = Request_RepositoryDeleteMirror( 2776 self._handle, 2777 host, 2778 ) 2779 response = await self._client.invoke(request) 2780 if isinstance(response, Response_Unit): 2781 return 2782 raise UnexpectedResponse() 2783 2784 async def export( 2785 self, 2786 *, 2787 output_path: str, 2788 ) -> str: 2789 """Export repository to file""" 2790 request = Request_RepositoryExport( 2791 self._handle, 2792 output_path, 2793 ) 2794 response = await self._client.invoke(request) 2795 if isinstance(response, Response_Path): 2796 return response.value 2797 raise UnexpectedResponse() 2798 2799 async def file_exists( 2800 self, 2801 *, 2802 path: str, 2803 ) -> bool: 2804 request = Request_RepositoryFileExists( 2805 self._handle, 2806 path, 2807 ) 2808 response = await self._client.invoke(request) 2809 if isinstance(response, Response_Bool): 2810 return response.value 2811 raise UnexpectedResponse() 2812 2813 async def get_access_mode( 2814 self, 2815 ) -> AccessMode: 2816 """Returns the access mode (*blind*, *read* or *write*) the repository is currently opened in.""" 2817 request = Request_RepositoryGetAccessMode( 2818 self._handle, 2819 ) 2820 response = await self._client.invoke(request) 2821 if isinstance(response, Response_AccessMode): 2822 return response.value 2823 raise UnexpectedResponse() 2824 2825 async def get_block_expiration( 2826 self, 2827 ) -> int | None: 2828 request = Request_RepositoryGetBlockExpiration( 2829 self._handle, 2830 ) 2831 response = await self._client.invoke(request) 2832 if isinstance(response, Response_Duration): 2833 return response.value 2834 if isinstance(response, Response_None): 2835 return None 2836 raise UnexpectedResponse() 2837 2838 async def get_credentials( 2839 self, 2840 ) -> bytes: 2841 """ 2842 Gets the current credentials of this repository. Can be used to restore access after closing 2843 and reopening the repository. 2844 """ 2845 request = Request_RepositoryGetCredentials( 2846 self._handle, 2847 ) 2848 response = await self._client.invoke(request) 2849 if isinstance(response, Response_Bytes): 2850 return response.value 2851 raise UnexpectedResponse() 2852 2853 async def get_entry_type( 2854 self, 2855 *, 2856 path: str, 2857 ) -> EntryType | None: 2858 """ 2859 Returns the type of repository entry (file, directory, ...) or `None` if the entry doesn't 2860 exist. 2861 """ 2862 request = Request_RepositoryGetEntryType( 2863 self._handle, 2864 path, 2865 ) 2866 response = await self._client.invoke(request) 2867 if isinstance(response, Response_EntryType): 2868 return response.value 2869 if isinstance(response, Response_None): 2870 return None 2871 raise UnexpectedResponse() 2872 2873 async def get_expiration( 2874 self, 2875 ) -> int | None: 2876 request = Request_RepositoryGetExpiration( 2877 self._handle, 2878 ) 2879 response = await self._client.invoke(request) 2880 if isinstance(response, Response_Duration): 2881 return response.value 2882 if isinstance(response, Response_None): 2883 return None 2884 raise UnexpectedResponse() 2885 2886 async def get_info_hash( 2887 self, 2888 ) -> str: 2889 """ 2890 Return the info-hash of the repository formatted as hex string. This can be used as a 2891 globally unique, non-secret identifier of the repository. 2892 """ 2893 request = Request_RepositoryGetInfoHash( 2894 self._handle, 2895 ) 2896 response = await self._client.invoke(request) 2897 if isinstance(response, Response_String): 2898 return response.value 2899 raise UnexpectedResponse() 2900 2901 async def get_joint_snapshot( 2902 self, 2903 ) -> JointSnapshot: 2904 """ 2905 Returns the current joint snapshot of the repository: an opaque token identifying the latest 2906 snapshot of each branch. Pass it to [Self::repository_read_directory] and 2907 [Self::repository_open_file] to read from exactly those snapshots. 2908 2909 Equal tokens mean the content of the repository (its directories and files) hasn't changed, 2910 but not that nothing has changed: blocks of those snapshots can keep arriving without 2911 creating new snapshots. So a read at a token that failed because some data hadn't been 2912 downloaded yet can succeed later at the same token. 2913 """ 2914 request = Request_RepositoryGetJointSnapshot( 2915 self._handle, 2916 ) 2917 response = await self._client.invoke(request) 2918 if isinstance(response, Response_JointSnapshot): 2919 return response.value 2920 raise UnexpectedResponse() 2921 2922 async def get_metadata( 2923 self, 2924 *, 2925 key: str, 2926 ) -> str | None: 2927 request = Request_RepositoryGetMetadata( 2928 self._handle, 2929 key, 2930 ) 2931 response = await self._client.invoke(request) 2932 if isinstance(response, Response_String): 2933 return response.value 2934 if isinstance(response, Response_None): 2935 return None 2936 raise UnexpectedResponse() 2937 2938 async def get_mount_point( 2939 self, 2940 ) -> str | None: 2941 request = Request_RepositoryGetMountPoint( 2942 self._handle, 2943 ) 2944 response = await self._client.invoke(request) 2945 if isinstance(response, Response_Path): 2946 return response.value 2947 if isinstance(response, Response_None): 2948 return None 2949 raise UnexpectedResponse() 2950 2951 async def get_path( 2952 self, 2953 ) -> str: 2954 request = Request_RepositoryGetPath( 2955 self._handle, 2956 ) 2957 response = await self._client.invoke(request) 2958 if isinstance(response, Response_Path): 2959 return response.value 2960 raise UnexpectedResponse() 2961 2962 async def get_quota( 2963 self, 2964 ) -> QuotaInfo: 2965 request = Request_RepositoryGetQuota( 2966 self._handle, 2967 ) 2968 response = await self._client.invoke(request) 2969 if isinstance(response, Response_QuotaInfo): 2970 return response.value 2971 raise UnexpectedResponse() 2972 2973 async def get_short_name( 2974 self, 2975 ) -> str: 2976 request = Request_RepositoryGetShortName( 2977 self._handle, 2978 ) 2979 response = await self._client.invoke(request) 2980 if isinstance(response, Response_String): 2981 return response.value 2982 raise UnexpectedResponse() 2983 2984 async def get_stats( 2985 self, 2986 ) -> Stats: 2987 request = Request_RepositoryGetStats( 2988 self._handle, 2989 ) 2990 response = await self._client.invoke(request) 2991 if isinstance(response, Response_Stats): 2992 return response.value 2993 raise UnexpectedResponse() 2994 2995 async def get_sync_progress( 2996 self, 2997 ) -> Progress: 2998 """ 2999 Returns the synchronization progress of this repository as the number of bytes already 3000 synced ([Progress.value]) vs. the total size of the repository in bytes ([Progress.total]). 3001 """ 3002 request = Request_RepositoryGetSyncProgress( 3003 self._handle, 3004 ) 3005 response = await self._client.invoke(request) 3006 if isinstance(response, Response_Progress): 3007 return response.value 3008 raise UnexpectedResponse() 3009 3010 async def is_dht_enabled( 3011 self, 3012 ) -> bool: 3013 """Is Bittorrent DHT enabled?""" 3014 request = Request_RepositoryIsDhtEnabled( 3015 self._handle, 3016 ) 3017 response = await self._client.invoke(request) 3018 if isinstance(response, Response_Bool): 3019 return response.value 3020 raise UnexpectedResponse() 3021 3022 async def is_pex_enabled( 3023 self, 3024 ) -> bool: 3025 """Is Peer Exchange enabled?""" 3026 request = Request_RepositoryIsPexEnabled( 3027 self._handle, 3028 ) 3029 response = await self._client.invoke(request) 3030 if isinstance(response, Response_Bool): 3031 return response.value 3032 raise UnexpectedResponse() 3033 3034 async def is_sync_enabled( 3035 self, 3036 ) -> bool: 3037 """Returns whether syncing with other replicas is enabled for this repository.""" 3038 request = Request_RepositoryIsSyncEnabled( 3039 self._handle, 3040 ) 3041 response = await self._client.invoke(request) 3042 if isinstance(response, Response_Bool): 3043 return response.value 3044 raise UnexpectedResponse() 3045 3046 async def mirror_exists( 3047 self, 3048 *, 3049 host: str, 3050 ) -> bool: 3051 """Checks if this repository is mirrored on the given cache server host.""" 3052 request = Request_RepositoryMirrorExists( 3053 self._handle, 3054 host, 3055 ) 3056 response = await self._client.invoke(request) 3057 if isinstance(response, Response_Bool): 3058 return response.value 3059 raise UnexpectedResponse() 3060 3061 async def mount( 3062 self, 3063 ) -> str: 3064 request = Request_RepositoryMount( 3065 self._handle, 3066 ) 3067 response = await self._client.invoke(request) 3068 if isinstance(response, Response_Path): 3069 return response.value 3070 raise UnexpectedResponse() 3071 3072 async def move( 3073 self, 3074 *, 3075 dst: str, 3076 ): 3077 request = Request_RepositoryMove( 3078 self._handle, 3079 dst, 3080 ) 3081 response = await self._client.invoke(request) 3082 if isinstance(response, Response_Unit): 3083 return 3084 raise UnexpectedResponse() 3085 3086 async def move_entry( 3087 self, 3088 *, 3089 src: str, 3090 dst: str, 3091 ): 3092 """Moves an entry (file or directory) from `src` to `dst`.""" 3093 request = Request_RepositoryMoveEntry( 3094 self._handle, 3095 src, 3096 dst, 3097 ) 3098 response = await self._client.invoke(request) 3099 if isinstance(response, Response_Unit): 3100 return 3101 raise UnexpectedResponse() 3102 3103 async def open_file( 3104 self, 3105 *, 3106 path: str, 3107 joint_snapshot: JointSnapshot | None = None, 3108 ) -> File: 3109 """ 3110 Opens an existing file at the given path in the repository. 3111 3112 - `joint_snapshot`: if given (see [Self::repository_get_joint_snapshot]), the file is opened 3113 and later read from exactly those snapshots, and it's read-only. Fails with 3114 `SnapshotNotFound` if any of the snapshots no longer exists. 3115 """ 3116 request = Request_RepositoryOpenFile( 3117 self._handle, 3118 path, 3119 joint_snapshot, 3120 ) 3121 response = await self._client.invoke(request) 3122 if isinstance(response, Response_File): 3123 return File(self._client, response.value) 3124 raise UnexpectedResponse() 3125 3126 async def read_directory( 3127 self, 3128 *, 3129 path: str, 3130 joint_snapshot: JointSnapshot | None = None, 3131 ) -> list[DirectoryEntry]: 3132 """ 3133 Returns the entries of the directory at the given path in the repository. 3134 3135 - `joint_snapshot`: if given (see [Self::repository_get_joint_snapshot]), the directory is 3136 read from exactly those snapshots. If some of its data hasn't been downloaded yet, this 3137 fails instead of falling back to an older version of the directory, and if any of the 3138 snapshots no longer exists, it fails with `SnapshotNotFound`. 3139 """ 3140 request = Request_RepositoryReadDirectory( 3141 self._handle, 3142 path, 3143 joint_snapshot, 3144 ) 3145 response = await self._client.invoke(request) 3146 if isinstance(response, Response_DirectoryEntries): 3147 return response.value 3148 raise UnexpectedResponse() 3149 3150 async def remove_directory( 3151 self, 3152 *, 3153 path: str, 3154 recursive: bool = False, 3155 ): 3156 """ 3157 Removes the directory at the given path from the repository. If `recursive` is true it removes 3158 also the contents, otherwise the directory must be empty. 3159 """ 3160 request = Request_RepositoryRemoveDirectory( 3161 self._handle, 3162 path, 3163 recursive, 3164 ) 3165 response = await self._client.invoke(request) 3166 if isinstance(response, Response_Unit): 3167 return 3168 raise UnexpectedResponse() 3169 3170 async def remove_file( 3171 self, 3172 *, 3173 path: str, 3174 ): 3175 """Removes (deletes) the file at the given path from the repository.""" 3176 request = Request_RepositoryRemoveFile( 3177 self._handle, 3178 path, 3179 ) 3180 response = await self._client.invoke(request) 3181 if isinstance(response, Response_Unit): 3182 return 3183 raise UnexpectedResponse() 3184 3185 async def reset_access( 3186 self, 3187 *, 3188 token: str, 3189 ): 3190 request = Request_RepositoryResetAccess( 3191 self._handle, 3192 token, 3193 ) 3194 response = await self._client.invoke(request) 3195 if isinstance(response, Response_Unit): 3196 return 3197 raise UnexpectedResponse() 3198 3199 async def set_access( 3200 self, 3201 *, 3202 read: AccessChange | None = None, 3203 write: AccessChange | None = None, 3204 ): 3205 """ 3206 Sets, unsets or changes local secrets for accessing the repository or disables the given 3207 access mode. 3208 3209 ## Examples 3210 3211 To protect both read and write access with the same password: 3212 3213 ```kotlin 3214 val password = Password("supersecret") 3215 repo.setAccess(read: AccessChange.Enable(password), write: AccessChange.Enable(password)) 3216 ``` 3217 3218 To require password only for writing: 3219 3220 ```kotlin 3221 repo.setAccess(read: AccessChange.Enable(null), write: AccessChange.Enable(password)) 3222 ``` 3223 3224 To competelly disable write access but leave read access as it was. Warning: this operation 3225 is currently irreversibe. 3226 3227 ```kotlin 3228 repo.setAccess(read: null, write: AccessChange.Disable) 3229 ``` 3230 """ 3231 request = Request_RepositorySetAccess( 3232 self._handle, 3233 read, 3234 write, 3235 ) 3236 response = await self._client.invoke(request) 3237 if isinstance(response, Response_Unit): 3238 return 3239 raise UnexpectedResponse() 3240 3241 async def set_access_mode( 3242 self, 3243 *, 3244 access_mode: AccessMode, 3245 local_secret: LocalSecret | None = None, 3246 ): 3247 """ 3248 Switches the repository to the given access mode. 3249 3250 - `access_mode` is the desired access mode to switch to. 3251 - `local_secret` is the local secret protecting the desired access mode. Can be `None` if no 3252 local secret is used. 3253 """ 3254 request = Request_RepositorySetAccessMode( 3255 self._handle, 3256 access_mode, 3257 local_secret, 3258 ) 3259 response = await self._client.invoke(request) 3260 if isinstance(response, Response_Unit): 3261 return 3262 raise UnexpectedResponse() 3263 3264 async def set_block_expiration( 3265 self, 3266 *, 3267 value: int | None = None, 3268 ): 3269 request = Request_RepositorySetBlockExpiration( 3270 self._handle, 3271 value, 3272 ) 3273 response = await self._client.invoke(request) 3274 if isinstance(response, Response_Unit): 3275 return 3276 raise UnexpectedResponse() 3277 3278 async def set_credentials( 3279 self, 3280 *, 3281 credentials: bytes, 3282 ): 3283 """Sets the current credentials of the repository.""" 3284 request = Request_RepositorySetCredentials( 3285 self._handle, 3286 credentials, 3287 ) 3288 response = await self._client.invoke(request) 3289 if isinstance(response, Response_Unit): 3290 return 3291 raise UnexpectedResponse() 3292 3293 async def set_dht_enabled( 3294 self, 3295 *, 3296 enabled: bool = False, 3297 ): 3298 """Enables/disabled Bittorrent DHT (for peer discovery).""" 3299 request = Request_RepositorySetDhtEnabled( 3300 self._handle, 3301 enabled, 3302 ) 3303 response = await self._client.invoke(request) 3304 if isinstance(response, Response_Unit): 3305 return 3306 raise UnexpectedResponse() 3307 3308 async def set_expiration( 3309 self, 3310 *, 3311 value: int | None = None, 3312 ): 3313 request = Request_RepositorySetExpiration( 3314 self._handle, 3315 value, 3316 ) 3317 response = await self._client.invoke(request) 3318 if isinstance(response, Response_Unit): 3319 return 3320 raise UnexpectedResponse() 3321 3322 async def set_metadata( 3323 self, 3324 *, 3325 edits: list[MetadataEdit], 3326 ) -> bool: 3327 request = Request_RepositorySetMetadata( 3328 self._handle, 3329 edits, 3330 ) 3331 response = await self._client.invoke(request) 3332 if isinstance(response, Response_Bool): 3333 return response.value 3334 raise UnexpectedResponse() 3335 3336 async def set_pex_enabled( 3337 self, 3338 *, 3339 enabled: bool = False, 3340 ): 3341 """Enables/disables Peer Exchange (for peer discovery).""" 3342 request = Request_RepositorySetPexEnabled( 3343 self._handle, 3344 enabled, 3345 ) 3346 response = await self._client.invoke(request) 3347 if isinstance(response, Response_Unit): 3348 return 3349 raise UnexpectedResponse() 3350 3351 async def set_quota( 3352 self, 3353 *, 3354 value: StorageSize | None = None, 3355 ): 3356 request = Request_RepositorySetQuota( 3357 self._handle, 3358 value, 3359 ) 3360 response = await self._client.invoke(request) 3361 if isinstance(response, Response_Unit): 3362 return 3363 raise UnexpectedResponse() 3364 3365 async def set_sync_enabled( 3366 self, 3367 *, 3368 enabled: bool = False, 3369 ): 3370 """ 3371 Enabled or disables syncing with other replicas. 3372 3373 Note syncing is initially disabled. 3374 """ 3375 request = Request_RepositorySetSyncEnabled( 3376 self._handle, 3377 enabled, 3378 ) 3379 response = await self._client.invoke(request) 3380 if isinstance(response, Response_Unit): 3381 return 3382 raise UnexpectedResponse() 3383 3384 async def share( 3385 self, 3386 *, 3387 access_mode: AccessMode, 3388 local_secret: LocalSecret | None = None, 3389 ) -> str: 3390 """ 3391 Creates a *share token* to share this repository with other devices. 3392 3393 By default the access mode of the token will be the same as the mode the repo is currently 3394 opened in but it can be escalated with the `local_secret` param or de-escalated with the 3395 `access_mode` param. 3396 3397 - `access_mode`: access mode of the token. Useful to de-escalate the access mode to below of 3398 what the repo is opened in. 3399 - `local_secret`: the local repo secret. If not `None`, the share token's access mode will 3400 be the same as what the secret provides. Useful to escalate the access mode to above of 3401 what the repo is opened in. 3402 """ 3403 request = Request_RepositoryShare( 3404 self._handle, 3405 access_mode, 3406 local_secret, 3407 ) 3408 response = await self._client.invoke(request) 3409 if isinstance(response, Response_ShareToken): 3410 return response.value 3411 raise UnexpectedResponse() 3412 3413 async def unmount( 3414 self, 3415 ): 3416 request = Request_RepositoryUnmount( 3417 self._handle, 3418 ) 3419 response = await self._client.invoke(request) 3420 if isinstance(response, Response_Unit): 3421 return 3422 raise UnexpectedResponse()
2687 async def close( 2688 self, 2689 ): 2690 """Closes the repository.""" 2691 request = Request_RepositoryClose( 2692 self._handle, 2693 ) 2694 response = await self._client.invoke(request) 2695 if isinstance(response, Response_Unit): 2696 return 2697 raise UnexpectedResponse()
Closes the repository.
2699 async def create_directory( 2700 self, 2701 *, 2702 path: str, 2703 ): 2704 """Creates a new directory at the given path in the repository.""" 2705 request = Request_RepositoryCreateDirectory( 2706 self._handle, 2707 path, 2708 ) 2709 response = await self._client.invoke(request) 2710 if isinstance(response, Response_Unit): 2711 return 2712 raise UnexpectedResponse()
Creates a new directory at the given path in the repository.
2714 async def create_file( 2715 self, 2716 *, 2717 path: str, 2718 ) -> File: 2719 """Creates a new file at the given path in the repository.""" 2720 request = Request_RepositoryCreateFile( 2721 self._handle, 2722 path, 2723 ) 2724 response = await self._client.invoke(request) 2725 if isinstance(response, Response_File): 2726 return File(self._client, response.value) 2727 raise UnexpectedResponse()
Creates a new file at the given path in the repository.
2729 async def create_mirror( 2730 self, 2731 *, 2732 host: str, 2733 ): 2734 """ 2735 Creates mirror of this repository on the given cache server host. 2736 2737 Cache servers relay traffic between Ouisync peers and also temporarily store data. They are 2738 useful when direct P2P connection fails (e.g. due to restrictive NAT) and also to allow 2739 syncing when the peers are not online at the same time (they still need to be online within 2740 ~24 hours of each other). 2741 2742 Requires the repository to be opened in write mode. 2743 """ 2744 request = Request_RepositoryCreateMirror( 2745 self._handle, 2746 host, 2747 ) 2748 response = await self._client.invoke(request) 2749 if isinstance(response, Response_Unit): 2750 return 2751 raise UnexpectedResponse()
Creates mirror of this repository on the given cache server host.
Cache servers relay traffic between Ouisync peers and also temporarily store data. They are useful when direct P2P connection fails (e.g. due to restrictive NAT) and also to allow syncing when the peers are not online at the same time (they still need to be online within ~24 hours of each other).
Requires the repository to be opened in write mode.
2753 async def delete( 2754 self, 2755 ): 2756 """Delete the repository""" 2757 request = Request_RepositoryDelete( 2758 self._handle, 2759 ) 2760 response = await self._client.invoke(request) 2761 if isinstance(response, Response_Unit): 2762 return 2763 raise UnexpectedResponse()
Delete the repository
2765 async def delete_mirror( 2766 self, 2767 *, 2768 host: str, 2769 ): 2770 """ 2771 Deletes mirror of this repository from the given cache server host. 2772 2773 Requires the repository to be opened in write mode. 2774 """ 2775 request = Request_RepositoryDeleteMirror( 2776 self._handle, 2777 host, 2778 ) 2779 response = await self._client.invoke(request) 2780 if isinstance(response, Response_Unit): 2781 return 2782 raise UnexpectedResponse()
Deletes mirror of this repository from the given cache server host.
Requires the repository to be opened in write mode.
2784 async def export( 2785 self, 2786 *, 2787 output_path: str, 2788 ) -> str: 2789 """Export repository to file""" 2790 request = Request_RepositoryExport( 2791 self._handle, 2792 output_path, 2793 ) 2794 response = await self._client.invoke(request) 2795 if isinstance(response, Response_Path): 2796 return response.value 2797 raise UnexpectedResponse()
Export repository to file
2799 async def file_exists( 2800 self, 2801 *, 2802 path: str, 2803 ) -> bool: 2804 request = Request_RepositoryFileExists( 2805 self._handle, 2806 path, 2807 ) 2808 response = await self._client.invoke(request) 2809 if isinstance(response, Response_Bool): 2810 return response.value 2811 raise UnexpectedResponse()
2813 async def get_access_mode( 2814 self, 2815 ) -> AccessMode: 2816 """Returns the access mode (*blind*, *read* or *write*) the repository is currently opened in.""" 2817 request = Request_RepositoryGetAccessMode( 2818 self._handle, 2819 ) 2820 response = await self._client.invoke(request) 2821 if isinstance(response, Response_AccessMode): 2822 return response.value 2823 raise UnexpectedResponse()
Returns the access mode (blind, read or write) the repository is currently opened in.
2825 async def get_block_expiration( 2826 self, 2827 ) -> int | None: 2828 request = Request_RepositoryGetBlockExpiration( 2829 self._handle, 2830 ) 2831 response = await self._client.invoke(request) 2832 if isinstance(response, Response_Duration): 2833 return response.value 2834 if isinstance(response, Response_None): 2835 return None 2836 raise UnexpectedResponse()
2838 async def get_credentials( 2839 self, 2840 ) -> bytes: 2841 """ 2842 Gets the current credentials of this repository. Can be used to restore access after closing 2843 and reopening the repository. 2844 """ 2845 request = Request_RepositoryGetCredentials( 2846 self._handle, 2847 ) 2848 response = await self._client.invoke(request) 2849 if isinstance(response, Response_Bytes): 2850 return response.value 2851 raise UnexpectedResponse()
Gets the current credentials of this repository. Can be used to restore access after closing and reopening the repository.
2853 async def get_entry_type( 2854 self, 2855 *, 2856 path: str, 2857 ) -> EntryType | None: 2858 """ 2859 Returns the type of repository entry (file, directory, ...) or `None` if the entry doesn't 2860 exist. 2861 """ 2862 request = Request_RepositoryGetEntryType( 2863 self._handle, 2864 path, 2865 ) 2866 response = await self._client.invoke(request) 2867 if isinstance(response, Response_EntryType): 2868 return response.value 2869 if isinstance(response, Response_None): 2870 return None 2871 raise UnexpectedResponse()
Returns the type of repository entry (file, directory, ...) or None if the entry doesn't
exist.
2873 async def get_expiration( 2874 self, 2875 ) -> int | None: 2876 request = Request_RepositoryGetExpiration( 2877 self._handle, 2878 ) 2879 response = await self._client.invoke(request) 2880 if isinstance(response, Response_Duration): 2881 return response.value 2882 if isinstance(response, Response_None): 2883 return None 2884 raise UnexpectedResponse()
2886 async def get_info_hash( 2887 self, 2888 ) -> str: 2889 """ 2890 Return the info-hash of the repository formatted as hex string. This can be used as a 2891 globally unique, non-secret identifier of the repository. 2892 """ 2893 request = Request_RepositoryGetInfoHash( 2894 self._handle, 2895 ) 2896 response = await self._client.invoke(request) 2897 if isinstance(response, Response_String): 2898 return response.value 2899 raise UnexpectedResponse()
Return the info-hash of the repository formatted as hex string. This can be used as a globally unique, non-secret identifier of the repository.
2901 async def get_joint_snapshot( 2902 self, 2903 ) -> JointSnapshot: 2904 """ 2905 Returns the current joint snapshot of the repository: an opaque token identifying the latest 2906 snapshot of each branch. Pass it to [Self::repository_read_directory] and 2907 [Self::repository_open_file] to read from exactly those snapshots. 2908 2909 Equal tokens mean the content of the repository (its directories and files) hasn't changed, 2910 but not that nothing has changed: blocks of those snapshots can keep arriving without 2911 creating new snapshots. So a read at a token that failed because some data hadn't been 2912 downloaded yet can succeed later at the same token. 2913 """ 2914 request = Request_RepositoryGetJointSnapshot( 2915 self._handle, 2916 ) 2917 response = await self._client.invoke(request) 2918 if isinstance(response, Response_JointSnapshot): 2919 return response.value 2920 raise UnexpectedResponse()
Returns the current joint snapshot of the repository: an opaque token identifying the latest snapshot of each branch. Pass it to [Self::repository_read_directory] and [Self::repository_open_file] to read from exactly those snapshots.
Equal tokens mean the content of the repository (its directories and files) hasn't changed, but not that nothing has changed: blocks of those snapshots can keep arriving without creating new snapshots. So a read at a token that failed because some data hadn't been downloaded yet can succeed later at the same token.
2922 async def get_metadata( 2923 self, 2924 *, 2925 key: str, 2926 ) -> str | None: 2927 request = Request_RepositoryGetMetadata( 2928 self._handle, 2929 key, 2930 ) 2931 response = await self._client.invoke(request) 2932 if isinstance(response, Response_String): 2933 return response.value 2934 if isinstance(response, Response_None): 2935 return None 2936 raise UnexpectedResponse()
2938 async def get_mount_point( 2939 self, 2940 ) -> str | None: 2941 request = Request_RepositoryGetMountPoint( 2942 self._handle, 2943 ) 2944 response = await self._client.invoke(request) 2945 if isinstance(response, Response_Path): 2946 return response.value 2947 if isinstance(response, Response_None): 2948 return None 2949 raise UnexpectedResponse()
2995 async def get_sync_progress( 2996 self, 2997 ) -> Progress: 2998 """ 2999 Returns the synchronization progress of this repository as the number of bytes already 3000 synced ([Progress.value]) vs. the total size of the repository in bytes ([Progress.total]). 3001 """ 3002 request = Request_RepositoryGetSyncProgress( 3003 self._handle, 3004 ) 3005 response = await self._client.invoke(request) 3006 if isinstance(response, Response_Progress): 3007 return response.value 3008 raise UnexpectedResponse()
Returns the synchronization progress of this repository as the number of bytes already synced ([Progress.value]) vs. the total size of the repository in bytes ([Progress.total]).
3010 async def is_dht_enabled( 3011 self, 3012 ) -> bool: 3013 """Is Bittorrent DHT enabled?""" 3014 request = Request_RepositoryIsDhtEnabled( 3015 self._handle, 3016 ) 3017 response = await self._client.invoke(request) 3018 if isinstance(response, Response_Bool): 3019 return response.value 3020 raise UnexpectedResponse()
Is Bittorrent DHT enabled?
3022 async def is_pex_enabled( 3023 self, 3024 ) -> bool: 3025 """Is Peer Exchange enabled?""" 3026 request = Request_RepositoryIsPexEnabled( 3027 self._handle, 3028 ) 3029 response = await self._client.invoke(request) 3030 if isinstance(response, Response_Bool): 3031 return response.value 3032 raise UnexpectedResponse()
Is Peer Exchange enabled?
3034 async def is_sync_enabled( 3035 self, 3036 ) -> bool: 3037 """Returns whether syncing with other replicas is enabled for this repository.""" 3038 request = Request_RepositoryIsSyncEnabled( 3039 self._handle, 3040 ) 3041 response = await self._client.invoke(request) 3042 if isinstance(response, Response_Bool): 3043 return response.value 3044 raise UnexpectedResponse()
Returns whether syncing with other replicas is enabled for this repository.
3046 async def mirror_exists( 3047 self, 3048 *, 3049 host: str, 3050 ) -> bool: 3051 """Checks if this repository is mirrored on the given cache server host.""" 3052 request = Request_RepositoryMirrorExists( 3053 self._handle, 3054 host, 3055 ) 3056 response = await self._client.invoke(request) 3057 if isinstance(response, Response_Bool): 3058 return response.value 3059 raise UnexpectedResponse()
Checks if this repository is mirrored on the given cache server host.
3086 async def move_entry( 3087 self, 3088 *, 3089 src: str, 3090 dst: str, 3091 ): 3092 """Moves an entry (file or directory) from `src` to `dst`.""" 3093 request = Request_RepositoryMoveEntry( 3094 self._handle, 3095 src, 3096 dst, 3097 ) 3098 response = await self._client.invoke(request) 3099 if isinstance(response, Response_Unit): 3100 return 3101 raise UnexpectedResponse()
Moves an entry (file or directory) from src to dst.
3103 async def open_file( 3104 self, 3105 *, 3106 path: str, 3107 joint_snapshot: JointSnapshot | None = None, 3108 ) -> File: 3109 """ 3110 Opens an existing file at the given path in the repository. 3111 3112 - `joint_snapshot`: if given (see [Self::repository_get_joint_snapshot]), the file is opened 3113 and later read from exactly those snapshots, and it's read-only. Fails with 3114 `SnapshotNotFound` if any of the snapshots no longer exists. 3115 """ 3116 request = Request_RepositoryOpenFile( 3117 self._handle, 3118 path, 3119 joint_snapshot, 3120 ) 3121 response = await self._client.invoke(request) 3122 if isinstance(response, Response_File): 3123 return File(self._client, response.value) 3124 raise UnexpectedResponse()
Opens an existing file at the given path in the repository.
joint_snapshot: if given (see [Self::repository_get_joint_snapshot]), the file is opened and later read from exactly those snapshots, and it's read-only. Fails withSnapshotNotFoundif any of the snapshots no longer exists.
3126 async def read_directory( 3127 self, 3128 *, 3129 path: str, 3130 joint_snapshot: JointSnapshot | None = None, 3131 ) -> list[DirectoryEntry]: 3132 """ 3133 Returns the entries of the directory at the given path in the repository. 3134 3135 - `joint_snapshot`: if given (see [Self::repository_get_joint_snapshot]), the directory is 3136 read from exactly those snapshots. If some of its data hasn't been downloaded yet, this 3137 fails instead of falling back to an older version of the directory, and if any of the 3138 snapshots no longer exists, it fails with `SnapshotNotFound`. 3139 """ 3140 request = Request_RepositoryReadDirectory( 3141 self._handle, 3142 path, 3143 joint_snapshot, 3144 ) 3145 response = await self._client.invoke(request) 3146 if isinstance(response, Response_DirectoryEntries): 3147 return response.value 3148 raise UnexpectedResponse()
Returns the entries of the directory at the given path in the repository.
joint_snapshot: if given (see [Self::repository_get_joint_snapshot]), the directory is read from exactly those snapshots. If some of its data hasn't been downloaded yet, this fails instead of falling back to an older version of the directory, and if any of the snapshots no longer exists, it fails withSnapshotNotFound.
3150 async def remove_directory( 3151 self, 3152 *, 3153 path: str, 3154 recursive: bool = False, 3155 ): 3156 """ 3157 Removes the directory at the given path from the repository. If `recursive` is true it removes 3158 also the contents, otherwise the directory must be empty. 3159 """ 3160 request = Request_RepositoryRemoveDirectory( 3161 self._handle, 3162 path, 3163 recursive, 3164 ) 3165 response = await self._client.invoke(request) 3166 if isinstance(response, Response_Unit): 3167 return 3168 raise UnexpectedResponse()
Removes the directory at the given path from the repository. If recursive is true it removes
also the contents, otherwise the directory must be empty.
3170 async def remove_file( 3171 self, 3172 *, 3173 path: str, 3174 ): 3175 """Removes (deletes) the file at the given path from the repository.""" 3176 request = Request_RepositoryRemoveFile( 3177 self._handle, 3178 path, 3179 ) 3180 response = await self._client.invoke(request) 3181 if isinstance(response, Response_Unit): 3182 return 3183 raise UnexpectedResponse()
Removes (deletes) the file at the given path from the repository.
3199 async def set_access( 3200 self, 3201 *, 3202 read: AccessChange | None = None, 3203 write: AccessChange | None = None, 3204 ): 3205 """ 3206 Sets, unsets or changes local secrets for accessing the repository or disables the given 3207 access mode. 3208 3209 ## Examples 3210 3211 To protect both read and write access with the same password: 3212 3213 ```kotlin 3214 val password = Password("supersecret") 3215 repo.setAccess(read: AccessChange.Enable(password), write: AccessChange.Enable(password)) 3216 ``` 3217 3218 To require password only for writing: 3219 3220 ```kotlin 3221 repo.setAccess(read: AccessChange.Enable(null), write: AccessChange.Enable(password)) 3222 ``` 3223 3224 To competelly disable write access but leave read access as it was. Warning: this operation 3225 is currently irreversibe. 3226 3227 ```kotlin 3228 repo.setAccess(read: null, write: AccessChange.Disable) 3229 ``` 3230 """ 3231 request = Request_RepositorySetAccess( 3232 self._handle, 3233 read, 3234 write, 3235 ) 3236 response = await self._client.invoke(request) 3237 if isinstance(response, Response_Unit): 3238 return 3239 raise UnexpectedResponse()
Sets, unsets or changes local secrets for accessing the repository or disables the given access mode.
Examples
To protect both read and write access with the same password:
val password = Password("supersecret")
repo.setAccess(read: AccessChange.Enable(password), write: AccessChange.Enable(password))
To require password only for writing:
repo.setAccess(read: AccessChange.Enable(null), write: AccessChange.Enable(password))
To competelly disable write access but leave read access as it was. Warning: this operation is currently irreversibe.
repo.setAccess(read: null, write: AccessChange.Disable)
3241 async def set_access_mode( 3242 self, 3243 *, 3244 access_mode: AccessMode, 3245 local_secret: LocalSecret | None = None, 3246 ): 3247 """ 3248 Switches the repository to the given access mode. 3249 3250 - `access_mode` is the desired access mode to switch to. 3251 - `local_secret` is the local secret protecting the desired access mode. Can be `None` if no 3252 local secret is used. 3253 """ 3254 request = Request_RepositorySetAccessMode( 3255 self._handle, 3256 access_mode, 3257 local_secret, 3258 ) 3259 response = await self._client.invoke(request) 3260 if isinstance(response, Response_Unit): 3261 return 3262 raise UnexpectedResponse()
Switches the repository to the given access mode.
access_modeis the desired access mode to switch to.local_secretis the local secret protecting the desired access mode. Can beNoneif no local secret is used.
3264 async def set_block_expiration( 3265 self, 3266 *, 3267 value: int | None = None, 3268 ): 3269 request = Request_RepositorySetBlockExpiration( 3270 self._handle, 3271 value, 3272 ) 3273 response = await self._client.invoke(request) 3274 if isinstance(response, Response_Unit): 3275 return 3276 raise UnexpectedResponse()
3278 async def set_credentials( 3279 self, 3280 *, 3281 credentials: bytes, 3282 ): 3283 """Sets the current credentials of the repository.""" 3284 request = Request_RepositorySetCredentials( 3285 self._handle, 3286 credentials, 3287 ) 3288 response = await self._client.invoke(request) 3289 if isinstance(response, Response_Unit): 3290 return 3291 raise UnexpectedResponse()
Sets the current credentials of the repository.
3293 async def set_dht_enabled( 3294 self, 3295 *, 3296 enabled: bool = False, 3297 ): 3298 """Enables/disabled Bittorrent DHT (for peer discovery).""" 3299 request = Request_RepositorySetDhtEnabled( 3300 self._handle, 3301 enabled, 3302 ) 3303 response = await self._client.invoke(request) 3304 if isinstance(response, Response_Unit): 3305 return 3306 raise UnexpectedResponse()
Enables/disabled Bittorrent DHT (for peer discovery).
3308 async def set_expiration( 3309 self, 3310 *, 3311 value: int | None = None, 3312 ): 3313 request = Request_RepositorySetExpiration( 3314 self._handle, 3315 value, 3316 ) 3317 response = await self._client.invoke(request) 3318 if isinstance(response, Response_Unit): 3319 return 3320 raise UnexpectedResponse()
3322 async def set_metadata( 3323 self, 3324 *, 3325 edits: list[MetadataEdit], 3326 ) -> bool: 3327 request = Request_RepositorySetMetadata( 3328 self._handle, 3329 edits, 3330 ) 3331 response = await self._client.invoke(request) 3332 if isinstance(response, Response_Bool): 3333 return response.value 3334 raise UnexpectedResponse()
3336 async def set_pex_enabled( 3337 self, 3338 *, 3339 enabled: bool = False, 3340 ): 3341 """Enables/disables Peer Exchange (for peer discovery).""" 3342 request = Request_RepositorySetPexEnabled( 3343 self._handle, 3344 enabled, 3345 ) 3346 response = await self._client.invoke(request) 3347 if isinstance(response, Response_Unit): 3348 return 3349 raise UnexpectedResponse()
Enables/disables Peer Exchange (for peer discovery).
3351 async def set_quota( 3352 self, 3353 *, 3354 value: StorageSize | None = None, 3355 ): 3356 request = Request_RepositorySetQuota( 3357 self._handle, 3358 value, 3359 ) 3360 response = await self._client.invoke(request) 3361 if isinstance(response, Response_Unit): 3362 return 3363 raise UnexpectedResponse()
3365 async def set_sync_enabled( 3366 self, 3367 *, 3368 enabled: bool = False, 3369 ): 3370 """ 3371 Enabled or disables syncing with other replicas. 3372 3373 Note syncing is initially disabled. 3374 """ 3375 request = Request_RepositorySetSyncEnabled( 3376 self._handle, 3377 enabled, 3378 ) 3379 response = await self._client.invoke(request) 3380 if isinstance(response, Response_Unit): 3381 return 3382 raise UnexpectedResponse()
Enabled or disables syncing with other replicas.
Note syncing is initially disabled.
597@dataclass 598class Request_Cancel(Request): 599 _tag: ClassVar[str] = "Cancel" 600 _shape: ClassVar[str] = "named" 601 id: MessageId
663@dataclass 664class Request_NetworkSocketSendTo(Request): 665 _tag: ClassVar[str] = "NetworkSocketSendTo" 666 _shape: ClassVar[str] = "named" 667 socket: NetworkSocketHandle 668 data: bytes 669 addr: str
677@dataclass 678class Request_NetworkStreamReadExact(Request): 679 _tag: ClassVar[str] = "NetworkStreamReadExact" 680 _shape: ClassVar[str] = "named" 681 stream: NetworkStreamHandle 682 len: int
684@dataclass 685class Request_NetworkStreamWriteAll(Request): 686 _tag: ClassVar[str] = "NetworkStreamWriteAll" 687 _shape: ClassVar[str] = "named" 688 stream: NetworkStreamHandle 689 buf: bytes
869@dataclass 870class Request_RepositoryMoveEntry(Request): 871 _tag: ClassVar[str] = "RepositoryMoveEntry" 872 _shape: ClassVar[str] = "named" 873 repo: RepositoryHandle 874 src: str 875 dst: str
877@dataclass 878class Request_RepositoryOpenFile(Request): 879 _tag: ClassVar[str] = "RepositoryOpenFile" 880 _shape: ClassVar[str] = "named" 881 repo: RepositoryHandle 882 path: str 883 joint_snapshot: JointSnapshot | None
885@dataclass 886class Request_RepositoryReadDirectory(Request): 887 _tag: ClassVar[str] = "RepositoryReadDirectory" 888 _shape: ClassVar[str] = "named" 889 repo: RepositoryHandle 890 path: str 891 joint_snapshot: JointSnapshot | None
893@dataclass 894class Request_RepositoryRemoveDirectory(Request): 895 _tag: ClassVar[str] = "RepositoryRemoveDirectory" 896 _shape: ClassVar[str] = "named" 897 repo: RepositoryHandle 898 path: str 899 recursive: bool
915@dataclass 916class Request_RepositorySetAccess(Request): 917 _tag: ClassVar[str] = "RepositorySetAccess" 918 _shape: ClassVar[str] = "named" 919 repo: RepositoryHandle 920 read: AccessChange | None 921 write: AccessChange | None
923@dataclass 924class Request_RepositorySetAccessMode(Request): 925 _tag: ClassVar[str] = "RepositorySetAccessMode" 926 _shape: ClassVar[str] = "named" 927 repo: RepositoryHandle 928 access_mode: AccessMode 929 local_secret: LocalSecret | None
931@dataclass 932class Request_RepositorySetBlockExpiration(Request): 933 _tag: ClassVar[str] = "RepositorySetBlockExpiration" 934 _shape: ClassVar[str] = "named" 935 repo: RepositoryHandle 936 value: int | None
938@dataclass 939class Request_RepositorySetCredentials(Request): 940 _tag: ClassVar[str] = "RepositorySetCredentials" 941 _shape: ClassVar[str] = "named" 942 repo: RepositoryHandle 943 credentials: bytes
945@dataclass 946class Request_RepositorySetDhtEnabled(Request): 947 _tag: ClassVar[str] = "RepositorySetDhtEnabled" 948 _shape: ClassVar[str] = "named" 949 repo: RepositoryHandle 950 enabled: bool
952@dataclass 953class Request_RepositorySetExpiration(Request): 954 _tag: ClassVar[str] = "RepositorySetExpiration" 955 _shape: ClassVar[str] = "named" 956 repo: RepositoryHandle 957 value: int | None
959@dataclass 960class Request_RepositorySetMetadata(Request): 961 _tag: ClassVar[str] = "RepositorySetMetadata" 962 _shape: ClassVar[str] = "named" 963 repo: RepositoryHandle 964 edits: list[MetadataEdit]
966@dataclass 967class Request_RepositorySetPexEnabled(Request): 968 _tag: ClassVar[str] = "RepositorySetPexEnabled" 969 _shape: ClassVar[str] = "named" 970 repo: RepositoryHandle 971 enabled: bool
973@dataclass 974class Request_RepositorySetQuota(Request): 975 _tag: ClassVar[str] = "RepositorySetQuota" 976 _shape: ClassVar[str] = "named" 977 repo: RepositoryHandle 978 value: StorageSize | None
980@dataclass 981class Request_RepositorySetSyncEnabled(Request): 982 _tag: ClassVar[str] = "RepositorySetSyncEnabled" 983 _shape: ClassVar[str] = "named" 984 repo: RepositoryHandle 985 enabled: bool
1040@dataclass 1041class Request_SessionCreateRepository(Request): 1042 _tag: ClassVar[str] = "SessionCreateRepository" 1043 _shape: ClassVar[str] = "named" 1044 path: str 1045 read_secret: SetLocalSecret | None 1046 write_secret: SetLocalSecret | None 1047 token: str | None 1048 sync_enabled: bool 1049 dht_enabled: bool 1050 pex_enabled: bool
1058@dataclass 1059class Request_SessionDeriveSecretKey(Request): 1060 _tag: ClassVar[str] = "SessionDeriveSecretKey" 1061 _shape: ClassVar[str] = "named" 1062 password: Password 1063 salt: PasswordSalt
1192@dataclass 1193class Request_SessionGetStateMonitor(Request): 1194 _tag: ClassVar[str] = "SessionGetStateMonitor" 1195 _shape: ClassVar[str] = "named" 1196 path: list[MonitorId]
1208@dataclass 1209class Request_SessionInitNetwork(Request): 1210 _tag: ClassVar[str] = "SessionInitNetwork" 1211 _shape: ClassVar[str] = "named" 1212 defaults: NetworkDefaults
1267@dataclass 1268class Request_SessionOpenNetworkStream(Request): 1269 _tag: ClassVar[str] = "SessionOpenNetworkStream" 1270 _shape: ClassVar[str] = "named" 1271 addr: str 1272 topic_id: TopicId
1274@dataclass 1275class Request_SessionOpenRepository(Request): 1276 _tag: ClassVar[str] = "SessionOpenRepository" 1277 _shape: ClassVar[str] = "named" 1278 path: str 1279 local_secret: LocalSecret | None
1304@dataclass 1305class Request_SessionSetDefaultQuota(Request): 1306 _tag: ClassVar[str] = "SessionSetDefaultQuota" 1307 _shape: ClassVar[str] = "named" 1308 value: StorageSize | None
1369@dataclass 1370class Request_SessionSubscribeToStateMonitor(Request): 1371 _tag: ClassVar[str] = "SessionSubscribeToStateMonitor" 1372 _shape: ClassVar[str] = "named" 1373 path: list[MonitorId]
1519@dataclass 1520class Response_AccessMode(Response): 1521 _tag: ClassVar[str] = "AccessMode" 1522 _shape: ClassVar[str] = "unnamed" 1523 value: AccessMode
1537@dataclass 1538class Response_Datagram(Response): 1539 _tag: ClassVar[str] = "Datagram" 1540 _shape: ClassVar[str] = "unnamed" 1541 value: Datagram
1543@dataclass 1544class Response_DirectoryEntries(Response): 1545 _tag: ClassVar[str] = "DirectoryEntries" 1546 _shape: ClassVar[str] = "unnamed" 1547 value: list[DirectoryEntry]
1555@dataclass 1556class Response_EntryType(Response): 1557 _tag: ClassVar[str] = "EntryType" 1558 _shape: ClassVar[str] = "unnamed" 1559 value: EntryType
1567@dataclass 1568class Response_JointSnapshot(Response): 1569 _tag: ClassVar[str] = "JointSnapshot" 1570 _shape: ClassVar[str] = "unnamed" 1571 value: JointSnapshot
1573@dataclass 1574class Response_NatBehavior(Response): 1575 _tag: ClassVar[str] = "NatBehavior" 1576 _shape: ClassVar[str] = "unnamed" 1577 value: NatBehavior
1579@dataclass 1580class Response_NetworkEvent(Response): 1581 _tag: ClassVar[str] = "NetworkEvent" 1582 _shape: ClassVar[str] = "unnamed" 1583 value: NetworkEvent
1602@dataclass 1603class Response_PasswordSalt(Response): 1604 _tag: ClassVar[str] = "PasswordSalt" 1605 _shape: ClassVar[str] = "unnamed" 1606 value: PasswordSalt
1632@dataclass 1633class Response_PeerInfos(Response): 1634 _tag: ClassVar[str] = "PeerInfos" 1635 _shape: ClassVar[str] = "unnamed" 1636 value: list[PeerInfo]
1638@dataclass 1639class Response_Progress(Response): 1640 _tag: ClassVar[str] = "Progress" 1641 _shape: ClassVar[str] = "unnamed" 1642 value: Progress
1644@dataclass 1645class Response_PublicRuntimeId(Response): 1646 _tag: ClassVar[str] = "PublicRuntimeId" 1647 _shape: ClassVar[str] = "unnamed" 1648 value: PublicRuntimeId
1650@dataclass 1651class Response_QuotaInfo(Response): 1652 _tag: ClassVar[str] = "QuotaInfo" 1653 _shape: ClassVar[str] = "unnamed" 1654 value: QuotaInfo
1668@dataclass 1669class Response_SecretKey(Response): 1670 _tag: ClassVar[str] = "SecretKey" 1671 _shape: ClassVar[str] = "unnamed" 1672 value: SecretKey
1692@dataclass 1693class Response_Stats(Response): 1694 _tag: ClassVar[str] = "Stats" 1695 _shape: ClassVar[str] = "unnamed" 1696 value: Stats
1698@dataclass 1699class Response_StorageSize(Response): 1700 _tag: ClassVar[str] = "StorageSize" 1701 _shape: ClassVar[str] = "unnamed" 1702 value: StorageSize
14@dataclass 15class SecretKey: 16 """ 17 Symmetric encryption/decryption secret key. 18 19 Note: this implementation tries to prevent certain types of attacks by making sure the 20 underlying sensitive key material is always stored at most in one place. This is achieved by 21 putting it on the heap which means it is not moved when the key itself is moved which could 22 otherwise leave a copy of the data in memory. Additionally, the data is behind a `Arc` which 23 means the key can be cheaply cloned without actually cloning the data. Finally, the data is 24 scrambled (overwritten with zeros) when the key is dropped to make sure it does not stay in 25 the memory past its lifetime. 26 """ 27 _shape: ClassVar[str] = "unnamed" 28 value: bytes 29 def __repr__(self) -> str: 30 return f"{type(self).__name__}(******)"
Symmetric encryption/decryption secret key.
Note: this implementation tries to prevent certain types of attacks by making sure the
underlying sensitive key material is always stored at most in one place. This is achieved by
putting it on the heap which means it is not moved when the key itself is moved which could
otherwise leave a copy of the data in memory. Additionally, the data is behind a Arc which
means the key can be cheaply cloned without actually cloning the data. Finally, the data is
scrambled (overwritten with zeros) when the key is dropped to make sure it does not stay in
the memory past its lifetime.
1772class Session: 1773 def __init__(self, client: Client): 1774 """@private""" 1775 self._client = client 1776 1777 async def add_user_provided_peers( 1778 self, 1779 *, 1780 addrs: list[str], 1781 ): 1782 """ 1783 Adds peers to connect to. 1784 1785 Normally peers are discovered automatically (using Bittorrent DHT, Peer exchange or Local 1786 discovery) but this function is useful in case when the discovery is not available for any 1787 reason (e.g. in an isolated network). 1788 1789 Note that peers added with this function are remembered across restarts. To forget peers, 1790 use [Self::session_remove_user_provided_peers]. 1791 """ 1792 request = Request_SessionAddUserProvidedPeers( 1793 addrs, 1794 ) 1795 response = await self._client.invoke(request) 1796 if isinstance(response, Response_Unit): 1797 return 1798 raise UnexpectedResponse() 1799 1800 async def bind_metrics( 1801 self, 1802 *, 1803 addr: str | None = None, 1804 ): 1805 request = Request_SessionBindMetrics( 1806 addr, 1807 ) 1808 response = await self._client.invoke(request) 1809 if isinstance(response, Response_Unit): 1810 return 1811 raise UnexpectedResponse() 1812 1813 async def bind_network( 1814 self, 1815 *, 1816 addrs: list[str], 1817 ): 1818 """ 1819 Binds the network listeners to the specified interfaces. 1820 1821 Up to four listeners can be bound, one for each combination of protocol (TCP or QUIC) and IP 1822 family (IPv4 or IPv6). The format of the interfaces is "PROTO/IP:PORT" where PROTO is "tcp" 1823 or "quic". If IP is IPv6, it needs to be enclosed in square brackets. 1824 1825 If port is `0`, binds to a random port initially but on subsequent starts tries to use the 1826 same port (unless it's already taken). This can be useful to configuring port forwarding. 1827 """ 1828 request = Request_SessionBindNetwork( 1829 addrs, 1830 ) 1831 response = await self._client.invoke(request) 1832 if isinstance(response, Response_Unit): 1833 return 1834 raise UnexpectedResponse() 1835 1836 async def bind_remote_control( 1837 self, 1838 *, 1839 addr: str | None = None, 1840 ) -> int: 1841 request = Request_SessionBindRemoteControl( 1842 addr, 1843 ) 1844 response = await self._client.invoke(request) 1845 if isinstance(response, Response_U16): 1846 return response.value 1847 raise UnexpectedResponse() 1848 1849 async def copy( 1850 self, 1851 *, 1852 src_repo: str | None = None, 1853 src_path: str, 1854 dst_repo: str | None = None, 1855 dst_path: str, 1856 ): 1857 """ 1858 Copy file or directory into, from or between repositories 1859 1860 - `src_repo`: Name of the repository from which file will be copied. 1861 - `src_path`: Path of to the entry to be copied. If `src_repo` is set, the `src_path` is 1862 relative to the corresponding repository root. If `src_repo` is null, `src_path` is 1863 interpreted as path on the local file system. 1864 - `dst_repo`: Name of the repository into which the entry will be copied. 1865 - `dst_path`: Destination entry 1866 """ 1867 request = Request_SessionCopy( 1868 src_repo, 1869 src_path, 1870 dst_repo, 1871 dst_path, 1872 ) 1873 response = await self._client.invoke(request) 1874 if isinstance(response, Response_Unit): 1875 return 1876 raise UnexpectedResponse() 1877 1878 async def create_repository( 1879 self, 1880 *, 1881 path: str, 1882 read_secret: SetLocalSecret | None = None, 1883 write_secret: SetLocalSecret | None = None, 1884 token: str | None = None, 1885 sync_enabled: bool = False, 1886 dht_enabled: bool = False, 1887 pex_enabled: bool = False, 1888 ) -> Repository: 1889 """ 1890 Creates a new repository. 1891 1892 - `path`: path to the repository file or name of the repository. 1893 - `read_secret`: local secret for reading the repository on this device only. Do not share 1894 with peers!. If null, the repo won't be protected and anyone with physical access to the 1895 device will be able to read it. 1896 - `write_secret`: local secret for writing to the repository on this device only. Do not 1897 share with peers! Can be the same as `read_secret` if one wants to use only one secret 1898 for both reading and writing. Separate secrets are useful for plausible deniability. If 1899 both `read_secret` and `write_secret` are `None`, the repo won't be protected and anyone 1900 with physical access to the device will be able to read and write to it. If `read_secret` 1901 is not `None` but `write_secret` is `None`, the repo won't be writable from this device. 1902 - `token`: used to share repositories between devices. If not `None`, this repo will be 1903 linked with the repos with the same token on other devices. See also 1904 [Self::repository_share]. This also determines the maximal access mode the repo can be 1905 opened in. If `None`, it's *write* mode. 1906 """ 1907 request = Request_SessionCreateRepository( 1908 path, 1909 read_secret, 1910 write_secret, 1911 token, 1912 sync_enabled, 1913 dht_enabled, 1914 pex_enabled, 1915 ) 1916 response = await self._client.invoke(request) 1917 if isinstance(response, Response_Repository): 1918 return Repository(self._client, response.value) 1919 raise UnexpectedResponse() 1920 1921 async def delete_repository_by_name( 1922 self, 1923 *, 1924 name: str, 1925 ): 1926 """Delete a repository with the given name.""" 1927 request = Request_SessionDeleteRepositoryByName( 1928 name, 1929 ) 1930 response = await self._client.invoke(request) 1931 if isinstance(response, Response_Unit): 1932 return 1933 raise UnexpectedResponse() 1934 1935 async def derive_secret_key( 1936 self, 1937 *, 1938 password: Password, 1939 salt: PasswordSalt, 1940 ) -> SecretKey: 1941 request = Request_SessionDeriveSecretKey( 1942 password, 1943 salt, 1944 ) 1945 response = await self._client.invoke(request) 1946 if isinstance(response, Response_SecretKey): 1947 return response.value 1948 raise UnexpectedResponse() 1949 1950 async def find_repository( 1951 self, 1952 *, 1953 name: str, 1954 ) -> Repository: 1955 request = Request_SessionFindRepository( 1956 name, 1957 ) 1958 response = await self._client.invoke(request) 1959 if isinstance(response, Response_Repository): 1960 return Repository(self._client, response.value) 1961 raise UnexpectedResponse() 1962 1963 async def generate_password_salt( 1964 self, 1965 ) -> PasswordSalt: 1966 request = Request_SessionGeneratePasswordSalt() 1967 response = await self._client.invoke(request) 1968 if isinstance(response, Response_PasswordSalt): 1969 return response.value 1970 raise UnexpectedResponse() 1971 1972 async def generate_secret_key( 1973 self, 1974 ) -> SecretKey: 1975 request = Request_SessionGenerateSecretKey() 1976 response = await self._client.invoke(request) 1977 if isinstance(response, Response_SecretKey): 1978 return response.value 1979 raise UnexpectedResponse() 1980 1981 async def get_current_protocol_version( 1982 self, 1983 ) -> int: 1984 """ 1985 Returns our Ouisync protocol version. 1986 1987 In order to establish connections with peers, they must use the same protocol version as 1988 us. 1989 1990 See also [Self::session_get_highest_seen_protocol_version] 1991 """ 1992 request = Request_SessionGetCurrentProtocolVersion() 1993 response = await self._client.invoke(request) 1994 if isinstance(response, Response_U64): 1995 return response.value 1996 raise UnexpectedResponse() 1997 1998 async def get_default_block_expiration( 1999 self, 2000 ) -> int | None: 2001 request = Request_SessionGetDefaultBlockExpiration() 2002 response = await self._client.invoke(request) 2003 if isinstance(response, Response_Duration): 2004 return response.value 2005 if isinstance(response, Response_None): 2006 return None 2007 raise UnexpectedResponse() 2008 2009 async def get_default_quota( 2010 self, 2011 ) -> StorageSize | None: 2012 request = Request_SessionGetDefaultQuota() 2013 response = await self._client.invoke(request) 2014 if isinstance(response, Response_StorageSize): 2015 return response.value 2016 if isinstance(response, Response_None): 2017 return None 2018 raise UnexpectedResponse() 2019 2020 async def get_default_repository_expiration( 2021 self, 2022 ) -> int | None: 2023 request = Request_SessionGetDefaultRepositoryExpiration() 2024 response = await self._client.invoke(request) 2025 if isinstance(response, Response_Duration): 2026 return response.value 2027 if isinstance(response, Response_None): 2028 return None 2029 raise UnexpectedResponse() 2030 2031 async def get_dht_routers( 2032 self, 2033 ) -> list[str]: 2034 """ 2035 Returns the current DHT routers (bootstrap nodes). If the routers haven't been changed by 2036 the user yet, returns the default routers. 2037 """ 2038 request = Request_SessionGetDhtRouters() 2039 response = await self._client.invoke(request) 2040 if isinstance(response, Response_Strings): 2041 return response.value 2042 raise UnexpectedResponse() 2043 2044 async def get_external_addr_v4( 2045 self, 2046 ) -> str | None: 2047 request = Request_SessionGetExternalAddrV4() 2048 response = await self._client.invoke(request) 2049 if isinstance(response, Response_SocketAddr): 2050 return response.value 2051 if isinstance(response, Response_None): 2052 return None 2053 raise UnexpectedResponse() 2054 2055 async def get_external_addr_v6( 2056 self, 2057 ) -> str | None: 2058 request = Request_SessionGetExternalAddrV6() 2059 response = await self._client.invoke(request) 2060 if isinstance(response, Response_SocketAddr): 2061 return response.value 2062 if isinstance(response, Response_None): 2063 return None 2064 raise UnexpectedResponse() 2065 2066 async def get_highest_seen_protocol_version( 2067 self, 2068 ) -> int: 2069 """ 2070 Returns the highest protocol version of all known peers. 2071 2072 If this is higher than [our version](Self::session_get_current_protocol_version) it likely 2073 means we are using an outdated version of Ouisync. When a peer with higher protocol version 2074 is found, a [NetworkEvent::ProtocolVersionMismatch] is emitted. 2075 """ 2076 request = Request_SessionGetHighestSeenProtocolVersion() 2077 response = await self._client.invoke(request) 2078 if isinstance(response, Response_U64): 2079 return response.value 2080 raise UnexpectedResponse() 2081 2082 async def get_local_listener_addrs( 2083 self, 2084 ) -> list[str]: 2085 """Returns the listener addresses of this Ouisync instance.""" 2086 request = Request_SessionGetLocalListenerAddrs() 2087 response = await self._client.invoke(request) 2088 if isinstance(response, Response_PeerAddrs): 2089 return response.value 2090 raise UnexpectedResponse() 2091 2092 async def get_metrics_listener_addr( 2093 self, 2094 ) -> str | None: 2095 request = Request_SessionGetMetricsListenerAddr() 2096 response = await self._client.invoke(request) 2097 if isinstance(response, Response_SocketAddr): 2098 return response.value 2099 if isinstance(response, Response_None): 2100 return None 2101 raise UnexpectedResponse() 2102 2103 async def get_mount_root( 2104 self, 2105 ) -> str | None: 2106 request = Request_SessionGetMountRoot() 2107 response = await self._client.invoke(request) 2108 if isinstance(response, Response_Path): 2109 return response.value 2110 if isinstance(response, Response_None): 2111 return None 2112 raise UnexpectedResponse() 2113 2114 async def get_nat_behavior( 2115 self, 2116 ) -> NatBehavior | None: 2117 request = Request_SessionGetNatBehavior() 2118 response = await self._client.invoke(request) 2119 if isinstance(response, Response_NatBehavior): 2120 return response.value 2121 if isinstance(response, Response_None): 2122 return None 2123 raise UnexpectedResponse() 2124 2125 async def get_network_stats( 2126 self, 2127 ) -> Stats: 2128 request = Request_SessionGetNetworkStats() 2129 response = await self._client.invoke(request) 2130 if isinstance(response, Response_Stats): 2131 return response.value 2132 raise UnexpectedResponse() 2133 2134 async def get_peers( 2135 self, 2136 ) -> list[PeerInfo]: 2137 """ 2138 Returns info about all known peers (both discovered and explicitly added). 2139 2140 When the set of known peers changes, a [NetworkEvent::PeerSetChange] is emitted. Calling 2141 this function afterwards returns the new peer info. 2142 """ 2143 request = Request_SessionGetPeers() 2144 response = await self._client.invoke(request) 2145 if isinstance(response, Response_PeerInfos): 2146 return response.value 2147 raise UnexpectedResponse() 2148 2149 async def get_remote_control_listener_addr( 2150 self, 2151 ) -> str | None: 2152 request = Request_SessionGetRemoteControlListenerAddr() 2153 response = await self._client.invoke(request) 2154 if isinstance(response, Response_SocketAddr): 2155 return response.value 2156 if isinstance(response, Response_None): 2157 return None 2158 raise UnexpectedResponse() 2159 2160 async def get_remote_listener_addrs( 2161 self, 2162 *, 2163 host: str, 2164 ) -> list[str]: 2165 """ 2166 Returns the listener addresses of the specified remote Ouisync instance. Works only if the 2167 remote control API is enabled on the remote instance. Typically used with cache servers. 2168 """ 2169 request = Request_SessionGetRemoteListenerAddrs( 2170 host, 2171 ) 2172 response = await self._client.invoke(request) 2173 if isinstance(response, Response_PeerAddrs): 2174 return response.value 2175 raise UnexpectedResponse() 2176 2177 async def get_runtime_id( 2178 self, 2179 ) -> PublicRuntimeId: 2180 """ 2181 Returns the runtime id of this Ouisync instance. 2182 2183 The runtime id is a unique identifier of this instance which is randomly generated every 2184 time Ouisync starts. 2185 """ 2186 request = Request_SessionGetRuntimeId() 2187 response = await self._client.invoke(request) 2188 if isinstance(response, Response_PublicRuntimeId): 2189 return response.value 2190 raise UnexpectedResponse() 2191 2192 async def get_share_token_access_mode( 2193 self, 2194 *, 2195 token: str, 2196 ) -> AccessMode: 2197 """Returns the access mode that the given token grants.""" 2198 request = Request_SessionGetShareTokenAccessMode( 2199 token, 2200 ) 2201 response = await self._client.invoke(request) 2202 if isinstance(response, Response_AccessMode): 2203 return response.value 2204 raise UnexpectedResponse() 2205 2206 async def get_share_token_info_hash( 2207 self, 2208 *, 2209 token: str, 2210 ) -> str: 2211 """ 2212 Return the info-hash of the repository corresponding to the given token, formatted as hex 2213 string. 2214 2215 See also: [repository_get_info_hash] 2216 """ 2217 request = Request_SessionGetShareTokenInfoHash( 2218 token, 2219 ) 2220 response = await self._client.invoke(request) 2221 if isinstance(response, Response_String): 2222 return response.value 2223 raise UnexpectedResponse() 2224 2225 async def get_share_token_suggested_name( 2226 self, 2227 *, 2228 token: str, 2229 ) -> str: 2230 """Returns the suggested name for the repository corresponding to the given token.""" 2231 request = Request_SessionGetShareTokenSuggestedName( 2232 token, 2233 ) 2234 response = await self._client.invoke(request) 2235 if isinstance(response, Response_String): 2236 return response.value 2237 raise UnexpectedResponse() 2238 2239 async def get_state_monitor( 2240 self, 2241 *, 2242 path: list[MonitorId], 2243 ) -> typing.Any | None: 2244 request = Request_SessionGetStateMonitor( 2245 path, 2246 ) 2247 response = await self._client.invoke(request) 2248 if isinstance(response, Response_StateMonitor): 2249 return response.value 2250 if isinstance(response, Response_None): 2251 return None 2252 raise UnexpectedResponse() 2253 2254 async def get_store_dirs( 2255 self, 2256 ) -> list[str]: 2257 request = Request_SessionGetStoreDirs() 2258 response = await self._client.invoke(request) 2259 if isinstance(response, Response_Paths): 2260 return response.value 2261 raise UnexpectedResponse() 2262 2263 async def get_user_provided_peers( 2264 self, 2265 ) -> list[str]: 2266 request = Request_SessionGetUserProvidedPeers() 2267 response = await self._client.invoke(request) 2268 if isinstance(response, Response_PeerAddrs): 2269 return response.value 2270 raise UnexpectedResponse() 2271 2272 async def init_network( 2273 self, 2274 *, 2275 defaults: NetworkDefaults, 2276 ): 2277 """ 2278 Initializes the network according to the stored configuration. If a particular network 2279 parameter is not yet configured, falls back to the given defaults. 2280 """ 2281 request = Request_SessionInitNetwork( 2282 defaults, 2283 ) 2284 response = await self._client.invoke(request) 2285 if isinstance(response, Response_Unit): 2286 return 2287 raise UnexpectedResponse() 2288 2289 async def insert_store_dirs( 2290 self, 2291 *, 2292 paths: list[str], 2293 ): 2294 request = Request_SessionInsertStoreDirs( 2295 paths, 2296 ) 2297 response = await self._client.invoke(request) 2298 if isinstance(response, Response_Unit): 2299 return 2300 raise UnexpectedResponse() 2301 2302 async def is_local_dht_enabled( 2303 self, 2304 ) -> bool: 2305 """Checks whether local DHT is enabled.""" 2306 request = Request_SessionIsLocalDhtEnabled() 2307 response = await self._client.invoke(request) 2308 if isinstance(response, Response_Bool): 2309 return response.value 2310 raise UnexpectedResponse() 2311 2312 async def is_local_discovery_enabled( 2313 self, 2314 ) -> bool: 2315 """Is local discovery enabled?""" 2316 request = Request_SessionIsLocalDiscoveryEnabled() 2317 response = await self._client.invoke(request) 2318 if isinstance(response, Response_Bool): 2319 return response.value 2320 raise UnexpectedResponse() 2321 2322 async def is_pex_recv_enabled( 2323 self, 2324 ) -> bool: 2325 """Checks whether accepting peers discovered on the peer exchange is enabled.""" 2326 request = Request_SessionIsPexRecvEnabled() 2327 response = await self._client.invoke(request) 2328 if isinstance(response, Response_Bool): 2329 return response.value 2330 raise UnexpectedResponse() 2331 2332 async def is_pex_send_enabled( 2333 self, 2334 ) -> bool: 2335 request = Request_SessionIsPexSendEnabled() 2336 response = await self._client.invoke(request) 2337 if isinstance(response, Response_Bool): 2338 return response.value 2339 raise UnexpectedResponse() 2340 2341 async def is_port_forwarding_enabled( 2342 self, 2343 ) -> bool: 2344 """Is port forwarding (UPnP) enabled?""" 2345 request = Request_SessionIsPortForwardingEnabled() 2346 response = await self._client.invoke(request) 2347 if isinstance(response, Response_Bool): 2348 return response.value 2349 raise UnexpectedResponse() 2350 2351 async def list_repositories( 2352 self, 2353 ) -> dict[str, Repository]: 2354 request = Request_SessionListRepositories() 2355 response = await self._client.invoke(request) 2356 if isinstance(response, Response_Repositories): 2357 return {k: Repository(self._client, v) for k, v in response.value.items()} 2358 raise UnexpectedResponse() 2359 2360 async def mirror_exists( 2361 self, 2362 *, 2363 token: str, 2364 host: str, 2365 ) -> bool: 2366 request = Request_SessionMirrorExists( 2367 token, 2368 host, 2369 ) 2370 response = await self._client.invoke(request) 2371 if isinstance(response, Response_Bool): 2372 return response.value 2373 raise UnexpectedResponse() 2374 2375 async def open_network_socket_v4( 2376 self, 2377 ) -> NetworkSocket | None: 2378 """ 2379 Opens a side channel to the underlying IPv4 UDP socket. The side channel is used to 2380 send/receive raw UDP datagrams on the same socket that the sync protocol uses. This is 2381 useful to share the socket between different protocols for hole punching. 2382 2383 Returns `None` if QUIC IPv4 endpoint isn't bound (see [Self::session_bind_network]). 2384 """ 2385 request = Request_SessionOpenNetworkSocketV4() 2386 response = await self._client.invoke(request) 2387 if isinstance(response, Response_NetworkSocket): 2388 return NetworkSocket(self._client, response.value) 2389 if isinstance(response, Response_None): 2390 return None 2391 raise UnexpectedResponse() 2392 2393 async def open_network_socket_v6( 2394 self, 2395 ) -> NetworkSocket | None: 2396 """ 2397 Opens a side channel to the underlying IPv6 UDP socket. The side channel is used to 2398 send/receive raw UDP datagrams on the same socket that the sync protocol uses. This is 2399 useful to share the socket between different protocols for hole punching. 2400 2401 Returns `None` if QUIC IPv6 endpoint isn't bound (see [Self::session_bind_network]). 2402 """ 2403 request = Request_SessionOpenNetworkSocketV6() 2404 response = await self._client.invoke(request) 2405 if isinstance(response, Response_NetworkSocket): 2406 return NetworkSocket(self._client, response.value) 2407 if isinstance(response, Response_None): 2408 return None 2409 raise UnexpectedResponse() 2410 2411 async def open_network_stream( 2412 self, 2413 *, 2414 addr: str, 2415 topic_id: TopicId, 2416 ) -> NetworkStream: 2417 """Opens a raw byte streams to the given peer, bound to the given topic.""" 2418 request = Request_SessionOpenNetworkStream( 2419 addr, 2420 topic_id, 2421 ) 2422 response = await self._client.invoke(request) 2423 if isinstance(response, Response_NetworkStream): 2424 return NetworkStream(self._client, response.value) 2425 raise UnexpectedResponse() 2426 2427 async def open_repository( 2428 self, 2429 *, 2430 path: str, 2431 local_secret: LocalSecret | None = None, 2432 ) -> Repository: 2433 """ 2434 Opens an existing repository. 2435 2436 - `path`: path to the local file the repo is stored in. 2437 - `local_secret`: a local secret. See the `read_secret` and `write_secret` params in 2438 [Self::session_create_repository] for more details. If this repo uses local secret 2439 (s), this determines the access mode the repo is opened in: `read_secret` opens it 2440 in *read* mode, `write_secret` opens it in *write* mode and no secret or wrong secret 2441 opens it in *blind* mode. If this repo doesn't use local secret(s), the repo is opened in 2442 the maximal mode specified when the repo was created. 2443 """ 2444 request = Request_SessionOpenRepository( 2445 path, 2446 local_secret, 2447 ) 2448 response = await self._client.invoke(request) 2449 if isinstance(response, Response_Repository): 2450 return Repository(self._client, response.value) 2451 raise UnexpectedResponse() 2452 2453 async def pin_dht( 2454 self, 2455 ): 2456 """ 2457 Pin the DHT to ensure it starts and remains running even when there are no active DHT 2458 lookups and no DHT-enabled repositories. This is useful to prevent the DHT restarting 2459 between the lookups (which could be slow). 2460 """ 2461 request = Request_SessionPinDht() 2462 response = await self._client.invoke(request) 2463 if isinstance(response, Response_Unit): 2464 return 2465 raise UnexpectedResponse() 2466 2467 async def remove_store_dirs( 2468 self, 2469 *, 2470 paths: list[str], 2471 ): 2472 request = Request_SessionRemoveStoreDirs( 2473 paths, 2474 ) 2475 response = await self._client.invoke(request) 2476 if isinstance(response, Response_Unit): 2477 return 2478 raise UnexpectedResponse() 2479 2480 async def remove_user_provided_peers( 2481 self, 2482 *, 2483 addrs: list[str], 2484 ): 2485 """Removes peers previously added with [Self::session_add_user_provided_peers].""" 2486 request = Request_SessionRemoveUserProvidedPeers( 2487 addrs, 2488 ) 2489 response = await self._client.invoke(request) 2490 if isinstance(response, Response_Unit): 2491 return 2492 raise UnexpectedResponse() 2493 2494 async def set_default_block_expiration( 2495 self, 2496 *, 2497 value: int | None = None, 2498 ): 2499 request = Request_SessionSetDefaultBlockExpiration( 2500 value, 2501 ) 2502 response = await self._client.invoke(request) 2503 if isinstance(response, Response_Unit): 2504 return 2505 raise UnexpectedResponse() 2506 2507 async def set_default_quota( 2508 self, 2509 *, 2510 value: StorageSize | None = None, 2511 ): 2512 request = Request_SessionSetDefaultQuota( 2513 value, 2514 ) 2515 response = await self._client.invoke(request) 2516 if isinstance(response, Response_Unit): 2517 return 2518 raise UnexpectedResponse() 2519 2520 async def set_default_repository_expiration( 2521 self, 2522 *, 2523 value: int | None = None, 2524 ): 2525 request = Request_SessionSetDefaultRepositoryExpiration( 2526 value, 2527 ) 2528 response = await self._client.invoke(request) 2529 if isinstance(response, Response_Unit): 2530 return 2531 raise UnexpectedResponse() 2532 2533 async def set_dht_routers( 2534 self, 2535 *, 2536 routers: list[str], 2537 ): 2538 """ 2539 Changes the DHT routers (bootstrap nodes), rebootstraps the DHTs and restart any ongoing 2540 lookups. If this is not called, a default set of routers is used. Each router is specified 2541 as hostname + port or ip address + port. 2542 """ 2543 request = Request_SessionSetDhtRouters( 2544 routers, 2545 ) 2546 response = await self._client.invoke(request) 2547 if isinstance(response, Response_Unit): 2548 return 2549 raise UnexpectedResponse() 2550 2551 async def set_local_dht_enabled( 2552 self, 2553 *, 2554 enabled: bool = False, 2555 ): 2556 """ 2557 Set whether DHT on the local network or localhost is allowed. By default this is `false` 2558 because DHT is a global discovery mechanism and finding a local peer on it is unexpected 2559 (and could indicate malice). However, is some situations it's still useful to enable it 2560 (typically for testing). 2561 2562 Note: this option is currently experimental and unstable (semver extempt). It's possible it 2563 will be removed in the future. 2564 """ 2565 request = Request_SessionSetLocalDhtEnabled( 2566 enabled, 2567 ) 2568 response = await self._client.invoke(request) 2569 if isinstance(response, Response_Unit): 2570 return 2571 raise UnexpectedResponse() 2572 2573 async def set_local_discovery_enabled( 2574 self, 2575 *, 2576 enabled: bool = False, 2577 ): 2578 """Enables/disables local discovery.""" 2579 request = Request_SessionSetLocalDiscoveryEnabled( 2580 enabled, 2581 ) 2582 response = await self._client.invoke(request) 2583 if isinstance(response, Response_Unit): 2584 return 2585 raise UnexpectedResponse() 2586 2587 async def set_mount_root( 2588 self, 2589 *, 2590 path: str | None = None, 2591 ): 2592 request = Request_SessionSetMountRoot( 2593 path, 2594 ) 2595 response = await self._client.invoke(request) 2596 if isinstance(response, Response_Unit): 2597 return 2598 raise UnexpectedResponse() 2599 2600 async def set_pex_recv_enabled( 2601 self, 2602 *, 2603 enabled: bool = False, 2604 ): 2605 request = Request_SessionSetPexRecvEnabled( 2606 enabled, 2607 ) 2608 response = await self._client.invoke(request) 2609 if isinstance(response, Response_Unit): 2610 return 2611 raise UnexpectedResponse() 2612 2613 async def set_pex_send_enabled( 2614 self, 2615 *, 2616 enabled: bool = False, 2617 ): 2618 request = Request_SessionSetPexSendEnabled( 2619 enabled, 2620 ) 2621 response = await self._client.invoke(request) 2622 if isinstance(response, Response_Unit): 2623 return 2624 raise UnexpectedResponse() 2625 2626 async def set_port_forwarding_enabled( 2627 self, 2628 *, 2629 enabled: bool = False, 2630 ): 2631 """Enables/disables port forwarding (UPnP).""" 2632 request = Request_SessionSetPortForwardingEnabled( 2633 enabled, 2634 ) 2635 response = await self._client.invoke(request) 2636 if isinstance(response, Response_Unit): 2637 return 2638 raise UnexpectedResponse() 2639 2640 async def set_store_dirs( 2641 self, 2642 *, 2643 paths: list[str], 2644 ): 2645 request = Request_SessionSetStoreDirs( 2646 paths, 2647 ) 2648 response = await self._client.invoke(request) 2649 if isinstance(response, Response_Unit): 2650 return 2651 raise UnexpectedResponse() 2652 2653 async def unpin_dht( 2654 self, 2655 ): 2656 """ 2657 Unpin the DHT. If the DHT is not pinned and there are no more active DHT lookups and no 2658 DHT-enabled repositories, the DHT shuts down. 2659 """ 2660 request = Request_SessionUnpinDht() 2661 response = await self._client.invoke(request) 2662 if isinstance(response, Response_Unit): 2663 return 2664 raise UnexpectedResponse() 2665 2666 async def validate_share_token( 2667 self, 2668 *, 2669 token: str, 2670 ) -> str: 2671 """Checks whether the given string is a valid share token.""" 2672 request = Request_SessionValidateShareToken( 2673 token, 2674 ) 2675 response = await self._client.invoke(request) 2676 if isinstance(response, Response_ShareToken): 2677 return response.value 2678 raise UnexpectedResponse()
1777 async def add_user_provided_peers( 1778 self, 1779 *, 1780 addrs: list[str], 1781 ): 1782 """ 1783 Adds peers to connect to. 1784 1785 Normally peers are discovered automatically (using Bittorrent DHT, Peer exchange or Local 1786 discovery) but this function is useful in case when the discovery is not available for any 1787 reason (e.g. in an isolated network). 1788 1789 Note that peers added with this function are remembered across restarts. To forget peers, 1790 use [Self::session_remove_user_provided_peers]. 1791 """ 1792 request = Request_SessionAddUserProvidedPeers( 1793 addrs, 1794 ) 1795 response = await self._client.invoke(request) 1796 if isinstance(response, Response_Unit): 1797 return 1798 raise UnexpectedResponse()
Adds peers to connect to.
Normally peers are discovered automatically (using Bittorrent DHT, Peer exchange or Local discovery) but this function is useful in case when the discovery is not available for any reason (e.g. in an isolated network).
Note that peers added with this function are remembered across restarts. To forget peers, use [Self::session_remove_user_provided_peers].
1813 async def bind_network( 1814 self, 1815 *, 1816 addrs: list[str], 1817 ): 1818 """ 1819 Binds the network listeners to the specified interfaces. 1820 1821 Up to four listeners can be bound, one for each combination of protocol (TCP or QUIC) and IP 1822 family (IPv4 or IPv6). The format of the interfaces is "PROTO/IP:PORT" where PROTO is "tcp" 1823 or "quic". If IP is IPv6, it needs to be enclosed in square brackets. 1824 1825 If port is `0`, binds to a random port initially but on subsequent starts tries to use the 1826 same port (unless it's already taken). This can be useful to configuring port forwarding. 1827 """ 1828 request = Request_SessionBindNetwork( 1829 addrs, 1830 ) 1831 response = await self._client.invoke(request) 1832 if isinstance(response, Response_Unit): 1833 return 1834 raise UnexpectedResponse()
Binds the network listeners to the specified interfaces.
Up to four listeners can be bound, one for each combination of protocol (TCP or QUIC) and IP family (IPv4 or IPv6). The format of the interfaces is "PROTO/IP:PORT" where PROTO is "tcp" or "quic". If IP is IPv6, it needs to be enclosed in square brackets.
If port is 0, binds to a random port initially but on subsequent starts tries to use the
same port (unless it's already taken). This can be useful to configuring port forwarding.
1836 async def bind_remote_control( 1837 self, 1838 *, 1839 addr: str | None = None, 1840 ) -> int: 1841 request = Request_SessionBindRemoteControl( 1842 addr, 1843 ) 1844 response = await self._client.invoke(request) 1845 if isinstance(response, Response_U16): 1846 return response.value 1847 raise UnexpectedResponse()
1849 async def copy( 1850 self, 1851 *, 1852 src_repo: str | None = None, 1853 src_path: str, 1854 dst_repo: str | None = None, 1855 dst_path: str, 1856 ): 1857 """ 1858 Copy file or directory into, from or between repositories 1859 1860 - `src_repo`: Name of the repository from which file will be copied. 1861 - `src_path`: Path of to the entry to be copied. If `src_repo` is set, the `src_path` is 1862 relative to the corresponding repository root. If `src_repo` is null, `src_path` is 1863 interpreted as path on the local file system. 1864 - `dst_repo`: Name of the repository into which the entry will be copied. 1865 - `dst_path`: Destination entry 1866 """ 1867 request = Request_SessionCopy( 1868 src_repo, 1869 src_path, 1870 dst_repo, 1871 dst_path, 1872 ) 1873 response = await self._client.invoke(request) 1874 if isinstance(response, Response_Unit): 1875 return 1876 raise UnexpectedResponse()
Copy file or directory into, from or between repositories
src_repo: Name of the repository from which file will be copied.src_path: Path of to the entry to be copied. Ifsrc_repois set, thesrc_pathis relative to the corresponding repository root. Ifsrc_repois null,src_pathis interpreted as path on the local file system.dst_repo: Name of the repository into which the entry will be copied.dst_path: Destination entry
1878 async def create_repository( 1879 self, 1880 *, 1881 path: str, 1882 read_secret: SetLocalSecret | None = None, 1883 write_secret: SetLocalSecret | None = None, 1884 token: str | None = None, 1885 sync_enabled: bool = False, 1886 dht_enabled: bool = False, 1887 pex_enabled: bool = False, 1888 ) -> Repository: 1889 """ 1890 Creates a new repository. 1891 1892 - `path`: path to the repository file or name of the repository. 1893 - `read_secret`: local secret for reading the repository on this device only. Do not share 1894 with peers!. If null, the repo won't be protected and anyone with physical access to the 1895 device will be able to read it. 1896 - `write_secret`: local secret for writing to the repository on this device only. Do not 1897 share with peers! Can be the same as `read_secret` if one wants to use only one secret 1898 for both reading and writing. Separate secrets are useful for plausible deniability. If 1899 both `read_secret` and `write_secret` are `None`, the repo won't be protected and anyone 1900 with physical access to the device will be able to read and write to it. If `read_secret` 1901 is not `None` but `write_secret` is `None`, the repo won't be writable from this device. 1902 - `token`: used to share repositories between devices. If not `None`, this repo will be 1903 linked with the repos with the same token on other devices. See also 1904 [Self::repository_share]. This also determines the maximal access mode the repo can be 1905 opened in. If `None`, it's *write* mode. 1906 """ 1907 request = Request_SessionCreateRepository( 1908 path, 1909 read_secret, 1910 write_secret, 1911 token, 1912 sync_enabled, 1913 dht_enabled, 1914 pex_enabled, 1915 ) 1916 response = await self._client.invoke(request) 1917 if isinstance(response, Response_Repository): 1918 return Repository(self._client, response.value) 1919 raise UnexpectedResponse()
Creates a new repository.
path: path to the repository file or name of the repository.read_secret: local secret for reading the repository on this device only. Do not share with peers!. If null, the repo won't be protected and anyone with physical access to the device will be able to read it.write_secret: local secret for writing to the repository on this device only. Do not share with peers! Can be the same asread_secretif one wants to use only one secret for both reading and writing. Separate secrets are useful for plausible deniability. If bothread_secretandwrite_secretareNone, the repo won't be protected and anyone with physical access to the device will be able to read and write to it. Ifread_secretis notNonebutwrite_secretisNone, the repo won't be writable from this device.token: used to share repositories between devices. If notNone, this repo will be linked with the repos with the same token on other devices. See also [Self::repository_share]. This also determines the maximal access mode the repo can be opened in. IfNone, it's write mode.
1921 async def delete_repository_by_name( 1922 self, 1923 *, 1924 name: str, 1925 ): 1926 """Delete a repository with the given name.""" 1927 request = Request_SessionDeleteRepositoryByName( 1928 name, 1929 ) 1930 response = await self._client.invoke(request) 1931 if isinstance(response, Response_Unit): 1932 return 1933 raise UnexpectedResponse()
Delete a repository with the given name.
1935 async def derive_secret_key( 1936 self, 1937 *, 1938 password: Password, 1939 salt: PasswordSalt, 1940 ) -> SecretKey: 1941 request = Request_SessionDeriveSecretKey( 1942 password, 1943 salt, 1944 ) 1945 response = await self._client.invoke(request) 1946 if isinstance(response, Response_SecretKey): 1947 return response.value 1948 raise UnexpectedResponse()
1950 async def find_repository( 1951 self, 1952 *, 1953 name: str, 1954 ) -> Repository: 1955 request = Request_SessionFindRepository( 1956 name, 1957 ) 1958 response = await self._client.invoke(request) 1959 if isinstance(response, Response_Repository): 1960 return Repository(self._client, response.value) 1961 raise UnexpectedResponse()
1981 async def get_current_protocol_version( 1982 self, 1983 ) -> int: 1984 """ 1985 Returns our Ouisync protocol version. 1986 1987 In order to establish connections with peers, they must use the same protocol version as 1988 us. 1989 1990 See also [Self::session_get_highest_seen_protocol_version] 1991 """ 1992 request = Request_SessionGetCurrentProtocolVersion() 1993 response = await self._client.invoke(request) 1994 if isinstance(response, Response_U64): 1995 return response.value 1996 raise UnexpectedResponse()
Returns our Ouisync protocol version.
In order to establish connections with peers, they must use the same protocol version as us.
See also [Self::session_get_highest_seen_protocol_version]
1998 async def get_default_block_expiration( 1999 self, 2000 ) -> int | None: 2001 request = Request_SessionGetDefaultBlockExpiration() 2002 response = await self._client.invoke(request) 2003 if isinstance(response, Response_Duration): 2004 return response.value 2005 if isinstance(response, Response_None): 2006 return None 2007 raise UnexpectedResponse()
2009 async def get_default_quota( 2010 self, 2011 ) -> StorageSize | None: 2012 request = Request_SessionGetDefaultQuota() 2013 response = await self._client.invoke(request) 2014 if isinstance(response, Response_StorageSize): 2015 return response.value 2016 if isinstance(response, Response_None): 2017 return None 2018 raise UnexpectedResponse()
2020 async def get_default_repository_expiration( 2021 self, 2022 ) -> int | None: 2023 request = Request_SessionGetDefaultRepositoryExpiration() 2024 response = await self._client.invoke(request) 2025 if isinstance(response, Response_Duration): 2026 return response.value 2027 if isinstance(response, Response_None): 2028 return None 2029 raise UnexpectedResponse()
2031 async def get_dht_routers( 2032 self, 2033 ) -> list[str]: 2034 """ 2035 Returns the current DHT routers (bootstrap nodes). If the routers haven't been changed by 2036 the user yet, returns the default routers. 2037 """ 2038 request = Request_SessionGetDhtRouters() 2039 response = await self._client.invoke(request) 2040 if isinstance(response, Response_Strings): 2041 return response.value 2042 raise UnexpectedResponse()
Returns the current DHT routers (bootstrap nodes). If the routers haven't been changed by the user yet, returns the default routers.
2044 async def get_external_addr_v4( 2045 self, 2046 ) -> str | None: 2047 request = Request_SessionGetExternalAddrV4() 2048 response = await self._client.invoke(request) 2049 if isinstance(response, Response_SocketAddr): 2050 return response.value 2051 if isinstance(response, Response_None): 2052 return None 2053 raise UnexpectedResponse()
2055 async def get_external_addr_v6( 2056 self, 2057 ) -> str | None: 2058 request = Request_SessionGetExternalAddrV6() 2059 response = await self._client.invoke(request) 2060 if isinstance(response, Response_SocketAddr): 2061 return response.value 2062 if isinstance(response, Response_None): 2063 return None 2064 raise UnexpectedResponse()
2066 async def get_highest_seen_protocol_version( 2067 self, 2068 ) -> int: 2069 """ 2070 Returns the highest protocol version of all known peers. 2071 2072 If this is higher than [our version](Self::session_get_current_protocol_version) it likely 2073 means we are using an outdated version of Ouisync. When a peer with higher protocol version 2074 is found, a [NetworkEvent::ProtocolVersionMismatch] is emitted. 2075 """ 2076 request = Request_SessionGetHighestSeenProtocolVersion() 2077 response = await self._client.invoke(request) 2078 if isinstance(response, Response_U64): 2079 return response.value 2080 raise UnexpectedResponse()
Returns the highest protocol version of all known peers.
If this is higher than our version it likely means we are using an outdated version of Ouisync. When a peer with higher protocol version is found, a [NetworkEvent::ProtocolVersionMismatch] is emitted.
2082 async def get_local_listener_addrs( 2083 self, 2084 ) -> list[str]: 2085 """Returns the listener addresses of this Ouisync instance.""" 2086 request = Request_SessionGetLocalListenerAddrs() 2087 response = await self._client.invoke(request) 2088 if isinstance(response, Response_PeerAddrs): 2089 return response.value 2090 raise UnexpectedResponse()
Returns the listener addresses of this Ouisync instance.
2092 async def get_metrics_listener_addr( 2093 self, 2094 ) -> str | None: 2095 request = Request_SessionGetMetricsListenerAddr() 2096 response = await self._client.invoke(request) 2097 if isinstance(response, Response_SocketAddr): 2098 return response.value 2099 if isinstance(response, Response_None): 2100 return None 2101 raise UnexpectedResponse()
2103 async def get_mount_root( 2104 self, 2105 ) -> str | None: 2106 request = Request_SessionGetMountRoot() 2107 response = await self._client.invoke(request) 2108 if isinstance(response, Response_Path): 2109 return response.value 2110 if isinstance(response, Response_None): 2111 return None 2112 raise UnexpectedResponse()
2114 async def get_nat_behavior( 2115 self, 2116 ) -> NatBehavior | None: 2117 request = Request_SessionGetNatBehavior() 2118 response = await self._client.invoke(request) 2119 if isinstance(response, Response_NatBehavior): 2120 return response.value 2121 if isinstance(response, Response_None): 2122 return None 2123 raise UnexpectedResponse()
2134 async def get_peers( 2135 self, 2136 ) -> list[PeerInfo]: 2137 """ 2138 Returns info about all known peers (both discovered and explicitly added). 2139 2140 When the set of known peers changes, a [NetworkEvent::PeerSetChange] is emitted. Calling 2141 this function afterwards returns the new peer info. 2142 """ 2143 request = Request_SessionGetPeers() 2144 response = await self._client.invoke(request) 2145 if isinstance(response, Response_PeerInfos): 2146 return response.value 2147 raise UnexpectedResponse()
Returns info about all known peers (both discovered and explicitly added).
When the set of known peers changes, a [NetworkEvent::PeerSetChange] is emitted. Calling this function afterwards returns the new peer info.
2149 async def get_remote_control_listener_addr( 2150 self, 2151 ) -> str | None: 2152 request = Request_SessionGetRemoteControlListenerAddr() 2153 response = await self._client.invoke(request) 2154 if isinstance(response, Response_SocketAddr): 2155 return response.value 2156 if isinstance(response, Response_None): 2157 return None 2158 raise UnexpectedResponse()
2160 async def get_remote_listener_addrs( 2161 self, 2162 *, 2163 host: str, 2164 ) -> list[str]: 2165 """ 2166 Returns the listener addresses of the specified remote Ouisync instance. Works only if the 2167 remote control API is enabled on the remote instance. Typically used with cache servers. 2168 """ 2169 request = Request_SessionGetRemoteListenerAddrs( 2170 host, 2171 ) 2172 response = await self._client.invoke(request) 2173 if isinstance(response, Response_PeerAddrs): 2174 return response.value 2175 raise UnexpectedResponse()
Returns the listener addresses of the specified remote Ouisync instance. Works only if the remote control API is enabled on the remote instance. Typically used with cache servers.
2177 async def get_runtime_id( 2178 self, 2179 ) -> PublicRuntimeId: 2180 """ 2181 Returns the runtime id of this Ouisync instance. 2182 2183 The runtime id is a unique identifier of this instance which is randomly generated every 2184 time Ouisync starts. 2185 """ 2186 request = Request_SessionGetRuntimeId() 2187 response = await self._client.invoke(request) 2188 if isinstance(response, Response_PublicRuntimeId): 2189 return response.value 2190 raise UnexpectedResponse()
Returns the runtime id of this Ouisync instance.
The runtime id is a unique identifier of this instance which is randomly generated every time Ouisync starts.
2239 async def get_state_monitor( 2240 self, 2241 *, 2242 path: list[MonitorId], 2243 ) -> typing.Any | None: 2244 request = Request_SessionGetStateMonitor( 2245 path, 2246 ) 2247 response = await self._client.invoke(request) 2248 if isinstance(response, Response_StateMonitor): 2249 return response.value 2250 if isinstance(response, Response_None): 2251 return None 2252 raise UnexpectedResponse()
2272 async def init_network( 2273 self, 2274 *, 2275 defaults: NetworkDefaults, 2276 ): 2277 """ 2278 Initializes the network according to the stored configuration. If a particular network 2279 parameter is not yet configured, falls back to the given defaults. 2280 """ 2281 request = Request_SessionInitNetwork( 2282 defaults, 2283 ) 2284 response = await self._client.invoke(request) 2285 if isinstance(response, Response_Unit): 2286 return 2287 raise UnexpectedResponse()
Initializes the network according to the stored configuration. If a particular network parameter is not yet configured, falls back to the given defaults.
2302 async def is_local_dht_enabled( 2303 self, 2304 ) -> bool: 2305 """Checks whether local DHT is enabled.""" 2306 request = Request_SessionIsLocalDhtEnabled() 2307 response = await self._client.invoke(request) 2308 if isinstance(response, Response_Bool): 2309 return response.value 2310 raise UnexpectedResponse()
Checks whether local DHT is enabled.
2312 async def is_local_discovery_enabled( 2313 self, 2314 ) -> bool: 2315 """Is local discovery enabled?""" 2316 request = Request_SessionIsLocalDiscoveryEnabled() 2317 response = await self._client.invoke(request) 2318 if isinstance(response, Response_Bool): 2319 return response.value 2320 raise UnexpectedResponse()
Is local discovery enabled?
2322 async def is_pex_recv_enabled( 2323 self, 2324 ) -> bool: 2325 """Checks whether accepting peers discovered on the peer exchange is enabled.""" 2326 request = Request_SessionIsPexRecvEnabled() 2327 response = await self._client.invoke(request) 2328 if isinstance(response, Response_Bool): 2329 return response.value 2330 raise UnexpectedResponse()
Checks whether accepting peers discovered on the peer exchange is enabled.
2341 async def is_port_forwarding_enabled( 2342 self, 2343 ) -> bool: 2344 """Is port forwarding (UPnP) enabled?""" 2345 request = Request_SessionIsPortForwardingEnabled() 2346 response = await self._client.invoke(request) 2347 if isinstance(response, Response_Bool): 2348 return response.value 2349 raise UnexpectedResponse()
Is port forwarding (UPnP) enabled?
2351 async def list_repositories( 2352 self, 2353 ) -> dict[str, Repository]: 2354 request = Request_SessionListRepositories() 2355 response = await self._client.invoke(request) 2356 if isinstance(response, Response_Repositories): 2357 return {k: Repository(self._client, v) for k, v in response.value.items()} 2358 raise UnexpectedResponse()
2360 async def mirror_exists( 2361 self, 2362 *, 2363 token: str, 2364 host: str, 2365 ) -> bool: 2366 request = Request_SessionMirrorExists( 2367 token, 2368 host, 2369 ) 2370 response = await self._client.invoke(request) 2371 if isinstance(response, Response_Bool): 2372 return response.value 2373 raise UnexpectedResponse()
2375 async def open_network_socket_v4( 2376 self, 2377 ) -> NetworkSocket | None: 2378 """ 2379 Opens a side channel to the underlying IPv4 UDP socket. The side channel is used to 2380 send/receive raw UDP datagrams on the same socket that the sync protocol uses. This is 2381 useful to share the socket between different protocols for hole punching. 2382 2383 Returns `None` if QUIC IPv4 endpoint isn't bound (see [Self::session_bind_network]). 2384 """ 2385 request = Request_SessionOpenNetworkSocketV4() 2386 response = await self._client.invoke(request) 2387 if isinstance(response, Response_NetworkSocket): 2388 return NetworkSocket(self._client, response.value) 2389 if isinstance(response, Response_None): 2390 return None 2391 raise UnexpectedResponse()
Opens a side channel to the underlying IPv4 UDP socket. The side channel is used to send/receive raw UDP datagrams on the same socket that the sync protocol uses. This is useful to share the socket between different protocols for hole punching.
Returns None if QUIC IPv4 endpoint isn't bound (see [Self::session_bind_network]).
2393 async def open_network_socket_v6( 2394 self, 2395 ) -> NetworkSocket | None: 2396 """ 2397 Opens a side channel to the underlying IPv6 UDP socket. The side channel is used to 2398 send/receive raw UDP datagrams on the same socket that the sync protocol uses. This is 2399 useful to share the socket between different protocols for hole punching. 2400 2401 Returns `None` if QUIC IPv6 endpoint isn't bound (see [Self::session_bind_network]). 2402 """ 2403 request = Request_SessionOpenNetworkSocketV6() 2404 response = await self._client.invoke(request) 2405 if isinstance(response, Response_NetworkSocket): 2406 return NetworkSocket(self._client, response.value) 2407 if isinstance(response, Response_None): 2408 return None 2409 raise UnexpectedResponse()
Opens a side channel to the underlying IPv6 UDP socket. The side channel is used to send/receive raw UDP datagrams on the same socket that the sync protocol uses. This is useful to share the socket between different protocols for hole punching.
Returns None if QUIC IPv6 endpoint isn't bound (see [Self::session_bind_network]).
2411 async def open_network_stream( 2412 self, 2413 *, 2414 addr: str, 2415 topic_id: TopicId, 2416 ) -> NetworkStream: 2417 """Opens a raw byte streams to the given peer, bound to the given topic.""" 2418 request = Request_SessionOpenNetworkStream( 2419 addr, 2420 topic_id, 2421 ) 2422 response = await self._client.invoke(request) 2423 if isinstance(response, Response_NetworkStream): 2424 return NetworkStream(self._client, response.value) 2425 raise UnexpectedResponse()
Opens a raw byte streams to the given peer, bound to the given topic.
2427 async def open_repository( 2428 self, 2429 *, 2430 path: str, 2431 local_secret: LocalSecret | None = None, 2432 ) -> Repository: 2433 """ 2434 Opens an existing repository. 2435 2436 - `path`: path to the local file the repo is stored in. 2437 - `local_secret`: a local secret. See the `read_secret` and `write_secret` params in 2438 [Self::session_create_repository] for more details. If this repo uses local secret 2439 (s), this determines the access mode the repo is opened in: `read_secret` opens it 2440 in *read* mode, `write_secret` opens it in *write* mode and no secret or wrong secret 2441 opens it in *blind* mode. If this repo doesn't use local secret(s), the repo is opened in 2442 the maximal mode specified when the repo was created. 2443 """ 2444 request = Request_SessionOpenRepository( 2445 path, 2446 local_secret, 2447 ) 2448 response = await self._client.invoke(request) 2449 if isinstance(response, Response_Repository): 2450 return Repository(self._client, response.value) 2451 raise UnexpectedResponse()
Opens an existing repository.
path: path to the local file the repo is stored in.local_secret: a local secret. See theread_secretandwrite_secretparams in [Self::session_create_repository] for more details. If this repo uses local secret (s), this determines the access mode the repo is opened in:read_secretopens it in read mode,write_secretopens it in write mode and no secret or wrong secret opens it in blind mode. If this repo doesn't use local secret(s), the repo is opened in the maximal mode specified when the repo was created.
2453 async def pin_dht( 2454 self, 2455 ): 2456 """ 2457 Pin the DHT to ensure it starts and remains running even when there are no active DHT 2458 lookups and no DHT-enabled repositories. This is useful to prevent the DHT restarting 2459 between the lookups (which could be slow). 2460 """ 2461 request = Request_SessionPinDht() 2462 response = await self._client.invoke(request) 2463 if isinstance(response, Response_Unit): 2464 return 2465 raise UnexpectedResponse()
Pin the DHT to ensure it starts and remains running even when there are no active DHT lookups and no DHT-enabled repositories. This is useful to prevent the DHT restarting between the lookups (which could be slow).
2480 async def remove_user_provided_peers( 2481 self, 2482 *, 2483 addrs: list[str], 2484 ): 2485 """Removes peers previously added with [Self::session_add_user_provided_peers].""" 2486 request = Request_SessionRemoveUserProvidedPeers( 2487 addrs, 2488 ) 2489 response = await self._client.invoke(request) 2490 if isinstance(response, Response_Unit): 2491 return 2492 raise UnexpectedResponse()
Removes peers previously added with [Self::session_add_user_provided_peers].
2494 async def set_default_block_expiration( 2495 self, 2496 *, 2497 value: int | None = None, 2498 ): 2499 request = Request_SessionSetDefaultBlockExpiration( 2500 value, 2501 ) 2502 response = await self._client.invoke(request) 2503 if isinstance(response, Response_Unit): 2504 return 2505 raise UnexpectedResponse()
2507 async def set_default_quota( 2508 self, 2509 *, 2510 value: StorageSize | None = None, 2511 ): 2512 request = Request_SessionSetDefaultQuota( 2513 value, 2514 ) 2515 response = await self._client.invoke(request) 2516 if isinstance(response, Response_Unit): 2517 return 2518 raise UnexpectedResponse()
2520 async def set_default_repository_expiration( 2521 self, 2522 *, 2523 value: int | None = None, 2524 ): 2525 request = Request_SessionSetDefaultRepositoryExpiration( 2526 value, 2527 ) 2528 response = await self._client.invoke(request) 2529 if isinstance(response, Response_Unit): 2530 return 2531 raise UnexpectedResponse()
2533 async def set_dht_routers( 2534 self, 2535 *, 2536 routers: list[str], 2537 ): 2538 """ 2539 Changes the DHT routers (bootstrap nodes), rebootstraps the DHTs and restart any ongoing 2540 lookups. If this is not called, a default set of routers is used. Each router is specified 2541 as hostname + port or ip address + port. 2542 """ 2543 request = Request_SessionSetDhtRouters( 2544 routers, 2545 ) 2546 response = await self._client.invoke(request) 2547 if isinstance(response, Response_Unit): 2548 return 2549 raise UnexpectedResponse()
Changes the DHT routers (bootstrap nodes), rebootstraps the DHTs and restart any ongoing lookups. If this is not called, a default set of routers is used. Each router is specified as hostname + port or ip address + port.
2551 async def set_local_dht_enabled( 2552 self, 2553 *, 2554 enabled: bool = False, 2555 ): 2556 """ 2557 Set whether DHT on the local network or localhost is allowed. By default this is `false` 2558 because DHT is a global discovery mechanism and finding a local peer on it is unexpected 2559 (and could indicate malice). However, is some situations it's still useful to enable it 2560 (typically for testing). 2561 2562 Note: this option is currently experimental and unstable (semver extempt). It's possible it 2563 will be removed in the future. 2564 """ 2565 request = Request_SessionSetLocalDhtEnabled( 2566 enabled, 2567 ) 2568 response = await self._client.invoke(request) 2569 if isinstance(response, Response_Unit): 2570 return 2571 raise UnexpectedResponse()
Set whether DHT on the local network or localhost is allowed. By default this is false
because DHT is a global discovery mechanism and finding a local peer on it is unexpected
(and could indicate malice). However, is some situations it's still useful to enable it
(typically for testing).
Note: this option is currently experimental and unstable (semver extempt). It's possible it will be removed in the future.
2573 async def set_local_discovery_enabled( 2574 self, 2575 *, 2576 enabled: bool = False, 2577 ): 2578 """Enables/disables local discovery.""" 2579 request = Request_SessionSetLocalDiscoveryEnabled( 2580 enabled, 2581 ) 2582 response = await self._client.invoke(request) 2583 if isinstance(response, Response_Unit): 2584 return 2585 raise UnexpectedResponse()
Enables/disables local discovery.
2600 async def set_pex_recv_enabled( 2601 self, 2602 *, 2603 enabled: bool = False, 2604 ): 2605 request = Request_SessionSetPexRecvEnabled( 2606 enabled, 2607 ) 2608 response = await self._client.invoke(request) 2609 if isinstance(response, Response_Unit): 2610 return 2611 raise UnexpectedResponse()
2613 async def set_pex_send_enabled( 2614 self, 2615 *, 2616 enabled: bool = False, 2617 ): 2618 request = Request_SessionSetPexSendEnabled( 2619 enabled, 2620 ) 2621 response = await self._client.invoke(request) 2622 if isinstance(response, Response_Unit): 2623 return 2624 raise UnexpectedResponse()
2626 async def set_port_forwarding_enabled( 2627 self, 2628 *, 2629 enabled: bool = False, 2630 ): 2631 """Enables/disables port forwarding (UPnP).""" 2632 request = Request_SessionSetPortForwardingEnabled( 2633 enabled, 2634 ) 2635 response = await self._client.invoke(request) 2636 if isinstance(response, Response_Unit): 2637 return 2638 raise UnexpectedResponse()
Enables/disables port forwarding (UPnP).
2653 async def unpin_dht( 2654 self, 2655 ): 2656 """ 2657 Unpin the DHT. If the DHT is not pinned and there are no more active DHT lookups and no 2658 DHT-enabled repositories, the DHT shuts down. 2659 """ 2660 request = Request_SessionUnpinDht() 2661 response = await self._client.invoke(request) 2662 if isinstance(response, Response_Unit): 2663 return 2664 raise UnexpectedResponse()
Unpin the DHT. If the DHT is not pinned and there are no more active DHT lookups and no DHT-enabled repositories, the DHT shuts down.
86class SetLocalSecret: 87 """Used to set or change the read or write local secret of a repository.""" 88 _variants: ClassVar[dict[str, type]] = {}
Used to set or change the read or write local secret of a repository.
97@dataclass 98class SetLocalSecret_KeyAndSalt(SetLocalSecret): 99 """ 100 Use to directly (without doing password hashing) set the `SecretKey` and `PasswordSalt` for 101 read or write access. 102 """ 103 _tag: ClassVar[str] = "KeyAndSalt" 104 _shape: ClassVar[str] = "named" 105 key: SecretKey 106 salt: PasswordSalt
Use to directly (without doing password hashing) set the SecretKey and PasswordSalt for
read or write access.
90@dataclass 91class SetLocalSecret_Password(SetLocalSecret): 92 """Password provided by the user""" 93 _tag: ClassVar[str] = "Password" 94 _shape: ClassVar[str] = "unnamed" 95 value: Password
Password provided by the user
218@dataclass 219class Stats: 220 """Network traffic statistics.""" 221 _shape: ClassVar[str] = "named" 222 bytes_tx: int 223 bytes_rx: int 224 throughput_tx: int 225 throughput_rx: int
Network traffic statistics.
48@dataclass 49class StorageSize: 50 """Strongly typed storage size.""" 51 _shape: ClassVar[str] = "named" 52 bytes: int
Strongly typed storage size.
247@dataclass 248class TopicId: 249 """ 250 Identified of a network stream topic. 251 252 When two connected peers open a stream with the same topic id, they can communicate over it with 253 each other. 254 """ 255 _shape: ClassVar[str] = "unnamed" 256 value: bytes
Identified of a network stream topic.
When two connected peers open a stream with the same topic id, they can communicate over it with each other.
3633class UnexpectedResponse(OuisyncError): 3634 def __init__(self): 3635 super().__init__(ErrorCode.INVALID_DATA, "unexpected response")
Common base class for all non-exit exceptions.
5@dataclass(frozen=True, order=True) 6class MonitorId: 7 name: str 8 disambiguator: int 9 10 @staticmethod 11 def parse(raw: str) -> "MonitorId": 12 name, _, disambiguator = raw.rpartition(":") 13 return MonitorId(name, int(disambiguator)) 14 15 def __str__(self) -> str: 16 return f"{self.name}:{self.disambiguator}"