Skip to main content

Forwarder

Struct Forwarder 

Source
pub struct Forwarder<'a> { /* private fields */ }
Available on crate feature hub only.
Expand description

Relays requests to the platforms in a RoutingTable.

Implementations§

Source§

impl<'a> Forwarder<'a>

Source

pub fn new( transport: &'a Transport, table: &'a RoutingTable, hub: PartyRef, ) -> Self

A forwarder for the hub party hub.

Source

pub const fn on_unbridgeable(self, policy: Unbridgeable) -> Self

What to do with a message between two versions this build cannot translate.

Source

pub const fn report_losses(self, report: bool) -> Self

Whether a translation’s losses are appended to the response’s status_message. On by default; switch it off for a peer that treats status_message as machine-readable.

Source

pub const fn hub(&self) -> &PartyRef

The hub’s own party reference.

Source

pub async fn relay( &self, request: &Forwardable, to: &PartyRef, routing: RoutingHeaders, ) -> Relayed

Relays one request to the party the OCPI-to-* headers name.

The forwarded request gets a new X-Request-ID and the same X-Correlation-ID:

When a Hub forwards a request to a party, the request to this party SHALL contain a new unique value in the X-Request-ID HTTP header, not a copy … the request SHALL contain the same X-Correlation-ID HTTP header.

§Errors

Returns the 4xxx code that fits: 4001 when the destination is unknown, 4003 when it is not connected, 4002 on a timeout, 4000 otherwise.

Spec: 2.3.0 §transport_and_format_unique_messageg_ids, §status_codes_4xxx_hub_errors

Source

pub async fn broadcast( &self, request: &Forwardable, sender_role: Role, ) -> Vec<Relayed>

Fans a Broadcast Push out to every party with an opposite role.

When using Broadcast Push, the Hub broadcasts received information to all connected clients … This means only one request to the Hub will be necessary.

Every target is attempted; the results are returned in full so the caller decides what to tell the sender. aggregate implements the usual policy.

Spec: 2.3.0 §transport_and_format_message_routing_broadcast_push

Source

pub async fn open_route( &self, request: &Forwardable, router: &dyn OpenRouter, ) -> Result<Relayed, OcpiError>

Answers an Open Routing Request by asking the router to pick a destination.

When a Hub has the intelligence to route messages based on the content of the request … The Hub can then decide to which party a request needs to be routed, or that it needs to be broadcasted if the destination cannot be determined.

§Errors

Returns 4001 when the router cannot decide.

Spec: 2.3.0 §transport_and_format_message_routing_open_routing_request

Source

pub async fn get_all(&self, request: &Forwardable) -> Vec<Relayed>

Answers a GET All by asking every party that implements the Sender interface.

The Hub can then combine objects from different connected parties and return them to the client. The client can determine the owner of the objects by looking at the country_code and party_id in the individual objects returned by the hub.

Because ownership is carried inside each object, merging is a concatenation; the hub does not have to rewrite anything, and — importantly — “the last_updated fields SHALL NOT be updated by the Hub”.

Spec: 2.3.0 §transport_and_format_get_all_via_hubs

Trait Implementations§

Source§

impl<'a> Debug for Forwarder<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Forwarder<'a>

§

impl<'a> !UnwindSafe for Forwarder<'a>

§

impl<'a> Freeze for Forwarder<'a>

§

impl<'a> Send for Forwarder<'a>

§

impl<'a> Sync for Forwarder<'a>

§

impl<'a> Unpin for Forwarder<'a>

§

impl<'a> UnsafeUnpin for Forwarder<'a>

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

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

Source§

type Error = !

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