Skip to main content

Peer

Struct Peer 

Source
pub struct Peer { /* private fields */ }
Available on crate feature client only.
Expand description

A connected platform: the version agreed with it, where its endpoints are, and the token to authenticate with.

A Peer is built by the registration handshake or, for a connection that was established before this process started, from stored state with Peer::builder.

use ocpi_kit::client::Peer;
use ocpi_kit::transport::CredentialsToken;
use ocpi_kit::types::{PartyRef, Url};
use ocpi_kit::{InterfaceRole, ModuleId, VersionNumber};

let peer = Peer::builder(VersionNumber::V2_3_0, CredentialsToken::new("token-c")?)
    .versions_url(Url::new("https://cpo.example.com/ocpi/versions")?)
    .endpoint(ModuleId::Locations, InterfaceRole::Sender,
              Url::new("https://cpo.example.com/ocpi/cpo/2.3.0/locations")?)
    .party(PartyRef::new("NL", "TNM")?)
    .build();

assert!(peer.implements(&ModuleId::Locations, InterfaceRole::Sender));
assert!(!peer.implements(&ModuleId::Cdrs, InterfaceRole::Sender));

Implementations§

Source§

impl Peer

Convenience constructors hanging off a Peer.

Source

pub fn module<'a>( &'a self, transport: &'a Transport, module: ModuleId, from: PartyRef, ) -> ModuleClient<'a>

A client for an arbitrary module.

Source

pub fn locations<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> LocationsSender<'a>

The Locations Sender client: pull Locations from this peer.

Source

pub fn locations_receiver<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> LocationsReceiver<'a>

The Locations Receiver client: push Locations to this peer.

Source

pub fn tokens<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> TokensSender<'a>

The Tokens Sender client: pull Tokens from, and authorize against, this peer.

Source

pub fn cdrs<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> CdrsClient<'a>

The CDRs client.

Source

pub fn tokens_receiver<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> TokensReceiver<'a>

The Tokens Receiver client: push Tokens to this peer.

Source

pub fn sessions<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> SessionsSender<'a>

The Sessions Sender client: pull Sessions from this peer.

Source

pub fn sessions_receiver<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> SessionsReceiver<'a>

The Sessions Receiver client: push Sessions to this peer.

Source

pub fn tariffs<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> TariffsSender<'a>

The Tariffs Sender client: pull Tariffs from this peer.

Source

pub fn tariffs_receiver<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> TariffsReceiver<'a>

The Tariffs Receiver client: push Tariffs to this peer.

Source

pub fn commands<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> CommandsClient<'a>

The Commands client.

Source

pub fn charging_profiles<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> ChargingProfilesClient<'a>

The Charging Profiles client.

Source

pub fn hub_client_info<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> HubClientInfoClient<'a>

The Hub Client Info client.

Source

pub fn payments<'a>( &'a self, transport: &'a Transport, from: PartyRef, ) -> PaymentsClient<'a>

The Payments client.

Source§

impl Peer

Source

pub fn builder(version: VersionNumber, token: CredentialsToken) -> PeerBuilder

Starts building a peer that was registered in a previous run of this process.

Source

pub const fn version(&self) -> &VersionNumber

The OCPI version agreed with this peer.

Source

pub const fn token(&self) -> &CredentialsToken

The credentials token to authenticate requests to this peer with.

Source

pub const fn versions_url(&self) -> Option<&Url>

The peer’s /versions endpoint.

Source

pub fn parties(&self) -> &[PartyRef]

The parties this peer speaks for, from the roles of its credentials.

Source

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

The hub this peer routes through, if it declared one.

Source

pub const fn quirks(&self) -> &Quirks

The interoperability profile for this peer.

Source

pub fn set_quirks(&mut self, quirks: Quirks)

Replaces the interoperability profile.

Source

pub fn set_token(&mut self, token: CredentialsToken)

Replaces the credentials token, as a credentials PUT does.

Source

pub fn implements(&self, module: &ModuleId, role: InterfaceRole) -> bool

Whether the peer implements a module in a given role.

Source

pub fn endpoint_url( &self, module: &ModuleId, role: InterfaceRole, ) -> Option<&Url>

The peer’s URL for a module and role.

Module identifiers are matched case-insensitively when Quirks::case_insensitive_module_ids is on, which matters for the Booking module.

Source

pub fn sender(&self, module: &ModuleId) -> Option<SenderEndpoint>

The Sender-interface endpoint of a module.

Source

pub fn receiver(&self, module: &ModuleId) -> Option<ReceiverEndpoint>

The Receiver-interface endpoint of a module.

Source

pub fn credentials_url(&self) -> Option<&Url>

The credentials endpoint, ignoring the advertised role as the specification instructs.

Source

pub fn endpoints( &self, ) -> impl Iterator<Item = (&ModuleId, InterfaceRole, &Url)>

Every endpoint the peer advertised.

Source

pub fn update_endpoints(&mut self, details: &VersionDetails)

Replaces the endpoint map from freshly fetched version details.

A credentials PUT requires this: “The server must fetch the client’s endpoints again, even if the version has not changed.”

Source

pub fn routing_for(&self, party: Option<&PartyRef>) -> RoutingScenario

The routing scenario for a direct request to party, or an open request when the destination is unknown.

Source

pub fn default_party(&self) -> Option<&PartyRef>

The party to address a functional request to, when the caller did not name one.

A peer that speaks for exactly one party needs no explicit to.

Trait Implementations§

Source§

impl Clone for Peer

Source§

fn clone(&self) -> Peer

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 Peer

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Peer

§

impl RefUnwindSafe for Peer

§

impl Send for Peer

§

impl Sync for Peer

§

impl Unpin for Peer

§

impl UnsafeUnpin for Peer

§

impl UnwindSafe for Peer

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

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
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> 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, 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