Browse Source

README, images

master
Lev 3 years ago
parent
commit
114dd10448
  1. 24
      README.md
  2. 1
      degeon/src/message.rs
  3. 61
      degeon/src/state.rs
  4. 2
      src/interfaces/ip.rs
  5. 4
      src/ironforce.rs

24
README.md

@ -1,3 +1,25 @@
# Ironforce + Degeon
IronForce is a peer-to-peer decentralized network, Degeon is a messenger built on it.
![](images/logo.png)
# Ironforce # Ironforce
IronForce is a decentralized network The Ironforce network:
- Has messages encrypted and signed using RSA
- Can build efficient tunnels between two nodes
- Is anonymous: it's very hard to create a connection between a node's IP and its public key
- Can be extended to support any interface, like Bluetooth or even radio
- Can run on ARM microcontrollers
![](images/scheme.png)
# Degeon
Degeon is just a messenger built on IronForce to show its abilities.

1
degeon/src/message.rs

@ -12,5 +12,4 @@ pub enum ServiceMsg {
NameRequest, NameRequest,
NameStatement(String), NameStatement(String),
Ping, Ping,
HiThere,
} }

61
degeon/src/state.rs

@ -3,11 +3,12 @@ use crate::message::{DegMessage, ServiceMsg};
use core::default::Default; use core::default::Default;
use futures::Stream; use futures::Stream;
use iced::{ use iced::{
button, Align, Application, Button, Column, Element, HorizontalAlignment, Length, Row, button, Align, Application, Button, Column, Element, HorizontalAlignment, Length, Row, Text,
Text, TextInput, VerticalAlignment, TextInput, VerticalAlignment,
}; };
use ironforce::res::{IFError, IFResult}; use ironforce::res::{IFError, IFResult};
use ironforce::{IronForce, Keys, Message, MessageType, PublicKey}; use ironforce::{IronForce, Keys, Message, MessageType, PublicKey};
use std::hash::Hash;
use std::pin::Pin; use std::pin::Pin;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
use std::task::{Context, Poll}; use std::task::{Context, Poll};
@ -223,7 +224,10 @@ impl Degeon {
pub fn process_message(&self, msg: ironforce::Message) -> IFResult<Option<GuiEvent>> { pub fn process_message(&self, msg: ironforce::Message) -> IFResult<Option<GuiEvent>> {
let deg_msg: DegMessage = let deg_msg: DegMessage =
serde_json::from_slice(msg.get_decrypted(&self.keys)?.as_slice())?; match serde_json::from_slice(msg.get_decrypted(&self.keys)?.as_slice()) {
Ok(r) => r,
Err(_) => return Ok(None)
};
let sender = msg.get_sender(&self.keys).unwrap(); let sender = msg.get_sender(&self.keys).unwrap();
Ok(match &deg_msg { Ok(match &deg_msg {
DegMessage::Text(_) | DegMessage::File(_) => { DegMessage::Text(_) | DegMessage::File(_) => {
@ -240,9 +244,8 @@ impl Degeon {
Some(GuiEvent::SetName(sender, name.to_string())) Some(GuiEvent::SetName(sender, name.to_string()))
} }
ServiceMsg::Ping => self ServiceMsg::Ping => self
.send_message(DegMessage::Service(ServiceMsg::HiThere), &sender) .send_message(DegMessage::Service(ServiceMsg::NameStatement(self.my_name.clone())), &sender)
.map(|_| None)?, .map(|_| None)?,
ServiceMsg::HiThere => Some(GuiEvent::NewChat(sender)),
}, },
}) })
} }
@ -258,21 +261,21 @@ impl Degeon {
} }
pub fn send_message(&self, msg: DegMessage, target: &PublicKey) -> IFResult<()> { pub fn send_message(&self, msg: DegMessage, target: &PublicKey) -> IFResult<()> {
if self.ironforce.lock().unwrap().get_tunnel(target).is_none() { // if self.ironforce.lock().unwrap().get_tunnel(target).is_none() {
println!("Creating a tunnel"); // println!("Creating a tunnel");
self.ironforce // self.ironforce
.lock() // .lock()
.unwrap() // .unwrap()
.initialize_tunnel_creation(target)?; // .initialize_tunnel_creation(target)?;
let mut counter = 0; // let mut counter = 0;
while self.ironforce.lock().unwrap().get_tunnel(target).is_none() { // while self.ironforce.lock().unwrap().get_tunnel(target).is_none() {
std::thread::sleep(std::time::Duration::from_millis(350)); // std::thread::sleep(std::time::Duration::from_millis(350));
counter += 1; // counter += 1;
if counter > 100 { // if counter > 100 {
return Err(IFError::TunnelNotFound); // return Err(IFError::TunnelNotFound);
} // }
} // }
} // }
self.ironforce.lock().unwrap().send_to_all( self.ironforce.lock().unwrap().send_to_all(
Message::build() Message::build()
.message_type(MessageType::Broadcast) .message_type(MessageType::Broadcast)
@ -290,9 +293,12 @@ impl Stream for Degeon {
fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> { fn poll_next(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
println!("Degeon worker is being polled"); println!("Degeon worker is being polled");
let msg = self.ironforce.lock().unwrap().read_message(); let msg = self.ironforce.lock().unwrap().read_message();
println!("Msg: {:?}", msg);
match msg.map(|msg| self.process_message(msg).unwrap()) { match msg.map(|msg| self.process_message(msg).unwrap()) {
None | Some(None) => Poll::Pending, None | Some(None) => Poll::Pending,
Some(Some(msg)) => Poll::Ready(Some(msg)), Some(Some(msg)) => {
Poll::Ready(Some(msg))
}
} }
} }
} }
@ -308,6 +314,13 @@ where
std::any::TypeId::of::<Self>().hash(state); std::any::TypeId::of::<Self>().hash(state);
self.ironforce.lock().unwrap().hash(state); self.ironforce.lock().unwrap().hash(state);
// std::time::SystemTime::now().hash(state);
std::time::UNIX_EPOCH
.elapsed()
.unwrap()
.as_secs()
.hash(state);
} }
fn stream( fn stream(
@ -414,11 +427,7 @@ impl Application for State {
.push((true, new_msg.clone())); .push((true, new_msg.clone()));
let data_cloned = self.data.clone(); let data_cloned = self.data.clone();
let target = self.data.chats[self.selected_chat].pkey.clone(); let target = self.data.chats[self.selected_chat].pkey.clone();
std::thread::spawn(move || { std::thread::spawn(move || data_cloned.send_message(new_msg, &target).unwrap());
data_cloned
.send_message(new_msg, &target)
.unwrap()
});
} }
GuiEvent::NewChat(pkey) => { GuiEvent::NewChat(pkey) => {
if self.data.chat_with(&pkey).is_none() { if self.data.chat_with(&pkey).is_none() {

2
src/interfaces/ip.rs

@ -177,7 +177,7 @@ impl Interface for IPInterface {
message, message,
}; };
self.package_queue self.package_queue
.push((package, format!("{:?}", connection.peer_addr()?))); .insert(0, (package, format!("{:?}", connection.peer_addr()?)));
} }
MessageType::PeersShared => { MessageType::PeersShared => {
let peers: Vec<Peer> = serde_cbor::from_slice(message.as_slice())?; let peers: Vec<Peer> = serde_cbor::from_slice(message.as_slice())?;

4
src/ironforce.rs

@ -291,7 +291,7 @@ impl IronForce {
MessageType::SingleCast if message.check_recipient(&self.keys) => { MessageType::SingleCast if message.check_recipient(&self.keys) => {
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("New message: {:?}", message.get_decrypted(&self.keys)); println!("New message: {:?}", message.get_decrypted(&self.keys));
self.messages.push(message.clone()) self.messages.insert(0, message.clone())
} }
MessageType::SingleCast => { MessageType::SingleCast => {
if let Some(tunnel) = self if let Some(tunnel) = self
@ -312,7 +312,7 @@ impl IronForce {
#[cfg(feature = "std")] #[cfg(feature = "std")]
println!("New message: {:?}", message.get_decrypted(&self.keys)); println!("New message: {:?}", message.get_decrypted(&self.keys));
if message.check_recipient(&self.keys) { if message.check_recipient(&self.keys) {
self.messages.push(message.clone()); self.messages.insert(0, message.clone());
} }
self.send_to_all(message)?; self.send_to_all(message)?;
} }

Loading…
Cancel
Save