Skip to main content

WebSocketOperation

Enum WebSocketOperation 

Source
pub enum WebSocketOperation {
    Connect {
        url: RexUrl,
        rex_id: RexId,
    },
    Read {
        connection_rex_id: RexId,
        mode: WebSocketReadMode,
    },
    Send {
        connection_rex_id: RexId,
        messages: Vec<RexValue>,
    },
    Close {
        connection_rex_id: RexId,
    },
}
Expand description

WebSocket operation types for the WebSocket REX.

This enum defines the different operations that can be performed on WebSocket connections. All WebSocket operations are handled through a single TargetRexProgram::WebSocket variant.

§Variants

  • Connect - Establish a new WebSocket connection to an external server
  • Read - Read the latest data from an existing WebSocket connection

§Future Extensions

Additional operations like Send and Close may be added in the future.

Variants§

§

Connect

Establish a new WebSocket connection.

When this operation is executed:

  • A validator is randomly selected to handle the connection
  • The TEE establishes the WebSocket connection to the specified URL
  • On success, the connection is registered in the WebSocket Registry
  • The assigned validator is recorded for future routing

Fields

§url: RexUrl

WebSocket URL (typically wss://…)

§rex_id: RexId

The RexId that represents this connection request

§

Read

Read data from an existing WebSocket connection.

When this operation is executed:

  • The operation is automatically routed to the TEE holding the connection
  • Returns messages from the connection’s buffer based on the read mode
  • The referenced connection must exist and be active

§Read Modes

  • Latest (default): Returns only the most recent message
  • All: Returns all accumulated messages in the buffer
  • FromIndex(n): Returns all messages with index > n, with gap detection

§Validation

The handler implementation must verify that:

  • connection_rex_id references an existing Connect operation in the WebSocket Registry
  • The connection is still active and hasn’t been closed
  • The requesting validator has permission to read from this connection

§Error Handling

If validation fails, the REX should return an appropriate error indicating:

  • ConnectionNotFound - if the referenced REX ID doesn’t exist
  • ConnectionClosed - if the connection has been terminated
  • InvalidConnectionType - if the referenced REX is not a WebSocket Connect operation

Fields

§connection_rex_id: RexId

References the RexId of the Connect operation that established the connection

§mode: WebSocketReadMode

The read mode determining which messages to return (defaults to Latest for backward compatibility)

§

Send

Send messages to an existing WebSocket connection.

When this operation is executed:

  • The operation is automatically routed to the TEE holding the connection
  • Each RexValue in messages is sent as a separate WebSocket message
  • The inner value is extracted: Plain(String) → sent as-is, Encrypted(String) → decrypted then sent
  • Returns the number of messages successfully sent
  • The referenced connection must exist and be active

§Validation

The handler implementation must verify that:

  • connection_rex_id references an existing Connect operation in the WebSocket Registry
  • The connection is still active and hasn’t been closed
  • The requesting validator has permission to send to this connection

§Error Handling

If validation fails, the REX should return an appropriate error indicating:

  • ConnectionNotFound - if the referenced REX ID doesn’t exist
  • ConnectionClosed - if the connection has been terminated
  • InvalidConnectionType - if the referenced REX is not a WebSocket Connect operation
  • SecretDecryptionFailed - if an encrypted message cannot be decrypted

Fields

§connection_rex_id: RexId

References the RexId of the Connect operation that established the connection

§messages: Vec<RexValue>

Messages to send to the WebSocket connection Each RexValue will be sent as a separate WebSocket message

§

Close

Close an existing WebSocket connection.

When this operation is executed:

  • The operation is automatically routed to the TEE holding the connection
  • The WebSocket connection is gracefully closed
  • The connection status in the WebSocket Registry is updated to Closed
  • The referenced connection must exist and be active

§Validation

The handler implementation must verify that:

  • connection_rex_id references an existing Connect operation in the WebSocket Registry
  • The requesting validator has permission to close this connection

§Error Handling

If validation fails, the REX should return an appropriate error indicating:

  • ConnectionNotFound - if the referenced REX ID doesn’t exist
  • ConnectionAlreadyClosed - if the connection has already been terminated
  • InvalidConnectionType - if the referenced REX is not a WebSocket Connect operation

Fields

§connection_rex_id: RexId

References the RexId of the Connect operation to close

Implementations§

Source§

impl WebSocketOperation

Source

pub fn connect(url: impl Into<RexUrl>, rex_id: RexId) -> Self

Create a new Connect operation.

Source

pub fn read(connection_rex_id: RexId) -> Self

Create a new Read operation with default Latest mode.

Source

pub fn read_with_mode(connection_rex_id: RexId, mode: WebSocketReadMode) -> Self

Create a new Read operation with a specific mode.

Source

pub fn send(connection_rex_id: RexId, messages: Vec<RexValue>) -> Self

Create a new Send operation.

Source

pub fn close(connection_rex_id: RexId) -> Self

Create a new Close operation.

Source

pub fn is_connect(&self) -> bool

Returns true if this is a Connect operation.

Source

pub fn is_read(&self) -> bool

Returns true if this is a Read operation.

Source

pub fn is_send(&self) -> bool

Returns true if this is a Send operation.

Source

pub fn is_close(&self) -> bool

Returns true if this is a Close operation.

Source

pub fn url(&self) -> Option<&RexUrl>

Returns the URL if this is a Connect operation, None otherwise.

Source

pub fn rex_id(&self) -> Option<&RexId>

Returns the rex_id if this is a Connect operation, None otherwise.

Source

pub fn connection_rex_id(&self) -> Option<&RexId>

Returns the connection_rex_id if this is a Read, Send, or Close operation, None otherwise.

Source

pub fn read_mode(&self) -> Option<&WebSocketReadMode>

Returns the read mode if this is a Read operation, None otherwise.

Source

pub fn messages(&self) -> Option<&[RexValue]>

Returns the messages if this is a Send operation, None otherwise.

Trait Implementations§

Source§

impl BorshDeserialize for WebSocketOperation

Source§

fn deserialize_reader<__R: Read>(reader: &mut __R) -> Result<Self, Error>

Source§

fn deserialize(buf: &mut &[u8]) -> Result<Self, Error>

Deserializes this instance from a given slice of bytes. Updates the buffer to point at the remaining bytes.
Source§

fn try_from_slice(v: &[u8]) -> Result<Self, Error>

Deserialize this instance from a slice of bytes.
Source§

fn try_from_reader<R>(reader: &mut R) -> Result<Self, Error>
where R: Read,

Source§

impl BorshSerialize for WebSocketOperation

Source§

fn serialize<__W: Write>(&self, writer: &mut __W) -> Result<(), Error>

Source§

impl Clone for WebSocketOperation

Source§

fn clone(&self) -> WebSocketOperation

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for WebSocketOperation

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for WebSocketOperation

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for WebSocketOperation

Source§

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

Formats the value using the given formatter. Read more
Source§

impl EnumExt for WebSocketOperation

Source§

fn deserialize_variant<__R: Read>( reader: &mut __R, variant_tag: u8, ) -> Result<Self, Error>

Deserialises given variant of an enum from the reader. Read more
Source§

impl Eq for WebSocketOperation

Source§

impl PartialEq for WebSocketOperation

Source§

fn eq(&self, other: &WebSocketOperation) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for WebSocketOperation

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for WebSocketOperation

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoRexValueFor<T> for T
where T: BorshSerialize,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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<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