pub struct RelayContext { /* private fields */ }Expand description
Relay connection context
This manages the state for a single relay connection, including:
- Key exchange state
- Encryption key
- Invoke ID counter
Implementations§
Source§impl RelayContext
impl RelayContext
Sourcepub fn set_target_public_key(&mut self, public_key: Vec<u8>)
pub fn set_target_public_key(&mut self, public_key: Vec<u8>)
Set the target’s public key for signature verification
Sourcepub fn next_invoke_id(&self) -> u64
pub fn next_invoke_id(&self) -> u64
Get the next invoke ID
Sourcepub fn state(&self) -> &RelayState
pub fn state(&self) -> &RelayState
Get current state
Sourcepub fn public_key_bytes(&self) -> [u8; 32]
pub fn public_key_bytes(&self) -> [u8; 32]
Get our public key bytes
Sourcepub fn public_key_base64(&self) -> String
pub fn public_key_base64(&self) -> String
Get our public key as base64 (SubjectPublicKeyInfo DER, matching JS client)
Sourcepub fn create_key_exchange_request(&mut self, token: &str) -> InvokeRequest
pub fn create_key_exchange_request(&mut self, token: &str) -> InvokeRequest
Create the initial key exchange request
This is the first message sent on the Invoke stream.
Sourcepub fn process_key_exchange_response(
&mut self,
key_exchange: &InvokeRequestKeyExchange,
) -> Result<()>
pub fn process_key_exchange_response( &mut self, key_exchange: &InvokeRequestKeyExchange, ) -> Result<()>
Process the key exchange response
This verifies the signature and derives the shared encryption key.
Sourcepub fn encrypt(&self, plaintext: &[u8]) -> Result<(Vec<u8>, [u8; 16])>
pub fn encrypt(&self, plaintext: &[u8]) -> Result<(Vec<u8>, [u8; 16])>
Encrypt a payload for sending
Sourcepub fn decrypt(&self, ciphertext: &[u8], iv: &[u8]) -> Result<Vec<u8>>
pub fn decrypt(&self, ciphertext: &[u8], iv: &[u8]) -> Result<Vec<u8>>
Decrypt a received payload
Sourcepub fn create_encrypted_request(
&self,
invoke_id: u64,
remote_response: &RemoteResponse,
) -> Result<InvokeRequest>
pub fn create_encrypted_request( &self, invoke_id: u64, remote_response: &RemoteResponse, ) -> Result<InvokeRequest>
Create an encrypted InvokeRequest wrapping a RemoteResponse
Note: In the relay protocol, the client sends “responses” to the relay which forwards them to the target Volt (which treats them as requests).
Sourcepub fn parse_response(
&mut self,
response: &InvokeResponse,
) -> Result<Option<RemoteRequest>>
pub fn parse_response( &mut self, response: &InvokeResponse, ) -> Result<Option<RemoteRequest>>
Parse an InvokeResponse and extract the RemoteRequest
Handles both key exchange responses and encrypted payload responses.
Sourcepub fn create_method_invoke(
&self,
invoke_id: u64,
service_id: &str,
method_name: &str,
method_type: MethodType,
request_data: Vec<u8>,
) -> RemoteResponse
pub fn create_method_invoke( &self, invoke_id: u64, service_id: &str, method_name: &str, method_type: MethodType, request_data: Vec<u8>, ) -> RemoteResponse
Create a MethodInvoke payload for calling a service method
Sourcepub fn create_method_payload(
&self,
invoke_id: u64,
payload: Vec<u8>,
) -> RemoteResponse
pub fn create_method_payload( &self, invoke_id: u64, payload: Vec<u8>, ) -> RemoteResponse
Create a MethodPayload for streaming data
Sourcepub fn create_method_end(&self, invoke_id: u64) -> RemoteResponse
pub fn create_method_end(&self, invoke_id: u64) -> RemoteResponse
Create a MethodEnd to signal end of stream
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for RelayContext
impl RefUnwindSafe for RelayContext
impl Send for RelayContext
impl Sync for RelayContext
impl Unpin for RelayContext
impl UnwindSafe for RelayContext
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request