Skip to main content

Connection

Struct Connection 

Source
pub struct Connection { /* private fields */ }
Expand description

ノードとの TLS の接続。Symbol のパケットで要求を送り、応答を受け取る。

こちらからつないだ接続も、相手から受けた接続もある。どちらでも相手のチェーンは catapult と同じ条件で 確かめる。drop すると TLS の close_notify を送って閉じる。

Implementations§

Source§

impl Connection

Source

pub fn open( address: &str, identity: &Identity, timeout: Duration, ) -> Result<Self, ConnectError>

address に接続してハンドシェイクを済ませる。読み書きは timeout で打ち切る。

Source

pub fn peer_key(&self) -> Option<PublicKey>

相手のノードの鍵(相手のチェーンの CA の公開鍵)。チェーンはハンドシェイクで確かめてある

Source

pub fn accept( socket: TcpStream, config: Arc<ServerConfig>, capabilities: &[&str], timeout: Duration, ) -> Result<Self, ConnectError>

受け付けた socket で、server_config で作った config のハンドシェイクを済ませる。 読み書きは timeout で打ち切る。相手が heika なら、capabilities をこちらができることとして伝える。

相手が ALPN を出していても、ALPN がなければ選ばずに続ける(rustls は、重なるものがなければ切る)。 版を上げた heika や、ほかの名前を出すものとも、今までどおりつながるように。

Source

pub fn is_heika(&self) -> bool

相手も heika で、heika だけのパケットを使えるか

Source

pub fn peer_capabilities(&self) -> Option<&[String]>

相手から届いた capability。相手が heika でないか、まだ届いていなければ None

Source

pub fn set_read_timeout(&self, timeout: Option<Duration>) -> Result<()>

読むときのタイムアウト。None なら、届くまで待つ

Source

pub fn set_write_timeout(&self, timeout: Option<Duration>) -> Result<()>

書くときのタイムアウト。None なら、書けるまで待つ

Source

pub fn peer_certificates(&self) -> Vec<Vec<u8>>

相手が出した証明書の DER。ノード、CA の順のはず。

Source

pub fn request( &mut self, packet_type: u32, body: &[u8], max_body_size: usize, ) -> Result<Vec<u8>, RequestError>

種類が packet_type で本体が body の要求を送り、同じ種類の応答を1つ受け取って本体を返す。 応答の本体が max_body_size を超えるなら、読まずに失敗する。

Source

pub fn send_packet( &mut self, packet_type: u32, body: &[u8], ) -> Result<(), RequestError>

種類が packet_type で本体が body のパケットを1つ送る。

Source

pub fn receive_packet( &mut self, max_body_size: usize, ) -> Result<(u32, Vec<u8>), RequestError>

パケットを1つ受け取って、種類と本体を返す。本体が max_body_size を超えるなら、読まずに失敗する。

相手も heika なら、heika だけのパケットのうち capability はここで扱って返さない。覚えて、まだ送って いなければこちらのものを返す。名前つきの拡張の封筒(extension::ENVELOPE)は返す。知らない種類は読み捨てる

Trait Implementations§

Source§

impl Debug for Connection

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for Connection

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

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.