grpc_server (0.5.5)
Installation
[registries.forgejo]
index = "sparse+ " # Sparse index
# index = " " # Git
[net]
git-fetch-with-cli = truecargo add grpc_server@0.5.5 --registry forgejoAbout this package
grpc_server
Important
The canonical repository for this project lives on Forgejo: https://code.bhk-itsolutions.com/homeiot/grpc_server.git. This GitHub repository is only a mirror and is not the primary git remote.
gRPC / gRPC-Web server for the Home IoT project. Exposes installation services (web client, bridge) and event broadcasting.
Prerequisites
- Rust (edition 2021, stable toolchain)
- Forgejo registry — This crate depends on
db_handler, which is published on a private Forgejo Cargo registry. You need access to that registry to build and run. - Configuration file (see below)
Forgejo registry setup
The registry is declared in .cargo/config.toml (sparse index URL). To authenticate:
- Obtain a token with read access to the Forgejo package registry (e.g. from your Forgejo instance: User → Settings → Access Tokens, or from the project/package permissions).
- Log in to the registry:
Alternatively, set the token in your environment so it is not stored in the Cargo credentials file:cargo login --registry forgejo <YOUR_TOKEN>export CARGO_REGISTRIES_FORGEJO_TOKEN="<YOUR_TOKEN>" - Run
cargo buildorcargo testas usual; Cargo will use the token to fetchdb_handlerfrom the registry.
Without valid credentials, cargo build will fail when resolving the db_handler dependency.
Configuration
Configuration is read by the db_handler crate via the CONFIG_FILE environment variable (path to a JSON file).
-
Copy the example file:
cp config.example.json config.json
(or create a config file at the path of your choice.) -
Adjust the fields (SQLite database URL, InfluxDB, etc.) in that file. The structure is defined by
db_handler(e.g.primary_db_url,history_db_url,history_db_org,history_db_token). -
Run the server or tests with
CONFIG_FILEset:export CONFIG_FILE=/path/to/config.json ./scripts/run.sh
A secret-free example is provided in config.example.json.
Server bind (loopback-only plaintext)
The plaintext gRPC listener is loopback-only by design: it binds to
127.0.0.1 (or ::1) and refuses to start on any non-loopback host with an
explicit error. Direct exposure of this process to a LAN or the internet is
impossible by construction; transport encryption is the responsibility of an
identified on-host TLS terminator (nginx) that proxies to the loopback port.
frontTs and bridge therefore connect via https://<host> through nginx —
never directly to this process.
GRPC_PORT— listening port (default50051).GRPC_HOST— bind host; only127.0.0.1(default) or::1are accepted, any other value aborts startup.
Build
cargo build
# Release
cargo build --release
# or
./scripts/build.sh
Tests
All tests (unit, integration, doc-tests) are run with:
./scripts/tests.sh
The script uses CONFIG_FILE=config_test.json (relative to the project root). Create it from the example if needed: cp config.example.json config_test.json, then run the script. Or set CONFIG_FILE to another path and run cargo test (or the script) as needed.
For integration test details (timeouts, concurrency, CORS, load), see tests/README.md.
Running
export CONFIG_FILE=/path/to/config.json
./scripts/run.sh
# or for development
./scripts/runDev.sh
Project structure
src/— Source code:main.rs, lib (shared modules)broadcaster/— Event broadcastingcommon/— Errors, response channels, shared typesinstall/— Installation:web_client(gRPC-Web),bridge
proto/—.protofiles (gRPC definitions)tests/— Integration tests and test documentationscripts/— Build, test, run, and deploy scripts
License
See LICENSE (Personal Use Only — Non-Commercial).
Dependencies
| ID | Version |
|---|---|
| chrono | ^0.4 |
| dashmap | ^6.1.0 |
| db_handler | =0.4.4 |
| getrandom | ^0.2 |
| homeiot-grpc-proto | =0.5.5 |
| http | ^1.4.0 |
| thiserror | ^2.0.18 |
| tokio | ^1.44.1 |
| tokio-stream | ^0.1.18 |
| tonic | ^0.14.5 |
| tonic-web | ^0.14 |
| tower | ^0.5 |
| tower-http | ^0.6.8 |
| anyhow | ^1.0.97 |
| futures | ^0.3 |
| password-hash | ^0.5 |
| reqwest | ^0.13.2 |
| sqlx | ^0.8 |