SecretConnection

Struct SecretConnection 

Source
pub struct SecretConnection<Io> { /* private fields */ }
Expand description

Encrypted connection between peers in a CometBFT network.

§Sending and receiving messages

The SecretConnection type implements a message-oriented interface which can send and receive Protobuf-encoded messages that impl the prost::Message trait.

The ReadMsg and WriteMsg traits can be used for sending/receiving Protobuf messages.

§Connection integrity and failures

Due to the underlying encryption mechanism (currently RFC 8439), when a read or write failure occurs, it is necessary to disconnect from the remote peer and attempt to reconnect.

Implementations§

Source§

impl<Io: Read + Write + Send + Sync + TryCloneIo> SecretConnection<Io>

Source

pub fn new<Identity>(io: Io, identity_key: &Identity) -> Result<Self>
where Identity: Signer<Signature>, VerifyingKey: for<'a> From<&'a Identity>,

Performs a handshake and returns a new SecretConnection, authenticating ourselves with the provided Identity (Ed25519 signing key).

The IdentitySecret type can be used as an identity_key.

§Errors
  • if sharing of the pubkey fails
  • if sharing of the signature fails
  • if receiving the signature fails
  • if verifying the signature fails
Source§

impl<Io: Write> SecretConnection<Io>

Source

pub fn flush(&mut self) -> Result<()>

Flush the underlying I/O object’s write buffer.

Source§

impl<Io> SecretConnection<Io>

Source

pub fn local_public_key(&self) -> &PublicKey

Get the local (i.e. our) PublicKey.

Source

pub fn peer_public_key(&self) -> &PublicKey

Returns the remote peer’s PublicKey.

Source

pub fn split(self) -> (SecretReader<Io>, SecretWriter<Io>)

Split this SecretConnection into a SecretReader and SecretWriter which can be used independently of each other.

Trait Implementations§

Source§

impl<M: Message + Default, Io: Read> ReadMsg<M> for SecretConnection<Io>

Source§

fn read_msg(&mut self) -> Result<M>

Read from the underlying I/O object, decoding (and if necessary decrypting) the data to the given Protobuf message.
Source§

impl<M: Message, Io: Write> WriteMsg<M> for SecretConnection<Io>

Source§

fn write_msg(&mut self, msg: &M) -> Result<()>

Encode the given Protobuf as bytes and write them to the underlying I/O object (and encrypting if necessary).

Auto Trait Implementations§

§

impl<Io> Freeze for SecretConnection<Io>
where Io: Freeze,

§

impl<Io> RefUnwindSafe for SecretConnection<Io>
where Io: RefUnwindSafe,

§

impl<Io> Send for SecretConnection<Io>
where Io: Send,

§

impl<Io> Sync for SecretConnection<Io>
where Io: Sync,

§

impl<Io> Unpin for SecretConnection<Io>
where Io: Unpin,

§

impl<Io> UnwindSafe for SecretConnection<Io>
where Io: UnwindSafe,

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, 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> Same for T

Source§

type Output = T

Should always be Self
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.