diff --git a/server/Cargo.lock b/server/Cargo.lock index 78e3aae..7c6678e 100644 --- a/server/Cargo.lock +++ b/server/Cargo.lock @@ -5,7 +5,7 @@ name = "MacTypes-sys" version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -39,7 +39,7 @@ name = "atty" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -57,7 +57,7 @@ dependencies = [ "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -68,7 +68,7 @@ version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -179,6 +179,8 @@ dependencies = [ "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "postgres 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "primitives 0.4.0 (git+https://github.com/CodeChain-io/rust-codechain-primitives.git)", + "r2d2 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)", + "r2d2_postgres 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sendgrid 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -237,7 +239,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -245,7 +247,7 @@ name = "core-foundation-sys" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -450,7 +452,7 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -657,7 +659,7 @@ name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -719,7 +721,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.50" +version = "0.2.65" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -731,6 +733,14 @@ dependencies = [ "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lock_api" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.3.9" @@ -762,7 +772,7 @@ name = "memchr" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -828,7 +838,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -842,7 +852,7 @@ dependencies = [ "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)", "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (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)", @@ -883,7 +893,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.10.20 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -900,7 +910,7 @@ version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -927,7 +937,7 @@ name = "num_cpus" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -939,7 +949,7 @@ dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -954,7 +964,7 @@ version = "0.9.43" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -977,18 +987,42 @@ dependencies = [ "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parking_lot" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (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.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (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.9 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parking_lot_core" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.51 (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.9 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "percent-encoding" version = "1.0.1" @@ -1126,12 +1160,32 @@ dependencies = [ "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "r2d2" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "scheduled-thread-pool 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "r2d2_postgres" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "postgres 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", + "postgres-shared 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "r2d2 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rand" version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1141,7 +1195,7 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (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.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1154,7 +1208,7 @@ 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.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1165,7 +1219,7 @@ version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (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)", @@ -1220,7 +1274,7 @@ name = "rand_jitter" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (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.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1232,7 +1286,7 @@ 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.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (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.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1378,11 +1432,24 @@ dependencies = [ "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "scheduled-thread-pool" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "parking_lot 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 = "scopeguard" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "security-framework" version = "0.2.2" @@ -1390,7 +1457,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "security-framework-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1401,7 +1468,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "MacTypes-sys 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1520,7 +1587,7 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1571,7 +1638,7 @@ version = "3.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1591,7 +1658,7 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1609,7 +1676,7 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2048,8 +2115,9 @@ dependencies = [ "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1" +"checksum libc 0.2.65 (registry+https://github.com/rust-lang/crates.io-index)" = "1a31a0627fdf1f6a39ec0dd577e101440b7db22672c0901fe00a9a6fbb5c24e8" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +"checksum lock_api 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8912e782533a93a167888781b836336a6ca5da6175c05944c86cf28c31104dc" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" @@ -2078,7 +2146,9 @@ dependencies = [ "checksum openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)" = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d" "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 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f842b1982eb6c2fe34036a4fbfb06dd185a3f5c8edfaacdf7d1ea10b07de6252" "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +"checksum parking_lot_core 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum phf 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b3da44b85f8e8dfaec21adae67f95d93244b2ecf6ad2a692320598dcc8e6dd18" "checksum phf_codegen 0.7.24 (registry+https://github.com/rust-lang/crates.io-index)" = "b03e85129e324ad4166b06b2c7491ae27fe3ec353af72e72cd1654c7225d517e" @@ -2094,6 +2164,8 @@ dependencies = [ "checksum publicsuffix 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5afecba86dcf1e4fd610246f89899d1924fe12e1e89f555eb7c7f710f3c5ad1d" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "cdd8e04bd9c52e0342b406469d494fcb033be4bdbe5c606016defbb1681411e1" +"checksum r2d2 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "e48fa64898ef0286b6ee4b4d8f61483f9182acf5e44e62a398b1c7f56f2f861d" +"checksum r2d2_postgres 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "78c7fe9c0c3d2c298cf262bc3ce4b89cdf0eab620fd9fe759f65b34a1a00fb93" "checksum rand 0.3.23 (registry+https://github.com/rust-lang/crates.io-index)" = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" @@ -2121,7 +2193,9 @@ dependencies = [ "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" "checksum schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f6abf258d99c3c1c5c2131d99d064e94b7b3dd5f416483057f308fea253339" +"checksum scheduled-thread-pool 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bd07742e081ff6c077f5f6b283f12f32b9e7cc765b316160d66289b74546fbb3" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" +"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" "checksum security-framework 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfab8dda0e7a327c696d893df9ffa19cadc4bd195797997f5223cf5831beaf05" "checksum security-framework-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3d6696852716b589dff9e886ff83778bb635150168e83afa8ac6b8a78cb82abc" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" diff --git a/server/Cargo.toml b/server/Cargo.toml index 02ae2b6..94a5404 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -24,3 +24,5 @@ serde_json = "1.0" slack-hook = "0.8.0" time = "0.1" ws = "*" +r2d2_postgres = "0.14.0" +r2d2 = "0.8.6" diff --git a/server/src/db/queries/client_extra.rs b/server/src/db/queries/client_extra.rs index 69d7b8b..6a63783 100644 --- a/server/src/db/queries/client_extra.rs +++ b/server/src/db/queries/client_extra.rs @@ -1,8 +1,7 @@ -use postgres; - +use super::super::types::DBConnection; use super::super::ClientExtra; -pub fn get(conn: &postgres::Connection, node_name: &str) -> postgres::Result> { +pub fn get(conn: &DBConnection, node_name: &str) -> postgres::Result> { ctrace!("Query client extra by name {}", node_name); let rows = conn.query("SELECT * FROM client_extra WHERE name=$1;", &[&node_name])?; @@ -16,7 +15,7 @@ pub fn get(conn: &postgres::Connection, node_name: &str) -> postgres::Result postgres::Result<()> { +pub fn upsert(conn: &DBConnection, node_name: &str, client_extra: &ClientExtra) -> postgres::Result<()> { ctrace!("Upsert client extra {:?}", client_extra); let result = conn.execute( "INSERT INTO client_extra (name, prev_env, prev_args) VALUES ($1, $2, $3) \ diff --git a/server/src/db/queries/config.rs b/server/src/db/queries/config.rs index 4ae41be..4ae6470 100644 --- a/server/src/db/queries/config.rs +++ b/server/src/db/queries/config.rs @@ -1,6 +1,6 @@ -use postgres; +use super::super::types::DBConnection; -pub fn set_query_timeout(conn: &postgres::Connection) -> postgres::Result<()> { +pub fn set_query_timeout(conn: &DBConnection) -> postgres::Result<()> { conn.execute("SET SESSION statement_timeout TO 2000", &[])?; Ok(()) } diff --git a/server/src/db/queries/logs.rs b/server/src/db/queries/logs.rs index 809e5bd..d371263 100644 --- a/server/src/db/queries/logs.rs +++ b/server/src/db/queries/logs.rs @@ -6,10 +6,11 @@ use postgres; use postgres::types::ToSql; use super::super::super::common_rpc_types::StructuredLog; +use super::super::types::DBConnection; use super::super::types::OrderBy; use super::super::types::{Log, LogQueryParams}; -pub fn insert(conn: &postgres::Connection, node_name: &str, logs: Vec) -> postgres::Result<()> { +pub fn insert(conn: &DBConnection, node_name: &str, logs: Vec) -> postgres::Result<()> { ctrace!("Add log {} : {:?}", node_name, logs); if logs.is_empty() { @@ -53,7 +54,7 @@ pub fn insert(conn: &postgres::Connection, node_name: &str, logs: Vec postgres::Result> { +pub fn search(conn: &DBConnection, params: LogQueryParams) -> postgres::Result> { ctrace!("Search log with {:?}", params); let mut parameters = Parameters::default(); let mut where_conditions = Vec::new(); @@ -145,7 +146,7 @@ impl Parameters { } } -pub fn get_targets(conn: &postgres::Connection) -> postgres::Result> { +pub fn get_targets(conn: &DBConnection) -> postgres::Result> { ctrace!("Query targets"); // let rows = conn.query("SELECT DISTINCT target FROM logs", &[])?; diff --git a/server/src/db/queries/network_usage.rs b/server/src/db/queries/network_usage.rs index 6ba8d4b..d4789d4 100644 --- a/server/src/db/queries/network_usage.rs +++ b/server/src/db/queries/network_usage.rs @@ -2,11 +2,12 @@ use chrono; use postgres; use regex::{Captures, Regex}; +use super::super::types::DBConnection; use common_rpc_types::NetworkUsage; use util::{floor_to_5min, start_of_day, start_of_hour}; pub fn insert( - conn: &postgres::Connection, + conn: &DBConnection, node_name: &str, network_usage: NetworkUsage, time: chrono::DateTime, diff --git a/server/src/db/queries/network_usage_graph.rs b/server/src/db/queries/network_usage_graph.rs index 28bc346..a2785a1 100644 --- a/server/src/db/queries/network_usage_graph.rs +++ b/server/src/db/queries/network_usage_graph.rs @@ -4,8 +4,10 @@ use common_rpc_types::{ }; use postgres; +use super::super::types::DBConnection; + pub fn query_network_out_all( - conn: &postgres::Connection, + conn: &DBConnection, graph_args: GraphCommonArgs, ) -> postgres::Result> { let time_column_name = get_sql_column_name_by_period(graph_args.period); @@ -38,7 +40,7 @@ fn get_sql_column_name_by_period(period: GraphPeriod) -> &'static str { } pub fn query_network_out_all_avg( - conn: &postgres::Connection, + conn: &DBConnection, graph_args: GraphCommonArgs, ) -> postgres::Result> { let time_column_name = get_sql_column_name_by_period(graph_args.period); @@ -63,7 +65,7 @@ pub fn query_network_out_all_avg( } pub fn query_network_out_node_extension( - conn: &postgres::Connection, + conn: &DBConnection, node_name: NodeName, graph_args: GraphCommonArgs, ) -> postgres::Result> { @@ -90,7 +92,7 @@ pub fn query_network_out_node_extension( } pub fn query_network_out_node_peer( - conn: &postgres::Connection, + conn: &DBConnection, node_name: NodeName, graph_args: GraphCommonArgs, ) -> postgres::Result> { diff --git a/server/src/db/queries/peer_count.rs b/server/src/db/queries/peer_count.rs index cbf4794..ad2292e 100644 --- a/server/src/db/queries/peer_count.rs +++ b/server/src/db/queries/peer_count.rs @@ -1,8 +1,10 @@ use chrono; use postgres; +use super::super::types::DBConnection; + pub fn insert( - conn: &postgres::Connection, + conn: &DBConnection, node_name: &str, peer_count: i32, time: chrono::DateTime, diff --git a/server/src/db/service.rs b/server/src/db/service.rs index 87f6c56..321424b 100644 --- a/server/src/db/service.rs +++ b/server/src/db/service.rs @@ -5,8 +5,7 @@ use std::net::SocketAddr; use std::sync::mpsc::{channel, Sender}; use std::thread; -use postgres; -use postgres::TlsMode; +use r2d2_postgres::PostgresConnectionManager; use super::super::common_rpc_types as rpc_type; use super::super::common_rpc_types::{NodeName, NodeStatus, StructuredLog}; @@ -17,6 +16,7 @@ use common_rpc_types::{ GraphCommonArgs, GraphNetworkOutAllAVGRow, GraphNetworkOutAllRow, GraphNetworkOutNodeExtensionRow, GraphNetworkOutNodePeerRow, NetworkUsage, }; +use db::types::DBConnection; use util; #[derive(Debug, Clone)] @@ -58,7 +58,7 @@ struct State { pub struct Service { state: State, event_subscriber: Box, - db_conn: postgres::Connection, + pool: r2d2::Pool, } pub struct ServiceNewArg { @@ -75,15 +75,20 @@ impl Service { db_password, }: ServiceNewArg, ) -> Self { - let conn_uri = format!("postgres://{}:{}@localhost", db_user, db_password); + let manager = PostgresConnectionManager::new( + format!("postgres://{}:{}@localhost", db_user, db_password), + r2d2_postgres::TlsMode::None, + ) + .expect("Create connection manager"); + let pool = r2d2::Pool::new(manager).expect("Create connection pool"); - let conn = postgres::Connection::connect(conn_uri, TlsMode::None).unwrap(); - queries::config::set_query_timeout(&conn).unwrap(); + let connection = pool.get().expect("Get connection"); + queries::config::set_query_timeout(&connection).unwrap(); Self { state: State::default(), event_subscriber, - db_conn: conn, + pool, } } @@ -187,8 +192,19 @@ impl Service { service_sender } + fn db_conn(&self) -> Result { + self.pool.get().map_err(|err| DBError::Internal(err.to_string())) + } + fn check_connection(&self, callback: Sender>) { - let result = self.db_conn.execute(&"SELECT 1", &[]).map_err(|err| DBError::Internal(err.to_string())); + let conn = match self.db_conn() { + Ok(conn) => conn, + Err(err) => { + cerror!("check_connection: {:?}", err); + return + } + }; + let result = conn.execute(&"SELECT 1", &[]).map_err(|err| DBError::Internal(err.to_string())); if let Err(err) = callback.send(result.map(|_| ())) { cerror!("Cannot send callback : {}", err); } @@ -299,13 +315,13 @@ impl Service { } fn save_start_option(&mut self, node_name: NodeName, env: &str, args: &str) -> Result<(), Box> { - let before_extra = queries::client_extra::get(&self.db_conn, &node_name)?; + let before_extra = queries::client_extra::get(&self.db_conn()?, &node_name)?; let mut extra = before_extra.clone().unwrap_or_default(); extra.prev_env = env.to_string(); extra.prev_args = args.to_string(); - queries::client_extra::upsert(&self.db_conn, &node_name, &extra)?; + queries::client_extra::upsert(&self.db_conn()?, &node_name, &extra)?; self.event_subscriber.on_event(Event::ClientExtraUpdated { name: node_name, @@ -321,7 +337,7 @@ impl Service { node_name: &str, callback: Sender>, ) -> Result<(), Box> { - let extra = queries::client_extra::get(&self.db_conn, node_name)?; + let extra = queries::client_extra::get(&self.db_conn()?, node_name)?; if let Err(err) = callback.send(extra) { cerror!("Callback error {}", err); } @@ -329,18 +345,18 @@ impl Service { } fn get_logs(&self, params: LogQueryParams, callback: Sender>) -> Result<(), Box> { - let logs = queries::logs::search(&self.db_conn, params)?; + let logs = queries::logs::search(&self.db_conn()?, params)?; callback.send(logs)?; Ok(()) } fn write_logs(&self, node_name: &str, logs: Vec) -> Result<(), Box> { - queries::logs::insert(&self.db_conn, node_name, logs)?; + queries::logs::insert(&self.db_conn()?, node_name, logs)?; Ok(()) } fn get_log_targets(&self, callback: Sender>) -> Result<(), Box> { - let targets = queries::logs::get_targets(&self.db_conn)?; + let targets = queries::logs::get_targets(&self.db_conn()?)?; callback.send(targets)?; Ok(()) } @@ -351,7 +367,7 @@ impl Service { network_usage: NetworkUsage, time: chrono::DateTime, ) -> Result<(), Box> { - queries::network_usage::insert(&self.db_conn, node_name, network_usage, time)?; + queries::network_usage::insert(&self.db_conn()?, node_name, network_usage, time)?; Ok(()) } @@ -361,7 +377,7 @@ impl Service { peer_count: i32, time: chrono::DateTime, ) -> Result<(), Box> { - queries::peer_count::insert(&self.db_conn, node_name, peer_count, time)?; + queries::peer_count::insert(&self.db_conn()?, node_name, peer_count, time)?; Ok(()) } @@ -369,7 +385,7 @@ impl Service { &self, args: GraphCommonArgs, ) -> Result, Box> { - let rows = queries::network_usage_graph::query_network_out_all(&self.db_conn, args)?; + let rows = queries::network_usage_graph::query_network_out_all(&self.db_conn()?, args)?; Ok(rows) } @@ -377,7 +393,7 @@ impl Service { &self, args: GraphCommonArgs, ) -> Result, Box> { - let rows = queries::network_usage_graph::query_network_out_all_avg(&self.db_conn, args)?; + let rows = queries::network_usage_graph::query_network_out_all_avg(&self.db_conn()?, args)?; Ok(rows) } @@ -386,7 +402,7 @@ impl Service { node_name: NodeName, args: GraphCommonArgs, ) -> Result, Box> { - let rows = queries::network_usage_graph::query_network_out_node_extension(&self.db_conn, node_name, args)?; + let rows = queries::network_usage_graph::query_network_out_node_extension(&self.db_conn()?, node_name, args)?; Ok(rows) } @@ -395,7 +411,7 @@ impl Service { node_name: NodeName, args: GraphCommonArgs, ) -> Result, Box> { - let rows = queries::network_usage_graph::query_network_out_node_peer(&self.db_conn, node_name, args)?; + let rows = queries::network_usage_graph::query_network_out_node_peer(&self.db_conn()?, node_name, args)?; Ok(rows) } } diff --git a/server/src/db/types.rs b/server/src/db/types.rs index 5beecfb..c059c01 100644 --- a/server/src/db/types.rs +++ b/server/src/db/types.rs @@ -8,6 +8,9 @@ use std::sync::mpsc::RecvError; use super::super::common_rpc_types::{ BlackList, BlockId, HardwareInfo, NodeName, NodeStatus, NodeVersion, PendingTransaction, WhiteList, }; +use serde::export::Formatter; + +pub type DBConnection = r2d2::PooledConnection; #[derive(PartialEq, Clone, Debug, Default)] pub struct ClientQueryResult { @@ -184,3 +187,13 @@ impl From for Error { Error::Internal(error.to_string()) } } + +impl std::error::Error for Error {} + +impl std::fmt::Display for Error { + fn fmt(&self, f: &mut Formatter) -> Result<(), std::fmt::Error> { + match self { + Error::Internal(log) => write!(f, "{}", log), + } + } +} diff --git a/server/src/main.rs b/server/src/main.rs index db5f392..41e3a18 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -16,6 +16,7 @@ extern crate serde; extern crate serde_derive; #[macro_use] extern crate serde_json; +extern crate r2d2_postgres; extern crate slack_hook; extern crate ws;