Skip to main content

TestPeer

Struct TestPeer 

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

Отдельный одноразовый узел GNUnet для интеграционных тестов. Создаётся через TestPeer::start; при уничтожении останавливает узел.

Implementations§

Source§

impl TestPeer

Source

pub fn config(&self) -> &Config

Конфигурация узла: её передают в connect сервисов.

Source

pub fn home(&self) -> &Path

Временный каталог с данными узла; удаляется вместе с ним.

Source

pub fn config_path(&self) -> &Path

Путь к файлу конфигурации узла, например для запуска программ GNUnet с ключом -c.

Source

pub fn runtime_dir(&self) -> &Path

Изолированная директория UNIXPATH-сокетов этого пира (GNUNET_RUNTIME_DIR) — нужна, например, чтобы дать другому TestPeer возможность обменяться HELLO без коллизии сокетов.

Source

pub fn export_hello(&self, timeout: Duration) -> Result<Vec<u8>, TestPeerError>

Экспортировать HELLO этого пира (сырые байты, бинарный формат) — через нативный gnunet-hello -e -b.

Сразу после start() PILS ещё может не успеть сгенерировать и подписать identity этого пира: экспорт в этом окне возвращает HELLO с нулевым временем истечения — который любой импортёр (в том числе сам GNUNET_PEERSTORE_hello_add, см. import_hello ниже) корректно отклоняет как просроченный (см. docs/research/gnunet-bugreports.md, BUG-004: gnunet-hello -i раньше на такой отказ просто зависал навсегда вместо явной ошибки — здесь пофикшено). Ретраим с бэкоффом вместо однократной попытки — то же самое окно ожидания, что wait_until_ready уже делает для самого ARM.

Source

pub fn export_addressed_hello( &self, timeout: Duration, ) -> Result<Vec<u8>, TestPeerError>

Как TestPeer::export_hello, но дожидается HELLO, в котором есть хотя бы один адрес: по HELLO без адресов соединиться нельзя.

Source

pub async fn suggest_transport_connection( &self, runtime: &GnunetRuntime, peer: PeerId, peer_hello: Vec<u8>, ) -> Result<TransportSuggestion, TestPeerError>

Просит TRANSPORT этого узла установить и держать соединение с узлом peer, адреса которого даны в peer_hello. Соединение поддерживается, пока живо возвращённое значение.

Source

pub fn import_hello(&self, hello: &[u8]) -> Result<(), TestPeerError>

Передаёт этому узлу чужой HELLO, полученный через TestPeer::export_hello другого узла (программой gnunet-hello -i). После этого узел знает адреса того узла.

Source

pub fn start() -> TestPeerStartBuilder

Запускает отдельный узел через gnunet-arm.

services — имена сервисов, которые нужно запустить дополнительно к тем, что стартуют сами. startup_timeout (по умолчанию 10 с) — сколько ждать готовности узла.

Trait Implementations§

Source§

impl Drop for TestPeer

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, 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.