diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 0505304b..10ea55b2 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -37,6 +37,12 @@ search = name = "veilid-tools" replace = name = "veilid-tools" version = "{new_version}" +[bumpversion:file:veilid-remote-api/Cargo.toml] +search = name = "veilid-remote-api" + version = "{current_version}" +replace = name = "veilid-remote-api" + version = "{new_version}" + [bumpversion:file:veilid-python/pyproject.toml] search = name = "veilid" version = "{current_version}" diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index a3f07a04..ce1101e4 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -27,11 +27,11 @@ format: - if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH changes: - veilid-*/**/*.rs #Should fire when rust source files are changed - - '**/*[Cc]argo*' + - "**/*[Cc]argo*" # base earthly setup for jobs .base: - tags: [ saas-linux-medium-amd64 ] + tags: [saas-linux-medium-amd64] image: docker services: - docker:dind @@ -55,20 +55,20 @@ build_cache: - 'echo "CI_PIPELINE_SOURCE: $CI_PIPELINE_SOURCE"' - apk update && apk add jq && apk add curl - if ! docker manifest inspect $CI_REGISTRY_IMAGE/build-cache:latest > /dev/null; then - - CACHE_EPOCH=0 + - CACHE_EPOCH=0 - else - - 'CONT_REPO_ID=$(curl "https://gitlab.com/api/graphql" --header "Content-Type: application/json" --request POST --data "{\"query\": \"query { project(fullPath: \\\"$CI_PROJECT_PATH\\\" ) { containerRepositories( name: \\\"build-cache\\\" ) { nodes { id }}}} \"}" | jq -r ".data.project.containerRepositories.nodes[0].id")' - - echo "CONTAINER REPO ID = $CONT_REPO_ID" - - 'CACHE_TS=$(curl "https://gitlab.com/api/graphql" --header "Content-Type: application/json" --request POST --data "{\"query\": \"query { containerRepository(id: \\\"$CONT_REPO_ID\\\") { tags( first: 1 name: \\\"latest\\\" ) { nodes { location publishedAt }}}} \"}" | jq -r ".data.containerRepository.tags.nodes[0].publishedAt" | cut -d "+" -f1 | sed "s/T/ /g" )' - - CACHE_EPOCH=$(date -d "$CACHE_TS" +%s) + - 'CONT_REPO_ID=$(curl "https://gitlab.com/api/graphql" --header "Content-Type: application/json" --request POST --data "{\"query\": \"query { project(fullPath: \\\"$CI_PROJECT_PATH\\\" ) { containerRepositories( name: \\\"build-cache\\\" ) { nodes { id }}}} \"}" | jq -r ".data.project.containerRepositories.nodes[0].id")' + - echo "CONTAINER REPO ID = $CONT_REPO_ID" + - 'CACHE_TS=$(curl "https://gitlab.com/api/graphql" --header "Content-Type: application/json" --request POST --data "{\"query\": \"query { containerRepository(id: \\\"$CONT_REPO_ID\\\") { tags( first: 1 name: \\\"latest\\\" ) { nodes { location publishedAt }}}} \"}" | jq -r ".data.containerRepository.tags.nodes[0].publishedAt" | cut -d "+" -f1 | sed "s/T/ /g" )' + - CACHE_EPOCH=$(date -d "$CACHE_TS" +%s) - fi - EARTHLY_EPOCH=$(git log -1 --format=%ct Earthfile) - echo "CACHE EPOCH = $CACHE_EPOCH, EARTHLY EPOCH = $EARTHLY_EPOCH" - if [[ $EARTHLY_EPOCH -gt $CACHE_EPOCH ]] || [[ "$CI_PIPELINE_SOURCE" == "schedule" ]] || [[ "$CI_PIPELINE_SOURCE" == "web" ]] ; then - - *earthly_setup - - earthly --use-inline-cache --save-inline-cache --strict --push -P +build-linux-cache $project_args + - *earthly_setup + - earthly --use-inline-cache --save-inline-cache --strict --push -P +build-linux-cache $project_args - else - - echo "No need to rebuild" + - echo "No need to rebuild" - fi rules: - if: $CI_COMMIT_MESSAGE =~ /\[ci dryrun]/ || $IS_NIGHTLY == "true" @@ -76,8 +76,7 @@ build_cache: - if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH changes: - veilid-*/**/* - - '**/*[Cc]argo*' - + - "**/*[Cc]argo*" # Runs a basic unit test build, this task will use the `build-cache:latest` as set up in the projects Container Registry test_build: @@ -91,7 +90,7 @@ test_build: - if: $CI_PIPELINE_SOURCE == "merge_request_event" || $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH changes: - veilid-*/**/* - - '**/*[Cc]argo*' + - "**/*[Cc]argo*" when: always - when: never @@ -132,9 +131,9 @@ release_job: image: registry.gitlab.com/gitlab-org/release-cli:latest script: - echo "running release_job" - release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties - tag_name: '$CI_COMMIT_TAG' - description: '$CI_COMMIT_TAG' + release: # See https://docs.gitlab.com/ee/ci/yaml/#release for available properties + tag_name: "$CI_COMMIT_TAG" + description: "$CI_COMMIT_TAG" rules: - if: '$CI_COMMIT_TAG =~ /v\d.+/' @@ -146,7 +145,7 @@ create_build_machine: - uv --directory scripts/cicd-python sync - uv --directory scripts/cicd-python run veilid_release_utils.py --create-build-machine artifacts: - paths: + paths: - scripts/cicd-python/config.json expire_in: 6 hours rules: @@ -166,39 +165,41 @@ package_linux: - if: '$CI_COMMIT_TAG =~ /v\d.+/' publish_crates: - stage: build_packages - needs: - - package_linux - tags: - - build-amd64-deb - script: - - vlt login - - vlt run --command="cargo publish -p veilid-tools --dry-run" - - vlt run --command="cargo publish -p veilid-tools" - - vlt run --command="cargo publish -p veilid-core --dry-run" - - vlt run --command="cargo publish -p veilid-core" - rules: - - if: '$CI_COMMIT_TAG =~ /v\d.+/' + stage: build_packages + needs: + - package_linux + tags: + - build-amd64-deb + script: + - vlt login + - vlt run --command="cargo publish -p veilid-tools --dry-run" + - vlt run --command="cargo publish -p veilid-tools" + - vlt run --command="cargo publish -p veilid-core --dry-run" + - vlt run --command="cargo publish -p veilid-core" + - vlt run --command="cargo publish -p veilid-remote-api --dry-run" + - vlt run --command="cargo publish -p veilid-remote-api" + rules: + - if: '$CI_COMMIT_TAG =~ /v\d.+/' publish_python: - stage: build_packages - needs: - - package_linux - tags: - - build-amd64-deb - script: - - vlt login - - cd veilid-python && /home/gitlab-runner/.local/bin/poetry build - - vlt run --command="/home/gitlab-runner/.local/bin/poetry publish" - rules: - - if: '$CI_COMMIT_TAG =~ /v\d.+/' + stage: build_packages + needs: + - package_linux + tags: + - build-amd64-deb + script: + - vlt login + - cd veilid-python && /home/gitlab-runner/.local/bin/poetry build + - vlt run --command="/home/gitlab-runner/.local/bin/poetry publish" + rules: + - if: '$CI_COMMIT_TAG =~ /v\d.+/' build_repositories: stage: distribute tags: - build-orchestration variables: - SECURE_FILES_DOWNLOAD_PATH: './' + SECURE_FILES_DOWNLOAD_PATH: "./" script: - curl --silent "https://gitlab.com/gitlab-org/incubation-engineering/mobile-devops/download-secure-files/-/raw/main/installer" | bash - cp scripts/cicd/build-orchestration/rpm-repo-building/Dockerfile ~/rpm-build-container @@ -232,7 +233,7 @@ dryrun_create_build_machine: - uv --directory scripts/cicd-python sync - uv --directory scripts/cicd-python run veilid_release_utils.py --create-build-machine artifacts: - paths: + paths: - scripts/cicd-python/config.json expire_in: 6 hours rules: @@ -279,7 +280,7 @@ dryrun_build_repositories: tags: - build-orchestration variables: - SECURE_FILES_DOWNLOAD_PATH: './' + SECURE_FILES_DOWNLOAD_PATH: "./" script: - curl --silent "https://gitlab.com/gitlab-org/incubation-engineering/mobile-devops/download-secure-files/-/raw/main/installer" | bash - cp scripts/cicd/build-orchestration/rpm-repo-building/Dockerfile ~/rpm-build-container @@ -314,7 +315,6 @@ dryrun_delete_build_machines: rules: - if: $CI_COMMIT_MESSAGE =~ /\[ci dryrun]/ - # Nightly build pipeline nightly_create_build_machines: @@ -325,7 +325,7 @@ nightly_create_build_machines: - uv --directory scripts/cicd-python sync - uv --directory scripts/cicd-python run veilid_release_utils.py --create-build-machine artifacts: - paths: + paths: - scripts/cicd-python/config.json expire_in: 6 hours rules: @@ -349,7 +349,7 @@ nightly_build_repositories: tags: - build-orchestration variables: - SECURE_FILES_DOWNLOAD_PATH: './' + SECURE_FILES_DOWNLOAD_PATH: "./" script: - curl --silent "https://gitlab.com/gitlab-org/incubation-engineering/mobile-devops/download-secure-files/-/raw/main/installer" | bash - cp scripts/cicd/build-orchestration/rpm-repo-building/Dockerfile ~/rpm-build-container diff --git a/Cargo.lock b/Cargo.lock index d7cd52f9..e17dfddf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6596,6 +6596,18 @@ dependencies = [ "xmltree", ] +[[package]] +name = "veilid-remote-api" +version = "0.4.6" +dependencies = [ + "parking_lot 0.12.3", + "schemars", + "serde", + "serde_json", + "tracing", + "veilid-core", +] + [[package]] name = "veilid-server" version = "0.4.6" @@ -6647,6 +6659,7 @@ dependencies = [ "url", "veilid-bugsalot", "veilid-core", + "veilid-remote-api", "wg", "windows-service", ] diff --git a/Cargo.toml b/Cargo.toml index 1c4b4e3a..183cd7b0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,6 +7,7 @@ members = [ "veilid-cli", "veilid-flutter/rust", "veilid-wasm", + "veilid-remote-api", ] resolver = "2" diff --git a/Earthfile b/Earthfile index 63b36f61..83f23131 100644 --- a/Earthfile +++ b/Earthfile @@ -138,20 +138,22 @@ deps-linux: # Make a cache image with downloaded and built dependencies build-linux-cache: FROM +deps-linux - RUN mkdir veilid-cli veilid-core veilid-server veilid-tools veilid-wasm veilid-flutter veilid-flutter/rust + RUN mkdir -p veilid-cli veilid-core veilid-core/examples/basic veilid-server veilid-tools veilid-wasm veilid-flutter veilid-flutter/rust veilid-remote-api COPY --keep-ts --dir .cargo scripts Cargo.lock Cargo.toml . COPY --keep-ts veilid-cli/Cargo.toml veilid-cli COPY --keep-ts veilid-core/Cargo.toml veilid-core + COPY --keep-ts veilid-core/examples/basic/Cargo.toml veilid-core/examples/basic COPY --keep-ts veilid-server/Cargo.toml veilid-server COPY --keep-ts veilid-tools/Cargo.toml veilid-tools + COPY --keep-ts veilid-remote-api/Cargo.toml veilid-remote-api COPY --keep-ts veilid-flutter/rust/Cargo.toml veilid-flutter/rust COPY --keep-ts veilid-wasm/Cargo.toml veilid-wasm/wasm_remap_paths.sh veilid-wasm RUN cargo chef prepare --recipe-path recipe.json - RUN cargo chef cook --profile=test --tests --target $DEFAULT_CARGO_TARGET --recipe-path recipe.json -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core - RUN cargo chef cook --zigbuild --release --target x86_64-unknown-linux-gnu --recipe-path recipe.json -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core - RUN cargo chef cook --zigbuild --release --target aarch64-unknown-linux-gnu --recipe-path recipe.json -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core - # RUN cargo chef cook --zigbuild --release --target x86_64-pc-windows-gnu --recipe-path recipe.json -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core - # RUN cargo chef cook --zigbuild --release --target aarch64-apple-darwin --recipe-path recipe.json -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core + RUN cargo chef cook --profile=test --tests --target $DEFAULT_CARGO_TARGET --recipe-path recipe.json -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core -p veilid-remote-api + RUN cargo chef cook --zigbuild --release --target x86_64-unknown-linux-gnu --recipe-path recipe.json -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core -p veilid-remote-api + RUN cargo chef cook --zigbuild --release --target aarch64-unknown-linux-gnu --recipe-path recipe.json -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core -p veilid-remote-api + # RUN cargo chef cook --zigbuild --release --target x86_64-pc-windows-gnu --recipe-path recipe.json -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core -p veilid-remote-api + # RUN cargo chef cook --zigbuild --release --target aarch64-apple-darwin --recipe-path recipe.json -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core -p veilid-remote-api RUN veilid-wasm/wasm_remap_paths.sh cargo chef cook --zigbuild --release --target wasm32-unknown-unknown --recipe-path recipe.json -p veilid-wasm ARG CI_REGISTRY_IMAGE=registry.gitlab.com/veilid/veilid SAVE IMAGE --push $CI_REGISTRY_IMAGE/build-cache:latest @@ -170,7 +172,7 @@ code-linux: FROM $CI_REGISTRY_IMAGE/build-cache:latest # FROM registry.gitlab.com/veilid/build-cache:latest END - COPY --keep-ts --dir .cargo build_docs.sh files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid + COPY --keep-ts --dir .cargo build_docs.sh files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm veilid-remote-api Cargo.lock Cargo.toml /veilid # Check to make sure Cargo.lock is up to date RUN cargo update -w --locked # Restore original Cargo.lock @@ -179,7 +181,7 @@ code-linux: # Code + Linux + Android deps code-android: FROM +deps-android - COPY --keep-ts --dir .cargo files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm Cargo.lock Cargo.toml /veilid + COPY --keep-ts --dir .cargo files scripts veilid-cli veilid-core veilid-server veilid-tools veilid-flutter veilid-wasm veilid-remote-api Cargo.lock Cargo.toml /veilid COPY --keep-ts scripts/earthly/cargo-android/config.toml /veilid/.cargo/config.toml # Clippy only @@ -198,7 +200,7 @@ build-linux-amd64: RUN echo "not enough container memory to build. increase build host memory." RUN false END - RUN cargo zigbuild --locked --target x86_64-unknown-linux-gnu --release -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core + RUN cargo zigbuild --locked --target x86_64-unknown-linux-gnu --release -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core -p veilid-remote-api SAVE ARTIFACT ./target/x86_64-unknown-linux-gnu AS LOCAL ./target/artifacts/x86_64-unknown-linux-gnu build-linux-arm64: @@ -208,7 +210,7 @@ build-linux-arm64: RUN echo "not enough container memory to build. increase build host memory." RUN false END - RUN cargo zigbuild --locked --target aarch64-unknown-linux-gnu --release -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core + RUN cargo zigbuild --locked --target aarch64-unknown-linux-gnu --release -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core -p veilid-remote-api SAVE ARTIFACT ./target/aarch64-unknown-linux-gnu AS LOCAL ./target/artifacts/aarch64-unknown-linux-gnu # build-windows-amd64: @@ -269,7 +271,7 @@ unit-tests-docs-linux: unit-tests-native-linux: FROM +code-linux - RUN cargo test --locked --tests --target $DEFAULT_CARGO_TARGET -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core + RUN cargo test --locked --tests --target $DEFAULT_CARGO_TARGET -p veilid-server -p veilid-cli -p veilid-tools -p veilid-core -p veilid-remote-api unit-tests-wasm-linux: FROM +code-linux diff --git a/veilid-core/examples/basic/Cargo.toml b/veilid-core/examples/basic/Cargo.toml index f9c180c3..545e0b07 100644 --- a/veilid-core/examples/basic/Cargo.toml +++ b/veilid-core/examples/basic/Cargo.toml @@ -8,6 +8,10 @@ edition.workspace = true rust-version.workspace = true publish = false +[[bin]] +name = "basic" +path = "./src/main.rs" + [dependencies] tokio = { version = "^1.43.0" } veilid-core = { version = "0.4.6", path = "../../../veilid-core" } diff --git a/veilid-core/src/lib.rs b/veilid-core/src/lib.rs index eaa08f79..17ffb2fe 100644 --- a/veilid-core/src/lib.rs +++ b/veilid-core/src/lib.rs @@ -135,7 +135,7 @@ use eyre::{bail, eyre, Report as EyreReport, Result as EyreResult, WrapErr}; use futures_util::stream::{FuturesOrdered, FuturesUnordered}; use indent::*; use parking_lot::*; -use schemars::{schema_for, JsonSchema}; +use schemars::JsonSchema; use serde::*; use stop_token::*; use thiserror::Error as ThisError; diff --git a/veilid-core/src/veilid_api/mod.rs b/veilid-core/src/veilid_api/mod.rs index f6d592f3..f4ea98b4 100644 --- a/veilid-core/src/veilid_api/mod.rs +++ b/veilid-core/src/veilid_api/mod.rs @@ -5,7 +5,6 @@ mod routing_context; mod serialize_helpers; mod types; -pub mod json_api; #[doc(hidden)] pub mod tests; diff --git a/veilid-remote-api/Cargo.toml b/veilid-remote-api/Cargo.toml new file mode 100644 index 00000000..73584a5a --- /dev/null +++ b/veilid-remote-api/Cargo.toml @@ -0,0 +1,25 @@ +[package] +name = "veilid-remote-api" +version = "0.4.6" +repository.workspace = true +authors.workspace = true +license.workspace = true +edition.workspace = true +rust-version.workspace = true +documentation = "https://docs.rs/veilid-remote-api" +homepage = "https://veilid.gitlab.io/developer-book/" + +[lib] +path = "src/lib.rs" + +[dependencies] +veilid-core = { version = "0.4.6", path = "../veilid-core" } + +tracing = { version = "^0", features = ["log", "attributes"] } +serde = { version = "1.0.218", features = ["derive", "rc"] } +serde_json = { version = "1.0.140" } +schemars = "0.8.22" +parking_lot = "0.12.3" + +[lints] +workspace = true diff --git a/veilid-remote-api/README.md b/veilid-remote-api/README.md new file mode 100644 index 00000000..047fc467 --- /dev/null +++ b/veilid-remote-api/README.md @@ -0,0 +1,10 @@ + + + +# veilid-remote-api + +This crate provides the ability to control a Veilid node remotely. + +The [JsonRequestProcessor] is a wrapper around the [VeilidAPI] and provides a way to process requests and send responses. + + diff --git a/veilid-core/src/veilid_api/json_api/crypto_system.rs b/veilid-remote-api/src/crypto_system.rs similarity index 100% rename from veilid-core/src/veilid_api/json_api/crypto_system.rs rename to veilid-remote-api/src/crypto_system.rs diff --git a/veilid-core/src/veilid_api/json_api/mod.rs b/veilid-remote-api/src/lib.rs similarity index 94% rename from veilid-core/src/veilid_api/json_api/mod.rs rename to veilid-remote-api/src/lib.rs index 125184bc..db034067 100644 --- a/veilid-core/src/veilid_api/json_api/mod.rs +++ b/veilid-remote-api/src/lib.rs @@ -1,4 +1,18 @@ -use super::*; +//! # veilid-remote-api +//! +//! This crate provides the ability to control a Veilid node remotely. +//! +//! The [JsonRequestProcessor] is a wrapper around the [VeilidAPI] and provides a way to process requests and send responses. + +use veilid_core::tools::*; +use veilid_core::*; + +use parking_lot::Mutex; +use schemars::{schema_for, JsonSchema}; +use serde::{Deserialize, Serialize}; +use std::collections::HashMap; +use std::fmt; +use tracing::*; mod routing_context; pub use routing_context::*; diff --git a/veilid-core/src/veilid_api/json_api/process.rs b/veilid-remote-api/src/process.rs similarity index 94% rename from veilid-core/src/veilid_api/json_api/process.rs rename to veilid-remote-api/src/process.rs index 8a552647..3249b4d5 100644 --- a/veilid-core/src/veilid_api/json_api/process.rs +++ b/veilid-remote-api/src/process.rs @@ -2,55 +2,55 @@ use super::*; pub fn to_json_api_result( r: VeilidAPIResult, -) -> json_api::ApiResult { +) -> super::ApiResult { match r { - Err(e) => json_api::ApiResult::Err { error: e }, - Ok(v) => json_api::ApiResult::Ok { value: v }, + Err(e) => super::ApiResult::Err { error: e }, + Ok(v) => super::ApiResult::Ok { value: v }, } } pub fn to_json_api_result_with_string( r: VeilidAPIResult, -) -> json_api::ApiResultWithString { +) -> super::ApiResultWithString { match r { - Err(e) => json_api::ApiResultWithString::Err { error: e }, - Ok(v) => json_api::ApiResultWithString::Ok { value: v }, + Err(e) => super::ApiResultWithString::Err { error: e }, + Ok(v) => super::ApiResultWithString::Ok { value: v }, } } pub fn to_json_api_result_with_vec_string( r: VeilidAPIResult, -) -> json_api::ApiResultWithVecString { +) -> super::ApiResultWithVecString { match r { - Err(e) => json_api::ApiResultWithVecString::Err { error: e }, - Ok(v) => json_api::ApiResultWithVecString::Ok { value: v }, + Err(e) => super::ApiResultWithVecString::Err { error: e }, + Ok(v) => super::ApiResultWithVecString::Ok { value: v }, } } pub fn to_json_api_result_with_opt_vec_string( r: VeilidAPIResult, -) -> json_api::ApiResultWithOptVecString { +) -> super::ApiResultWithOptVecString { match r { - Err(e) => json_api::ApiResultWithOptVecString::Err { error: e }, - Ok(v) => json_api::ApiResultWithOptVecString::Ok { value: v }, + Err(e) => super::ApiResultWithOptVecString::Err { error: e }, + Ok(v) => super::ApiResultWithOptVecString::Ok { value: v }, } } #[must_use] -pub fn to_json_api_result_with_vec_u8(r: VeilidAPIResult>) -> json_api::ApiResultWithVecU8 { +pub fn to_json_api_result_with_vec_u8(r: VeilidAPIResult>) -> super::ApiResultWithVecU8 { match r { - Err(e) => json_api::ApiResultWithVecU8::Err { error: e }, - Ok(v) => json_api::ApiResultWithVecU8::Ok { value: v }, + Err(e) => super::ApiResultWithVecU8::Err { error: e }, + Ok(v) => super::ApiResultWithVecU8::Ok { value: v }, } } #[must_use] pub fn to_json_api_result_with_vec_vec_u8( r: VeilidAPIResult>>, -) -> json_api::ApiResultWithVecVecU8 { +) -> super::ApiResultWithVecVecU8 { match r { - Err(e) => json_api::ApiResultWithVecVecU8::Err { error: e }, - Ok(v) => json_api::ApiResultWithVecVecU8::Ok { + Err(e) => super::ApiResultWithVecVecU8::Err { error: e }, + Ok(v) => super::ApiResultWithVecVecU8::Ok { value: v.into_iter().map(|v| VecU8 { value: v }).collect(), }, } @@ -211,29 +211,6 @@ impl JsonRequestProcessor { 1 } - // Target - - // Parse target - fn parse_target(&self, s: String) -> VeilidAPIResult { - // Is this a route id? - if let Ok(rrid) = RouteId::from_str(&s) { - let routing_table = self.api.core_context()?.routing_table(); - let rss = routing_table.route_spec_store(); - - // Is this a valid remote route id? (can't target allocated routes) - if rss.is_route_id_remote(&rrid) { - return Ok(Target::PrivateRoute(rrid)); - } - } - - // Is this a node id? - if let Ok(nid) = TypedNodeId::from_str(&s) { - return Ok(Target::NodeId(nid)); - } - - Err(VeilidAPIError::parse_error("Unable to parse as target", s)) - } - ////////////////////////////////////////////////////////////////////////////////////// #[instrument(level = "trace", target = "json_api", skip_all)] @@ -281,7 +258,7 @@ impl JsonRequestProcessor { result: to_json_api_result_with_vec_u8( async { routing_context - .app_call(self.parse_target(target)?, message) + .app_call(self.api.parse_as_target(target)?, message) .await } .await, @@ -293,7 +270,7 @@ impl JsonRequestProcessor { result: to_json_api_result( async { routing_context - .app_message(self.parse_target(target)?, message) + .app_message(self.api.parse_as_target(target)?, message) .await } .await, diff --git a/veilid-core/src/veilid_api/json_api/routing_context.rs b/veilid-remote-api/src/routing_context.rs similarity index 100% rename from veilid-core/src/veilid_api/json_api/routing_context.rs rename to veilid-remote-api/src/routing_context.rs diff --git a/veilid-core/src/veilid_api/json_api/table_db.rs b/veilid-remote-api/src/table_db.rs similarity index 100% rename from veilid-core/src/veilid_api/json_api/table_db.rs rename to veilid-remote-api/src/table_db.rs diff --git a/veilid-server/Cargo.toml b/veilid-server/Cargo.toml index 9567a48c..c844c281 100644 --- a/veilid-server/Cargo.toml +++ b/veilid-server/Cargo.toml @@ -55,6 +55,7 @@ geolocation = ["veilid-core/geolocation"] [dependencies] veilid-core = { path = "../veilid-core", default-features = false } +veilid-remote-api = { path = "../veilid-remote-api"} tracing = { version = "^0.1.41", features = ["log", "attributes"] } tracing-subscriber = { version = "^0.3.19", features = ["env-filter", "time"] } tracing-appender = "^0.2.3" diff --git a/veilid-server/src/client_api.rs b/veilid-server/src/client_api.rs index fb7f0eb1..99115b7e 100644 --- a/veilid-server/src/client_api.rs +++ b/veilid-server/src/client_api.rs @@ -11,9 +11,9 @@ use std::sync::Arc; use stop_token::future::FutureExt as _; use stop_token::*; use tracing::*; -use veilid_core::json_api::JsonRequestProcessor; use veilid_core::tools::*; use veilid_core::*; +use veilid_remote_api::JsonRequestProcessor; use wg::AsyncWaitGroup; const MAX_NON_JSON_LOGGING: usize = 50; @@ -251,7 +251,7 @@ impl ClientApi { } let mut schemas = HashMap::::new(); - veilid_core::json_api::emit_schemas(&mut schemas); + veilid_remote_api::emit_schemas(&mut schemas); let Some(schema) = schemas.get(&args[1]) else { apibail_invalid_argument!("invalid schema", "schema", args[1].clone()); @@ -282,18 +282,18 @@ impl ClientApi { // Unmarshal NDJSON - newline => json // (trim all whitespace around input lines just to make things more permissive for API users) - let request: json_api::Request = deserialize_json(&sanitized_line)?; + let request: veilid_remote_api::Request = deserialize_json(&sanitized_line)?; #[cfg(feature = "debug-json-api")] debug!("JSONAPI: Request: {:?}", request); // See if this is a control message or a veilid-core message - let response = if let json_api::RequestOp::Control { args } = request.op { + let response = if let veilid_remote_api::RequestOp::Control { args } = request.op { // Process control messages - json_api::Response { + veilid_remote_api::Response { id: request.id, - op: json_api::ResponseOp::Control { - result: json_api::to_json_api_result(self.process_control(args)), + op: veilid_remote_api::ResponseOp::Control { + result: veilid_remote_api::to_json_api_result(self.process_control(args)), }, } } else { @@ -306,7 +306,7 @@ impl ClientApi { // Marshal json + newline => NDJSON let response_string = - Arc::new(serialize_json(json_api::RecvMessage::Response(response)) + "\n"); + Arc::new(serialize_json(veilid_remote_api::RecvMessage::Response(response)) + "\n"); if let Err(e) = responses_tx.send_async(response_string).await { eprintln!("response not sent: {}", e) } @@ -375,7 +375,7 @@ impl ClientApi { { // Make request processor for this connection let api = self.inner.lock().veilid_api.clone(); - let jrp = json_api::JsonRequestProcessor::new(api); + let jrp = veilid_remote_api::JsonRequestProcessor::new(api); // Futures to process unordered let mut unord = FuturesUnordered::new(); @@ -533,7 +533,7 @@ impl ClientApi { // serialize update to NDJSON let veilid_update = - Arc::new(serialize_json(json_api::RecvMessage::Update(veilid_update)) + "\n"); + Arc::new(serialize_json(veilid_remote_api::RecvMessage::Update(veilid_update)) + "\n"); // Pass updates to clients for ch in inner.update_channels.values() { diff --git a/veilid-server/src/main.rs b/veilid-server/src/main.rs index 0457fe02..7e322d67 100644 --- a/veilid-server/src/main.rs +++ b/veilid-server/src/main.rs @@ -446,7 +446,7 @@ fn main() -> EyreResult<()> { // -- Emit JSON-Schema -- if let Some(esstr) = args.emit_schema { let mut schemas = HashMap::::new(); - veilid_core::json_api::emit_schemas(&mut schemas); + veilid_remote_api::emit_schemas(&mut schemas); if let Some(schema) = schemas.get(&esstr) { println!("{}", schema); diff --git a/version_bump.sh b/version_bump.sh index 8299dea1..b73aaa7c 100755 --- a/version_bump.sh +++ b/version_bump.sh @@ -1,7 +1,7 @@ #!/bin/bash # Fail out if any step has an error -set -e +set -ex if [ "$1" == "patch" ]; then echo Bumping patch version @@ -25,7 +25,7 @@ NEW_VERSION=$(cat .bumpversion.cfg | grep current_version\ = | cut -d\ -f3) echo NEW_VERSION=$NEW_VERSION # Update crate dependencies for the crates we publish -cargo upgrade -p veilid-tools@$NEW_VERSION -p veilid-core@$NEW_VERSION +cargo upgrade -p veilid-tools@$NEW_VERSION -p veilid-core@$NEW_VERSION -p veilid-remote-api@$NEW_VERSION # Update lockfile -cargo update \ No newline at end of file +cargo update -w \ No newline at end of file