[][src]Crate koibumi_node_sync

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

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

Examples

use std::{path::PathBuf, str::FromStr};

use koibumi_node_sync::{self as node, 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 = {
    let db_path = PathBuf::from_str("sqlite::memory:").unwrap();

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

while let Ok(event) = receiver.recv() {
    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);
        }
    }
}

if let Err(err) = handle.join() {
    eprintln!("{:?}", err);
    return
}

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.