Commit e42f5a9c authored by dns2utf8's avatar dns2utf8

Slides and some cleanup

parent 315b3908
......@@ -363,6 +363,20 @@ dependencies = [
"lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "distributed_gallery"
version = "0.1.0"
dependencies = [
"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-web 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
"native-tls 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "dtoa"
version = "0.4.3"
......@@ -676,20 +690,6 @@ dependencies = [
"linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "master"
version = "0.1.0"
dependencies = [
"actix 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)",
"actix-web 0.7.14 (registry+https://github.com/rust-lang/crates.io-index)",
"env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)",
"native-tls 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "matches"
version = "0.1.8"
......
[package]
name = "master"
name = "distributed_gallery"
version = "0.1.0"
authors = ["Stefan Schindler <dns2utf8@estada.ch>"]
edition = "2018"
......
......@@ -84,7 +84,7 @@ fn main() {
.index_file("index.html"))
//.finish();
})
.bind_tls(bind_addr, native_acceptor.clone())
.bind_tls(bind_addr, native_acceptor)
.expect("unable to construct HttpServer")
.start();
......@@ -93,10 +93,12 @@ fn main() {
}
fn get_native_tls_acceptor() -> Result<TlsAcceptor, native_tls::Error> {
const P12_PASSWORD: &str = "";
let mut file = File::open("identity.pfx").expect("unable to open identity");
let mut identity = vec![];
file.read_to_end(&mut identity).expect("unable to read identity");
let identity = Identity::from_pkcs12(&identity, "")?;
let identity = Identity::from_pkcs12(&identity, P12_PASSWORD)?;
TlsAcceptor::new(identity)
}
......
......@@ -63,8 +63,8 @@
\begin{itemize}
\item 18:00 => Venue opens
\item now => Talk Stefan: Distributed and Secure Systems
\item 19:30 => Break
\item 20:15 => Discussions
%\item 19:30 => Break
\item after => Discussions
\item 21:00 => Venue closes
\item tomorrow => ???
\item the day after => secure the distributed World!
......@@ -103,6 +103,7 @@ Or more catchy: uplift instead of upset
\item Basics of computer networks
\item What common assumptions are inside our technology
\item TCP \& TLS
\item Encrypted communication is not hard
\item The actor model
\item Basic protocol design steps
\item RPC vs. MessagePassing
......@@ -239,18 +240,12 @@ Per Layer
\begin{frame}[fragile]{Loops 0 - What happened so far}
\begin{minted}{C}
\end{minted}
\end{frame}
{
%{
\usebackgroundtemplate{\pgfuseimage{bgdark}}
\section{Example Project}
\subsection{A distributed Gallery}
}
\usebackgroundtemplate{\pgfuseimage{bg}}
%}
\begin{frame}{User Goals}
......@@ -279,7 +274,7 @@ B. Share Images:
\begin{frame}{Features}
\begin{columns}
\begin{column}{.28\textwidth}
\begin{column}{.3\textwidth}
Clients
\begin{itemize}
\item Subscribe to Hub Meta Data Service
......@@ -288,7 +283,7 @@ B. Share Images:
\item Responsive
\end{itemize}
\end{column}
\begin{column}{.28\textwidth}
\begin{column}{.3\textwidth}
Central Hub
\begin{itemize}
\item Fully transport encrypted (TLSv1.2)
......@@ -298,7 +293,7 @@ B. Share Images:
\item Multiple Clients at the same time
\end{itemize}
\end{column}
\begin{column}{.28\textwidth}
\begin{column}{.3\textwidth}
Storage Pods
\begin{itemize}
\item Easy to setup
......@@ -311,6 +306,243 @@ B. Share Images:
\end{frame}
{
\usebackgroundtemplate{\pgfuseimage{bgdark}}
\subsection{Multi-Processing}
%\usebackgroundtemplate{\pgfuseimage{bg}}
}
\begin{frame}[fragile]{The crates - Cargo.toml}
\begin{minted}{yaml}
[package]
name = "distributed_gallery"
version = "0.1.0"
authors = ["Stefan Schindler <dns2utf8@estada.ch>"]
edition = "2018"
[dependencies]
actix = "=0.7.9"
actix-web = { version="0.7", features=["tls"] }
native-tls = "0.2"
env_logger = "0.6"
futures = "0.1"
serde_derive = "1.0"
serde_json = "1.0"
serde = "1.0"
\end{minted}
\end{frame}
\begin{frame}[fragile]{The project layout}
\begin{minted}{yaml}
├── Cargo.lock └── static
├── Cargo.toml ├── gallery.js
├── cert.pem ├── index.html
├── identity.pfx ├── main.js
├── key_decrypted.pem ├── self_host.js
├── key.pem └── style.css
├── Makefile
├── README.md
├── src
│ ├── actors.rs
│ ├── main.rs
│ └── protocols.rs
...
\end{minted}
\end{frame}
\begin{frame}[fragile]{Preparing the actor system - main.rs}
\begin{minted}{rust}
let sys = actix::System::new("master process");
let incrementor = Arc::new(Mutex::new(
Incrementor { i: 0 }
));
let hub = SyncArbiter::start(1, || {
Hub::default()
});
\end{minted}
\end{frame}
\begin{frame}[fragile]{Loading the keys - main.rs}
\begin{minted}{rust}
fn get_native_tls_acceptor() ->
Result<TlsAcceptor, native_tls::Error> {
const P12_PASSWORD: &str = "";
let mut file = File::open("identity.pfx")
.expect("unable to open identity");
let mut identity = vec![];
file.read_to_end(&mut identity)
.expect("unable to read identity");
let identity = Identity::from_pkcs12(&identity, P12_PASSWORD)?;
TlsAcceptor::new(identity)
}
\end{minted}
\end{frame}
\begin{frame}[fragile]{Starting the server - main.rs}
\begin{minted}{rust}
server::HttpServer::new(move || {
App::with_state((incrementor.clone(), hub.clone()))
.resource("/ws/", |r| { r.f(|req| {
let (incrementor, hub) = req.state();
ws::start( &req.drop_state(),
Ws {
id: incrementor.lock().unwrap().increment(),
hub: hub.clone(), is_pod: false,
}, ) }) })
.handler("/", fs::StaticFiles::new("static/").expect("unable to locate ./static folder")
.show_files_listing().index_file("index.html"))
})
.bind_tls(bind_addr, native_acceptor)
.expect("unable to construct HttpServer")
.start();
\end{minted}
\end{frame}
\begin{frame}[fragile]{The Hub - actors.rs}
\begin{minted}{rust}
#[derive(Default)]
pub struct Hub {
pods: HashMap<PodId, PodInfo>,
clients: HashMap<PodId, Addr<Ws>>,
}
impl Hub {
fn broadcast_client_response(&self, message: ClientResponse) {
for addr in self.clients.values() {
addr.do_send(message.clone())
}
}
}
impl Actor for Hub {
type Context = SyncContext<Self>;
}
\end{minted}
\end{frame}
\begin{frame}[fragile]{The Hub handling rpc style messages - actors.rs}
\begin{minted}{rust}
impl Handler<SubscribePod> for Hub {
type Result = ();
fn handle(&mut self, msg: SubscribePod,
_ctx: &mut Self::Context) -> Self::Result {
self.pods.insert(msg.id, PodInfo {
addr: msg.addr,
name: msg.name.clone(),
image_paths: vec![],
});
self.broadcast_client_response(ClientResponse::NewPod {
id: msg.id, name: msg.name, });
}
}
\end{minted}
\end{frame}
\begin{frame}[fragile]{The Hub handling async style messages - actors.rs}
\begin{minted}{rust}
impl Handler<IdedPodRequest> for Hub {
type Result = ();
fn handle(&mut self, msg: IdedPodRequest,
_ctx: &mut Self::Context) -> Self::Result {
use PodRequest::*;
match msg.message {
RegisterSelf { .. } =>
unreachable!("must be handled by Ws"),
UpdateTitle { name } => {
self.pods.get_mut(&msg.id).expect("unable to find PodInfo")
.name = name.clone();
self.broadcast_client_response(ClientResponse::PodUpdateName{ id: msg.id, name, });
}
...
\end{minted}
\end{frame}
\begin{frame}[fragile]{The super protocol - protocols.rs}
\begin{minted}{rust}
use serde_json as json;
pub type PodId = u64;
#[derive(Serialize, Deserialize, Debug, Message)]
/// Communicate with everything
pub enum JsonProtocol {
ClientRequest(ClientRequest),
ClientRequestAsync(ClientRequestAsync),
ClientResponse(ClientResponse),
PodRequest(PodRequest),
PodResponse(PodResponse),
}
\end{minted}
\end{frame}
\begin{frame}[fragile]{The client client - protocols.rs}
\begin{minted}{rust}
/// Browser -> Master rpc style
#[derive(Serialize, Deserialize, Debug, Message)]
#[rtype(result = "ClientResponse")]
pub enum ClientRequest {
ListAllPods, ListPodStructure(PodId),
}
/// Browser -> Master
#[derive(Serialize, Deserialize, Debug, Message)]
pub enum ClientRequestAsync {
RequestImage {
gallery_id: PodId, path: String,
#[serde(skip)]
client_id: PodId,
},
}
\end{minted}
\end{frame}
\begin{frame}[fragile]{Working with the client 1/2 - protocols.rs}
\begin{minted}{rust}
pub(crate) fn print_all_messages() {
let t = |t| { println!("\n==== {} ====", t); };
let p = |obj| {
let s = json::to_string(&obj).unwrap();
println!(" {}", s);
};
t("ClientRequest");
p(JsonProtocol::ClientRequest(ClientRequest::ListAllPods));
p(JsonProtocol::ClientRequest(
ClientRequest::ListPodStructure(42)));
...
\end{minted}
\end{frame}
\begin{frame}[fragile]{Working with the client 2/2 - protocols.rs}
\begin{minted}{rust}
==== ClientRequest ====
{"ClientRequest":"ListAllPods"}
{"ClientRequest":{"ListPodStructure":42}}
==== ClientRequestAsync ====
{"ClientRequestAsync":{"RequestImage":{"gallery_id":42,"path":"bla"}}}
==== ClientResponse ====
{"ClientResponse":{"Pods":[{"id":42,"name":"bla"}]}}
{"ClientResponse":{"NewPod":{"id":23,"name":"blubb"}}}
{"ClientResponse":{"UnknownPod":123}}
{"ClientResponse":{"PodGone":1234}}
{"ClientResponse":{"PodUpdateName":{"id":42,"name":"String"}}}
{"ClientResponse":{"PodUpdatePaths":{"id":42,"paths":["String"]}}}
{"ClientResponse":{"DeliverImage":{"gallery_id":42,"path":"String","blob":"String"}}}
\end{minted}
\end{frame}
{
\usebackgroundtemplate{\pgfuseimage{bgdark}}
\section{Questions}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment