Skip to main content

PacketEncoder

Trait PacketEncoder 

Source
pub trait PacketEncoder {
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn encode_packet<T: AsRef<[u8]> + Send + 'static, S: Into<PacketSignals> + Send + 'static>(
        &self,
        data: T,
        routing: ResolvedTransportRouting<HoprSurb>,
        signals: S,
        generation: Option<u8>,
    ) -> Result<OutgoingPacket, Self::Error>;
    fn encode_acknowledgements(
        &self,
        acks: &[VerifiedAcknowledgement],
        destination: &OffchainPublicKey,
    ) -> Result<OutgoingPacket, Self::Error>;
}
Expand description

Trait defining encoder for outgoing HOPR packets.

These operations are done directly by the packet processing pipeline before the outgoing packet is handled to the underlying p2p transport.

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

Required Methods§

Source

fn encode_packet<T: AsRef<[u8]> + Send + 'static, S: Into<PacketSignals> + Send + 'static>( &self, data: T, routing: ResolvedTransportRouting<HoprSurb>, signals: S, generation: Option<u8>, ) -> Result<OutgoingPacket, Self::Error>

Encodes the given data and signals for sending.

The data MUST be already correctly sized for HOPR packets, otherwise the operation must fail.

generation is the SURB-batch generation to stamp onto SURBs minted for a forward packet’s return paths, captured when those return paths were resolved (see PathPlanner::resolve_routing). It must be captured with the plan rather than read here, so a concurrent return-path re-plan cannot label an already-chosen batch with a newer generation. None (no return path, or a non-forward packet) falls back to the store’s current generation.

Source

fn encode_acknowledgements( &self, acks: &[VerifiedAcknowledgement], destination: &OffchainPublicKey, ) -> Result<OutgoingPacket, Self::Error>

Encodes the given vector of VerifiedAcknowledgements as an outgoing packet to be sent to the given destination.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl<'a, U: 'a + PacketEncoder + ?Sized> PacketEncoder for &'a U

Source§

type Error = <U as PacketEncoder>::Error

Source§

fn encode_packet<T: AsRef<[u8]> + Send + 'static, S: Into<PacketSignals> + Send + 'static>( &self, data: T, routing: ResolvedTransportRouting<HoprSurb>, signals: S, generation: Option<u8>, ) -> Result<OutgoingPacket, Self::Error>

Source§

fn encode_acknowledgements( &self, acks: &[VerifiedAcknowledgement], destination: &OffchainPublicKey, ) -> Result<OutgoingPacket, Self::Error>

Source§

impl<U: PacketEncoder + ?Sized> PacketEncoder for Arc<U>

Source§

type Error = <U as PacketEncoder>::Error

Source§

fn encode_packet<T: AsRef<[u8]> + Send + 'static, S: Into<PacketSignals> + Send + 'static>( &self, data: T, routing: ResolvedTransportRouting<HoprSurb>, signals: S, generation: Option<u8>, ) -> Result<OutgoingPacket, Self::Error>

Source§

fn encode_acknowledgements( &self, acks: &[VerifiedAcknowledgement], destination: &OffchainPublicKey, ) -> Result<OutgoingPacket, Self::Error>

Source§

impl<U: PacketEncoder + ?Sized> PacketEncoder for Box<U>

Source§

type Error = <U as PacketEncoder>::Error

Source§

fn encode_packet<T: AsRef<[u8]> + Send + 'static, S: Into<PacketSignals> + Send + 'static>( &self, data: T, routing: ResolvedTransportRouting<HoprSurb>, signals: S, generation: Option<u8>, ) -> Result<OutgoingPacket, Self::Error>

Source§

fn encode_acknowledgements( &self, acks: &[VerifiedAcknowledgement], destination: &OffchainPublicKey, ) -> Result<OutgoingPacket, Self::Error>

Implementors§

Source§

impl<Chain, G, S, T> PacketEncoder for HoprEncoder<Chain, G, S, T>
where Chain: ChainKeyOperations + ChainReadChannelOperations + ChainReadTicketOperations + ChainValues + Send + Sync, G: EntryShareGenerator<HoprPixSpec>, S: SurbStore + Send + Sync, T: TicketFactory + Send + Sync,