Browse Source

Made the network a separate crate

master
Lev 3 years ago
parent
commit
ea5b473763
  1. 15
      Cargo.lock
  2. 31
      Cargo.toml
  3. 4
      degeon/Cargo.toml
  4. 7
      degeon/src/state.rs
  5. 2
      degeon_core/Cargo.toml
  6. 2
      degeon_core/src/message.rs
  7. 8
      degeon_py/active_chat.py
  8. 2
      degeon_py/degeon.py
  9. 2
      degeon_py/message.py
  10. 49
      examples/test_ip_connection.rs
  11. 226
      images/explanation.svg
  12. 35
      ironforce/Cargo.toml
  13. 0
      ironforce/src/bin/worker.rs
  14. 0
      ironforce/src/crypto.rs
  15. 0
      ironforce/src/interface.rs
  16. 32
      ironforce/src/interfaces/ip.rs
  17. 0
      ironforce/src/interfaces/mod.rs
  18. 0
      ironforce/src/ironforce.rs
  19. 2
      ironforce/src/lib.rs
  20. 0
      ironforce/src/message.rs
  21. 0
      ironforce/src/res.rs
  22. 0
      ironforce/src/transport.rs
  23. 0
      ironforce/src/tunnel.rs

15
Cargo.lock generated

@ -1586,6 +1586,16 @@ dependencies = [
"unicode-normalization",
]
[[package]]
name = "include_optional"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3328afceb205b7534c691f71b12334973dbfdfe0eecb9e345bddfbb925bc55fc"
dependencies = [
"quote",
"syn",
]
[[package]]
name = "indexmap"
version = "1.7.0"
@ -1649,6 +1659,7 @@ version = "0.1.0"
dependencies = [
"base64",
"core-error",
"include_optional",
"rand",
"rand_os",
"rayon",
@ -1660,6 +1671,10 @@ dependencies = [
"spin 0.9.2",
]
[[package]]
name = "ironforce_degeon"
version = "0.1.0"
[[package]]
name = "itoa"
version = "0.4.8"

31
Cargo.toml

@ -1,35 +1,14 @@
[package]
name = "ironforce"
name = "ironforce_degeon"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[workspace]
members = ["degeon", "degeon_core"]
[features]
default = []
std = ["rayon"]
members = ["degeon", "degeon_core", "ironforce"]
[dependencies]
rand_os = "*"
# x25519-dalek = "0.6.0"
# ed25519-dalek = { version = "1.0", features = ["serde"] }
sha2 = "0.8.1"
rand = "*"
rsa = { version = "0.5", features = ["serde"] }
serde = { version = "1.0", features = ["derive", "alloc"], default-features = false }
rayon = { version = "1.5.1", optional = true }
core-error = "0.0.1-rc4"
serde_cbor = "0.11.2"
serde_json = "1.0.72"
spin = "0.9.2"
base64 = "0.13.0"
[profile.dev.package.num-bigint-dig]
opt-level = 3
[lib]
name = "ironforce"
path = "ironforce/src/lib.rs"
[[bin]]
name = "worker"
required-features = ["std"]

4
degeon/Cargo.toml

@ -7,11 +7,11 @@ edition = "2021"
[dependencies]
iced = { version = "0.3.0", features = ["glow"] }
ironforce = { path = "..", features = ["std"] }
ironforce = { path = "../ironforce", features = ["std", "image"] }
degeon_core = { path = "../degeon_core" }
base64 = "0.13.0"
serde = { version = "1.0" }
serde_json = "1.0.72"
futures = "0.3.18"
iced_native = "0.4.0"
chrono = "0.4.19"
chrono = "0.4.19"

7
degeon/src/state.rs

@ -242,8 +242,15 @@ impl Application for DegeonApp {
self.data.save_to_file("".to_string()).unwrap();
}
GuiEvent::ChangeScreen(sc) => {
let prev_screen = self.screen;
self.screen = sc;
self.data.save_to_file("".to_string()).unwrap();
if prev_screen == AppScreen::ProfileEditor {
return self.data.get_send_command(
ProtocolMsg::ProfileResponse(self.data.get_profile()),
&target,
);
}
}
GuiEvent::ChangeName(name) => self.data.profile.name = name,
// The following events are already handled in Degeon::process_event

2
degeon_core/Cargo.toml

@ -6,7 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
ironforce = { path = "..", features = ["std"] }
ironforce = { path = "../ironforce", features = ["std"] }
base64 = "0.13.0"
serde = { version = "1.0" }
serde_json = "1.0.72"

2
degeon_core/src/message.rs

@ -43,6 +43,8 @@ pub enum DegMessageContent {
pub struct Profile {
#[pyo3(get, set)]
pub name: String,
#[pyo3(get, set)]
pub bio: String,
}
/// A protocol message (that's sent through IF)

8
degeon_py/active_chat.py

@ -44,14 +44,14 @@ class ActiveChat:
"""
return cls(chat=chat, **kwargs)
def get_messages(self) -> typing.Iterable[Message]:
def get_messages(self, core: dc.Degeon) -> typing.Iterable[Message]:
"""
Get an iterator over all messages in this chat in the backwards order
This function creates a python `message.Message` object from rust instances
:return: an iterator of `message.Message` objects
"""
for msg in reversed(self.chat.messages):
yield Message(text=msg.get_content_py().text, is_from_me=False)
yield Message(text=msg.get_content_py().text, is_from_me=core.check_message_ownership(msg))
def get_header(self) -> pygame.Surface:
"""
@ -66,7 +66,7 @@ class ActiveChat:
surface.blit(name_surface, (20, 20))
return surface
def render(self) -> pygame.Surface:
def render(self, core: dc.Degeon) -> pygame.Surface:
"""
Creates a pygame surface and draws the chat on it
:return: the surface with the chat on it
@ -77,7 +77,7 @@ class ActiveChat:
# Render messages
# This is the y0 for the last message
last_message_y = self.height - MESSAGE_HEIGHT * 2
for i, message in zip(range(30), self.get_messages()):
for i, message in zip(range(30), self.get_messages(core)):
msg_surface = message.render()
surface.blit(msg_surface, (0, last_message_y - (MESSAGE_HEIGHT + 30) * (i + 1)))
# Render header

2
degeon_py/degeon.py

@ -44,7 +44,7 @@ class Degeon:
chats_surface = self.chat_selector.render()
screen.blit(chats_surface, (0, 0))
if self.active_chat is not None:
active_chat_surface = self.active_chat.render()
active_chat_surface = self.active_chat.render(self.core)
screen.blit(active_chat_surface, (self.active_chat.delta_x, 0))
else:
text_surface: pygame.Surface = font.render('<- Select chat in the menu', True, WHITE)

2
degeon_py/message.py

@ -35,7 +35,7 @@ class Message:
# Size of the scaled text surface
blit_height: int = self.height - padding * 2
blit_width: int = round(text_surface.get_width() * blit_height / text_surface.get_height())
x: int = 0 if not self.is_from_me else self.chat_width - blit_width - padding * 2
x: int = 0 if not self.is_from_me else self.chat_width - blit_width - padding * 3.5
pygame.draw.rect(surface, bg_color, (x, 0, blit_width + padding * 2, self.height))
text_surface: pygame.Surface = pygame.transform.smoothscale(text_surface, (blit_width, blit_height))
surface.blit(text_surface, (x + padding, padding))

49
examples/test_ip_connection.rs

@ -1,49 +0,0 @@
#[cfg(feature = "std")]
use ironforce::interface::Interface;
#[cfg(feature = "std")]
use ironforce::interfaces::ip::IPInterface;
#[cfg(feature = "std")]
use std::net;
use std::thread;
use std::time::Duration;
#[cfg(feature = "std")]
use ironforce::res::IFResult;
#[cfg(feature = "std")]
fn main() {
println!("hello");
test();
}
#[cfg(feature = "std")]
fn test() -> IFResult<()> {
let message = *b"Hello world from iron forest";
let mut interface1 = IPInterface::new()?;
let mut interface2 = IPInterface::new()?;
let t1 = std::thread::spawn(move || {
interface1.send(&message, Some(String::from("127.0.0.1:50001"))).unwrap();
interface1
});
thread::sleep(Duration::from_millis(10));
let t2 = std::thread::spawn(move || {
interface2.main_loop_iteration().unwrap();
interface2
});
let res1 = t1.join();
match res1 {
Ok(_) => println!("Ok"),
Err(e) => println!("{:?}", e)
}
let res2 = t2.join();
match res2 {
Ok(_) => println!("Ok"),
Err(e) => println!("{:?}", e)
}
Ok(())
}
#[cfg(not(feature = "std"))]
fn main() {}

226
images/explanation.svg

@ -24,9 +24,9 @@
inkscape:pagecheckerboard="0"
inkscape:document-units="mm"
showgrid="false"
inkscape:zoom="1.0684095"
inkscape:cx="198.89378"
inkscape:cy="192.34198"
inkscape:zoom="0.42190593"
inkscape:cx="117.32473"
inkscape:cy="387.52714"
inkscape:window-width="1920"
inkscape:window-height="1036"
inkscape:window-x="0"
@ -111,13 +111,19 @@
height="93.487419"
x="8.5933933"
y="5.2217455"
ry="8.0541668" />
ry="8.0541668"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:9.34861px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.247343"
x="17.57098"
y="46.311989"
id="text2360"><tspan
id="text2360"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan2358"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.34861px;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';stroke-width:0.247343"
@ -125,7 +131,10 @@
y="46.311989">IronForce worker</tspan></text>
<g
id="g44157"
transform="matrix(0.50052676,0,0,0.50052676,86.42112,10.813918)">
transform="matrix(0.50052676,0,0,0.50052676,86.42112,10.813918)"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49">
<circle
style="fill:#282e46;fill-opacity:1;stroke-width:0.130543"
id="path3611"
@ -149,7 +158,10 @@
style="font-style:normal;font-weight:normal;font-size:9.89368px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.247343"
x="177.74512"
y="23.484995"
id="text2360-3"><tspan
id="text2360-3"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan2358-6"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';stroke-width:0.247343"
@ -160,7 +172,10 @@
style="font-style:normal;font-weight:normal;font-size:9.89368px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.247343"
x="150.64513"
y="113.5675"
id="text2360-3-9"><tspan
id="text2360-3-9"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan2358-6-3"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';stroke-width:0.247343"
@ -172,27 +187,33 @@
x="33.883114"
y="151.60315"
id="text4446"
transform="translate(-15.875,-84.666647)"><tspan
transform="translate(-15.875,-84.666647)"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
x="33.883114"
y="151.60315"
id="tspan44781">keys
id="tspan44898">keys
</tspan><tspan
x="33.883114"
y="159.01149"
id="tspan44783">messages
id="tspan44900">messages
</tspan><tspan
x="33.883114"
y="166.41983"
id="tspan44785">transport
id="tspan44902">transport
</tspan><tspan
x="33.883114"
y="173.82817"
id="tspan44787">tunnels</tspan></text>
id="tspan44904">tunnels</tspan></text>
<path
style="fill:none;stroke:#000000;stroke-width:0.265;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Lend)"
d="m 51.174695,80.963928 c 36.826182,0 59.037355,-4.807892 71.522105,-13.48959 15.03496,-10.455072 5.67718,-25.115468 43.44786,-25.115468"
id="path8991"
sodipodi:nodetypes="csc" />
sodipodi:nodetypes="csc"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<rect
style="fill:none;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:none"
id="rect9382"
@ -200,7 +221,10 @@
height="73.67466"
x="168.431"
y="9.6066799"
ry="8.0541553" />
ry="8.0541553"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<rect
style="fill:none;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:none"
id="rect9627"
@ -208,7 +232,10 @@
height="32.60709"
x="175.8605"
y="39.549267"
ry="8.0541553" />
ry="8.0541553"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<rect
style="fill:none;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:1.06, 0.264999;stroke-dashoffset:0"
id="rect9711"
@ -216,7 +243,10 @@
height="13.677299"
x="244.65224"
y="39.549267"
ry="3.5077736" />
ry="3.5077736"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<rect
style="fill:none;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:1.06, 0.264999;stroke-dashoffset:0"
id="rect9735"
@ -224,13 +254,19 @@
height="13.496747"
x="245.31032"
y="58.290329"
ry="3.5077665" />
ry="3.5077665"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:7.05556px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="183.20638"
y="58.762375"
id="text10765"><tspan
id="text10765"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan10763"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:7.05556px;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';stroke-width:0.264583"
@ -241,7 +277,10 @@
style="font-style:normal;font-weight:normal;font-size:5.29167px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="250.38287"
y="48.283943"
id="text10765-7"><tspan
id="text10765-7"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan10763-5"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.29167px;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';stroke-width:0.264583"
@ -252,7 +291,10 @@
style="font-style:normal;font-weight:normal;font-size:5.29167px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="255.28795"
y="67.200043"
id="text10765-7-3"><tspan
id="text10765-7-3"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan10763-5-5"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:5.29167px;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';stroke-width:0.264583"
@ -263,7 +305,10 @@
style="font-style:normal;font-weight:normal;font-size:4.93889px;line-height:1.25;font-family:sans-serif;fill:#646363;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="16.850649"
y="54.463711"
id="text15881"><tspan
id="text15881"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan15879"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.93889px;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';fill:#646363;fill-opacity:1;stroke-width:0.264583"
@ -274,7 +319,10 @@
style="font-style:normal;font-weight:normal;font-size:4.93889px;line-height:1.25;font-family:sans-serif;fill:#646363;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="177.25208"
y="31.169495"
id="text15881-6"><tspan
id="text15881-6"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan15879-2"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.93889px;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';fill:#646363;fill-opacity:1;stroke-width:0.264583"
@ -285,7 +333,10 @@
style="font-style:normal;font-weight:normal;font-size:4.93889px;line-height:1;font-family:sans-serif;fill:#646363;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="151.44145"
y="121.18497"
id="text15881-6-6"><tspan
id="text15881-6-6"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan15879-2-0"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:4.93889px;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';fill:#646363;fill-opacity:1;stroke-width:0.264583"
@ -300,18 +351,27 @@
style="fill:none;stroke:#000000;stroke-width:0.265;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Lend)"
d="m 60.158434,62.055153 c -5.042315,0 -11.192659,3.575902 -24.273172,3.575902"
id="path22086"
sodipodi:nodetypes="cc" />
sodipodi:nodetypes="cc"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<path
style="fill:none;stroke:#000000;stroke-width:0.265;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Lend-9)"
d="m 61.630871,68.80989 c -5.042315,0 -6.677553,4.097977 -16.625154,4.097977"
id="path22086-2"
sodipodi:nodetypes="cc" />
sodipodi:nodetypes="cc"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:3.52778px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="61.826317"
y="63.422222"
id="text23762"><tspan
id="text23762"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan23760"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.52778px;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';stroke-width:0.264583"
@ -323,24 +383,27 @@
x="62.18861"
y="50.598217"
id="text23762-7"
transform="translate(0,17.991672)"><tspan
transform="translate(0,17.991672)"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
x="62.18861"
y="50.598217"
id="tspan44791"><tspan
id="tspan44908"><tspan
style="font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC'"
id="tspan44789">Messages are collected
id="tspan44906">Messages are collected
</tspan></tspan><tspan
x="62.18861"
y="54.296866"
id="tspan44795"><tspan
id="tspan44912"><tspan
style="font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC'"
id="tspan44793">into a queue
id="tspan44910">into a queue
</tspan></tspan><tspan
x="62.18861"
y="57.995517"
id="tspan44799"><tspan
id="tspan44916"><tspan
style="font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC'"
id="tspan44797">in another thread</tspan></tspan></text>
id="tspan44914">in another thread</tspan></tspan></text>
<rect
style="fill:none;fill-opacity:1;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="rect29127"
@ -348,73 +411,112 @@
height="80.150284"
x="144.03688"
y="100.24098"
ry="3.5077665" />
ry="3.5077665"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<circle
style="fill:none;fill-opacity:1;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="path33335"
cx="175.70769"
cy="154.38387"
r="6.170032" />
r="6.170032"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<circle
style="fill:none;fill-opacity:1;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="path33335-6"
cx="195.01611"
cy="142.44"
r="6.170032" />
r="6.170032"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<circle
style="fill:none;fill-opacity:1;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="path33335-2"
cx="195.01611"
cy="168.89836"
r="6.170032" />
r="6.170032"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<circle
style="fill:none;fill-opacity:1;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="path33335-61"
cx="210.89113"
cy="154.08167"
r="6.170032" />
r="6.170032"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<circle
style="fill:none;fill-opacity:1;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="path33335-8"
cx="233.21059"
cy="169.51178"
r="6.170032" />
r="6.170032"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<circle
style="fill:none;fill-opacity:1;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="path33335-7"
cx="233.7605"
cy="140.73239"
r="6.170032" />
r="6.170032"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<circle
style="fill:none;fill-opacity:1;stroke:#1a5fb4;stroke-width:0.264999;stroke-miterlimit:4;stroke-dasharray:none;stroke-dashoffset:0"
id="path33335-9"
cx="248.32843"
cy="154.43222"
r="6.170032" />
r="6.170032"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<path
style="fill:#1c71d8;stroke:#1a5fb4;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 180.83782,150.86848 9.12905,-4.79725"
id="path33547" />
id="path33547"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<path
style="fill:none;stroke:#1a5fb4;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 200.13891,146.14863 5.96908,3.93308"
id="path33812" />
id="path33812"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<path
style="fill:none;stroke:#1a5fb4;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 216.18252,150.63428 12.1567,-6.80918"
id="path33847"
sodipodi:nodetypes="cc" />
sodipodi:nodetypes="cc"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<path
style="fill:none;stroke:#1a5fb4;stroke-width:0.264583px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1"
d="m 238.59271,144.77704 5.65362,5.05602"
id="path34269"
sodipodi:nodetypes="cc" />
sodipodi:nodetypes="cc"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:9.87778px;line-height:1.25;font-family:sans-serif;fill:#1a5fb4;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="172.59557"
y="157.42624"
id="text35365"><tspan
id="text35365"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan35363"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.87778px;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';fill:#1a5fb4;fill-opacity:1;stroke-width:0.264583"
@ -425,7 +527,10 @@
style="font-style:normal;font-weight:normal;font-size:9.87778px;line-height:1.25;font-family:sans-serif;fill:#1a5fb4;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="245.73502"
y="158.07724"
id="text35365-2"><tspan
id="text35365-2"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan35363-0"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:9.87778px;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';fill:#1a5fb4;fill-opacity:1;stroke-width:0.264583"
@ -435,10 +540,16 @@
style="fill:none;stroke:#000000;stroke-width:0.265;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Lend)"
d="m 49.263104,88.1016 c 48.905701,0 81.209076,-4.448346 111.236186,11.120146"
id="path39105"
sodipodi:nodetypes="cc" />
sodipodi:nodetypes="cc"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<g
id="g39376"
transform="matrix(0.45409146,0,0,0.45409146,31.061511,94.796231)">
transform="matrix(0.45409146,0,0,0.45409146,31.061511,94.796231)"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49">
<path
d="m 46.303616,184.7066 c 7.73086,-1.52982 13.840883,-6.70904 21.987933,-5.12339 1.985169,0.38629 7.916068,1.97432 5.763948,-2.24155 -1.360488,-2.66462 -6.466152,-2.6588 -8.965936,-3.09563 -2.146829,-0.37544 -2.518039,-0.38946 -2.028031,-2.56169 0.523611,-2.32119 1.455738,-2.86835 3.522398,-3.73592 3.063346,-1.28614 6.074569,-3.00249 8.859308,-4.69635 2.342621,-1.42505 4.705086,-3.10356 6.724915,-5.12339 1.521883,-1.52189 4.344458,-5.17155 6.564312,-4.42966 5.774796,1.92961 11.273107,3.95632 17.024877,5.39036 2.96836,0.74004 6.27671,2.46274 8.75268,2.66832 4.90988,0.40746 7.80865,-9.69804 7.57873,-13.66255 -0.14552,-2.50772 -0.5543,-6.75349 -2.88211,-8.11213 -1.42637,-0.83238 -4.18862,-0.77602 -5.76368,-0.85407 -9.29799,-0.46117 -18.443312,2.18889 -27.752411,1.06759 -4.295511,-0.51752 -7.162271,-2.45242 -10.780448,-4.58973 -3.092979,-1.82721 -6.380163,-2.81066 -9.660202,-4.21613 -3.353329,-1.43722 -7.07681,-2.21589 -10.513748,-3.46922 -2.35241,-0.85778 -2.785533,-1.82695 -4.376208,-3.4155 -2.010569,-2.00819 -3.066521,-4.88104 -5.123656,-6.93817 -2.100527,-2.10053 -3.953669,-4.31747 -6.190721,-6.29762 -4.250267,-3.76211 -9.460442,-7.94728 -15.530777,-5.92402 -2.823369,0.94113 -5.056717,2.1635 -6.884723,4.64318 -1.106487,1.50098 -1.403614,2.72282 -1.707621,4.58972 -0.167746,1.03029 0.01667,1.00965 -0.320146,1.81452 -0.294216,0.70299 -0.989541,1.21258 -1.280847,2.02803 -0.6731,1.88357 -0.305065,4.67042 1.600993,5.12365 -0.294216,-0.0701 1.657086,-0.41883 1.707886,-0.42703 0.841904,-0.136 1.715823,-0.0262 2.56196,-0.10663 4.463521,-0.42519 7.593277,2.07671 8.752681,6.61802 3.120496,12.22481 0.262731,28.58797 12.381706,36.50483 3.822436,2.49714 7.502261,1.60099 11.794861,1.60099 4.696618,0 6.56537,2.36591 6.777831,6.61802 -1.454415,-0.2667 -4.790281,-1.80392 -5.870311,-2.8821 -0.695854,-0.6948 -1.998397,-0.80751 -2.882106,-0.58711 -1.209939,0.30162 -1.621896,3.13822 -2.033323,3.16045 -4.399227,0.23759 -5.496718,0.42386 -4.584435,4.36456 0.225954,0.97552 0.509852,0.54743 0.2667,1.76107 -0.150283,0.75089 -0.382323,1.4224 -0.160073,2.1881 0.354013,1.22026 1.51421,2.07143 2.667794,2.34818"
id="path3"
@ -533,13 +644,19 @@
id="path39400"
cx="58.1259"
cy="167.87944"
r="39.348465" />
r="39.348465"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
<text
xml:space="preserve"
style="font-style:normal;font-weight:normal;font-size:10.5833px;line-height:1.25;font-family:sans-serif;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.264583"
x="41.161209"
y="187.81125"
id="text41324"><tspan
id="text41324"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49"><tspan
sodipodi:role="line"
id="tspan41322"
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-family:'Inconsolata LGC';-inkscape-font-specification:'Inconsolata LGC';stroke-width:0.264583"
@ -549,6 +666,9 @@
style="fill:none;stroke:#c01c28;stroke-width:2;stroke-linecap:butt;stroke-linejoin:miter;stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1;marker-end:url(#Arrow1Mend)"
d="M 58.794197,125.3495 V 102.52049"
id="path42639"
sodipodi:nodetypes="cc" />
sodipodi:nodetypes="cc"
inkscape:export-filename="/home/ennucore/dev/ironforce/scheme.png"
inkscape:export-xdpi="1121.49"
inkscape:export-ydpi="1121.49" />
</g>
</svg>

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 40 KiB

35
ironforce/Cargo.toml

@ -0,0 +1,35 @@
[package]
name = "ironforce"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "ironforce"
path = "src/lib.rs"
[features]
default = []
std = ["rayon"]
[dependencies]
rand_os = "*"
# x25519-dalek = "0.6.0"
# ed25519-dalek = { version = "1.0", features = ["serde"] }
sha2 = "0.8.1"
rand = "*"
rsa = { version = "0.5", features = ["serde"] }
serde = { version = "1.0", features = ["derive", "alloc"], default-features = false }
rayon = { version = "1.5.1", optional = true }
core-error = "0.0.1-rc4"
serde_cbor = "0.11.2"
serde_json = "1.0.72"
spin = "0.9.2"
base64 = "0.13.0"
include_optional = "1.0.1"
[[bin]]
name = "worker"
required-features = ["std"]

0
src/bin/worker.rs → ironforce/src/bin/worker.rs

0
src/crypto.rs → ironforce/src/crypto.rs

0
src/interface.rs → ironforce/src/interface.rs

32
src/interfaces/ip.rs → ironforce/src/interfaces/ip.rs

@ -2,9 +2,9 @@ use alloc::borrow::ToOwned;
use alloc::string::{String, ToString};
use alloc::vec;
use alloc::vec::Vec;
use core::ops::RangeInclusive;
use core::str::FromStr;
use core::time::Duration;
use include_optional::include_str_optional;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use std::net::TcpStream;
@ -17,11 +17,13 @@ use crate::std::io::{Read, Write};
use crate::std::println;
pub const DEFAULT_PORT: u16 = 50000;
const SOCKET_RANGE: RangeInclusive<u16> = 50000..=50010;
/// The threshold for the number of peers below which we are desperate
const PEER_THRESHOLD: usize = 70;
/// Default peers
const DEFAULT_PEERS_FILE: Option<&'static str> = include_str_optional!(".if_ip_peers");
type Peer = (net::IpAddr, u16);
/// Interface for interactions using tcp sockets
@ -271,12 +273,12 @@ impl Interface for IPInterface {
Err(_) => {
self.remove_all_connections_to_peer(&peer);
let index = self.obtain_connection(&(addr.ip(), addr.port()))?;
IPInterface::send_package(&mut self.connections[index], package).map_err(
|e| {
IPInterface::send_package(&mut self.connections[index], package)
.map_err(|e| {
println!("Error while sending: {:?}", e);
e
},
).unwrap_or_default();
})
.unwrap_or_default();
}
}
}
@ -342,17 +344,19 @@ impl Interface for IPInterface {
IPInterface::new(data.port, data.peers)
} else {
let ip_path = std::path::Path::new(".if_ip_peers");
let peers = if ip_path.exists() {
std::fs::read_to_string(ip_path)
.unwrap()
.split('\n')
.filter_map(|line| net::SocketAddr::from_str(line).ok())
.map(|addr| (addr.ip(), addr.port()))
.collect()
let data = if ip_path.exists() {
std::fs::read_to_string(ip_path).unwrap()
} else if let Some(data) = DEFAULT_PEERS_FILE {
data.to_string()
} else {
println!("Warning: there are no peers in IP, which makes it essentially useless");
vec![]
"".to_string()
};
let peers = data
.split('\n')
.filter_map(|line| net::SocketAddr::from_str(line).ok())
.map(|addr| (addr.ip(), addr.port()))
.collect();
IPInterface::new(DEFAULT_PORT, peers)
}
}

0
src/interfaces/mod.rs → ironforce/src/interfaces/mod.rs

0
src/ironforce.rs → ironforce/src/ironforce.rs

2
src/lib.rs → ironforce/src/lib.rs

@ -12,6 +12,8 @@ extern crate rsa;
extern crate serde;
extern crate core_error;
extern crate spin;
#[cfg(feature = "std")]
extern crate include_optional;
mod crypto;
mod ironforce;

0
src/message.rs → ironforce/src/message.rs

0
src/res.rs → ironforce/src/res.rs

0
src/transport.rs → ironforce/src/transport.rs

0
src/tunnel.rs → ironforce/src/tunnel.rs

Loading…
Cancel
Save