A peer to peer chat application using libp2p Swarm and Gossipsub protocols.
Almost all major instant messaging apps are made by big tech who have a less than stellar track record of respecting user privacy. Imhoteph aims to be reliable, scalable and at the same time respect the privacy of the user.
imhoteph-cli [SUBCOMMAND]
dial --id [PEER ID] --topic [TOPIC NAME]
Dial the given Peer ID and subscribe to the topictest --id [PEER ID] --addr [PEER MULTIADDR]
Test dial a the given peer id with the given multiaddr.
There are several independent working parts of Imhoteph.
network
Manages network events, establishes connections and publishes messages to the network.cli
Handles commands given by the user
On startup two threads are spawned one for displaying the messages and notifying the user about network events the other thread manages the network Eventloop
struct.
// Run the network eventloop
pub async fn run(mut self) {
loop {
futures::select! {
event = self.swarm.select_next_some() => {
self.handle_event(event).await;
}
command = self.command_receiver.select_next_some() => {
self.handle_command(command).await;
}
}
}
}
The Eventloop
struct has event_sender
field of type mpsc::channel
which is used to pass messages to other the corresponding event_listner
in the Client.
There are a number of network events in Imhoteph. Client
handles the event any way it wants to, as of now it displays the output in the terminal.
async fn handle_event(event: Event) {
match event {
Event::NewListenAddr { addr } => {
println!("Starting Listening at {}", addr);
}
Event::Subscribed { peer_id, topic } => {
println!("Peer {} joined {}", peer_id, topic)
}
Event::Unsubscribed { peer_id, topic } => {
println!("Peer {} left {}", peer_id, topic)
}
Event::Message {
propagation_source,
message,
..
} => {
println!(
"{}: {}",
propagation_source,
String::from_utf8_lossy(&message.data)
)
}
_ => {}
}
}
Download Rust
git clone https://github.com/omkar-mohanty/imhoteph.git
cd imhoteph
cargo build
cd target/debug
./imhoteph-cli