Skip to content
This repository has been archived by the owner on Aug 27, 2024. It is now read-only.

feat: add Rust chat example #51

Merged
merged 3 commits into from
Sep 7, 2022
Merged

Conversation

rvolosatovs
Copy link
Member

@rvolosatovs rvolosatovs commented Sep 1, 2022

Add a chat server and client for the upcoming Summer of Code project.

The idea is really simple, the chat server listens on port 50000, assigns a randomly-generated ULID to each peer connecting and broadcasts messages to all connected peers.

Messages are simply lines of text (i.e. they should be newline-delimited)

Since there's no way to read from stdin in async manner, clients first have to write all messages, close STDIN (^D) and only then receive messages. @haraldh any ideas how to do this nicer? Can we write to stdout from tokio::spawn somehow?

In any case, we probably do want to have a web interface here, such that input would come from a socket (i.e. from the browser interface) cc @nickvidal

Example

nix build .#chat-server-rust-tokio && enarx run --wasmcfgfile ./result/Enarx.toml ./result/main.wasm
01GBX5FCPNAM8ZF16469C79ED4 peer joined
01GBX5FH2BM4G4XSVF3CTEJSEY peer joined
> 01GBX5FCPNAM8ZF16469C79ED4: peer 1
> 01GBX5FH2BM4G4XSVF3CTEJSEY: peer 2
> 01GBX5FCPNAM8ZF16469C79ED4: quick
> 01GBX5FH2BM4G4XSVF3CTEJSEY: brown
> 01GBX5FCPNAM8ZF16469C79ED4: fox
01GBX5FCPNAM8ZF16469C79ED4 peer left
nix build .#chat-client-rust-tokio && enarx run --wasmcfgfile ./result/Enarx.toml ./result/main.wasm
peer 1
quick
fox
01GBX5FCPNAM8ZF16469C79ED4 joined the chat
01GBX5FH2BM4G4XSVF3CTEJSEY joined the chat
01GBX5FCPNAM8ZF16469C79ED4: peer 1
01GBX5FH2BM4G4XSVF3CTEJSEY: peer 2
01GBX5FCPNAM8ZF16469C79ED4: quick
01GBX5FH2BM4G4XSVF3CTEJSEY: brown
01GBX5FCPNAM8ZF16469C79ED4: fox
^C
nix build .#chat-client-rust-tokio && enarx run --wasmcfgfile ./result/Enarx.toml ./result/main.wasm
peer 2
brown
01GBX5FH2BM4G4XSVF3CTEJSEY joined the chat
01GBX5FCPNAM8ZF16469C79ED4: peer 1
01GBX5FH2BM4G4XSVF3CTEJSEY: peer 2
01GBX5FCPNAM8ZF16469C79ED4: quick
01GBX5FH2BM4G4XSVF3CTEJSEY: brown
01GBX5FCPNAM8ZF16469C79ED4: fox
01GBX5FCPNAM8ZF16469C79ED4 left the chat

cc @rjzak

@rvolosatovs rvolosatovs marked this pull request as ready for review September 1, 2022 19:08
@rvolosatovs rvolosatovs enabled auto-merge (rebase) September 1, 2022 19:08
@rvolosatovs rvolosatovs force-pushed the feat/chat branch 2 times, most recently from 03d2dba to ff45d88 Compare September 2, 2022 07:50
@haraldh
Copy link
Member

haraldh commented Sep 2, 2022

Why does the client have to run in the a Keep? Shouldn't the native client just have to check, that the server cert is signed by profian (running in a keep)?

@rvolosatovs
Copy link
Member Author

rvolosatovs commented Sep 2, 2022

The intention is to have a private, secure chatroom. The server will have to validate the client's certificate to determine whether to admit the client or not.
In this scenario, a compromised client means a compromised chat room.

If this were a real service, then the clients would be hosted services with a web UI. (i.e. hosted by third parties the actual user does not need to trust)

The overall idea is that clients are associated with an OIDC identity, e.g. a Github username. The client auth state could also then securely be stored by the keep.

@rvolosatovs
Copy link
Member Author

rvolosatovs commented Sep 2, 2022

To clarify, this is really not about the chat, the end goal is to have a peer-to-peer networked application, where workloads running in Enarx can establish trust relationships given what Enarx platform offers.

Making this a chat is just a simplification for SoC. This is essentially just an exploration into what we can achieve with a network of communicating Enarx keeps.

There should not be a centralized "server", but rather each peer should be able to act as both a client and a server routing messages to other peers

The focus is on the attestation and the Steward certificates associated.

You will notice that the examples use plain TCP, the reason is two-fold:

  1. Outgoing TLS is broken in Enarx (issue already exists and assigned to me)
  2. We need to give students something to work on and start with quickly. TCP is way easier to develop against

@rvolosatovs rvolosatovs force-pushed the feat/chat branch 3 times, most recently from 3d53689 to 53b7a23 Compare September 6, 2022 16:26
Signed-off-by: Roman Volosatovs <roman@profian.com>
Signed-off-by: Roman Volosatovs <roman@profian.com>
Signed-off-by: Roman Volosatovs <roman@profian.com>
Copy link
Member

@rjzak rjzak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants