Skip to content

Commit

Permalink
Merge branch 'one-crate'
Browse files Browse the repository at this point in the history
This merges everything (the sans-io core library, the blocking IO layer, and
the as-yet-unwritten Tokio-based IO layer) into a single crate. Feature flags
are now used to enable/disable the different IO layers. `cargo install
magic-wormhole` will still be used to install the executable tool.

Closes #28
  • Loading branch information
warner committed Oct 30, 2018
2 parents 0871513 + 9799be0 commit 35ca374
Show file tree
Hide file tree
Showing 40 changed files with 397 additions and 276 deletions.
49 changes: 42 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,49 @@
[workspace]
members = [
"core",
# "io/tokio",
"io/blocking",
"cli",
]
[package]
name = "magic-wormhole"
version = "0.0.1"
authors = ["Brian Warner <warner@lothar.com>"]

[badges]
travis-ci = { repository = "warner/magic-wormhole.rs" }

[dependencies]
serde = "1.0"
serde_json = "1.0"
serde_derive = "1.0"
sodiumoxide = "0.0.16"
spake2 = "0.1.0"
sha2 = "0.8"
hkdf = "0.7.0"
hex = "0.3"
rand = "0.5"
rustc-serialize = "0.3"
regex = "1.0"

# for "io_blocking" feature
ws = { version = "0.7.*", optional = true }
url = { version = "1.7", optional = true }

# for "io_tokio" feature
websocket = { version = "0.20", optional = true }
futures = { version = "0.1", optional = true }
tokio-core = { version = "0.1", optional = true }

[dev-dependencies]
ws = "0.7"
url = "1.7"
rustyline = "2.0"
parking_lot = {version = "0.6", features = ["deadlock_detection"]}
hex = "0.3"

[features]
default = ["io-blocking", "io-tokio"]
io-blocking = ["ws", "url"]
io-tokio = ["websocket", "futures", "tokio-core"]

[[bin]]
name = "wormhole"
path = "src/bin/main.rs"
required-features = ["io-blocking"]

[profile.release]
overflow-checks = true
6 changes: 0 additions & 6 deletions cli/Cargo.toml

This file was deleted.

24 changes: 0 additions & 24 deletions core/Cargo.toml

This file was deleted.

7 changes: 3 additions & 4 deletions core/examples/readline.rs → examples/readline-core.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
extern crate magic_wormhole_core;
extern crate magic_wormhole;
extern crate parking_lot;
extern crate regex;
extern crate rustyline;
extern crate serde_json;
extern crate url;
extern crate ws;

use magic_wormhole_core::{
use magic_wormhole::core::{
APIAction, APIEvent, Action, IOAction, IOEvent, OfferType, PeerMessage,
WSHandle, WormholeCore,
};
Expand Down Expand Up @@ -111,8 +111,7 @@ impl Completer for CodeCompleter {
self.tx_event
.send(APIEvent::InputHelperChooseNameplate(
nameplate.clone(),
))
.unwrap();
)).unwrap();
Ok((0, Vec::new()))
}
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
extern crate hex;
extern crate magic_wormhole_core;
extern crate magic_wormhole_io_blocking;
extern crate magic_wormhole;

use magic_wormhole_core::{file_ack, message_ack, OfferType, PeerMessage};
use magic_wormhole_io_blocking::Wormhole;
use magic_wormhole::core::{file_ack, message_ack, OfferType, PeerMessage};
use magic_wormhole::io::blocking::Wormhole;
use std::str;

// Can ws do hostname lookup? Use ip addr, not localhost, for now
Expand Down
7 changes: 3 additions & 4 deletions io/blocking/examples/send.rs → examples/send-blocking.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
extern crate hex;
extern crate magic_wormhole_core;
extern crate magic_wormhole_io_blocking;
extern crate magic_wormhole;

use magic_wormhole_core::message;
use magic_wormhole_io_blocking::Wormhole;
use magic_wormhole::core::message;
use magic_wormhole::io::blocking::Wormhole;

// Can ws do hostname lookup? Use ip addr, not localhost, for now
const MAILBOX_SERVER: &'static str = "ws://127.0.0.1:4000/v1";
Expand Down
4 changes: 2 additions & 2 deletions core/examples/ws.rs → examples/ws-core.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
extern crate magic_wormhole_core;
extern crate magic_wormhole;
extern crate url;
extern crate ws;
use magic_wormhole_core::{
use magic_wormhole::core::{
message, APIAction, APIEvent, Action, AnswerType, IOAction, IOEvent,
PeerMessage, WSHandle, WormholeCore,
};
Expand Down
13 changes: 0 additions & 13 deletions io/blocking/Cargo.toml

This file was deleted.

7 changes: 0 additions & 7 deletions io/blocking/src/lib.rs

This file was deleted.

12 changes: 0 additions & 12 deletions io/tokio/Cargo.toml

This file was deleted.

Empty file removed io/tokio/src/lib.rs
Empty file.
File renamed without changes.
10 changes: 6 additions & 4 deletions core/src/allocator.rs → src/core/allocator.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
use events::{Code, Events, Wordlist};
use super::events::{Code, Events, Wordlist};
use std::sync::Arc;

// we process these
use events::AllocatorEvent::{self, Allocate, Connected, Lost, RxAllocated};
use super::events::AllocatorEvent::{
self, Allocate, Connected, Lost, RxAllocated,
};
// we emit these
use events::CodeEvent::Allocated as C_Allocated;
use events::RendezvousEvent::TxAllocate as RC_TxAllocate;
use super::events::CodeEvent::Allocated as C_Allocated;
use super::events::RendezvousEvent::TxAllocate as RC_TxAllocate;

pub struct AllocatorMachine {
state: State,
Expand Down
4 changes: 2 additions & 2 deletions core/src/api.rs → src/core/api.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use events::{Code, Key};
use super::events::{Code, Key};
use super::util::maybe_utf8;
use hex;
use serde_json::Value;
use std::error::Error;
use std::fmt;
use util::maybe_utf8;

#[derive(PartialEq)]
pub enum APIEvent {
Expand Down
30 changes: 15 additions & 15 deletions core/src/boss.rs → src/core/boss.rs
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
use api::Mood;
use events::{Code, Events, Nameplate, Phase};
use super::api::Mood;
use super::events::{Code, Events, Nameplate, Phase};
use super::wordlist::default_wordlist;
use std::str::FromStr;
use std::sync::Arc;
use wordlist::default_wordlist;

use regex::Regex;
use serde_json;

// we process these
use api::APIEvent;
use events::BossEvent;
use super::api::APIEvent;
use super::events::BossEvent;
// we emit these
use api::APIAction;
use events::CodeEvent::{
use super::api::APIAction;
use super::events::CodeEvent::{
AllocateCode as C_AllocateCode, InputCode as C_InputCode,
SetCode as C_SetCode,
};
use events::InputEvent::{
use super::events::InputEvent::{
ChooseNameplate as I_ChooseNameplate, ChooseWords as I_ChooseWords,
RefreshNameplates as I_RefreshNameplates,
};
use events::RendezvousEvent::Start as RC_Start;
use events::SendEvent::Send as S_Send;
use events::TerminatorEvent::Close as T_Close;
use super::events::RendezvousEvent::Start as RC_Start;
use super::events::SendEvent::Send as S_Send;
use super::events::TerminatorEvent::Close as T_Close;

#[derive(Debug, PartialEq, Copy, Clone)]
enum State {
Expand Down Expand Up @@ -64,7 +64,7 @@ impl BossMachine {
}

pub fn process_api(&mut self, event: APIEvent) -> Events {
use api::APIEvent::*;
use super::api::APIEvent::*;

match event {
Start => self.start(),
Expand All @@ -86,7 +86,7 @@ impl BossMachine {
}

pub fn process(&mut self, event: BossEvent) -> Events {
use events::BossEvent::*;
use super::events::BossEvent::*;
match event {
GotCode(code) => self.got_code(&code),
GotKey(key) => events![APIAction::GotUnverifiedKey(key.clone())],
Expand Down Expand Up @@ -292,8 +292,8 @@ impl BossMachine {
#[cfg(test)]
mod test {
use super::*;
use api::{APIEvent, Mood};
use events::{Key, RendezvousEvent, TerminatorEvent};
use core::api::{APIEvent, Mood};
use core::events::{Key, RendezvousEvent, TerminatorEvent};

#[test]
fn create() {
Expand Down
24 changes: 12 additions & 12 deletions core/src/code.rs → src/core/code.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use events::{Events, Nameplate};
use super::events::{Events, Nameplate};
// we process these
use events::CodeEvent;
use super::events::CodeEvent;
// we emit these
use events::AllocatorEvent::Allocate as A_Allocate;
use events::BossEvent::GotCode as B_GotCode;
use events::InputEvent::Start as I_Start;
use events::KeyEvent::GotCode as K_GotCode;
use events::NameplateEvent::SetNameplate as N_SetNameplate;
use super::events::AllocatorEvent::Allocate as A_Allocate;
use super::events::BossEvent::GotCode as B_GotCode;
use super::events::InputEvent::Start as I_Start;
use super::events::KeyEvent::GotCode as K_GotCode;
use super::events::NameplateEvent::SetNameplate as N_SetNameplate;

#[derive(Debug, PartialEq)]
enum State {
Expand Down Expand Up @@ -44,7 +44,7 @@ impl CodeMachine {
}

fn in_idle(&mut self, event: CodeEvent) -> (Option<State>, Events) {
use events::CodeEvent::*;
use super::events::CodeEvent::*;
match event {
AllocateCode(wordlist) => {
(Some(State::Allocating), events![A_Allocate(wordlist)])
Expand Down Expand Up @@ -74,7 +74,7 @@ impl CodeMachine {
&mut self,
event: CodeEvent,
) -> (Option<State>, Events) {
use events::CodeEvent::*;
use super::events::CodeEvent::*;
match event {
AllocateCode(..) => panic!(),
InputCode => panic!(),
Expand All @@ -92,7 +92,7 @@ impl CodeMachine {
&mut self,
event: CodeEvent,
) -> (Option<State>, Events) {
use events::CodeEvent::*;
use super::events::CodeEvent::*;
match event {
AllocateCode(..) => panic!(),
InputCode => panic!(),
Expand All @@ -107,7 +107,7 @@ impl CodeMachine {
}

fn in_allocating(&mut self, event: CodeEvent) -> (Option<State>, Events) {
use events::CodeEvent::*;
use super::events::CodeEvent::*;
match event {
AllocateCode(..) => panic!(),
InputCode => panic!(),
Expand All @@ -129,7 +129,7 @@ impl CodeMachine {
}

fn in_known(&mut self, event: &CodeEvent) -> (Option<State>, Events) {
use events::CodeEvent::*;
use super::events::CodeEvent::*;
match *event {
AllocateCode(..) => panic!(),
InputCode => panic!(),
Expand Down
10 changes: 5 additions & 5 deletions core/src/events.rs → src/core/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use std::iter::FromIterator;
use std::ops::Deref;
use std::sync::Arc;
// Events come into the core, Actions go out of it (to the IO glue layer)
use api::{APIAction, IOAction, Mood};
use util::maybe_utf8;
use super::api::{APIAction, IOAction, Mood};
use super::util::maybe_utf8;

pub use wordlist::Wordlist;
pub use super::wordlist::Wordlist;

#[derive(PartialEq, Eq, Clone, Debug)]
pub struct AppID(pub String);
Expand Down Expand Up @@ -538,13 +538,13 @@ impl FromIterator<Event> for Events {
macro_rules! events {
( ) => {
{
use events::Events;
use core::events::Events;
Events::new()
}
};
( $( $x:expr ),* $(,)*) => {
{
use events::Events;
use core::events::Events;
let mut temp_vec = Events::new();
$(
temp_vec.push($x);
Expand Down
Loading

0 comments on commit 35ca374

Please sign in to comment.