diff --git a/.env.example b/.env.example index 2897a23..42d6af9 100644 --- a/.env.example +++ b/.env.example @@ -1 +1 @@ -DATABASE_URL=postgres://username:password@localhost/diesel_demo +DATABASE_URL=astrocore_db.sqlite3 diff --git a/.gitignore b/.gitignore index 5525e0a..50febea 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ xdr-test .byebug_history Gemfile.lock .env +.vscode +astrocore_db.sqlite3 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8c65f58..0ed8b43 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -14,7 +14,8 @@ sodiumoxide libs in your OS 3. Change `.env.example` to `.env` and change DATABASE_URL 3. Install diesel and run migrations: ``` -cargo install diesel_cli --no-default-features --features postgres +sudo apt-get install sqlite3 libsqlite3-dev +cargo install diesel_cli --no-default-features --features sqlite diesel migration run ``` diff --git a/Cargo.lock b/Cargo.lock index de93867..92387fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,3 +1,5 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. [[package]] name = "adler32" version = "1.0.3" @@ -34,6 +36,8 @@ dependencies = [ "num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "riker 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "riker-default 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", "serde-xdr 0.5.0 (git+https://github.com/Arkweid/serde-xdr)", "serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -147,6 +151,15 @@ name = "byteorder" version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "bytes" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "bzip2" version = "0.3.3" @@ -175,6 +188,16 @@ name = "cfg-if" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "chrono" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cloudabi" version = "0.0.3" @@ -183,6 +206,21 @@ dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "config" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-ini 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde-hjson 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crc16" version = "0.3.4" @@ -218,10 +256,9 @@ name = "diesel" version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libsqlite3-sys 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "r2d2 0.8.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -318,6 +355,76 @@ name = "fuchsia-cprng" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "futures-channel-preview" +version = "0.3.0-alpha.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "futures-core-preview" +version = "0.3.0-alpha.15" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "futures-executor-preview" +version = "0.3.0-alpha.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-channel-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "futures-io-preview" +version = "0.3.0-alpha.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-core-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "futures-preview" +version = "0.3.0-alpha.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-channel-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-executor-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-io-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-util-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "futures-sink-preview" +version = "0.3.0-alpha.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-channel-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "futures-util-preview" +version = "0.3.0-alpha.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures-channel-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-core-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-io-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-sink-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "generic-array" version = "0.12.0" @@ -349,6 +456,15 @@ dependencies = [ "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "iovec" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "itertools" version = "0.8.0" @@ -357,6 +473,16 @@ dependencies = [ "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "itoa" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "lazy_static" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "lazy_static" version = "1.3.0" @@ -393,6 +519,29 @@ dependencies = [ "zip 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "libsqlite3-sys" +version = "0.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "linked-hash-map" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_test 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "linked-hash-map" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "lock_api" version = "0.1.5" @@ -415,6 +564,15 @@ name = "memchr" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "nom" +version = "4.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num" version = "0.1.42" @@ -467,6 +625,14 @@ name = "num-traits" version = "0.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "num_cpus" +version = "1.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "opaque-debug" version = "0.2.2" @@ -501,6 +667,11 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pin-utils" +version = "0.1.0-alpha.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "pkg-config" version = "0.3.14" @@ -511,14 +682,6 @@ name = "podio" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "pq-sys" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "proc-macro2" version = "0.4.27" @@ -724,6 +887,84 @@ dependencies = [ "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "riker" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "config 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "riker-deadletter" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "riker 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "riker-default" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "riker 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "riker-deadletter 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "riker-dispatcher 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "riker-log 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "riker-mapvec 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "riker-timer 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "riker-dispatcher" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "config 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)", + "riker 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "riker-log" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "config 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "riker 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "runtime-fmt 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "riker-mapvec" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "config 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "riker 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "riker-timer" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "config 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)", + "riker 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ring" version = "0.14.6" @@ -737,6 +978,16 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "runtime-fmt" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rust-ini" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rustc-demangle" version = "0.1.13" @@ -768,6 +1019,11 @@ dependencies = [ "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ryu" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "safemem" version = "0.3.0" @@ -808,6 +1064,11 @@ name = "semver-parser" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "serde" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "serde" version = "1.0.89" @@ -816,6 +1077,18 @@ dependencies = [ "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "serde-hjson" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "serde-xdr" version = "0.5.0" @@ -845,6 +1118,16 @@ dependencies = [ "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "serde_json" +version = "1.0.39" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "serde_repr" version = "0.1.3" @@ -855,6 +1138,14 @@ dependencies = [ "syn 0.15.29 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "serde_test" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "sha2" version = "0.8.0" @@ -911,6 +1202,11 @@ dependencies = [ "simulacrum_shared 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "slab" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "smallvec" version = "0.6.9" @@ -1060,6 +1356,15 @@ name = "utf8-ranges" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "uuid" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "vcpkg" version = "0.2.6" @@ -1088,6 +1393,11 @@ dependencies = [ "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "winapi" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "winapi" version = "0.3.6" @@ -1132,6 +1442,14 @@ dependencies = [ "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "yaml-rust" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "zip" version = "0.5.1" @@ -1161,11 +1479,14 @@ dependencies = [ "checksum block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d75255892aeb580d3c566f213a2b6fdc1c66667839f45719ee1d30ebf2aea591" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" +"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum bzip2 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "42b7c3cbf0fa9c1b82308d57191728ca0256cb821220f4e2fd410a72ade26e3b" "checksum bzip2-sys 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "6584aa36f5ad4c9247f5323b0a42f37802b37a836f0ad87084d7a33961abe25f" "checksum cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ce8bb087aacff865633f0bd5aeaed910fe2fe55b55f4739527f2e023a2e53d" "checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" +"checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum config 0.9.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e82d07fac0a5eeaa9d959b5194d01bb66e414665f547416958d2b430f8f4852" "checksum crc16 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "11a65c4797332f3e3a5945e0377875afc79b1bdc87082a4f98ac1ef15b47e2dd" "checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" "checksum debugit 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "63c2f7e3034df2b09f750327e23c1adfe33301e6b7388f05bb4fcc0fa46825e3" @@ -1182,31 +1503,46 @@ dependencies = [ "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum filetime 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a2df5c1a8c4be27e7707789dc42ae65976e60b394afd293d1419ab915833e646" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +"checksum futures-channel-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)" = "edf150887ba490560f3d732e479a383ca4b8696af98651806d3f4edc1d968585" +"checksum futures-core-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)" = "10a3833d58fd08b3a40203613ed3a93c8bc0bc0181af5dd6422a0e08df1bfa68" +"checksum futures-executor-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)" = "0a75c64f20734619b4668e87f902544ce8c108dfcb6c9b6b2fcefdd1a848c15a" +"checksum futures-io-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)" = "b24891994ce1445f7e0cd494e4f57fd79f5bd9d37e9cc90a31d109e9a06d9073" +"checksum futures-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f5b8da0ac7e67b6341b8c971918f2bb6540f57b06a8644a76edf17dda0728709" +"checksum futures-sink-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f64fa75a0ce02dee949c8c9447abfc117df214054d6e96755d329c9053baf2fd" +"checksum futures-util-preview 0.3.0-alpha.15 (registry+https://github.com/rust-lang/crates.io-index)" = "ca958da50f4073c475d9f7ec6ce405451e06707bfd69686e83abd76cb4e1e7fb" "checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" "checksum handlebox 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4726136a7636c738124814f1275dd59a709f4cf4dd7b4b670df95b6bf6c4a0ae" "checksum http_req 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "04683f906f43d8773f936a72c9b1b25cd3ee45d07d49479b8d000493358d3b8c" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" +"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" +"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" +"checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1" "checksum libflate 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "7346a83e8a2c3958d44d24225d905385dc31fc16e89dffb356c457b278914d20" "checksum libsodium-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "09ff79e60003db178b30f7a43a56edfb726889f247a2a3b5d7a777bc0f8349f5" +"checksum libsqlite3-sys 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fd6457c70bbff456d9fe49deaba35ec47c3e598bf8d7950ff0575ceb7a8a6ad1" +"checksum linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6d262045c5b87c0861b3f004610afd0e2c851e2908d08b6c870cbb9d5f494ecd" +"checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" +"checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" "checksum num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" "checksum num-bigint 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1" "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" "checksum num-iter 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "af3fdbbc3291a5464dc57b03860ec37ca6bf915ed6ee385e7c6c052c422b2124" "checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" +"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" "checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" "checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +"checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum podio 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "780fb4b6698bbf9cf2444ea5d22411cef2953f0824b98f33cf454ec5615645bd" -"checksum pq-sys 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "6ac25eee5a0582f45a67e837e350d784e7003bd29a5f460796772061ca49ffda" "checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" @@ -1230,28 +1566,43 @@ dependencies = [ "checksum regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53ee8cfdddb2e0291adfb9f13d31d3bbe0a03c9a402c01b1e24188d86c35b24f" "checksum regex-syntax 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7d707a4fa2637f2dca2ef9fd02225ec7661fe01a53623c1e6515b6916511f7a7" "checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" +"checksum riker 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f95ad8d914c4b9ef0afa713694ba6477f37ca8f45c3aa64a354f6ac9d3a3826c" +"checksum riker-deadletter 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4babf9dbc8a84eac86f873441c0e61ed4b43eb795e3336e76c6acdc2ea0e49f4" +"checksum riker-default 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "dab8848e5bb493c0ede4ffb8579417715aceab2ec4af80d794f029c2900931b1" +"checksum riker-dispatcher 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "45eddf3ed91bf72b5612fa6aa55e79ff8d76f23d64bce96935f0f121cf273eac" +"checksum riker-log 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "580e763ff3bc41910944da311536178e674912c4f319863b1c613b0a2f9c7d9a" +"checksum riker-mapvec 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "97afa546a3f5fb42792be071fad172fa6b28f44c2429387922a08e362962e726" +"checksum riker-timer 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b58fda680add7e10b6fea3d428e139ddb9725365395d220e200de1e6c99e444d" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" +"checksum runtime-fmt 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "647a821d66049faccc993fc3c379d1181b81a484097495cda79ffdb17b55b87f" +"checksum rust-ini 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e52c148ef37f8c375d49d5a73aa70713125b7f19095948a923f80afdeb22ec2" "checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rustls 0.15.1 (registry+https://github.com/rust-lang/crates.io-index)" = "38af00e78b66109e7184a0ee16940f41583161b7ec0518af258e4bcaed15db25" +"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" "checksum scheduled-thread-pool 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a2ff3fc5223829be817806c6441279c676e454cc7da608faf03b0ccc09d3889" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" "checksum sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f5adf8fbd58e1b1b52699dc8bed2630faecb6d8c7bee77d009d6bbe4af569b9" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +"checksum serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" "checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560" +"checksum serde-hjson 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0b833c5ad67d52ced5f5938b2980f32a9c1c5ef047f0b4fb3127e7a423c76153" "checksum serde-xdr 0.5.0 (git+https://github.com/Arkweid/serde-xdr)" = "" "checksum serde_bytes 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)" = "defbb8a83d7f34cc8380751eeb892b825944222888aff18996ea7901f24aec88" "checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c" +"checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" "checksum serde_repr 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "27eea49bc616621e68d4de38110ff9e18ab8bd4c61dae48c477e85587571afc1" +"checksum serde_test 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "110b3dbdf8607ec493c22d5d947753282f3bae73c0f56d322af1e8c78e4c23d5" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" "checksum simulacrum 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fc6cbc16111f66b2f6e0d5c523221fefbfbc5db82fe53a1797bd0840d20958ce" "checksum simulacrum_macros 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dfdc5aa67bc316dca41675f669d544aea393f6319dd8bf921b03dc113d09adca" "checksum simulacrum_mock 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b0a3be81ab017d792fee7be1faa37f3949ebde8f85351951fa1758ae95baec4a" "checksum simulacrum_shared 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f784fd3a3691ec375a713ee20dff673a45ca221002e7b4e69c7940320b7e316a" "checksum simulacrum_user 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "db58f8fdfe08b9b95bf3ebce8d92091a5d65107da1afdeeb9004e1f6ed2ae81f" +"checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum sodiumoxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "59f5fc75b810875ade9581b15c68543367dbba8bf3d0ae1ba63989171803d357" "checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" @@ -1272,14 +1623,17 @@ dependencies = [ "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" +"checksum uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e1436e58182935dcd9ce0add9ea0b558e8a87befe01c1a301e6020aeb0876363" "checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4f7e1cd7900a3a6b65a3e8780c51a3e6b59c0e2c55c6dc69578c288d69f7d082" "checksum webpki-roots 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c10fa4212003ba19a564f25cd8ab572c6791f99a03cc219c13ed35ccab00de0e" +"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" "checksum xattr 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" +"checksum yaml-rust 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "65923dd1784f44da1d2c3dbbc5e822045628c590ba72123e1c73d3c230c4434d" "checksum zip 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1cbbddef6339155bc4fa8e2609040078ff18f3011117b55caa9f0516d544a357" diff --git a/Cargo.toml b/Cargo.toml index e842b23..67b88d5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,8 +27,10 @@ simulacrum = "0.3.0" itertools = "0.8" toml = "0.4" lazy_static = "1.3" -diesel = { version = "1.4", features = ["postgres", "r2d2"] } +diesel = { version = "1.4", features = ["sqlite", "r2d2"] } dotenv = "0.10" +riker = "0.2.4" +riker-default = "0.2.4" [profile.dev] debug = true diff --git a/README.md b/README.md index 1de0171..c6c0d13 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,7 @@ We already complete handsnake process with remote peer. So you can monitor all m ## Requirements PostgreSQL +libsodium-dev ## Quick start @@ -13,7 +14,7 @@ PostgreSQL 2. Change `.env.example` to `.env` and change DATABASE_URL 3. Install diesel and run migrations: ``` -cargo install diesel_cli --no-default-features --features postgres +cargo install diesel_cli --no-default-features --features sqlite diesel migration run ``` diff --git a/migrations/00000000000000_diesel_initial_setup/down.sql b/migrations/00000000000000_diesel_initial_setup/down.sql deleted file mode 100644 index a9f5260..0000000 --- a/migrations/00000000000000_diesel_initial_setup/down.sql +++ /dev/null @@ -1,6 +0,0 @@ --- This file was automatically created by Diesel to setup helper functions --- and other internal bookkeeping. This file is safe to edit, any future --- changes will be added to existing projects as new migrations. - -DROP FUNCTION IF EXISTS diesel_manage_updated_at(_tbl regclass); -DROP FUNCTION IF EXISTS diesel_set_updated_at(); diff --git a/migrations/00000000000000_diesel_initial_setup/up.sql b/migrations/00000000000000_diesel_initial_setup/up.sql deleted file mode 100644 index d68895b..0000000 --- a/migrations/00000000000000_diesel_initial_setup/up.sql +++ /dev/null @@ -1,36 +0,0 @@ --- This file was automatically created by Diesel to setup helper functions --- and other internal bookkeeping. This file is safe to edit, any future --- changes will be added to existing projects as new migrations. - - - - --- Sets up a trigger for the given table to automatically set a column called --- `updated_at` whenever the row is modified (unless `updated_at` was included --- in the modified columns) --- --- # Example --- --- ```sql --- CREATE TABLE users (id SERIAL PRIMARY KEY, updated_at TIMESTAMP NOT NULL DEFAULT NOW()); --- --- SELECT diesel_manage_updated_at('users'); --- ``` -CREATE OR REPLACE FUNCTION diesel_manage_updated_at(_tbl regclass) RETURNS VOID AS $$ -BEGIN - EXECUTE format('CREATE TRIGGER set_updated_at BEFORE UPDATE ON %s - FOR EACH ROW EXECUTE PROCEDURE diesel_set_updated_at()', _tbl); -END; -$$ LANGUAGE plpgsql; - -CREATE OR REPLACE FUNCTION diesel_set_updated_at() RETURNS trigger AS $$ -BEGIN - IF ( - NEW IS DISTINCT FROM OLD AND - NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at - ) THEN - NEW.updated_at := current_timestamp; - END IF; - RETURN NEW; -END; -$$ LANGUAGE plpgsql; diff --git a/migrations/2019-04-16-150207_create_peers/up.sql b/migrations/2019-04-16-150207_create_peers/up.sql index 8216c19..36217ef 100644 --- a/migrations/2019-04-16-150207_create_peers/up.sql +++ b/migrations/2019-04-16-150207_create_peers/up.sql @@ -1,4 +1,4 @@ CREATE TABLE peers ( - id SERIAL PRIMARY KEY, + id INTEGER PRIMARY KEY, address VARCHAR (20) UNIQUE NOT NULL ) diff --git a/riker.toml b/riker.toml new file mode 100644 index 0000000..50c0b1e --- /dev/null +++ b/riker.toml @@ -0,0 +1,38 @@ + +[log] +# max level to log +level = "debug" + +filter = [ "test", "debug" ] + +# log format to use +# correlates to format!(log_format, date=, time=, level=, module=, body=); +# since named parameters are used the order of the fields is flexible +# the formatting of each field can be changed also +# e.g. to completely hide a field: {module:.0} +# See: https://doc.rust-lang.org/std/fmt/#syntax + +# {date} the calendar day +# {time} the calendar time +# {level} the level for the entry +# {module} the module path originating the entry +# {body} the message body +log_format = "{date} {time} {level} [{module}] {body}" +date_format = "%Y-%m-%d" +time_format = "%H:%M:%S%:z" + +[mailbox] +# maximum number of messages to process in each execution of mailbox +# the mailbox will be rescheduled if there are any remaining messages +msg_process_limit = 1000 + +[dispatcher] +# number of threads available to the CPU pool +pool_size = 12 + +[scheduler] +frequency_millis = 50 + +[cqrs] +# number of seconds of inactivity after which a cqrs actor will sleep +sleep_after_secs = 120 diff --git a/src/astro_protocol.rs b/src/astro_protocol.rs new file mode 100644 index 0000000..f91d540 --- /dev/null +++ b/src/astro_protocol.rs @@ -0,0 +1,32 @@ +use crate::overlay::Peer; +use crate::xdr; +use riker::actors::*; + +/** + * AstroProtocol contains all kind of messages we use for + * communication between actors +*/ + +#[derive(Clone, Debug)] +pub enum AstroProtocol { + /// New Peer incoming from Listener + HandleOverlayIncomingPeerCmd(Peer), + /// Check connections limit + CheckOverlayMinConnectionsCmd, + /// Awaiting incoming messag from remote peer + ServePeerCmd, + /// PeerActor must send message + SendPeerMessageCmd(xdr::StellarMessage), + /// Received message from PeerActor + ReceivedPeerMessageCmd(String, xdr::StellarMessage), + /// Authentication process between PeerActor and remote peer succeed + AuthPeerOkCmd(String), + /// PeerActor interaction failed + FailedPeerCmd(String), +} + +impl Into> for AstroProtocol { + fn into(self) -> ActorMsg { + ActorMsg::User(self) + } +} diff --git a/src/database/mod.rs b/src/database/mod.rs index cb60515..b71e74c 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -8,8 +8,8 @@ mod repository; pub(crate) use self::repository::db_conn; pub(crate) use crate::config::CONFIG; pub(crate) use crate::schema; -pub(crate) use diesel::pg::PgConnection; pub(crate) use diesel::r2d2::{ConnectionManager, Pool, PooledConnection}; +pub(crate) use diesel::sqlite::SqliteConnection; pub(crate) use dotenv::dotenv; pub(crate) use lazy_static::lazy_static; pub(crate) use log::info; diff --git a/src/database/models/peer.rs b/src/database/models/peer.rs index 9fbc5b6..50b491e 100644 --- a/src/database/models/peer.rs +++ b/src/database/models/peer.rs @@ -16,12 +16,12 @@ impl Peer { peers.load::(&*db_conn()) } - pub fn create<'a>(addr: &String) -> Result { + pub fn create<'a>(addr: &String) -> Result { let new_peer = NewPeer { address: addr }; diesel::insert_into(peers::table) .values(&new_peer) - .get_result(&*db_conn()) + .execute(&*db_conn()) } pub fn get<'a>(addr: &String) -> Result> { diff --git a/src/database/repository.rs b/src/database/repository.rs index c42fddb..f6d0a76 100644 --- a/src/database/repository.rs +++ b/src/database/repository.rs @@ -1,17 +1,18 @@ use super::{ - dotenv, env, info, lazy_static, ConnectionManager, PgConnection, Pool, PooledConnection, CONFIG, + dotenv, env, info, lazy_static, ConnectionManager, Pool, PooledConnection, SqliteConnection, + CONFIG, }; lazy_static! { - pub static ref DB: Pool> = establish_connection(); + pub static ref DB: Pool> = establish_connection(); } -fn establish_connection() -> Pool> { +fn establish_connection() -> Pool> { dotenv().ok(); let database_url = env::var("DATABASE_URL").expect("[DB] DATABASE_URL must be set"); - let manager = ConnectionManager::::new(database_url.to_owned()); + let manager = ConnectionManager::::new(database_url.to_owned()); let pool = Pool::builder() .max_size(*CONFIG.db_pool()) .build(manager) @@ -24,6 +25,6 @@ fn establish_connection() -> Pool> { pool } -pub(crate) fn db_conn() -> PooledConnection> { +pub(crate) fn db_conn() -> PooledConnection> { DB.get().unwrap() } diff --git a/src/lib.rs b/src/lib.rs index 908f07e..4d5d510 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,6 +4,7 @@ extern crate diesel; pub mod factories; pub mod xdr; +pub(crate) mod astro_protocol; pub(crate) mod config; pub(crate) mod crypto; pub(crate) mod database; diff --git a/src/main.rs b/src/main.rs index 506140a..7e6ef32 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,7 @@ #[macro_use] extern crate diesel; +mod astro_protocol; mod config; mod crypto; mod database; @@ -10,10 +11,20 @@ mod overlay; mod schema; mod scp; mod xdr; -use overlay::overlay_manager::OverlayManager; + +use astro_protocol::AstroProtocol; +use overlay::overlay_manager::OverlayManagerActor; +use riker::actors::*; +use riker_default::DefaultModel; fn main() { env_logger::init(); database::init(); - OverlayManager::new().start(); + + let model: DefaultModel = DefaultModel::new(); + let sys = ActorSystem::new(&model).unwrap(); + let props = OverlayManagerActor::props(); + sys.actor_of(props, "overlay_manager").unwrap(); + + loop {} } diff --git a/src/overlay/mod.rs b/src/overlay/mod.rs index a2fb50b..d364040 100644 --- a/src/overlay/mod.rs +++ b/src/overlay/mod.rs @@ -5,6 +5,7 @@ pub(crate) mod overlay_manager; pub(crate) mod peer; pub(crate) use crate::{ + astro_protocol::AstroProtocol, config::CONFIG, crypto, database, scp::local_node::{LocalNode, LOCAL_NODE}, @@ -12,11 +13,15 @@ pub(crate) use crate::{ }; pub(crate) use byteorder::{BigEndian, WriteBytesExt}; pub(crate) use itertools; -pub(crate) use log::{debug, error, info}; +pub(crate) use log::{debug, error, info, trace}; pub(crate) use rand::Rng; +pub(crate) use riker; pub(crate) use serde_xdr; pub(crate) use sha2; +pub(crate) use self::overlay_manager::{OverlayManager, OverlayManagerActor}; +pub(crate) use self::peer::Peer; + pub fn message_abbr(message: &xdr::StellarMessage) -> String { let bytes = serde_xdr::to_bytes(message).unwrap(); String::from_utf8_lossy(crypto::hash(&bytes.as_slice()).as_slice()).to_string() diff --git a/src/overlay/overlay_manager.rs b/src/overlay/overlay_manager.rs index 741099d..995f21f 100644 --- a/src/overlay/overlay_manager.rs +++ b/src/overlay/overlay_manager.rs @@ -1,11 +1,13 @@ use super::{ database, error, flood_gate::FloodGate, - info, + info, debug, itertools::join, - peer::{Peer, PeerInterface}, - xdr, CONFIG, + peer::{Peer, PeerActor, PeerInterface}, + riker::actors::*, + xdr, AstroProtocol, CONFIG, }; + use std::collections::{HashMap, HashSet}; use std::net::{TcpListener, TcpStream}; use std::thread; @@ -45,10 +47,12 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; * The OverlayManager tracks its known peers in the Database and shares peer * records with other peers when asked. */ +#[derive(Clone, Debug)] pub struct OverlayManager { known_peer_adresses: HashSet, - authenticated_peers: HashMap, + authenticated_peers: HashSet, pending_peers: HashSet, + failed_peers: HashSet, } #[derive(Debug)] @@ -58,96 +62,13 @@ pub enum OverlayError { InvalidPeerAddress, } -pub enum OverlayMessages { - NewConnection(String), - NewPeer(String), - PeerFailure(String), - NewStellarMessage(String, xdr::StellarMessage), -} - impl OverlayManager { pub fn new() -> Self { - // RWlock OverlayManager { known_peer_adresses: HashSet::new(), - authenticated_peers: HashMap::new(), + authenticated_peers: HashSet::new(), pending_peers: HashSet::new(), - } - } - - /// start main overlay manager process - pub fn start(&mut self) { - thread::spawn(move || handle_clients()); - - self.populate_known_peers_from_db(); - - let mut flood_gate = FloodGate::new(); - let mut received_messages: HashMap = HashMap::new(); - let mut failed_peers: HashSet = HashSet::new(); - - loop { - self.auth_all_known_peers(); - info!("Auth peers: {:?}", self.authenticated_peers.keys()); - - for (peer_address, peer) in &mut self.authenticated_peers { - match peer.receive_message() { - Ok(msg) => { - let message: xdr::StellarMessage = msg.into(); - info!("Received message from: {}", peer_address); - received_messages.insert(peer_address.clone(), message.clone()); - } - Err(e) => { - error!("Cant read XDR message cause: {}", e); - failed_peers.insert(peer_address.clone()); - } - }; - } - - let current_ledger = unix_time(); - for (addr, msg) in received_messages.drain().take(1) { - match msg { - xdr::StellarMessage::Peers(ref message) => self.add_known_peers(message), - xdr::StellarMessage::Transaction(_) | xdr::StellarMessage::Envelope(_) => { - flood_gate.add_record(&msg, addr.clone(), current_ledger); - flood_gate.broadcast(msg.clone(), false, &mut self.authenticated_peers); - } - _ => (), - } - } - - flood_gate.clear_below(current_ledger); - - for addr in failed_peers.drain().take(1) { - self.remove_peer_from_authenticated_list(&addr); - } - } - } - - /// Accept peer_address in parseable format and trying to start_authenticate new connection - fn connect_to(&self, peer_address: String) -> Result { - let address = match peer_address.parse() { - Ok(addr) => addr, - Err(_) => return Err(OverlayError::InvalidPeerAddress), - }; - - match TcpStream::connect_timeout(&address, Duration::new(2, 0)) { - Ok(stream) => { - info!("Successfully connected to peer {}", address); - let cloned_stream = stream.try_clone().expect("clone failed..."); - - let mut peer = Peer::new(cloned_stream, peer_address); - peer.start_authentication(true); - - if peer.is_authenticated() { - return Ok(peer); - } else { - return Err(OverlayError::AuthFail); - } - } - Err(e) => { - error!("Failed to connect: {}, cause {}", address, e); - return Err(OverlayError::ConnectionFail); - } + failed_peers: HashSet::new(), } } @@ -160,14 +81,17 @@ impl OverlayManager { .. } = peer_addres { - self.add_known_peer(format!("{}:{}", join(addr, "."), peer_addres.port)); + let peer_format_name = format!("{}:{}", join(addr, "."), peer_addres.port); + self.add_known_peer(peer_format_name); } } } - /// Add single peer address to known_peer_adresses list + /// Add new peer address to known_peer_adresses list fn add_known_peer(&mut self, peer_address: String) { - self.known_peer_adresses.insert(peer_address); + if self.is_new_peer(&peer_address) { + self.known_peer_adresses.insert(peer_address); + } } /// Remove single peer address from known_peer_adresses list @@ -185,51 +109,56 @@ impl OverlayManager { self.pending_peers.remove(peer_address); } + /// Add single peer address to authenticated_peers list + fn add_authenticated_peer(&mut self, peer_address: String) { + self.authenticated_peers.insert(peer_address); + } + + /// Remove single peer address from authenticated_peers list + fn remove_authenticated_peer(&mut self, peer_address: &String) { + self.authenticated_peers.remove(peer_address); + } + + /// Add single peer address to failed_peer list + fn add_failed_peer(&mut self, peer_address: String) { + self.failed_peers.insert(peer_address); + } + + /// Remove single peer address from failed_peer list + fn remove_failed_peer(&mut self, peer_address: &String) { + self.failed_peers.remove(peer_address); + } + fn is_new_peer(&self, peer_address: &String) -> bool { !self.is_peer_exist(peer_address) } fn is_peer_exist(&self, peer_address: &String) -> bool { self.known_peer_adresses.contains(peer_address) - || self.authenticated_peers.contains_key(peer_address) + || self.authenticated_peers.contains(peer_address) || self.pending_peers.contains(peer_address) - } - - /// Iterate through known_peer_adresses and trying to a authenticate each. - /// If authentication procees is Ok(), so move new peer in list of authenticated_peers - fn auth_all_known_peers(&mut self) { - if self.reached_limit_of_authenticated_peers() { - return; - }; - - let peers_address = self.known_peer_adresses.clone(); - for peer_address in peers_address { - if self.authenticated_peers.contains_key(&peer_address) { - continue; - }; - - let peer_result = self.connect_to(peer_address.to_owned()); - if let Ok(peer) = peer_result { - self.move_peer_to_authenticated_list(peer_address.to_owned(), peer); - } else { - self.move_peer_to_pending_list(peer_address.to_owned()); - }; - - if self.reached_limit_of_authenticated_peers() { - break; - }; - } + || self.failed_peers.contains(peer_address) } /// Move peer to authenticated_peers list - fn move_peer_to_authenticated_list(&mut self, peers_addresses: String, peer: Peer) { + fn move_peer_to_authenticated_list(&mut self, peers_addresses: String) { self.remove_known_peer(&peers_addresses); - self.authenticated_peers.insert(peers_addresses, peer); + self.remove_pending_peer(&peers_addresses); + self.add_authenticated_peer(peers_addresses); } - /// Remove single peer address from authenticated_peers list - fn remove_peer_from_authenticated_list(&mut self, peers_addresses: &String) { - self.authenticated_peers.remove(peers_addresses); + fn move_peer_to_pending_list(&mut self, peers_address: String) { + self.remove_known_peer(&peers_address); + self.remove_authenticated_peer(&peers_address); + self.remove_failed_peer(&peers_address); + self.add_pending_peer(peers_address); + } + + fn move_peer_to_failed_list(&mut self, peers_address: String) { + self.remove_known_peer(&peers_address); + self.remove_authenticated_peer(&peers_address); + self.remove_pending_peer(&peers_address); + self.add_failed_peer(peers_address); } /// Limit number of connections we can have between peers @@ -244,13 +173,13 @@ impl OverlayManager { } } - fn move_peer_to_pending_list(&mut self, peers_address: String) { - self.remove_known_peer(&peers_address); - } - fn reached_limit_of_authenticated_peers(&self) -> bool { self.authenticated_peers.len() >= self.limit_authenticated_peers() } + + fn peers_to_authenticated_limit(&self) -> i32 { + self.limit_authenticated_peers() as i32 - self.authenticated_peers.len() as i32 + } } // stub for current ledger value @@ -261,27 +190,183 @@ fn unix_time() -> u32 { .as_secs() as u32 } -fn handle_clients() { - let listener = TcpListener::bind(CONFIG.local_node().address()) - .expect("Unable to send on OverlayManager channel");; - for stream in listener.incoming() { - match stream { - Ok(stream) => launch_new_peer(stream, false), - Err(e) => { - error!("CONNECTION FAILED, cause: {:?}", e); +#[derive(Clone, Debug)] +pub(crate) struct OverlayManagerActor { + state: OverlayManager, +} + +impl OverlayManagerActor { + pub fn new() -> BoxActor { + let actor = OverlayManagerActor { + state: OverlayManager::new(), + }; + + Box::new(actor) + } + + pub fn props() -> BoxActorProd { + Props::new(Box::new(OverlayManagerActor::new)) + } + + /// Run Listener actor for checking incoming connections + pub fn run_listener_actor(&mut self, ctx: &Context) { + ctx.system + .actor_of(OverlayListenerActor::props(), "overlay_connection_listener") + .unwrap(); + } + + /// Run sheduler for checking minimal count of connections with peers + pub fn run_periodic_checker(&mut self, ctx: &Context) { + let delay = Duration::from_millis(1000); + ctx.schedule_once( + delay, + ctx.myself(), + None, + AstroProtocol::CheckOverlayMinConnectionsCmd, + ); + } + + /// Check minimal connections + pub fn check_min_connections(&mut self, ctx: &Context) { + if self.state.reached_limit_of_authenticated_peers() { + return; + } + + let limit = self.state.peers_to_authenticated_limit() as usize; + let mut taked_peers: Vec<_> = self + .state + .known_peer_adresses + .iter() + .cloned() + .take(limit) + .collect(); + + for peer in taked_peers { + self.state.move_peer_to_pending_list(peer.to_owned()); + self.handle_new_initiated_peer(ctx, peer); + } + + self.run_periodic_checker(ctx); + } + + pub fn handle_new_incoming_peer(&mut self, ctx: &Context, mut peer: Peer) { + if !self.state.reached_limit_of_authenticated_peers() { + let name = format!("peer-{}", peer.peer_addr()); + ctx.system + .actor_of(PeerActor::incoming_peer_props(peer), &name); + } + } + + pub fn handle_new_initiated_peer(&mut self, ctx: &Context, address: String) { + let name = format!("peer-{}", address); + ctx.system + .actor_of(PeerActor::initiated_peer_props(address), &name); + } + + pub fn handle_incoming_message(&mut self, address: String, message: xdr::StellarMessage) { + match message { + xdr::StellarMessage::Peers(ref set_of_peers) => { + self.state.add_known_peers(set_of_peers); + info!("[OverlayManager][add_known_peers] {:?}", self.state.known_peer_adresses); + } + xdr::StellarMessage::Transaction(_) | xdr::StellarMessage::Envelope(_) => { + // flood_gate.add_record(&msg, addr.clone(), current_ledger); + // flood_gate.broadcast(msg.clone(), false, &mut self.authenticated_peers); } + _ => (), } + // flood_gate.clear_below(current_ledger); } - unreachable!(); } -fn launch_new_peer(stream: TcpStream, we_called_remote: bool) { - thread::spawn(move || { - let mut peer = Peer::new(stream, CONFIG.local_node().address()); - peer.start_authentication(we_called_remote); - if peer.is_authenticated() { - peer.start_serve(); - } else { +impl Actor for OverlayManagerActor { + type Msg = AstroProtocol; + + fn pre_start(&mut self, ctx: &Context) { + self.state = OverlayManager::new(); + self.state.populate_known_peers_from_db(); + } + + fn receive( + &mut self, + ctx: &Context, + msg: Self::Msg, + sender: Option>, + ) { + debug!("OVERLAY RECEIVE: {:?}", msg); + match msg { + AstroProtocol::CheckOverlayMinConnectionsCmd => self.check_min_connections(ctx), + AstroProtocol::HandleOverlayIncomingPeerCmd(peer) => { + self.handle_new_incoming_peer(ctx, peer) + } + AstroProtocol::ReceivedPeerMessageCmd(address, message) => { + self.handle_incoming_message(address, message) + } + AstroProtocol::AuthPeerOkCmd(address) => { + self.state.move_peer_to_authenticated_list(address) + } + AstroProtocol::FailedPeerCmd(address) => { + self.state.move_peer_to_failed_list(address); + ctx.system.stop(&sender.unwrap()); + } + _ => unreachable!(), } - }); + } + + fn post_start(&mut self, ctx: &Context) { + self.run_listener_actor(ctx); + self.run_periodic_checker(ctx); + } +} + +pub(crate) struct OverlayListenerActor; + +impl OverlayListenerActor { + pub fn new() -> BoxActor { + Box::new(OverlayListenerActor) + } + + fn props() -> BoxActorProd { + Props::new(Box::new(OverlayListenerActor::new)) + } +} + +impl Actor for OverlayListenerActor { + type Msg = AstroProtocol; + + fn receive( + &mut self, + ctx: &Context, + msg: Self::Msg, + _sender: Option>, + ) { + unreachable!(); + } + + fn post_start(&mut self, ctx: &Context) { + let listener = TcpListener::bind(CONFIG.local_node().address()).expect( + "[Overlay][Listener] Unable to listen local address to handle incoming connections", + ); + + info!( + "[Overlay][Listener] start to listen incoming connections on {:?}", + CONFIG.local_node().address() + ); + + for stream in listener.incoming() { + match stream { + Ok(stream) => { + stream.set_read_timeout(Some(Duration::from_millis(300))); + let peer = Peer::new(stream, CONFIG.local_node().address()); + ctx.myself() + .parent() + .tell(AstroProtocol::HandleOverlayIncomingPeerCmd(peer), None) + } + Err(e) => { + info!("[Overlay][Listener] CONNECTION FAILED, cause: {:?}", e); + } + } + } + unreachable!(); + } } diff --git a/src/overlay/peer.rs b/src/overlay/peer.rs index ad3aeb0..5da10b2 100644 --- a/src/overlay/peer.rs +++ b/src/overlay/peer.rs @@ -1,9 +1,10 @@ use super::{ - crypto, debug, error, info, serde_xdr, sha2::Digest, xdr, + crypto, debug, error, trace, info, riker::actors::*, serde_xdr, sha2::Digest, xdr, AstroProtocol, BigEndian, LocalNode, Rng, WriteBytesExt, LOCAL_NODE, }; use std::io::{Cursor, Read, Write}; -use std::time::{SystemTime, UNIX_EPOCH}; +use std::net::TcpStream; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; #[derive(Debug)] pub struct Peer { @@ -62,6 +63,13 @@ pub trait PeerInterface { fn address(&self) -> &String; } +#[derive(Debug)] +pub enum PeerError { + AuthFail, + ConnectionFail, + InvalidPeerAddress, +} + impl Peer { /// Return peer instance with connection pub fn new(stream: std::net::TcpStream, address: String) -> Peer { @@ -106,20 +114,27 @@ impl Peer { } } - pub fn peer_addr(&self) -> String { - self.stream.peer_addr().unwrap().ip().to_string() - } + /// Accept peer_address in parseable format and trying to start_authenticate new connection + fn connect_to(peer_address: String) -> Result { + let address = match peer_address.parse() { + Ok(addr) => addr, + Err(_) => return Err(PeerError::InvalidPeerAddress), + }; - pub fn start_serve(&mut self) { - match self.receive_message() { - Ok(msg) => { - let message: xdr::StellarMessage = msg.into(); - info!("Received message from: {:?}", message); + match TcpStream::connect_timeout(&address, Duration::new(5, 0)) { + Ok(stream) => { + trace!("Established peer connection with: {}", address); + Ok(Peer::new(stream, peer_address)) } Err(e) => { - error!("Cant read XDR message cause: {}", e); + trace!("Failed to connect: {}, cause {}", address, e); + Err(PeerError::ConnectionFail) } - }; + } + } + + pub fn peer_addr(&self) -> String { + self.stream.peer_addr().unwrap().ip().to_string() } } @@ -143,7 +158,7 @@ impl PeerInterface for Peer { /// More additional info: https://github.com/stellar/stellar-core/blob/ddef8bcacc5193bdd4daa07af404f1b6b1adaf39/src/overlay/OverlayManagerImpl.cpp#L28-L45 fn start_authentication(&mut self, we_called_remote: bool) -> () { info!( - "[Overlay] Started authentication proccess peer: {}", + "[Overlay][Peer] Started authentication proccess peer: {}", self.address ); @@ -154,8 +169,8 @@ impl PeerInterface for Peer { self.handle_hello(hello.message, we_called_remote); } _ => { - error!( - "[Overlay] Received not hello message from peer {}. Authentication aborted", + info!( + "[Overlay][Peer] Received not hello message from peer {}. Authentication aborted", self.address ); return; @@ -165,8 +180,8 @@ impl PeerInterface for Peer { // last auth message from remote peer match self.receive_message() { Err(_) => { - error!( - "[Overlay] Not received last auth message {}. Authentication aborted", + info!( + "[Overlay][Peer] Not received last auth message {}. Authentication aborted", self.address ); return; @@ -179,8 +194,8 @@ impl PeerInterface for Peer { self.handle_hello(hello.message, we_called_remote); } _ => { - error!( - "[Overlay] Received not hello message from peer {}. Authentication aborted", + info!( + "[Overlay][Peer] Received non hello message from peer {}. Authentication aborted", self.address ); return; @@ -191,8 +206,8 @@ impl PeerInterface for Peer { // last auth message from remote peer match self.receive_message() { Err(_) => { - error!( - "[Overlay] Not received last auth message {}. Authentication aborted", + info!( + "[Overlay][Peer] Not received last auth message {}. Authentication aborted", self.address ); return; @@ -321,7 +336,6 @@ impl PeerInterface for Peer { } } - // TODO: mutex required? /// Send XDR message to remote peer fn send_message(&mut self, message: xdr::StellarMessage) { let mut am0 = xdr::AuthenticatedMessageV0 { @@ -376,7 +390,7 @@ impl PeerInterface for Peer { fn receive_header(&mut self) -> usize { let mut header: [u8; 4] = Default::default(); if let Err(e) = self.stream.read_exact(&mut header) { - error!("[Overlay] header reading error: {}", e); + // error!("[Overlay] header reading error: {}", e); return 0; } @@ -390,7 +404,7 @@ impl PeerInterface for Peer { message_length <<= 8; message_length |= header[3] as usize; - debug!( + trace!( "[Overlay] RECEIVE HEADER {:?} \nWITH LENGTH {:?}", header, message_length ); @@ -404,10 +418,10 @@ impl PeerInterface for Peer { let message_length = self.receive_header(); let mut message_content = vec![0u8; message_length]; - debug!("[Overlay] Message len {:?}", message_content.len()); + trace!("[Overlay] Message len {:?}", message_content.len()); self.stream.read_exact(&mut message_content).unwrap(); - debug!("[Overlay] Message content {:?}", message_content); + trace!("[Overlay] Message content {:?}", message_content); let mut cursor = Cursor::new(message_content); @@ -437,3 +451,138 @@ impl PeerInterface for Peer { &self.address } } + +impl Clone for Peer { + fn clone(&self) -> Self { + Peer { + stream: self + .stream + .try_clone() + .expect("Failed when try to clone socket stream"), + send_message_sequence: self.send_message_sequence.clone(), + cached_auth_cert: self.cached_auth_cert.clone(), + auth_secret_key: self.auth_secret_key.clone(), + auth_public_key: self.auth_public_key.clone(), + auth_shared_key: self.auth_shared_key.clone(), + received_mac_key: self.received_mac_key.clone(), + sended_mac_key: self.sended_mac_key.clone(), + nonce: self.nonce.clone(), + hello: self.hello.clone(), + address: self.address.clone(), + peer_info: self.peer_info.clone(), + is_authenticated: self.is_authenticated.clone(), + } + } +} + +#[derive(Debug)] +pub struct PeerActor { + address: Option, + peer: Option, +} + +impl PeerActor { + pub fn new((address, peer): (Option, Option)) -> BoxActor { + let actor = PeerActor { address, peer }; + + Box::new(actor) + } + + pub fn initiated_peer_props(address: String) -> BoxActorProd { + Props::new_args(Box::new(PeerActor::new), (Some(address), None)) + } + + pub fn incoming_peer_props(peer: Peer) -> BoxActorProd { + Props::new_args(Box::new(PeerActor::new), (None, Some(peer))) + } + + pub fn overlay_manager_ref(&self, ctx: &Context) -> ActorSelection { + ctx.select("/user/overlay_manager").unwrap() + } +} + +impl Actor for PeerActor { + type Msg = AstroProtocol; + + fn receive( + &mut self, + ctx: &Context, + msg: Self::Msg, + _sender: Option>, + ) { + match msg { + AstroProtocol::ServePeerCmd => { + match self.peer.as_mut().unwrap().receive_message() { + Ok(msg) => { + self.overlay_manager_ref(ctx).tell( + AstroProtocol::ReceivedPeerMessageCmd( + self.address.as_ref().unwrap().to_owned(), + msg.into(), + ), + Some(ctx.myself()), + ) + } + Err(e) => { + debug!("Cant read XDR message cause: {}", e); + self.overlay_manager_ref(ctx).tell( + AstroProtocol::FailedPeerCmd(self.address.as_ref().unwrap().to_owned()), + Some(ctx.myself()), + ); + } + }; + + let delay = Duration::from_millis(1000); + ctx.schedule_once( + delay, + ctx.myself(), + None, + AstroProtocol::ServePeerCmd, + ); + } + AstroProtocol::SendPeerMessageCmd(message) => { + self.peer.as_mut().unwrap().send_message(message); + } + _ => unreachable!(), + } + } + + fn post_start(&mut self, ctx: &Context) { + if self.address.is_some() && self.peer.is_none() { + let mut result = Peer::connect_to(self.address.as_ref().unwrap().to_owned()); + if result.is_ok() { + let mut peer = result.unwrap(); + peer.start_authentication(true); + if peer.is_authenticated() { + self.peer = Some(peer); + } + } + } else if self.address.is_none() && self.peer.is_some() { + self.peer.as_mut().unwrap().start_authentication(false); + } else { + unreachable!() + } + + if let Some(ref peer) = self.peer { + if peer.is_authenticated() { + + ctx.myself().parent().tell( + AstroProtocol::AuthPeerOkCmd(self.address.as_ref().unwrap().to_owned()), + Some(ctx.myself()), + ); + + let delay = Duration::from_millis(500); + ctx.schedule_once( + delay, + ctx.myself(), + None, + AstroProtocol::ServePeerCmd, + ); + return; + } + } + self.overlay_manager_ref(ctx).tell( + AstroProtocol::FailedPeerCmd(self.address.as_ref().unwrap().to_owned()), + Some(ctx.myself()), + ); + } +} diff --git a/src/schema.rs b/src/schema.rs index 2538b66..91f560f 100644 --- a/src/schema.rs +++ b/src/schema.rs @@ -1,6 +1,6 @@ table! { peers (id) { - id -> Int4, - address -> Varchar, + id -> Integer, + address -> Text, } }