Browse Source

Init

develop
Lev 5 years ago
commit
cc270bda89
  1. 1
      .gitignore
  2. 307
      Cargo.lock
  3. 14
      Cargo.toml
  4. 85
      README.md
  5. BIN
      scheme.fzz
  6. 14
      src/addresses.rs
  7. 16
      src/ironforce.rs
  8. 33
      src/lib.rs
  9. 36
      src/message.rs
  10. 2
      src/transport.rs

1
.gitignore vendored

@ -0,0 +1 @@
target/*

307
Cargo.lock generated

@ -0,0 +1,307 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "alt_serde"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "block-buffer"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "block-padding"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "byte-tools"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "curve25519-dalek"
version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"subtle 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "digest"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ecdsa"
version = "0.5.0-pre"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"elliptic-curve 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
"sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"signature 1.0.0-pre.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "elliptic-curve"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)",
"getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"subtle 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "generic-array"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "getrandom"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
"wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "half"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "ironforest"
version = "0.1.0"
dependencies = [
"alt_serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"curve25519-dalek 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ecdsa 0.5.0-pre (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_cbor 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "libc"
version = "0.2.67"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "opaque-debug"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "ppv-lite86"
version = "0.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "proc-macro2"
version = "1.0.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "quote"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand"
version = "0.7.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_chacha"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_core"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rand_hc"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_cbor"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"half 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "serde_derive"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "sha2"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)",
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
"fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "signature"
version = "1.0.0-pre.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "subtle"
version = "2.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "syn"
version = "1.0.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
"quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "typenum"
version = "1.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-xid"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "zeroize"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[metadata]
"checksum alt_serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "03beeddedd09889b96def26f78ba46e34ffd9bdaaa33b2c980cbaa1d0e762686"
"checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b"
"checksum block-padding 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5"
"checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum curve25519-dalek 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "26778518a7f6cffa1d25a44b602b62b979bd88adb9e99ffec546998cf3404839"
"checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
"checksum ecdsa 0.5.0-pre (registry+https://github.com/rust-lang/crates.io-index)" = "1d7e523a6e90b7682c0857c1d26cf06f3a0224bc2dfb0766f5e35a0a71ad3dbe"
"checksum elliptic-curve 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01f69be7d1feb7a7a04f158aaf32c7deaa7604e9bd58145525e536438c4e5096"
"checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed"
"checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec"
"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
"checksum half 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f36b5f248235f45773d4944f555f83ea61fe07b18b561ccf99d7483d7381e54d"
"checksum libc 0.2.67 (registry+https://github.com/rust-lang/crates.io-index)" = "eb147597cdf94ed43ab7a9038716637d2d1bf2bc571da995d0028dec06bd3018"
"checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c"
"checksum ppv-lite86 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "74490b50b9fbe561ac330df47c08f3f33073d2d00c150f719147d7c54522fa1b"
"checksum proc-macro2 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6c09721c6781493a2a492a96b5a5bf19b65917fe6728884e7c44dd0c60ca3435"
"checksum quote 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2bdc6c187c65bca4260c9011c9e3132efe4909da44726bad24cf7572ae338d7f"
"checksum rand 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03"
"checksum rand_chacha 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402"
"checksum rand_core 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19"
"checksum rand_hc 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c"
"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"
"checksum serde_cbor 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e18acfa2f90e8b735b2836ab8d538de304cbb6729a7360729ea5a895d15a622"
"checksum serde_derive 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "128f9e303a5a29922045a830221b8f78ec74a5f544944f3d5984f8ec3895ef64"
"checksum sha2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "27044adfd2e1f077f649f59deb9490d3941d674002f7d062870a60ebe9bd47a0"
"checksum signature 1.0.0-pre.3 (registry+https://github.com/rust-lang/crates.io-index)" = "561619c00cf6a187ebfc21e46bc4c0ce4e4d5f67cd640e7b1c58d9c3754b38aa"
"checksum subtle 2.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c65d530b10ccaeac294f349038a597e435b18fb456aadd0840a623f83b9e941"
"checksum syn 1.0.16 (registry+https://github.com/rust-lang/crates.io-index)" = "123bd9499cfb380418d509322d7a6d52e5315f064fe4b3ad18a53d6b92c07859"
"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9"
"checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c"
"checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
"checksum zeroize 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3cbac2ed2ba24cc90f5e06485ac8c7c1e5449fe8911aef4d8877218af021a5b8"

14
Cargo.toml

@ -0,0 +1,14 @@
[package]
name = "ironforest"
version = "0.1.0"
authors = ["ennucore <ennucore@gmail.com>"]
edition = "2018"
[dependencies]
ecdsa = "0.5.0-pre"
curve25519-dalek = "2"
alt_serde = "1.0.104"
rand = "*"
serde = { version = "1.0", features = ["derive", "alloc"], default-features = false }
serde_cbor = { version = "0.11", default-features = false }

85
README.md

@ -0,0 +1,85 @@
# IronForest
__IronForest__ _(IF)_ is a decentralized P2P network.
IronForest hardware network has two types of devices: digital (IronForest Digital Device, IFDD) and analog (IronForest Digital Device, IFAD)
## IronForest tonnels
Devices communicate through tonnels. Tonnel is a list of IF nodes' IDs: $ T(a_1, a_n)=[a_1, a_2, \,..., \, a_n] $, where $a_i$ is an id. _Short tonnel_ ($s(T)$) is one of the $min\_tonnels$ shortest paths (by time) between two nodes. Each IF node $X$ has its own list of short tonnels $X.TT$ ($\forall \, T \in X.TT\,\, X\in T$). It is obvious, that if $T(a_1, a_n)_p=A$ and $T(a_1, a_n)_q=B$ , then $T(A, B)=T(a_1,a_n)_{p:q}$. Therefore, if node $X$ has ID of node $Y$ somewhere in its list of tonnels, it knows a tonnel to $Y$.
```mermaid
graph TD;
A --- E --- F --- B;
A---G---B;
E---Z---F;
```
_Here [A, G, B], [A, E, F, B], [A, E, Z, F, B] are tonnels from A to B, but the last one will not probably be short tonnel, because it will highly likely take more time for a packet to reach the $B$ node by this path._
Node $N$ is _known_ to node $B$ if node $B$ has node $N$ in its list of tonnels: $kn(N, B)=\exists T \in N.TT\,:\,B\in T$.
On low-level, a also tonnel has its frequency $T.F$: IFADs retranslate signals on all frequencies from $F_2 \cup \{F_1\}$ and IFDDs set one of their transmitters to the $T.F$ frequency.
#### Building a tonnel
How does node $A$ build a tonnel to an unknown node $B$?
$A$ sends a multicast message to the network. This message consists of type (tonnel request), destination $m.d=B$ and path (list) $m.P$ ($P_0=[A]$) and tonnel (empty for now). When another node $N$ receives message of this type, it appends its id to the path ($m.P+=[N]$) and resends this message either nobody if $N$ is a part of too much tonnels (this number is equal to the number of $F2$ radio modules on the IFDD board) either to all available nodes if node $B$ is not a known node to $N$ (if $!kn(N, B) = \nexists T \in N.TT: B\in T$) and message has no tonnel parameter either only to some nodes. Let's see the second variant more detailed.
So, node $N$ receives a message $m$. If message has not empty tonnel parameter $m.T$, then $N$ remembers tonnel T, sends message to the next node in the tonnel ($m.T_{k+1}, k: m.T_k = N$). If node $B$($m.d$) is known to $N$ ($kn(N, B)$), then:
1. $N$ checks if number of tonnels to $B$ is enough: $TT_2=\{T \in N.TT: B \in T\},\,\,|TT_2|>= tonnel\_num$, if not, then message is resent through all paths
2. $N$ sends message $m$ to $tonnel\_num$ of $TT_2$ ($TT_{2\,[1:tonnel\_num]}$)
$M=[m_1, \,...,\,m_{tonnel\_num}]$ is a list of first $tonnel\_num$ messages that reached B
When message $m_i \in M$ with updated path reaches $B$, $B$ remembers reversed of $m_i.P$ as the tonnel from $B$ to $A$: $T(A, B)=m.P$. $B$ decides frequency $T.F$ of tonnel (for hardware network). It sends a message with this frequency. to $A$ as multicast message using this tonnel. $A$ receives this tonnel and remembers it. Now $kn(A, B) \and kn(B, A)$.
## IronForest Hardware Network
There are two types of IFHN devices: analog devices (IFAD) and digital (IFDD). The analog devices are very cheap, because they are just a electronic circuits with analog components. They just re-translate all the signals instantly, without any delay. Digital devices are more complicated. They decode messages and then resend them with filtering and processing. Digital devices provide spam protection and logic.
IronForest hardware0 network has two frequencies: one (_F1_) for multicast and a frequency range (F2) for tonnels.
## IronForest analog device (IFAD) description
IFADs work as retranslators. Analog devices receive the signal, amplify it and send it further. They do not react on signals weaker then some threshold. But the output strength of the signal is lower then it was when it was send by the previous device. Therefore, a packet will not go far only through IFADs. This also solves the problem of signals circulating through analog network being amplified every time.
## IronForest digital device (IFDD) description
IFDD can be connected to another device or to another network, and it will use available network for overlay.
IFDD have radio transmitters: one for $F_1$ frequency and several transmitters for $F_2$ messages. Transmitters of the second type can be set to any frequency of the $F_2$ range using varicond/varicap.
Digital device receives signal, amplifies it and demodulates. Then signal is processed by a micro-controller (MC):
1. MC checks validity
2. Spam protection (PoW, for example) is done
3. If this is an $F2$ signal, check if it needs resending by this IFDD, resend by radio and overlays if needed
4. If this is an $F1$ signal, process it and resend by radio and overlays
IFDD's MC has a list of known tonnels. If it is clear that the destination of a packet is a known node (known as a part of a tonnel), IFDD will not send packet to all available nodes, it will send it just like through a usual tonnel to this known node.
## Calculating network speed and price for square kilometer
_todo_
## Some schemes
![image-20200119194630807](/home/ennucore/.config/Typora/typora-user-images/image-20200119194630807.png)
http://www.diagram.com.ua/list/am-mod.shtml
![Высоколинейный амплитудный модулятор](http://www.diagram.com.ua/li/am-mod1.gif)
http://rtf.sfedu.ru/!rpru/files/upos04.pdf

BIN
scheme.fzz

Binary file not shown.

14
src/addresses.rs

@ -0,0 +1,14 @@
extern crate rand;
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct PublicKey {
pub id: u64
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct SecretKey {}
pub fn gen_keys() -> (PublicKey, SecretKey) {
(PublicKey { id: rand::random::<u64>() }, SecretKey {})
}

16
src/ironforce.rs

@ -0,0 +1,16 @@
use crate::transport::Transport;
use crate::addresses::{PublicKey, SecretKey, gen_keys};
pub struct IronForce {
transport: Transport,
public: PublicKey,
secret: SecretKey,
}
impl IronForce {
pub fn new() -> IronForce {
let (public, secret) = gen_keys();
IronForce { transport: Transport {}, public, secret }
}
}

33
src/lib.rs

@ -0,0 +1,33 @@
#![feature(alloc)]
#![no_std]
extern crate alloc;
mod ironforce;
mod transport;
mod message;
mod addresses;
#[cfg(test)]
mod tests {
use crate::ironforce::IronForce;
use crate::message::{MsgType, Message};
use alloc::vec::Vec;
#[test]
fn creation_works() {
IronForce::new();
}
#[test]
fn serialization() {
let msg = crate::message::Message {
msg_type: MsgType::MultiCast,
hash: 0,
body: 0,
source: crate::addresses::PublicKey { id: 0 },
};
let serialized = msg.ser();
let msg2 = Message::deserialize(serialized);
}
}

36
src/message.rs

@ -0,0 +1,36 @@
use serde::{Serialize, Deserialize};
use crate::addresses::PublicKey;
use alloc::vec::Vec;
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub enum MsgType {
MultiCast,
ToTarget(PublicKey),
}
#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct Message {
pub msg_type: MsgType,
pub hash: u64,
pub body: u64,
pub source: PublicKey,
}
impl Message {
pub fn ser(self) -> Vec<u8> {
let mut buf = [0u8; 8192];
let mut ser = serde_cbor::Serializer::new(
serde_cbor::ser::SliceWrite::new(&mut buf[..])
);
self.serialize(&mut ser).unwrap();
let writer = ser.into_inner();
buf.to_vec()
}
pub fn deserialize(serialized: Vec<u8>) -> Self {
let mut scratch = [0u8; 8192];
let msg = serde_cbor::de::from_slice_with_scratch(&serialized.as_slice(), &mut scratch).unwrap();
msg
}
}

2
src/transport.rs

@ -0,0 +1,2 @@
pub(crate) struct Transport {}
Loading…
Cancel
Save