Skip to main content

RelayContext

Struct RelayContext 

Source
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

Source

pub fn new(target_did: String) -> Self

Create a new relay context

Source

pub fn set_target_public_key(&mut self, public_key: Vec<u8>)

Set the target’s public key for signature verification

Source

pub fn next_invoke_id(&self) -> u64

Get the next invoke ID

Source

pub fn state(&self) -> &RelayState

Get current state

Source

pub fn public_key_bytes(&self) -> [u8; 32]

Get our public key bytes

Source

pub fn public_key_base64(&self) -> String

Get our public key as base64 (SubjectPublicKeyInfo DER, matching JS client)

Source

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.

Source

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.

Source

pub fn encrypt(&self, plaintext: &[u8]) -> Result<(Vec<u8>, [u8; 16])>

Encrypt a payload for sending

Source

pub fn decrypt(&self, ciphertext: &[u8], iv: &[u8]) -> Result<Vec<u8>>

Decrypt a received payload

Source

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).

Source

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.

Source

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

Source

pub fn create_method_payload( &self, invoke_id: u64, payload: Vec<u8>, ) -> RemoteResponse

Create a MethodPayload for streaming data

Source

pub fn create_method_end(&self, invoke_id: u64) -> RemoteResponse

Create a MethodEnd to signal end of stream

Trait Implementations§

Source§

impl Debug for RelayContext

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more