feat(gva): reget conf handling & handle public ips
This commit is contained in:
parent
496c1a913d
commit
bbecb1a1cc
10 changed files with 458 additions and 52 deletions
298
Cargo.lock
generated
298
Cargo.lock
generated
|
@ -99,7 +99,7 @@ checksum = "6fd4c2eb837e894909fe13509f2351fa3990c114426e41255936800892ccbe26"
|
|||
dependencies = [
|
||||
"Inflector",
|
||||
"async-graphql-parser",
|
||||
"darling",
|
||||
"darling 0.12.4",
|
||||
"proc-macro-crate",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -466,14 +466,38 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858"
|
||||
dependencies = [
|
||||
"darling_core 0.10.2",
|
||||
"darling_macro 0.10.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling"
|
||||
version = "0.12.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5f2c43f534ea4b0b049015d00269734195e6d3f0f6635cb692251aca6f9f8b3c"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_macro",
|
||||
"darling_core 0.12.4",
|
||||
"darling_macro 0.12.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_core"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b"
|
||||
dependencies = [
|
||||
"fnv",
|
||||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim 0.9.3",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -486,7 +510,18 @@ dependencies = [
|
|||
"ident_case",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"strsim",
|
||||
"strsim 0.10.0",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "darling_macro"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72"
|
||||
dependencies = [
|
||||
"darling_core 0.10.2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
|
@ -496,7 +531,49 @@ version = "0.12.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "29b5acf0dea37a7f66f7b25d2c5e93fd46f8f6968b1a5d7a3e02e97768afc95a"
|
||||
dependencies = [
|
||||
"darling_core",
|
||||
"darling_core 0.12.4",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "data-encoding"
|
||||
version = "2.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ee2393c4a91429dffb4bedf19f4d6abf27d8a732c8ce4980305d782e5426d57"
|
||||
|
||||
[[package]]
|
||||
name = "derivative"
|
||||
version = "2.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2658621297f2cf68762a6f7dc0bb7e1ff2cfd6583daef8ee0fed6f7ec468ec0"
|
||||
dependencies = [
|
||||
"darling 0.10.2",
|
||||
"derive_builder_core",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derive_builder_core"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2791ea3e372c8495c0bc2033991d76b512cd799d07491fbd6890124db9458bef"
|
||||
dependencies = [
|
||||
"darling 0.10.2",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
@ -543,6 +620,18 @@ dependencies = [
|
|||
"generic-array 0.14.4",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dns-lookup"
|
||||
version = "1.0.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "eb4c5ce3a7034c5eb66720bb16e9ac820e01b29032ddc06dd0fe47072acf7454"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"libc",
|
||||
"socket2",
|
||||
"winapi",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "downcast"
|
||||
version = "0.10.0"
|
||||
|
@ -636,7 +725,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-bc-reader"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#e75d971b7c9f7f67ac108eac6777940dabff49df"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#65dd5cf572e4fffa0f4b6f70d04c3fe65ecffd69"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"dubp",
|
||||
|
@ -682,7 +771,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-conf"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#e75d971b7c9f7f67ac108eac6777940dabff49df"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#65dd5cf572e4fffa0f4b6f70d04c3fe65ecffd69"
|
||||
dependencies = [
|
||||
"dubp",
|
||||
"serde",
|
||||
|
@ -691,7 +780,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-core"
|
||||
version = "1.8.1"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#e75d971b7c9f7f67ac108eac6777940dabff49df"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#65dd5cf572e4fffa0f4b6f70d04c3fe65ecffd69"
|
||||
dependencies = [
|
||||
"duniter-bc-reader",
|
||||
"duniter-conf",
|
||||
|
@ -704,7 +793,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-dbs"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#e75d971b7c9f7f67ac108eac6777940dabff49df"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#65dd5cf572e4fffa0f4b6f70d04c3fe65ecffd69"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bincode",
|
||||
|
@ -715,7 +804,7 @@ dependencies = [
|
|||
"log",
|
||||
"parking_lot",
|
||||
"paste",
|
||||
"rand 0.7.3",
|
||||
"rand 0.8.3",
|
||||
"serde",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
|
@ -727,7 +816,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-dbs-write-ops"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#e75d971b7c9f7f67ac108eac6777940dabff49df"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#65dd5cf572e4fffa0f4b6f70d04c3fe65ecffd69"
|
||||
dependencies = [
|
||||
"chrono",
|
||||
"dubp",
|
||||
|
@ -742,7 +831,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-global"
|
||||
version = "1.8.1"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#e75d971b7c9f7f67ac108eac6777940dabff49df"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#65dd5cf572e4fffa0f4b6f70d04c3fe65ecffd69"
|
||||
dependencies = [
|
||||
"async-rwlock",
|
||||
"dubp",
|
||||
|
@ -766,6 +855,7 @@ dependencies = [
|
|||
"dubp",
|
||||
"duniter-bca",
|
||||
"duniter-core",
|
||||
"duniter-gva-conf",
|
||||
"duniter-gva-db",
|
||||
"duniter-gva-dbs-reader",
|
||||
"duniter-gva-gql",
|
||||
|
@ -785,6 +875,13 @@ dependencies = [
|
|||
"warp",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "duniter-gva-conf"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "duniter-gva-db"
|
||||
version = "0.1.0"
|
||||
|
@ -860,7 +957,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-mempools"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#e75d971b7c9f7f67ac108eac6777940dabff49df"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#65dd5cf572e4fffa0f4b6f70d04c3fe65ecffd69"
|
||||
dependencies = [
|
||||
"dubp",
|
||||
"duniter-bc-reader",
|
||||
|
@ -873,17 +970,23 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "duniter-module"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#e75d971b7c9f7f67ac108eac6777940dabff49df"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#65dd5cf572e4fffa0f4b6f70d04c3fe65ecffd69"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"async-mutex",
|
||||
"async-trait",
|
||||
"dubp",
|
||||
"duniter-conf",
|
||||
"duniter-dbs",
|
||||
"duniter-global",
|
||||
"duniter-mempools",
|
||||
"envy",
|
||||
"fast-threadpool",
|
||||
"futures-util",
|
||||
"log",
|
||||
"public-ip",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -933,6 +1036,33 @@ dependencies = [
|
|||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "endian-type"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d"
|
||||
|
||||
[[package]]
|
||||
name = "enum-as-inner"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7c5f0096a91d210159eceb2ff5e1c4da18388a170e1e3ce948aac9c8fdbbf595"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "envy"
|
||||
version = "0.4.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3f47e0157f2cb54f5ae1bd371b30a2ae4311e1c028f575cd4e81de7353215965"
|
||||
dependencies = [
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "event-listener"
|
||||
version = "2.5.1"
|
||||
|
@ -1216,6 +1346,15 @@ dependencies = [
|
|||
"http",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.3.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "87cbf45460356b7deeb5e3415b5563308c0a9b057c85e12b06ad551f98d0a6ac"
|
||||
dependencies = [
|
||||
"unicode-segmentation",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hermit-abi"
|
||||
version = "0.1.18"
|
||||
|
@ -1289,6 +1428,21 @@ dependencies = [
|
|||
"want",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hyper-system-resolver"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "12f3e7696766b62825bf735a1df9d8b727525b83ae5427ee955258800858bd73"
|
||||
dependencies = [
|
||||
"derivative",
|
||||
"derive_builder",
|
||||
"dns-lookup",
|
||||
"hyper",
|
||||
"tokio",
|
||||
"tower-service",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ident_case"
|
||||
version = "1.0.1"
|
||||
|
@ -1334,6 +1488,12 @@ dependencies = [
|
|||
"cfg-if 1.0.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ipnet"
|
||||
version = "2.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "47be2f14c678be2fdcab04ab1171db51b2762ce6f0a8ee87c8dd4a04ed216135"
|
||||
|
||||
[[package]]
|
||||
name = "itertools"
|
||||
version = "0.9.0"
|
||||
|
@ -1382,7 +1542,7 @@ dependencies = [
|
|||
[[package]]
|
||||
name = "kv_typed"
|
||||
version = "0.1.0"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#e75d971b7c9f7f67ac108eac6777940dabff49df"
|
||||
source = "git+https://git.duniter.org/nodes/rust/duniter-core#65dd5cf572e4fffa0f4b6f70d04c3fe65ecffd69"
|
||||
dependencies = [
|
||||
"byteorder",
|
||||
"cfg-if 0.1.10",
|
||||
|
@ -1589,6 +1749,15 @@ dependencies = [
|
|||
"getrandom 0.2.2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "nibble_vec"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43"
|
||||
dependencies = [
|
||||
"smallvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "normalize-line-endings"
|
||||
version = "0.3.0"
|
||||
|
@ -1850,6 +2019,26 @@ dependencies = [
|
|||
"unicode-xid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "public-ip"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ba5e48e5087711724b4536dfe11a201a20ae91a7f1b08e3e17a1053459e20580"
|
||||
dependencies = [
|
||||
"dns-lookup",
|
||||
"futures-core",
|
||||
"futures-util",
|
||||
"http",
|
||||
"hyper",
|
||||
"hyper-system-resolver",
|
||||
"pin-project-lite",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"tracing",
|
||||
"trust-dns-client",
|
||||
"trust-dns-proto",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-error"
|
||||
version = "1.2.3"
|
||||
|
@ -1865,6 +2054,16 @@ dependencies = [
|
|||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "radix_trie"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd"
|
||||
dependencies = [
|
||||
"endian-type",
|
||||
"nibble_vec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rand"
|
||||
version = "0.7.3"
|
||||
|
@ -2209,6 +2408,12 @@ version = "1.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.9.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c"
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
|
@ -2393,9 +2598,21 @@ dependencies = [
|
|||
"cfg-if 1.0.0",
|
||||
"log",
|
||||
"pin-project-lite",
|
||||
"tracing-attributes",
|
||||
"tracing-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-attributes"
|
||||
version = "0.1.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c42e6fa53307c8a17e4ccd4dc81cf5ec38db9209f59b222210375b54ee40d1e2"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tracing-core"
|
||||
version = "0.1.17"
|
||||
|
@ -2411,6 +2628,51 @@ version = "0.1.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7f741b240f1a48843f9b8e0444fb55fb2a4ff67293b50a9179dfd5ea67f8d41"
|
||||
|
||||
[[package]]
|
||||
name = "trust-dns-client"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f557e7009d16747a0363f9127588c3c236f279b4caa1177d703221a258dd3f3"
|
||||
dependencies = [
|
||||
"cfg-if 1.0.0",
|
||||
"chrono",
|
||||
"data-encoding",
|
||||
"futures-channel",
|
||||
"futures-util",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"radix_trie",
|
||||
"rand 0.8.3",
|
||||
"thiserror",
|
||||
"tokio",
|
||||
"trust-dns-proto",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "trust-dns-proto"
|
||||
version = "0.20.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "952a078337565ba39007de99b151770f41039253a31846f0a3d5cd5a4ac8eedf"
|
||||
dependencies = [
|
||||
"async-trait",
|
||||
"cfg-if 1.0.0",
|
||||
"data-encoding",
|
||||
"enum-as-inner",
|
||||
"futures-channel",
|
||||
"futures-io",
|
||||
"futures-util",
|
||||
"idna",
|
||||
"ipnet",
|
||||
"lazy_static",
|
||||
"log",
|
||||
"rand 0.8.3",
|
||||
"smallvec",
|
||||
"thiserror",
|
||||
"tinyvec",
|
||||
"tokio",
|
||||
"url",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "try-lock"
|
||||
version = "0.2.3"
|
||||
|
@ -2500,6 +2762,12 @@ dependencies = [
|
|||
"tinyvec",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-segmentation"
|
||||
version = "1.7.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bb0d2e7be6ae3a5fa87eed5fb451aff96f2573d2694942e40543ae0bbe19c796"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-xid"
|
||||
version = "0.2.1"
|
||||
|
|
|
@ -16,6 +16,7 @@ bytes = "1.0"
|
|||
dubp = { version = "0.53.1", features = ["duniter"] }
|
||||
duniter-bca = { path = "./bca" }
|
||||
duniter-core = { git = "https://git.duniter.org/nodes/rust/duniter-core" }
|
||||
duniter-gva-conf = { path = "./conf" }
|
||||
duniter-gva-db = { path = "./db" }
|
||||
duniter-gva-dbs-reader = { path = "./dbs-reader" }
|
||||
duniter-gva-indexer = { path = "./indexer" }
|
||||
|
@ -41,8 +42,13 @@ unwrap = "1.2.1"
|
|||
[workspace]
|
||||
members = [
|
||||
"bca",
|
||||
"conf",
|
||||
"db",
|
||||
"dbs-reader",
|
||||
"gql",
|
||||
"indexer",
|
||||
]
|
||||
|
||||
[patch.crates-io]
|
||||
#duniter-core = { path = "../duniter-core" }
|
||||
|
||||
|
|
18
conf/Cargo.toml
Normal file
18
conf/Cargo.toml
Normal file
|
@ -0,0 +1,18 @@
|
|||
[package]
|
||||
name = "duniter-gva-conf"
|
||||
version = "0.1.0"
|
||||
authors = ["elois <elois@duniter.org>"]
|
||||
description = "Duniter GVA DB"
|
||||
repository = "https://git.duniter.org/nodes/rust/modules/duniter-gva"
|
||||
license = "AGPL-3.0"
|
||||
edition = "2018"
|
||||
|
||||
[lib]
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1.0.105", features = ["derive"] }
|
||||
|
||||
[dev-dependencies]
|
||||
|
||||
[features]
|
98
conf/src/lib.rs
Normal file
98
conf/src/lib.rs
Normal file
|
@ -0,0 +1,98 @@
|
|||
// Copyright (C) 2020 Éloïs SANCHEZ.
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as
|
||||
// published by the Free Software Foundation, either version 3 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
net::{IpAddr, Ipv4Addr, Ipv6Addr},
|
||||
vec,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct GvaConf {
|
||||
pub enabled: bool,
|
||||
#[serde(default = "ip4_default")]
|
||||
pub ip4: Ipv4Addr,
|
||||
pub ip6: Option<Ipv6Addr>,
|
||||
#[serde(default = "port_default")]
|
||||
pub port: u16,
|
||||
#[serde(default = "path_default")]
|
||||
pub path: String,
|
||||
#[serde(default = "subscriptions_path_default")]
|
||||
pub subscriptions_path: String,
|
||||
pub remote_host: Option<String>,
|
||||
pub remote_port: Option<u16>,
|
||||
pub remote_path: Option<String>,
|
||||
pub remote_subscriptions_path: Option<String>,
|
||||
pub remote_tls: Option<bool>,
|
||||
pub whitelist: Vec<IpAddr>,
|
||||
}
|
||||
|
||||
const fn ip4_default() -> Ipv4Addr {
|
||||
Ipv4Addr::UNSPECIFIED
|
||||
}
|
||||
|
||||
const fn ip6_default() -> Ipv6Addr {
|
||||
Ipv6Addr::UNSPECIFIED
|
||||
}
|
||||
|
||||
fn path_default() -> String {
|
||||
"gva".to_owned()
|
||||
}
|
||||
|
||||
const fn port_default() -> u16 {
|
||||
30_901
|
||||
}
|
||||
|
||||
fn subscriptions_path_default() -> String {
|
||||
"gva-sub".to_owned()
|
||||
}
|
||||
|
||||
impl Default for GvaConf {
|
||||
fn default() -> Self {
|
||||
GvaConf {
|
||||
enabled: false,
|
||||
ip4: ip4_default(),
|
||||
ip6: Some(ip6_default()),
|
||||
port: port_default(),
|
||||
path: path_default(),
|
||||
subscriptions_path: subscriptions_path_default(),
|
||||
remote_host: None,
|
||||
remote_port: None,
|
||||
remote_path: None,
|
||||
remote_subscriptions_path: None,
|
||||
remote_tls: None,
|
||||
whitelist: vec![
|
||||
IpAddr::V4(Ipv4Addr::LOCALHOST),
|
||||
IpAddr::V6(Ipv6Addr::LOCALHOST),
|
||||
],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl GvaConf {
|
||||
pub fn get_remote_port(&self) -> u16 {
|
||||
self.remote_port.unwrap_or(self.port)
|
||||
}
|
||||
pub fn get_remote_path(&self) -> String {
|
||||
self.remote_path
|
||||
.clone()
|
||||
.unwrap_or_else(|| self.path.clone())
|
||||
}
|
||||
pub fn get_remote_subscriptions_path(&self) -> String {
|
||||
self.remote_subscriptions_path
|
||||
.clone()
|
||||
.unwrap_or_else(|| self.subscriptions_path.clone())
|
||||
}
|
||||
}
|
|
@ -3,7 +3,7 @@ name = "duniter-gva-db"
|
|||
version = "0.1.0"
|
||||
authors = ["elois <elois@duniter.org>"]
|
||||
description = "Duniter GVA DB"
|
||||
repository = "https://git.duniter.org/nodes/typescript/duniter"
|
||||
repository = "https://git.duniter.org/nodes/rust/modules/duniter-gva"
|
||||
license = "AGPL-3.0"
|
||||
edition = "2018"
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ name = "duniter-gva-dbs-reader"
|
|||
version = "0.1.0"
|
||||
authors = ["elois <elois@duniter.org>"]
|
||||
description = "Duniter GVA DBs read operations"
|
||||
repository = "https://git.duniter.org/nodes/typescript/duniter"
|
||||
repository = "https://git.duniter.org/nodes/rust/modules/duniter-gva"
|
||||
keywords = ["dubp", "duniter", "blockchain", "database"]
|
||||
license = "AGPL-3.0"
|
||||
edition = "2018"
|
||||
|
|
|
@ -3,7 +3,7 @@ name = "duniter-gva-indexer"
|
|||
version = "0.1.0"
|
||||
authors = ["elois <elois@duniter.org>"]
|
||||
description = "Duniter GVA DB writer"
|
||||
repository = "https://git.duniter.org/nodes/typescript/duniter"
|
||||
repository = "https://git.duniter.org/nodes/rust/modules/duniter-gva"
|
||||
keywords = ["dubp", "duniter", "blockchain", "database"]
|
||||
license = "AGPL-3.0"
|
||||
edition = "2018"
|
||||
|
|
|
@ -77,7 +77,7 @@ impl From<&GvaConf> for AntiSpam {
|
|||
ban: HashMap::with_capacity(10),
|
||||
ips_time: HashMap::with_capacity(10),
|
||||
})),
|
||||
whitelist: conf.get_whitelist().iter().copied().collect(),
|
||||
whitelist: conf.whitelist.iter().copied().collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
78
src/lib.rs
78
src/lib.rs
|
@ -25,8 +25,6 @@
|
|||
mod anti_spam;
|
||||
mod warp_;
|
||||
|
||||
pub use duniter_core::conf::gva_conf::GvaConf;
|
||||
|
||||
use async_graphql::http::GraphQLPlaygroundConfig;
|
||||
use dubp::common::prelude::*;
|
||||
use dubp::documents::transaction::TransactionDocumentV10;
|
||||
|
@ -41,6 +39,7 @@ use duniter_core::dbs::prelude::*;
|
|||
use duniter_core::dbs::{kv_typed::prelude::*, FileBackend};
|
||||
use duniter_core::global::AsyncAccessor;
|
||||
use duniter_core::mempools::Mempools;
|
||||
use duniter_gva_conf::GvaConf;
|
||||
use duniter_gva_db::*;
|
||||
use duniter_gva_gql::{GvaSchema, QueryContext};
|
||||
use duniter_gva_indexer::{get_gva_db_ro, get_gva_db_rw};
|
||||
|
@ -63,10 +62,13 @@ pub struct GvaModule {
|
|||
#[async_trait::async_trait]
|
||||
impl duniter_core::module::DuniterModule for GvaModule {
|
||||
const INDEX_BLOCKS: bool = true;
|
||||
const MODULE_NAME: &'static str = "gva";
|
||||
|
||||
type Conf = GvaConf;
|
||||
|
||||
fn apply_block(
|
||||
block: &DubpBlockV10,
|
||||
_conf: &duniter_core::conf::DuniterConf,
|
||||
_conf: &duniter_core::conf::DuniterCoreConf,
|
||||
profile_path_opt: Option<&Path>,
|
||||
) -> KvResult<()> {
|
||||
let gva_db = get_gva_db_rw(profile_path_opt);
|
||||
|
@ -74,14 +76,15 @@ impl duniter_core::module::DuniterModule for GvaModule {
|
|||
}
|
||||
fn revert_block(
|
||||
block: &DubpBlockV10,
|
||||
_conf: &duniter_core::conf::DuniterConf,
|
||||
_conf: &duniter_core::conf::DuniterCoreConf,
|
||||
profile_path_opt: Option<&Path>,
|
||||
) -> KvResult<()> {
|
||||
let gva_db = get_gva_db_rw(profile_path_opt);
|
||||
duniter_gva_indexer::revert_block(&block, gva_db)
|
||||
}
|
||||
fn init(
|
||||
conf: &duniter_core::conf::DuniterConf,
|
||||
async fn init(
|
||||
conf: Self::Conf,
|
||||
core_conf: &duniter_core::conf::DuniterCoreConf,
|
||||
currency: &str,
|
||||
dbs_pool: &fast_threadpool::ThreadPoolAsyncHandler<SharedDbs<FileBackend>>,
|
||||
mempools: Mempools,
|
||||
|
@ -89,30 +92,43 @@ impl duniter_core::module::DuniterModule for GvaModule {
|
|||
profile_path_opt: Option<&Path>,
|
||||
software_version: &'static str,
|
||||
) -> anyhow::Result<(Self, Vec<duniter_core::module::Endpoint>)> {
|
||||
let self_keypair = conf.self_key_pair.clone();
|
||||
let conf = conf.gva.clone();
|
||||
let self_keypair = core_conf.self_key_pair.clone();
|
||||
let remote_port = conf.get_remote_port();
|
||||
let mut endpoints = Vec::new();
|
||||
if conf.enabled() {
|
||||
if conf.enabled {
|
||||
let remote_hosh = if let Some(remote_host) = conf.remote_host.clone() {
|
||||
remote_host
|
||||
} else {
|
||||
let public_ips = duniter_core::module::public_ips::get_public_ips().await;
|
||||
if let Some(ip6) = public_ips.public_ip6_opt {
|
||||
format!("[{}]", ip6.to_string())
|
||||
} else if let Some(ip4) = public_ips.public_ip4_opt {
|
||||
ip4.to_string()
|
||||
} else {
|
||||
return Err(anyhow::Error::msg(
|
||||
"Fail to found public IPs, please configure remote_host manually",
|
||||
));
|
||||
}
|
||||
};
|
||||
endpoints.push(format!(
|
||||
"GVA {}{} {} {}",
|
||||
if remote_port == 443 || conf.get_remote_tls() {
|
||||
if remote_port == 443 || conf.remote_tls.unwrap_or_default() {
|
||||
"S "
|
||||
} else {
|
||||
""
|
||||
},
|
||||
conf.get_remote_host(),
|
||||
remote_hosh,
|
||||
remote_port,
|
||||
conf.get_remote_path(),
|
||||
));
|
||||
endpoints.push(format!(
|
||||
"GVASUB {}{} {} {}",
|
||||
if remote_port == 443 || conf.get_remote_tls() {
|
||||
if remote_port == 443 || conf.remote_tls.unwrap_or_default() {
|
||||
"S "
|
||||
} else {
|
||||
""
|
||||
},
|
||||
conf.get_remote_host(),
|
||||
remote_hosh,
|
||||
remote_port,
|
||||
conf.get_remote_subscriptions_path(),
|
||||
));
|
||||
|
@ -147,7 +163,7 @@ impl duniter_core::module::DuniterModule for GvaModule {
|
|||
} = self;
|
||||
|
||||
if let DuniterMode::Start = mode {
|
||||
if conf.enabled() {
|
||||
if conf.enabled {
|
||||
GvaModule::start_inner(
|
||||
conf,
|
||||
currency,
|
||||
|
@ -281,16 +297,16 @@ impl GvaModule {
|
|||
|
||||
let conf_clone = conf.clone();
|
||||
let graphql_playground =
|
||||
warp::path::path(conf.get_path())
|
||||
warp::path::path(conf.path.clone())
|
||||
.and(warp::get())
|
||||
.map(move || {
|
||||
HttpResponse::builder()
|
||||
.header("content-type", "text/html")
|
||||
.body(async_graphql::http::playground_source(
|
||||
GraphQLPlaygroundConfig::new(&format!("/{}", &conf_clone.get_path()))
|
||||
GraphQLPlaygroundConfig::new(&format!("/{}", &conf_clone.path))
|
||||
.subscription_endpoint(&format!(
|
||||
"/{}",
|
||||
&conf_clone.get_subscriptions_path(),
|
||||
&conf_clone.subscriptions_path,
|
||||
)),
|
||||
))
|
||||
});
|
||||
|
@ -315,26 +331,24 @@ impl GvaModule {
|
|||
// Start warp server
|
||||
log::info!(
|
||||
"GVA server listen on http://{}:{}/{}",
|
||||
conf.get_ip4(),
|
||||
conf.get_port(),
|
||||
&conf.get_path()
|
||||
conf.ip4,
|
||||
conf.port,
|
||||
&conf.path
|
||||
);
|
||||
if let Some(ip6) = conf.get_ip6() {
|
||||
if let Some(ip6) = conf.ip6 {
|
||||
log::info!(
|
||||
"GVA server listen on http://{}:{}/{}",
|
||||
ip6,
|
||||
conf.get_port(),
|
||||
&conf.get_path()
|
||||
conf.port,
|
||||
&conf.path
|
||||
);
|
||||
futures::future::join(
|
||||
warp::serve(routes.clone()).run((conf.get_ip4(), conf.get_port())),
|
||||
warp::serve(routes).run((ip6, conf.get_port())),
|
||||
warp::serve(routes.clone()).run((conf.ip4, conf.port)),
|
||||
warp::serve(routes).run((ip6, conf.port)),
|
||||
)
|
||||
.await;
|
||||
} else {
|
||||
warp::serve(routes)
|
||||
.run((conf.get_ip4(), conf.get_port()))
|
||||
.await;
|
||||
warp::serve(routes).run((conf.ip4, conf.port)).await;
|
||||
}
|
||||
log::warn!("GVA server stopped");
|
||||
}
|
||||
|
@ -343,7 +357,7 @@ impl GvaModule {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use duniter_core::conf::DuniterConf;
|
||||
use duniter_core::conf::DuniterCoreConf;
|
||||
use duniter_core::mempools::Mempools;
|
||||
use duniter_core::module::DuniterModule;
|
||||
use fast_threadpool::{ThreadPool, ThreadPoolConfig};
|
||||
|
@ -356,14 +370,16 @@ mod tests {
|
|||
let threadpool = ThreadPool::start(ThreadPoolConfig::default(), dbs);
|
||||
|
||||
GvaModule::init(
|
||||
&DuniterConf::default(),
|
||||
GvaConf::default(),
|
||||
&DuniterCoreConf::default(),
|
||||
"",
|
||||
&threadpool.into_async_handler(),
|
||||
Mempools::default(),
|
||||
duniter_core::conf::DuniterMode::Start,
|
||||
None,
|
||||
"test",
|
||||
)?
|
||||
)
|
||||
.await?
|
||||
.0
|
||||
.start()
|
||||
.await?;
|
||||
|
|
|
@ -149,7 +149,7 @@ pub(crate) fn graphql(
|
|||
) -> impl warp::Filter<Extract = (impl warp::Reply,), Error = Rejection> + Clone {
|
||||
let anti_spam = AntiSpam::from(conf);
|
||||
let opts = Arc::new(opts);
|
||||
warp::path::path(conf.get_path())
|
||||
warp::path::path(conf.path.clone())
|
||||
.and(warp::method())
|
||||
.and(warp::query::raw().or(warp::any().map(String::new)).unify())
|
||||
.and(warp::addr::remote())
|
||||
|
@ -267,7 +267,7 @@ pub(crate) fn graphql_ws(
|
|||
schema: GvaSchema,
|
||||
) -> impl warp::Filter<Extract = (impl warp::Reply,), Error = Rejection> + Clone {
|
||||
let anti_spam = AntiSpam::from(conf);
|
||||
warp::path::path(conf.get_subscriptions_path())
|
||||
warp::path::path(conf.subscriptions_path.clone())
|
||||
.and(warp::addr::remote())
|
||||
.and(warp::header::optional::<IpAddr>("X-Real-IP"))
|
||||
.and(warp::ws())
|
||||
|
|
Loading…
Add table
Reference in a new issue