From 5a7ecaee6b5d2066e6b1d2902c09036b67669aec Mon Sep 17 00:00:00 2001 From: Jali Date: Sat, 22 Jun 2019 21:17:04 +0200 Subject: [PATCH] Implemented a tcp listener --- Cargo.lock | 651 ++++++++++++++++++++++++++++++++ Cargo.toml | 1 + Readme.md | 29 ++ doc/rsc/rfc1436.txt | 899 ++++++++++++++++++++++++++++++++++++++++++++ src/main.rs | 50 ++- 5 files changed, 1627 insertions(+), 3 deletions(-) create mode 100644 Readme.md create mode 100644 doc/rsc/rfc1436.txt diff --git a/Cargo.lock b/Cargo.lock index 086e534..314672a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,6 +8,14 @@ dependencies = [ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "arrayvec" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "atty" version = "0.2.11" @@ -18,11 +26,35 @@ dependencies = [ "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "autocfg" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bitflags" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "byteorder" +version = "1.3.2" +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.2 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "cfg-if" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "clap" version = "2.33.0" @@ -37,23 +69,339 @@ dependencies = [ "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "cloudabi" +version = "0.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-deque" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-epoch" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-queue" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crossbeam-utils" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (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 = "fuchsia-cprng" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "fuchsia-zircon" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "fuchsia-zircon-sys" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "futures" +version = "0.1.27" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "gopherbridge" version = "0.1.0" dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (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.57 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "kernel32-sys" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "lazy_static" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "libc" version = "0.2.57" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "lock_api" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "log" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "memoffset" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "mio" +version = "0.6.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "mio-uds" +version = "0.6.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miow" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "net2" +version = "0.2.33" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "nodrop" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num_cpus" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "numtoa" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "owning_ref" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_chacha" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_core" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "rand_hc" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_isaac" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_jitter" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_os" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_pcg" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rand_xorshift" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rdrand" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "redox_syscall" version = "0.1.54" @@ -67,6 +415,47 @@ dependencies = [ "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc_version" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "scopeguard" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "semver" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "semver-parser" +version = "0.7.0" +source = "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.10" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "stable_deref_trait" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "strsim" version = "0.8.0" @@ -91,6 +480,184 @@ dependencies = [ "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-trace-core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-codec" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-current-thread" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-executor" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-fs" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-io" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-reactor" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-sync" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-tcp" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-threadpool" +version = "0.1.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-timer" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-trace-core" +version = "0.2.0" +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)", +] + +[[package]] +name = "tokio-udp" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-uds" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "unicode-width" version = "0.1.5" @@ -101,6 +668,11 @@ name = "vec_map" version = "0.8.1" source = "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.7" @@ -110,6 +682,11 @@ dependencies = [ "winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "winapi-build" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "winapi-i686-pc-windows-gnu" version = "0.4.0" @@ -120,20 +697,94 @@ name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "ws2_32-sys" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" +"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" +"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" +"checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" +"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" +"checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" +"checksum crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71" +"checksum crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "04c9e3102cc2d69cd681412141b390abd55a362afc1540965dad0ad4d34280b4" +"checksum crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7c979cd6cfe72335896575c6b5688da489e420d36a27a0b9eb0c73db574b4a4b" +"checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" +"checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" +"checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" +"checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" +"checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" +"checksum futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "a2037ec1c6c1c4f79557762eab1f7eae1f64f6cb418ace90fae88f0942b60139" +"checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" +"checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" +"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum libc 0.2.57 (registry+https://github.com/rust-lang/crates.io-index)" = "a844cabbd5a77e60403a58af576f0a1baa83c3dd2670be63e615bd24fc58b82d" +"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 memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" +"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" +"checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" +"checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" +"checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" +"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" +"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" +"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 rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" +"checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" +"checksum rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" +"checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" +"checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" +"checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" +"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" +"checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" +"checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" +"checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" +"checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" "checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" +"checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" +"checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" +"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 slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" +"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" +"checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" "checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" "checksum textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" +"checksum tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "ec2ffcf4bcfc641413fa0f1427bf8f91dfc78f56a6559cbf50e04837ae442a87" +"checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f" +"checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443" +"checksum tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "83ea44c6c0773cc034771693711c35c677b4b5a4b21b9e7071704c54de7d555e" +"checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af" +"checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" +"checksum tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6af16bfac7e112bea8b0442542161bfc41cbfa4466b580bdda7d18cb88b911ce" +"checksum tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2162248ff317e2bc713b261f242b69dbb838b85248ed20bb21df56d60ea4cae7" +"checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" +"checksum tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72558af20be886ea124595ea0f806dd5703b8958e4705429dd58b3d8231f72f2" +"checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" +"checksum tokio-trace-core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9c8a256d6956f7cb5e2bdfe8b1e8022f1a09206c6c2b1ba00f3b746b260c613" +"checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92" +"checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +"checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" +"checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "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" +"checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" diff --git a/Cargo.toml b/Cargo.toml index cb4e169..365438c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,3 +6,4 @@ edition = "2018" [dependencies] clap = "2.33.0" +tokio = "0.1" diff --git a/Readme.md b/Readme.md new file mode 100644 index 0000000..f95e32e --- /dev/null +++ b/Readme.md @@ -0,0 +1,29 @@ +# Gopherbridge +# A bridge between worlds + +> Version: 1.0.19171.1 \ +> Created By: jali \ \ +> Created On: Sat 22 Jun 2019 08:17:31 pm CEST \ +> Last Modified On: Sat 22 Jun 2019 08:17:31 pm CEST + + +# What is gopherbridge? + +Gopherbridge is a [gopher](https://en.wikipedia.org/wiki/Gopher_\(protocol\)) +server. + +Gopher is an old protocol. that provides documents and files to users. It allows +downloading data and linking to other documents. Gopher was published around the +same time as the [World Wide Web](https://en.wikipedia.org/wiki/World_Wide_Web). + +It works somewhat similar, but is a lot simpler. It has none of the feats of the modern +web, like playing videos or using JavaScript. It's generally text based. + +It's shortcomings are also the biggest feature: Since gopher doesn't transfer much data, it +is fast. Even on small bandwidth dial-up lines, it operates at sufficient speed. + +Gopherbridge allows the user to brigde a website into a gopher document, thus making use of +the fast download-speeds it allows, and allow formatting documents as text. + +This does for your website, what [gopherpedia](gopher://gopherpedia.com) is for the +Wikipedia. diff --git a/doc/rsc/rfc1436.txt b/doc/rsc/rfc1436.txt new file mode 100644 index 0000000..a4cd7e0 --- /dev/null +++ b/doc/rsc/rfc1436.txt @@ -0,0 +1,899 @@ + + + + + + +Network Working Group F. Anklesaria +Request for Comments: 1436 M. McCahill + P. Lindner + D. Johnson + D. Torrey + B. Alberti + University of Minnesota + March 1993 + + + The Internet Gopher Protocol + (a distributed document search and retrieval protocol) + +Status of this Memo + + This memo provides information for the Internet community. It does + not specify an Internet standard. Distribution of this memo is + unlimited. + +Abstract + + The Internet Gopher protocol is designed for distributed document + search and retrieval. This document describes the protocol, lists + some of the implementations currently available, and has an overview + of how to implement new client and server applications. This + document is adapted from the basic Internet Gopher protocol document + first issued by the Microcomputer Center at the University of + Minnesota in 1991. + +Introduction + + gopher n. 1. Any of various short tailed, burrowing mammals of the + family Geomyidae, of North America. 2. (Amer. colloq.) Native or + inhabitant of Minnesota: the Gopher State. 3. (Amer. colloq.) One + who runs errands, does odd-jobs, fetches or delivers documents for + office staff. 4. (computer tech.) software following a simple + protocol for burrowing through a TCP/IP internet. + + The Internet Gopher protocol and software follow a client-server + model. This protocol assumes a reliable data stream; TCP is assumed. + Gopher servers should listen on port 70 (port 70 is assigned to + Internet Gopher by IANA). Documents reside on many autonomous + servers on the Internet. Users run client software on their desktop + systems, connecting to a server and sending the server a selector (a + line of text, which may be empty) via a TCP connection at a well- + known port. The server responds with a block of text terminated by a + period on a line by itself and closes the connection. No state is + retained by the server. + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 1] + +RFC 1436 Gopher March 1993 + + + While documents (and services) reside on many servers, Gopher client + software presents users with a hierarchy of items and directories + much like a file system. The Gopher interface is designed to + resemble a file system since a file system is a good model for + organizing documents and services; the user sees what amounts to one + big networked information system containing primarily document items, + directory items, and search items (the latter allowing searches for + documents across subsets of the information base). + + Servers return either directory lists or documents. Each item in a + directory is identified by a type (the kind of object the item is), + user-visible name (used to browse and select from listings), an + opaque selector string (typically containing a pathname used by the + destination host to locate the desired object), a host name (which + host to contact to obtain this item), and an IP port number (the port + at which the server process listens for connections). The user only + sees the user-visible name. The client software can locate and + retrieve any item by the trio of selector, hostname, and port. + + To use a search item, the client submits a query to a special kind of + Gopher server: a search server. In this case, the client sends the + selector string (if any) and the list of words to be matched. The + response yields "virtual directory listings" that contain items + matching the search criteria. + + Gopher servers and clients exist for all popular platforms. Because + the protocol is so sparse and simple, writing servers or clients is + quick and straightforward. + +1. Introduction + + The Internet Gopher protocol is designed primarily to act as a + distributed document delivery system. While documents (and services) + reside on many servers, Gopher client software presents users with a + hierarchy of items and directories much like a file system. In fact, + the Gopher interface is designed to resemble a file system since a + file system is a good model for locating documents and services. Why + model a campus-wide information system after a file system? Several + reasons: + + (a) A hierarchical arrangement of information is familiar to many + users. Hierarchical directories containing items (such as + documents, servers, and subdirectories) are widely used in + electronic bulletin boards and other campus-wide information + systems. People who access a campus-wide information server will + expect some sort of hierarchical organization to the information + presented. + + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 2] + +RFC 1436 Gopher March 1993 + + + (b) A file-system style hierarchy can be expressed in a simple + syntax. The syntax used for the internet Gopher protocol is + easily understandable, and was designed to make debugging servers + and clients easy. You can use Telnet to simulate an internet + Gopher client's requests and observe the responses from a server. + Special purpose software tools are not required. By keeping the + syntax of the pseudo-file system client/server protocol simple, we + can also achieve better performance for a very common user + activity: browsing through the directory hierarchy. + + (c) Since Gopher originated in a University setting, one of the + goals was for departments to have the option of publishing + information from their inexpensive desktop machines, and since + much of the information can be presented as simple text files + arranged in directories, a protocol modeled after a file system + has immediate utility. Because there can be a direct mapping from + the file system on the user's desktop machine to the directory + structure published via the Gopher protocol, the problem of + writing server software for slow desktop systems is minimized. + + (d) A file system metaphor is extensible. By giving a "type" + attribute to items in the pseudo-file system, it is possible to + accommodate documents other than simple text documents. Complex + database services can be handled as a separate type of item. A + file-system metaphor does not rule out search or database-style + queries for access to documents. A search-server type is also + defined in this pseudo-file system. Such servers return "virtual + directories" or list of documents matching user specified + criteria. + +2. The internet Gopher Model + + A detailed BNF rendering of the internet Gopher syntax is available + in the appendix...but a close reading of the appendix may not be + necessary to understand the internet Gopher protocol. + + In essence, the Gopher protocol consists of a client connecting to a + server and sending the server a selector (a line of text, which may + be empty) via a TCP connection. The server responds with a block of + text terminated with a period on a line by itself, and closes the + connection. No state is retained by the server between transactions + with a client. The simple nature of the protocol stems from the need + to implement servers and clients for the slow, smaller desktop + computers (1 MB Macs and DOS machines), quickly, and efficiently. + + Below is a simple example of a client/server interaction; more + complex interactions are dealt with later. Assume that a "well- + known" Gopher server (this may be duplicated, details are discussed + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 3] + +RFC 1436 Gopher March 1993 + + + later) listens at a well known port for the campus (much like a + domain-name server). The only configuration information the client + software retains is this server's name and port number (in this + example that machine is rawBits.micro.umn.edu and the port 70). In + the example below the F character denotes the TAB character. + + Client: {Opens connection to rawBits.micro.umn.edu at port 70} + + Server: {Accepts connection but says nothing} + + Client: {Sends an empty line: Meaning "list what you have"} + + Server: {Sends a series of lines, each ending with CR LF} + 0About internet GopherFStuff:About usFrawBits.micro.umn.eduF70 + 1Around University of MinnesotaFZ,5692,AUMFunderdog.micro.umn.eduF70 + 1Microcomputer News & PricesFPrices/Fpserver.bookstore.umn.eduF70 + 1Courses, Schedules, CalendarsFFevents.ais.umn.eduF9120 + 1Student-Staff DirectoriesFFuinfo.ais.umn.eduF70 + 1Departmental PublicationsFStuff:DP:FrawBits.micro.umn.eduF70 + {.....etc.....} + . {Period on a line by itself} + {Server closes connection} + + + The first character on each line tells whether the line describes a + document, directory, or search service (characters '0', '1', '7'; + there are a handful more of these characters described later). The + succeeding characters up to the tab form a user display string to be + shown to the user for use in selecting this document (or directory) + for retrieval. The first character of the line is really defining + the type of item described on this line. In nearly every case, the + Gopher client software will give the users some sort of idea about + what type of item this is (by displaying an icon, a short text tag, + or the like). + + The characters following the tab, up to the next tab form a selector + string that the client software must send to the server to retrieve + the document (or directory listing). The selector string should mean + nothing to the client software; it should never be modified by the + client. In practice, the selector string is often a pathname or + other file selector used by the server to locate the item desired. + The next two tab delimited fields denote the domain-name of the host + that has this document (or directory), and the port at which to + connect. If there are yet other tab delimited fields, the basic + Gopher client should ignore them. A CR LF denotes the end of the + item. + + + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 4] + +RFC 1436 Gopher March 1993 + + + In the example, line 1 describes a document the user will see as + "About internet Gopher". To retrieve this document, the client + software must send the retrieval string: "Stuff:About us" to + rawBits.micro.umn.edu at port 70. If the client does this, the + server will respond with the contents of the document, terminated by + a period on a line by itself. A client might present the user with a + view of the world something like the following list of items: + + + About Internet Gopher + Around the University of Minnesota... + Microcomputer News & Prices... + Courses, Schedules, Calendars... + Student-Staff Directories... + Departmental Publications... + + + + In this case, directories are displayed with an ellipsis and files + are displayed without any. However, depending on the platform the + client is written for and the author's taste, item types could be + denoted by other text tags or by icons. For example, the UNIX + curses-based client displays directories with a slash (/) following + the name; Macintosh clients display directories alongside an icon of + a folder. + + The user does not know or care that the items up for selection may + reside on many different machines anywhere on the Internet. + + Suppose the user selects the line "Microcomputer News & Prices...". + This appears to be a directory, and so the user expects to see + contents of the directory upon request that it be fetched. The + following lines illustrate the ensuing client-server interaction: + + + Client: (Connects to pserver.bookstore.umn.edu at port 70) + Server: (Accepts connection but says nothing) + Client: Prices/ (Sends the magic string terminated by CRLF) + Server: (Sends a series of lines, each ending with CR LF) + 0About PricesFPrices/AboutusFpserver.bookstore.umn.eduF70 + 0Macintosh PricesFPrices/MacFpserver.bookstore.umn.eduF70 + 0IBM PricesFPrices/IckFpserver.bookstore.umn.eduF70 + 0Printer & Peripheral PricesFPrices/PPPFpserver.bookstore.umn.eduF70 + (.....etc.....) + . (Period on a line by itself) + (Server closes connection) + + + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 5] + +RFC 1436 Gopher March 1993 + + +3. More details + +3.1 Locating services + + Documents (or other services that may be viewed ultimately as + documents, such as a student-staff phonebook) are linked to the + machine they are on by the trio of selector string, machine domain- + name, and IP port. It is assumed that there will be one well-known + top-level or root server for an institution or campus. The + information on this server may be duplicated by one or more other + servers to avoid a single point of failure and to spread the load + over several servers. Departments that wish to put up their own + departmental servers need to register the machine name and port with + the administrators of the top-level Gopher server, much the same way + as they register a machine name with the campus domain-name server. + An entry which points to the departmental server will then be made at + the top level server. This ensures that users will be able to + navigate their way down what amounts to a virtual hierarchical file + system with a well known root to any campus server if they desire. + + Note that there is no requirement that a department register + secondary servers with the central top-level server; they may just + place a link to the secondary servers in their own primary servers. + They may indeed place links to any servers they desire in their own + server, thus creating a customized view of thethe Gopher information + universe; links can of course point back at the top-level server. + The virtual (networked) file system is therefore an arbitrary graph + structure and not necessarily a rooted tree. The top-level node is + merely one convenient, well-known point of entry. A set of Gopher + servers linked in this manner may function as a campus-wide + information system. + + Servers may of course point links at other than secondary servers. + Indeed servers may point at other servers offering useful services + anywhere on the internet. Viewed in this manner, Gopher can be seen + as an Internet-wide information system. + +3.2 Server portability and naming + + It is recommended that all registered servers have alias names + (domain name system CNAME) that are used by Gopher clients to locate + them. Links to these servers should use these alias names rather + than the primary names. If information needs to be moved from one + machine to another, a simple change of domain name system alias + (CNAME) allows this to occur without any reconfiguration of clients + in the field. In short, the domain name system may be used to re-map + a server to a new address. There is nothing to prevent secondary + servers or services from running on otherwise named servers or ports + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 6] + +RFC 1436 Gopher March 1993 + + + other than 70, however these should be reachable via a primary + server. + +3.3 Contacting server administrators + + It is recommended that every server administrator have a document + called something like: "About Bogus University's Gopher server" as + the first item in their server's top level directory. In this + document should be a short description of what the server holds, as + well as name, address, phone, and an e-mail address of the person who + administers the server. This provides a way for users to get word to + the administrator of a server that has inaccurate information or is + not running correctly. It is also recommended that administrators + place the date of last update in files for which such information + matters to the users. + +3.4 Modular addition of services + + The first character of each line in a server-supplied directory + listing indicates whether the item is a file (character '0'), a + directory (character '1'), or a search (character '7'). This is the + base set of item types in the Gopher protocol. It is desirable for + clients to be able to use different services and speak different + protocols (simple ones such as finger; others such as CSO phonebook + service, or Telnet, or X.500 directory service) as needs dictate. + CSO phonebook service is a client/server phonebook system typically + used at Universities to publish names, e-mail addresses, and so on. + The CSO phonebook software was developed at the University of + Illinois and is also sometimes refered to as ph or qi. For example, + if a server-supplied directory listing marks a certain item with type + character '2', then it means that to use this item, the client must + speak the CSO protocol. This removes the need to be able to + anticipate all future needs and hard-wire them in the basic Internet + Gopher protocol; it keeps the basic protocol extremely simple. In + spite of this simplicity, the scheme has the capability to expand and + change with the times by adding an agreed upon type-character for a + new service. This also allows the client implementations to evolve + in a modular fashion, simply by dropping in a module (or launching a + new process) for some new service. The servers for the new service + of course have to know nothing about Internet Gopher; they can just + be off-the shelf CSO, X.500, or other servers. We do not however, + encourage arbitrary or machine-specific proliferation of service + types in the basic Gopher protocol. + + On the other hand, subsets of other document retrieval schemes may be + mapped onto the Gopher protocol by means of "gateway-servers". + Examples of such servers include Gopher-to-FTP gateways, Gopher-to- + archie gateways, Gopher-to-WAIS gateways, etc. There are a number of + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 7] + +RFC 1436 Gopher March 1993 + + + advantages of such mechanisms. First, a relatively powerful server + machine inherits both the intelligence and work, rather than the more + modest, inexpensive desktop system that typically runs client + software or basic server software. Equally important, clients do not + have to be modified to take advantage of a new resource. + +3.5 Building clients + + A client simply sends the retrieval string to a server if it wants to + retrieve a document or view the contents of a directory. Of course, + each host may have pointers to other hosts, resulting in a "graph" + (not necessarily a rooted tree) of hosts. The client software may + save (or rather "stack") the locations that it has visited in search + of a document. The user could therefore back out of the current + location by unwinding the stack. Alternatively, a client with + multiple-window capability might just be able to display more than + one directory or document at the same time. + + A smart client could cache the contents of visited directories + (rather than just the directory's item descriptor), thus avoiding + network transactions if the information has been previously + retrieved. + + If a client does not understand what a say, type 'B' item (not a core + item) is, then it may simply ignore the item in the directory + listing; the user never even has to see it. Alternatively, the item + could be displayed as an unknown type. + + Top-level or primary servers for a campus are likely to get more + traffic than secondary servers, and it would be less tolerable for + such primary servers to be down for any long time. So it makes sense + to "clone" such important servers and construct clients that can + randomly choose between two such equivalent primary servers when they + first connect (to balance server load), moving to one if the other + seems to be down. In fact, smart client implementations do this + clone server and load balancing. Alternatively, it may make sense to + have the domain name system return one of a set of redundant of + server's IP address to load balance betwen redundant sets of + important servers. + +3.6 Building ordinary internet Gopher servers + + The retrieval string sent to the server might be a path to a file or + directory. It might be the name of a script, an application or even + a query that generates the document or directory returned. The basic + server uses the string it gets up to but not including a CR-LF or a + TAB, whichever comes first. + + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 8] + +RFC 1436 Gopher March 1993 + + + All intelligence is carried by the server implementation rather than + the protocol. What you build into more exotic servers is up to you. + Server implementations may grow as needs dictate and time allows. + +3.7 Special purpose servers + + There are two special server types (beyond the normal Gopher server) + also discussed below: + + 1. A server directory listing can point at a CSO nameserver (the + server returns a type character of '2') to allow a campus + student-staff phonebook lookup service. This may show up on the + user's list of choices, perhaps preceded by the icon of a phone- + book. If this item is selected, the client software must resort + to a pure CSO nameserver protocol when it connects to the + appropriate host. + + 2. A server can also point at a "search server" (returns a first + character of '7'). Such servers may implement campus network (or + subnet) wide searching capability. The most common search servers + maintain full-text indexes on the contents of text documents held + by some subset of Gopher servers. Such a "full-text search + server" responds to client requests with a list of all documents + that contain one or more words (the search criteria). The client + sends the server the selector string, a tab, and the search string + (words to search for). If the selector string is empty, the client + merely sends the search string. The server returns the equivalent + of a directory listing for documents matching the search criteria. + Spaces between words are usually implied Boolean ANDs (although in + different implementations or search types, this may not + necessarily be true). + + The CSO addition exists for historical reasons: at time of design, + the campus phone-book servers at the University of Minnesota used the + CSO protocol and it seemed simplest to just engulf them. The index- + server is however very much a Gopher in spirit, albeit with a slight + twist in the meaning of the selector-string. Index servers are a + natural place to incorperate gateways to WAIS and WHOIS services. + +3.7.1 Building CSO-servers + + A CSO Nameserver implementation for UNIX and associated documentation + is available by anonymous ftp from uxa.cso.uiuc.edu. We do not + anticipate implementing it on other machines. + + + + + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 9] + +RFC 1436 Gopher March 1993 + + +3.7.2 Building full-text search servers + + A full-text search server is a special-purpose server that knows + about the Gopher scheme for retrieving documents. These servers + maintain a full-text index of the contents of plain text documents on + Gopher servers in some specified domain. A Gopher full-text search + server was implemented using several NeXTstations because it was easy + to take advantage of the full-text index/search engine built into the + NeXT system software. A search server for generic UNIX systems based + on the public domain WAIS search engine, is also available and + currently an optional part of the UNIX gopher server. In addition, + at least one implementation of the gopher server incorperates a + gateway to WAIS servers by presenting the WAIS servers to gopherspace + as full-text search servers. The gopher<->WAIS gateway servers does + the work of translating from gopher protocol to WAIS so unmodified + gopher clients can access WAIS servers via the gateway server. + + By using several index servers (rather than a monolithic index + server) indexes may be searched in parallel (although the client + software is not aware of this). While maintaining full-text indexes + of documents distributed over many machines may seem a daunting task, + the task can be broken into smaller pieces (update only a portion of + the indexes, search several partial indexes in parallel) so that it + is manageable. By spreading this task over several small, cheap (and + fast) workstations it is possible to take advantage of fine-grain + parallelism. Again, the client software is not aware of this. Client + software only needs to know that it can send a search string to an + index server and will receive a list of documents that contain the + words in the search string. + +3.8 Item type characters + + The client software decides what items are available by looking at + the first character of each line in a directory listing. Augmenting + this list can extend the protocol. A list of defined item-type + characters follows: + + 0 Item is a file + 1 Item is a directory + 2 Item is a CSO phone-book server + 3 Error + 4 Item is a BinHexed Macintosh file. + 5 Item is DOS binary archive of some sort. + Client must read until the TCP connection closes. Beware. + 6 Item is a UNIX uuencoded file. + 7 Item is an Index-Search server. + 8 Item points to a text-based telnet session. + 9 Item is a binary file! + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 10] + +RFC 1436 Gopher March 1993 + + + Client must read until the TCP connection closes. Beware. + + Item is a redundant server + T Item points to a text-based tn3270 session. + g Item is a GIF format graphics file. + I Item is some kind of image file. Client decides how to display. + + Characters '0' through 'Z' are reserved. Local experiments should + use other characters. Machine-specific extensions are not + encouraged. Note that for type 5 or type 9 the client must be + prepared to read until the connection closes. There will be no + period at the end of the file; the contents of these files are binary + and the client must decide what to do with them based perhaps on the + .xxx extension. + +3.9 User display strings and server selector strings + + User display strings are intended to be displayed on a line on a + typical screen for a user's viewing pleasure. While many screens can + accommodate 80 character lines, some space is needed to display a tag + of some sort to tell the user what sort of item this is. Because of + this, the user display string should be kept under 70 characters in + length. Clients may truncate to a length convenient to them. + +4. Simplicity is intentional + + As far as possible we desire any new features to be carried as new + protocols that will be hidden behind new document-types. The + internet Gopher philosophy is: + + (a) Intelligence is held by the server. Clients have the option + of being able to access new document types (different, other types + of servers) by simply recognizing the document-type character. + Further intelligence to be borne by the protocol should be + minimized. + + (b) The well-tempered server ought to send "text" (unless a file + must be transferred as raw binary). Should this text include + tabs, formfeeds, frufru? Probably not, but rude servers will + probably send them anyway. Publishers of documents should be + given simple tools (filters) that will alert them if there are any + funny characters in the documents they wish to publish, and give + them the opportunity to strip the questionable characters out; the + publisher may well refuse. + + (c) The well-tempered client should do something reasonable with + funny characters received in text; filter them out, leave them in, + whatever. + + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 11] + +RFC 1436 Gopher March 1993 + + +Appendix + + Paul's NQBNF (Not Quite BNF) for the Gopher Protocol. + + Note: This is modified BNF (as used by the Pascal people) with a few + English modifiers thrown in. Stuff enclosed in '{}' can be + repeated zero or more times. Stuff in '[]' denotes a set of + items. The '-' operator denotes set subtraction. + + +Directory Entity + +CR-LF ::= ASCII Carriage Return Character followed by Line Feed + character. + +Tab ::= ASCII Tab character. + +NUL ::= ASCII NUL character. + +UNASCII ::= ASCII - [Tab CR-LF NUL]. + +Lastline ::= '.'CR-LF. + +TextBlock ::= Block of ASCII text not containing Lastline pattern. + +Type ::= UNASCII. + +RedType ::= '+'. + +User_Name ::= {UNASCII}. + +Selector ::= {UNASCII}. + +Host ::= {{UNASCII - ['.']} '.'} {UNASCII - ['.']}. + +Note: This is a Fully Qualified Domain Name as defined in RFC 1034. + (e.g., gopher.micro.umn.edu) Hosts that have a CR-LF + TAB or NUL in their name get what they deserve. + +Digit ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' . + +DigitSeq ::= digit {digit}. + +Port ::= DigitSeq. + +Note: Port corresponds the the TCP Port Number, its value should + be in the range [0..65535]; port 70 is officially assigned + to gopher. + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 12] + +RFC 1436 Gopher March 1993 + + +DirEntity ::= Type User_Name Tab Selector Tab Host Tab Port CR-LF + {RedType User_Name Tab Selector Tab Host Tab Port CR-LF} + + + +Notes: + + It is *highly* recommended that the User_Name field contain only + printable characters, since many different clients will be using + it. However if eight bit characters are used, the characters + should conform with the ISO Latin1 Character Set. The length of + the User displayable line should be less than 70 Characters; longer + lines may not fit across some screens. + + The Selector string should be no longer than 255 characters. + + +Menu Entity + +Menu ::= {DirEntity} Lastline. + + +Menu Transaction (Type 1 item) + +C: Opens Connection +S: Accepts Connection +C: Sends Selector String +S: Sends Menu Entity + + Connection is closed by either client or server (typically server). + + +Textfile Entity + +TextFile ::= {TextBlock} Lastline + +Note: Lines beginning with periods must be prepended with an extra + period to ensure that the transmission is not terminated early. + The client should strip extra periods at the beginning of the line. + + +TextFile Transaction (Type 0 item) + +C: Opens Connection. +S: Accepts connection +C: Sends Selector String. +S: Sends TextFile Entity. + + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 13] + +RFC 1436 Gopher March 1993 + + + Connection is closed by either client or server (typically server). + +Note: The client should be prepared for the server closing the + connection without sending the Lastline. This allows the + client to use fingerd servers. + + +Full-Text Search Transaction (Type 7 item) + +Word ::= {UNASCII - ' '} +BoolOp ::= 'and' | 'or' | 'not' | SPACE +SearchStr ::= Word {{SPACE BoolOp} SPACE Word} + +C: Opens Connection. +C: Sends Selector String, Tab, Search String. +S: Sends Menu Entity. + +Note: In absence of 'and', 'or', or 'not' operators, a SPACE is + regarded as an implied 'and' operator. Expression is evaluated + left to right. Further, not all search engines or search + gateways currently implemented have the boolean operators + implemented. + +Binary file Transaction (Type 9 or 5 item) + +C: Opens Connection. +S: Accepts connection +C: Sends Selector String. +S: Sends a binary file and closes connection when done. + + +Syntactic Meaning for Directory Entities + + +The client should interpret the type field as follows: + +0 The item is a TextFile Entity. + Client should use a TextFile Transaction. + +1 The item is a Menu Entity. + Client should use a Menu Transaction. + +2 The information applies to a CSO phone book entity. + Client should talk CSO protocol. + +3 Signals an error condition. + +4 Item is a Macintosh file encoded in BINHEX format + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 14] + +RFC 1436 Gopher March 1993 + + +5 Item is PC-DOS binary file of some sort. Client gets to decide. + +6 Item is a uuencoded file. + +7 The information applies to a Index Server. + Client should use a FullText Search transaction. + +8 The information applies to a Telnet session. + Connect to given host at given port. The name to login as at this + host is in the selector string. + +9 Item is a binary file. Client must decide what to do with it. + ++ The information applies to a duplicated server. The information + contained within is a duplicate of the primary server. The primary + server is defined as the last DirEntity that is has a non-plus + "Type" field. The client should use the transaction as defined by + the primary server Type field. + +g Item is a GIF graphic file. + +I Item is some kind of image file. Client gets to decide. + +T The information applies to a tn3270 based telnet session. + Connect to given host at given port. The name to login as at this + host is in the selector string. + +Security Considerations + + Security issues are not discussed in this memo. + +Authors' Addresses + + Farhad Anklesaria + Computer and Information Services, University of Minnesota + Room 152 Shepherd Labs + 100 Union Street SE + Minneapolis, MN 55455 + + Phone: (612) 625 1300 + EMail: fxa@boombox.micro.umn.edu + + + + + + + + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 15] + +RFC 1436 Gopher March 1993 + + + Mark McCahill + Computer and Information Services, University of Minnesota + Room 152 Shepherd Labs + 100 Union Street SE + Minneapolis, MN 55455 + + Phone: (612) 625 1300 + EMail: mpm@boombox.micro.umn.edu + + + Paul Lindner + Computer and Information Services, University of Minnesota + Room 152 Shepherd Labs + 100 Union Street SE + Minneapolis, MN 55455 + + Phone: (612) 625 1300 + EMail: lindner@boombox.micro.umn.edu + + + David Johnson + Computer and Information Services, University of Minnesota + Room 152 Shepherd Labs + 100 Union Street SE + Minneapolis, MN 55455 + + Phone: (612) 625 1300 + EMail: dmj@boombox.micro.umn.edu + + + Daniel Torrey + Computer and Information Services, University of Minnesota + Room 152 Shepherd Labs + 100 Union Street SE + Minneapolis, MN 55455 + + Phone: (612) 625 1300 + EMail: daniel@boombox.micro.umn.edu + + + Bob Alberti + Computer and Information Services, University of Minnesota + Room 152 Shepherd Labs + 100 Union Street SE + Minneapolis, MN 55455 + + Phone: (612) 625 1300 + EMail: alberti@boombox.micro.umn.edu + + + +Anklesari, McCahill, Lindner, Johnson, Torrey & Alberti [Page 16] + \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 322d39a..f83db89 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,8 +1,13 @@ #[macro_use] extern crate clap; +extern crate tokio; + mod configuration; use crate::configuration::Settings; +use tokio::io; +use tokio::net::TcpListener; +use tokio::prelude::*; /** * Initiates an instance of the gopherbridge server and @@ -14,7 +19,46 @@ fn main() { println!("Program listens on {}", settings.listen); println!("Loading plugins {:?}", settings.plugins); println!("Listening on port {}", settings.port); - if settings.foreground { - println!("Server runs in the foreground"); - } + + let addr = format!("{}:{}", settings.listen, settings.port) + .parse() + .unwrap(); + + let listener = TcpListener::bind(&addr).unwrap(); + let server = listener + .incoming() + .for_each(|socket| { + let (reader, writer) = socket.split(); + let amount = io::copy(reader, writer); + + let msg = amount.then(|result| { + match result { + Ok((amount, _, _)) => println!("wrote {} bytes", amount), + Err(e) => println!("error: {}", e), + } + Ok(()) + }); + + tokio::spawn(msg); + Ok(()) + }) + .map_err(|err| { + // Handle error by stdout + println!("accept error = {:?}", err); + }); + + println!( + "Started the server on {}:{}", + settings.listen, settings.port + ); + + // Start the server + // + // This does a few things: + // + // * Start the Tokio runtime + // * Spawns the `server` task onto the runtime. + // * Blocks the current thread until the runtime becomes idle, i.e. all + // spawned tasks have completed. + tokio::run(server); }