[][src]Crate koibumi_node

This crate is a Bitmessage node implementation as a library for Koibumi, an experimental Bitmessage client.

See koibumi for more about the application. See Bitmessage for more about the protocol.

Examples

use std::str::FromStr;

use async_std::task;
use futures::{sink::SinkExt, stream::StreamExt};

use koibumi_node::{self as node, db, Command, Config, Event, Response};

let (command_sender, mut response_receiver, handle) = node::spawn();

let config = Config::builder()
    .server(Some("127.0.0.1:8444".parse().unwrap()))
    .socks(Some("127.0.0.1:9050".parse().unwrap()))
    .connect_to_onion(true)
    .connect_to_ip(true)
    .seeds(vec!["quzwelsuziwqgpt2.onion:8444".parse().unwrap()])
    .build();

let mut sender = command_sender;
let response = task::block_on(async {
    let pool = db::SqlitePool::connect_with(
        sqlx::sqlite::SqliteConnectOptions::from_str("sqlite::memory:").unwrap()
    ).await;
    if let Err(err) = pool {
        eprintln!("{}", err);
        return None;
    }
    let pool = pool.unwrap();

    if let Err(err) = sender.send(Command::Start(config.into(), pool, Vec::new())).await {
        eprintln!("{}", err);
        return None;
    }
    response_receiver.next().await
});
let Response::Started(mut receiver) = response.unwrap();

task::block_on(async {
    while let Some(event) = receiver.next().await {
        match event {
            Event::ConnectionCounts { .. } => (),
            Event::AddrCount(_count) => (),
            Event::Established { addr, user_agent, rating } => {
                println!("established: {} {} rating:{}", addr, user_agent, rating);
            }
            Event::Disconnected { addr } => {
                println!("disconnected: {}", addr);
            }
            Event::Objects { .. } => (),
            Event::Stopped => {
                break;
            }
            Event::Broadcast {
                user_id,
                address,
                object,
            } => {
                println!("broadcast received from {}", address);
            }
            Event::Msg {
                user_id,
                address,
                object,
            } => {
                println!("received msg for {}", address);
            }
        }
    }

    handle.await;
});

Modules

db

Provides wrappers for database interfaces.

Structs

Config

A set of configurations for a Koibumi Bitmessage node.

ConfigBuilder

A builder for building a configuration set for a Koibumi Bitmessage node.

Rating

A rating of the connectivity of a node.

SocksAuth

Represents a username and a password used to authenticate SOCKS5 connection.

User

An object represents an user.

Enums

Command

The commands which accepted by a node.

Event

The events which occur in a Bitmessage node.

Response

The responses to the commands.

SocketAddrNode

A bootstrap socket address or an extended socket address.

Functions

run

Runs an event loop that manage a Bitmessage node.

spawn

Spawns a task that manage a Bitmessage node.