#bitmessage #p2p #protocols

koibumi-node

A Bitmessage node implementation as a library for Koibumi, an experimental Bitmessage client

10 releases

0.0.9 Jun 26, 2024
0.0.8 Jan 6, 2021
0.0.7 Sep 9, 2020
0.0.5 Aug 24, 2020
0.0.1 May 26, 2020

#1236 in Network programming

Download history 2/week @ 2024-07-01 1/week @ 2024-07-08 60/week @ 2024-07-29 1/week @ 2024-08-12 3/week @ 2024-08-19 5/week @ 2024-08-26 20/week @ 2024-09-16 28/week @ 2024-09-23 10/week @ 2024-09-30 13/week @ 2024-10-14

52 downloads per month
Used in 4 crates

AGPL-3.0-or-later

460KB
12K SLoC

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.


lib.rs:

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;
});

Dependencies

~51MB
~829K SLoC