Browse Source

Initial commit

master
Weird Constructor 4 years ago
commit
3ac13b618a
  1. 2
      .gitignore
  2. 398
      Cargo.lock
  3. 10
      Cargo.toml
  4. 76
      README.md
  5. 249
      src/detached_command.rs
  6. 127
      src/main.rs

2
.gitignore vendored

@ -0,0 +1,2 @@
/target
**/*.rs.bk

398
Cargo.lock generated

@ -0,0 +1,398 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "aho-corasick"
version = "0.7.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"memchr 2.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "arrayref"
version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "arrayvec"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "autocfg"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "autocfg"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "base64"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "bitflags"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "blake2b_simd"
version = "0.5.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
"arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)",
"constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "byteorder"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cc"
version = "1.0.50"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "cfg-if"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "chrono"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
"time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "constant_time_eq"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "crossbeam-utils"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "datynapse"
version = "0.1.0"
dependencies = [
"wlambda 0.3.6",
]
[[package]]
name = "dirs"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_users 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "fnv"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "getrandom"
version = "0.1.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "itoa"
version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "lazy_static"
version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "libc"
version = "0.2.66"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "log"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memchr"
version = "2.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "nix"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
"cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)",
"cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-integer"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "num-traits"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_syscall"
version = "0.1.56"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "redox_users"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
"rust-argon2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex"
version = "1.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"aho-corasick 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"regex-syntax 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)",
"thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "regex-syntax"
version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "rmp"
version = "0.8.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rmp-serde"
version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rmp 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rust-argon2"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"blake2b_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
"crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "rustyline"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)",
"memchr 2.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"nix 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "ryu"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde"
version = "1.0.104"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "serde_json"
version = "1.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "thread_local"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "time"
version = "0.1.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
"redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "unicode-segmentation"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "unicode-width"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "utf8parse"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "void"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wasi"
version = "0.9.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi"
version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "wlambda"
version = "0.3.6"
dependencies = [
"chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)",
"rmp-serde 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rustyline 4.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)",
]
[metadata]
"checksum aho-corasick 0.7.8 (registry+https://github.com/rust-lang/crates.io-index)" = "743ad5a418686aad3b87fd14c43badd828cf26e214a00f92a384291cf22e1811"
"checksum arrayref 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544"
"checksum arrayvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cff77d8686867eceff3105329d4698d96c2391c176d5d03adc90c7389162b5b8"
"checksum autocfg 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2"
"checksum autocfg 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f8aac770f1885fd7e387acedd76065302551364496e46b3dd00860b2f8359b9d"
"checksum base64 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b41b7ea54a0c9d92199de89e20e58d49f02f8e699814ef3fdf266f6f748d15c7"
"checksum bitflags 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693"
"checksum blake2b_simd 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "d8fb2d74254a3a0b5cac33ac9f8ed0e44aa50378d9dbb2e5d83bd21ed1dc2c8a"
"checksum byteorder 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "08c48aae112d48ed9f069b33538ea9e3e90aa263cfa3d1c24309612b1f7472de"
"checksum cc 1.0.50 (registry+https://github.com/rust-lang/crates.io-index)" = "95e28fa049fda1c330bcf9d723be7663a899c4679724b34c81e9f5a326aab8cd"
"checksum cfg-if 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
"checksum chrono 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "31850b4a4d6bae316f7a09e691c944c28299298837edc0a03f755618c23cbc01"
"checksum constant_time_eq 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "245097e9a4535ee1e3e3931fcfcd55a796a44c643e8596ff6566d68f09b87bbc"
"checksum crossbeam-utils 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ce446db02cdc3165b94ae73111e570793400d0794e46125cc4056c81cbb039f4"
"checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901"
"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3"
"checksum getrandom 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb"
"checksum itoa 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "b8b7a7c0c47db5545ed3fef7468ee7bb5b74691498139e4b3f6a20685dc6dd8e"
"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646"
"checksum libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)" = "d515b1f41455adea1313a4a2ac8a8a477634fbae63cc6100e3aebb207ce61558"
"checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7"
"checksum memchr 2.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53445de381a1f436797497c61d851644d0e8e88e6140f22872ad33a704933978"
"checksum nix 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4dbdc256eaac2e3bd236d93ad999d3479ef775c863dbda3068c4006a92eec51b"
"checksum num-integer 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "3f6ea62e9d81a77cd3ee9a2a5b9b609447857f3d358704331e4ef39eb247fcba"
"checksum num-traits 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "c62be47e61d1842b9170f0fdeec8eba98e60e90e5446449a0545e5152acd7096"
"checksum redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)" = "2439c63f3f6139d1b57529d16bc3b8bb855230c8efcc5d3a896c8bea7c3b1e84"
"checksum redox_users 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "09b23093265f8d200fa7b4c2c76297f47e681c655f6f1285a8780d6a022f7431"
"checksum regex 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "322cf97724bea3ee221b78fe25ac9c46114ebb51747ad5babd51a2fc6a8235a8"
"checksum regex-syntax 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)" = "b28dfe3fe9badec5dbf0a79a9cccad2cfc2ab5484bdb3e44cbd1ae8b3ba2be06"
"checksum rmp 0.8.9 (registry+https://github.com/rust-lang/crates.io-index)" = "0f10b46df14cf1ee1ac7baa4d2fbc2c52c0622a4b82fa8740e37bc452ac0184f"
"checksum rmp-serde 0.14.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4c1ee98f14fe8b8e9c5ea13d25da7b2a1796169202c57a09d7288de90d56222b"
"checksum rust-argon2 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2bc8af4bda8e1ff4932523b94d3dd20ee30a87232323eda55903ffd71d2fb017"
"checksum rustyline 4.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0f47ea1ceb347d2deae482d655dc8eef4bd82363d3329baffa3818bd76fea48b"
"checksum ryu 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfa8506c1de11c9c4e4c38863ccbe02a305c8188e85a05a784c9e11e1c3910c8"
"checksum serde 1.0.104 (registry+https://github.com/rust-lang/crates.io-index)" = "414115f25f818d7dfccec8ee535d76949ae78584fc4f79a6f45a904bf8ab4449"
"checksum serde_json 1.0.48 (registry+https://github.com/rust-lang/crates.io-index)" = "9371ade75d4c2d6cb154141b9752cf3781ec9c05e0e5cf35060e1e70ee7b9c25"
"checksum thread_local 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d40c6d1b69745a6ec6fb1ca717914848da4b44ae29d9b3080cbee91d72a69b14"
"checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f"
"checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0"
"checksum unicode-width 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "caaa9d531767d1ff2150b9332433f32a24622147e5ebb1f26409d5da67afd479"
"checksum utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d"
"checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d"
"checksum wasi 0.9.0+wasi-snapshot-preview1 (registry+https://github.com/rust-lang/crates.io-index)" = "cccddf32554fecc6acb585f82a32a72e28b48f8c4c1883ddfeeeaa96f7d8e519"
"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6"
"checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
"checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"

10
Cargo.toml

@ -0,0 +1,10 @@
[package]
name = "datynapse"
version = "0.1.0"
authors = ["weictr"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
wlambda = { path = "../WLambda" }

76
README.md

@ -0,0 +1,76 @@
Datynapse - A protocol transformer and message router shell
===========================================================
This application can start sub processes and acts as protocol transformer
to connect all these processes with each other. It can also connect to
other Daynapse nodes and thus form distributed networks and connect processes
between multiple computers in a network.
# License
This project is licensed under the GNU General Public License Version 3 or
later.
## Why GPL?
Picking a license for my code bothered me for a long time. I read many
discussions about this topic. Read the license explanations. And discussed
this matter with other developers.
First about _why I write code for free_ at all:
- It's my passion to write computer programs. In my free time I can
write the code I want, when I want and the way I want. I can freely
allocate my time and freely choose the projects I want to work on.
- To help a friend or member of my family.
- To solve a problem I have.
Those are the reasons why I write code for free. Now the reasons
_why I publish the code_, when I could as well keep it to myself:
- So that it may bring value to users and the free software community.
- Show my work as an artist.
- To get into contact with other developers.
- And it's a nice change to put some more polish on my private projects.
Most of those reasons don't yet justify GPL. The main point of the GPL, as far
as I understand: The GPL makes sure the software stays free software until
eternity. That the user of the software always stays in control. That the users
have _at least the means_ to adapt the software to new platforms or use cases.
Even if the original authors don't maintain the software anymore.
It ultimately prevents _"vendor lock in"_. I really dislike vendor lock in,
especially as developer. Especially as developer I want and need to stay
in control of the computers I use.
Another point is, that my work has a value. If I give away my work without
_any_ strings attached, I effectively work for free. Work for free for
companies. I would compromise the price I can demand for my skill, workforce
and time.
This makes two reasons for me to choose the GPL:
1. I do not want to support vendor lock in scenarios. At least not for free.
I want to prevent those when I have a choice.
And before you ask, yes I work for a company that sells closed source
software. I am not happy about the closed source fact.
But it pays my bills and gives me the freedom to write free software
in my free time.
2. I don't want to low ball my own wage and prices by giving away free software
with no strings attached (for companies).
## If you need a permissive or private license (MIT)
Please contact me if you need a different license and really want to use
my code. As long as I am the only author, I can change the license.
We might find an agreement.
# Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in WLambda by you, shall be licensed as GPLv3 or later,
without any additional terms or conditions.
# Authors
* Weird Constructor <weirdconstructor@gmail.com>
(You may find me as `WeirdConstructor` on the Rust Discord.)

249
src/detached_command.rs

@ -0,0 +1,249 @@
// Copyright (c) 2019 Weird Constructor <weirdconstructor@gmail.com>
// This is a part of gtp-rs. See README.md and COPYING for details.
/*!
An abstraction for running background processes with a line based
I/O protocol on stdin/stdout.
It uses 3 threads for I/O of the child stdin/stdout/stderr and
some std::sync::mpsc channels for synchronization. It's not the
fastest as `tokio_process` would provide a non-blocking
interface to child processes (which is hopefully more
efficiently implemented).
Unfortunately at the time of this writing I only have prototype code for
tokio_process and the futures don't really make the solution easier to read and
maintain than this one. I also believe, that the bottleneck of todays GTP
engines is not the interface with the GTP controller. So this might
never gets optimized.
*/
use std::process::Command;
use std::process::Stdio;
use std::sync::mpsc;
use std::io::Write;
use std::io::BufRead;
use std::thread;
#[derive(Debug, Clone)]
pub enum CapturedOutput {
Stderr(String),
Stdout(String),
}
pub struct DetachedCommand {
child: std::process::Child,
reader: Option<std::thread::JoinHandle<()>>,
err_reader: Option<std::thread::JoinHandle<()>>,
writer: Option<std::thread::JoinHandle<()>>,
rd_rx: Option<mpsc::Receiver<CapturedOutput>>,
wr_tx: Option<mpsc::Sender<Vec<u8>>>,
stdout_chunks: Vec<String>,
stderr_chunks: Vec<String>,
}
#[derive(Debug)]
pub enum Error {
StartupFailed(std::io::Error),
Disconnected,
}
impl DetachedCommand {
pub fn start(cmd: &str, args: &[&str]) -> Result<DetachedCommand, Error> {
let mut o = Command::new(cmd);
o.stdout(Stdio::piped())
.stderr(Stdio::piped())
.stdin(Stdio::piped());
for arg in args.iter() {
o.arg(arg);
}
let o = o.spawn();
if let Err(io_err) = o {
return Err(Error::StartupFailed(io_err));
}
let mut o = o.unwrap();
let stdin = o.stdin.take().unwrap();
let stdout = o.stdout.take().unwrap();
let stderr = o.stderr.take().unwrap();
let (tx, rx) = std::sync::mpsc::channel();
let (stdin_tx , stdin_rx) : (mpsc::Sender<Vec<u8>>, mpsc::Receiver<Vec<u8>>) = std::sync::mpsc::channel();
let writer = thread::spawn(move || {
let mut bw = std::io::BufWriter::new(stdin);
while let Ok(bytes) = stdin_rx.recv() {
if let Ok(s) = bw.write(&bytes) {
if s == 0 { break; }
if bw.flush().is_err() { break; }
} else {
break;
}
};
});
let tx_stdout = tx.clone();
let reader = thread::spawn(move || {
let mut br = std::io::BufReader::new(stdout);
loop {
let mut line = String::from("");
if let Ok(s) = br.read_line(&mut line) {
if tx_stdout.send(CapturedOutput::Stdout(line)).is_err() { break; }
if s == 0 { break; }
} else {
break;
}
}
});
let tx_stderr = tx.clone();
let err_reader = thread::spawn(move || {
let mut br = std::io::BufReader::new(stderr);
loop {
let mut line = String::from("");
if let Ok(s) = br.read_line(&mut line) {
if tx_stderr.send(CapturedOutput::Stderr(line)).is_err() { break; }
if s == 0 { break; }
} else {
break;
}
}
});
Ok(DetachedCommand {
child: o,
stderr_chunks: Vec::new(),
stdout_chunks: Vec::new(),
reader: Some(reader),
err_reader: Some(err_reader),
writer: Some(writer),
rd_rx: Some(rx),
wr_tx: Some(stdin_tx),
})
}
pub fn send_str(&mut self, s: &str) {
let b : Vec<u8> = s.bytes().collect();
self.send(b);
// dc.wr_tx.as_ref().unwrap().send("foobar!\n".to_string());
}
#[allow(unused_must_use)]
pub fn send(&mut self, buffer: Vec<u8>) {
self.wr_tx.as_ref().unwrap().send(buffer);
}
#[allow(dead_code)]
pub fn recv_blocking(&mut self) -> CapturedOutput {
self.rd_rx.as_ref().unwrap().recv().unwrap()
}
pub fn stdout_available(&self) -> bool {
!self.stdout_chunks.is_empty()
}
pub fn stderr_available(&self) -> bool {
!self.stderr_chunks.is_empty()
}
pub fn recv_stdout(&mut self) -> String {
let ret : String = self.stdout_chunks.join("");
self.stdout_chunks.clear();
ret
}
pub fn recv_stderr(&mut self) -> String {
let ret : String = self.stderr_chunks.join("");
self.stderr_chunks.clear();
ret
}
pub fn poll(&mut self) -> Result<(), Error> {
if self.rd_rx.is_none() {
return Err(Error::Disconnected);
}
loop {
match self.rd_rx.as_ref().unwrap().try_recv() {
Ok(CapturedOutput::Stdout(input)) => {
self.stdout_chunks.push(input);
},
Ok(CapturedOutput::Stderr(input)) => {
self.stderr_chunks.push(input);
},
Err(mpsc::TryRecvError::Empty) => {
return Ok(());
},
Err(mpsc::TryRecvError::Disconnected) => {
return Err(Error::Disconnected);
},
}
}
}
#[allow(unused_must_use)]
pub fn shutdown(&mut self) {
drop(self.wr_tx.take().unwrap());
self.child.kill();
self.writer.take().unwrap().join();
self.reader.take().unwrap().join();
self.err_reader.take().unwrap().join();
}
}
//pub fn doit() {
// println!("FOO {}", std::env::current_dir().unwrap().to_str().unwrap());
// let mut dc =
// DetachedCommand::start("gnugo-3.8\\gnugo.exe", &["--mode", "gtp"])
// .expect("failed gnugo");
//
// let mut rp = self::ResponseParser::new();
//
// dc.send_str("10 list_commands\n");
// loop {
// let p = dc.poll();
// if p.is_err() {
// println!("stdout: [{}]", dc.recv_stdout());
// println!("stderr: [{}]", dc.recv_stderr());
// println!("Error in poll: {:?}", p.unwrap_err());
// break;
//
// }
// if dc.stderr_available() {
// println!("err: {}", dc.recv_stderr());
// }
//
// if dc.stdout_available() {
// rp.feed(&dc.recv_stdout());
//
// if let Ok(resp) = rp.get_response() {
// match resp.id_0() {
// 10 => {
// let ents = resp.entities(|ep| { while !ep.is_eof() { ep.s(); } ep }).unwrap();
// for cmd in ents.iter() {
// println!("command {}", cmd.to_string());
// }
// dc.send_str("11 showboard\n");
// },
// 11 => {
// println!("board: {}", resp.text());
// dc.send_str("12 genmove w\n");
// },
// 12 => {
// println!("Vertex: {:?}", resp.entities(|ep| ep.vertex()).unwrap()[0]);
// dc.send_str("quit\n");
// },
// _ => {
// println!("resp: {}", resp.text());
// dc.send_str("quit\n");
// },
// }
// }
// }
// }
//
// dc.shutdown();
//}

127
src/main.rs

@ -0,0 +1,127 @@
mod detached_command;
use detached_command::*;
use wlambda::VVal;
/*
There are different kinds of processes:
- Two-Way adapters
- accept messages and generate a response immediately
- responses sometimes
- Call adapters
- on incoming message a process is spawned and the output
is sent as a new message
*/
#[derive(Debug, Clone)]
struct Message {
dest: String,
src: String,
payload: VVal,
}
#[derive(Debug, Copy, Clone)]
enum AdapterError {
Again,
End,
Crash,
}
trait Adapter {
fn try_poll_one(&mut self) -> Result<Message, AdapterError>;
fn send(&mut self, msg: &Message);
}
#[derive(Debug, Clone)]
struct ConsoleAdapter {
name: String,
cnt: usize,
}
impl Adapter for ConsoleAdapter {
fn try_poll_one(&mut self) -> Result<Message, AdapterError> {
if self.cnt > 0 {
self.cnt -= 1;
let v = VVal::vec();
v.push(VVal::new_str("OK"));
v.push(VVal::Int((self.cnt + 1) as i64));
return Ok(Message {
src: self.name.to_string(),
dest: "@Out".to_string(),
payload: v,
});
} else {
return Err(AdapterError::End);
}
}
fn send(&mut self, msg: &Message) {
println!("TO[{}/{}] FROM[{}]: {}", msg.dest, self.name, msg.src, msg.payload.s());
}
}
fn route() {
let mut ads : std::vec::Vec<Box<dyn Adapter>> = vec![];
ads.push(Box::new(ConsoleAdapter { name: "A".to_string(), cnt: 2 }));
ads.push(Box::new(ConsoleAdapter { name: "B".to_string(), cnt: 3 }));
let mut snd_queue : std::vec::Vec<Message> = vec![];
loop {
let mut i = 0;
while !snd_queue.is_empty() {
let len = ads.len();
ads[i % len].send(&snd_queue.pop().unwrap());
i += 1;
}
for a in ads.iter_mut() {
// if let Some(ref mut adap) = a {
match a.try_poll_one() {
Ok(msg) => {
snd_queue.push(msg);
},
Err(e) => {
match e {
AdapterError::End => (),
_ => {
println!("ERR {:?}", e);
}
}
},
}
// }
}
}
}
fn main() {
route();
// let mut dc = DetachedCommand::start("wlambda", &[]).expect("X");
//
// dc.send_str("10 + 20\n");
// loop {
// match dc.poll() {
// Ok(()) => {
// if dc.stderr_available() {
// println!("SE: {}", dc.recv_stderr());
// }
// if dc.stdout_available() {
// println!("SO: {}", dc.recv_stdout());
// }
// },
// Err(err) => {
// println!("stdout: [{}]", dc.recv_stdout());
// println!("stderr: [{}]", dc.recv_stderr());
// println!("Error in poll: {:?}", err);
// break;
// },
// }
// }
//
// dc.shutdown();
}
Loading…
Cancel
Save