[][src]Struct discv5::service::Service

pub(crate) struct Service {
    events: VecDeque<ServiceEvent>,
    config: Discv5Config,
    enr: Enr<CombinedKey>,
    key: CombinedKey,
    pending_requests: TimedRequests,
    pending_messages: HashMap<NodeId, Vec<ProtocolMessage>>,
    sessions: TimedSessions,
    transport: Transport,
}

Fields

events: VecDeque<ServiceEvent>

Queue of events produced by the session service.

config: Discv5Config

Configuration for the discv5 service.

enr: Enr<CombinedKey>

The local ENR.

key: CombinedKey

The key to sign the ENR and set up encrypted communication with peers.

pending_requests: TimedRequests

Pending raw requests. A list of raw messages we are awaiting a response from the remote. These are indexed by SocketAddr as WHOAREYOU messages do not return a source node id to match against.

pending_messages: HashMap<NodeId, Vec<ProtocolMessage>>

Pending messages. Messages awaiting to be sent, once a handshake has been established.

sessions: TimedSessions

Sessions that have been created for each node id. These can be established or awaiting response from remote nodes.

transport: Transport

The discovery v5 UDP service.

Implementations

impl Service[src]

pub(crate) fn new(
    enr: Enr<CombinedKey>,
    key: CombinedKey,
    listen_socket: SocketAddr,
    config: Discv5Config
) -> Result<Self, Discv5Error>
[src]

A new Session service which instantiates the UDP socket.

pub(crate) fn enr(&self) -> &Enr<CombinedKey>[src]

The local ENR of the service.

pub(crate) fn enr_insert(
    &mut self,
    key: &str,
    value: Vec<u8>
) -> Result<Option<Vec<u8>>, EnrError>
[src]

Generic function to modify a field in the local ENR.

pub(crate) fn update_local_enr_socket(
    &mut self,
    socket: SocketAddr,
    is_tcp: bool
) -> Result<(), EnrError>
[src]

Updates the local ENR SocketAddr for either the TCP or UDP port.

pub(crate) fn update_enr(&mut self, enr: Enr<CombinedKey>)[src]

Updates a session if a new ENR or an updated ENR is discovered.

pub(crate) fn send_request(
    &mut self,
    dst_enr: &Enr<CombinedKey>,
    message: ProtocolMessage
) -> Result<(), Discv5Error>
[src]

Sends a ProtocolMessage request to a known ENR. It is possible to send requests to IP addresses not related to the ENR.

pub(crate) fn send_request_unknown_enr(
    &mut self,
    dst: SocketAddr,
    dst_id: &NodeId,
    message: ProtocolMessage
) -> Result<(), Discv5Error>
[src]

Similar to send_request but for requests which an ENR may be unknown. A session is therefore assumed to be valid.

pub(crate) fn send_response(
    &mut self,
    dst: SocketAddr,
    dst_id: &NodeId,
    message: ProtocolMessage
) -> Result<(), Discv5Error>
[src]

Sends an RPC Response. This differs from send request as responses do not require a known ENR to send messages and session's should already be established.

pub(crate) fn send_whoareyou(
    &mut self,
    dst: SocketAddr,
    node_id: &NodeId,
    enr_seq: u64,
    remote_enr: Option<Enr<CombinedKey>>,
    auth_tag: AuthTag
)
[src]

This is called in response to a ServiceMessage::WhoAreYou event. The protocol finds the highest known ENR then calls this function to send a WHOAREYOU packet.

fn src_id(&self, tag: &Tag) -> NodeId[src]

Calculates the src NodeId given a tag.

fn tag(&self, dst_id: &NodeId) -> Tag[src]

Calculates the tag given a NodeId.

fn handle_whoareyou(
    &mut self,
    src: SocketAddr,
    token: AuthTag,
    id_nonce: Nonce,
    enr_seq: u64
) -> Result<(), ()>
[src]

Handles a WHOAREYOU packet that was received from the network.

fn handle_auth_message(
    &mut self,
    src: SocketAddr,
    tag: Tag,
    auth_header: AuthHeader,
    message: &[u8]
) -> Result<(), ()>
[src]

Handle a message that contains an authentication header.

fn handle_message(
    &mut self,
    src: SocketAddr,
    src_id: NodeId,
    auth_tag: AuthTag,
    message: &[u8],
    tag: Tag
) -> Result<(), ()>
[src]

Handle a standard message that does not contain an authentication header.

fn flush_messages(&mut self, dst: SocketAddr, dst_id: &NodeId) -> Result<(), ()>[src]

Encrypts and sends any messages that were waiting for a session to be established.

fn process_request(
    &mut self,
    dst: SocketAddr,
    dst_id: NodeId,
    packet: Packet,
    message: Option<ProtocolMessage>
)
[src]

Wrapper around transport.send() that adds all sent messages to the pending_requests. This builds a request adds a timeout and sends the request.

fn check_timeouts(&mut self, cx: &mut Context)[src]

The heartbeat which checks for timeouts and reports back failed RPC requests/sessions.

Trait Implementations

impl Stream for Service[src]

type Item = ServiceEvent

Values yielded by the stream.

Auto Trait Implementations

impl !RefUnwindSafe for Service

impl Send for Service

impl Sync for Service

impl Unpin for Service

impl !UnwindSafe for Service

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> StreamExt for T where
    T: Stream + ?Sized
[src]

impl<St> StreamExt for St where
    St: Stream + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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