organized snp proto through shared crate
This commit is contained in:
parent
75b25ab7d3
commit
ad0c284467
43
Cargo.lock
generated
43
Cargo.lock
generated
@ -370,6 +370,20 @@ dependencies = [
|
|||||||
"zeroize",
|
"zeroize",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "detee-shared"
|
||||||
|
version = "0.1.0"
|
||||||
|
source = "git+ssh://git@gitea.detee.cloud/testnet/proto?branch=main#be4e41db050c6d59e9fb5abf47e647f5bbdc24b2"
|
||||||
|
dependencies = [
|
||||||
|
"base64",
|
||||||
|
"prost",
|
||||||
|
"serde",
|
||||||
|
"serde_yaml",
|
||||||
|
"thiserror",
|
||||||
|
"tonic",
|
||||||
|
"tonic-build",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "detee-snp-daemon"
|
name = "detee-snp-daemon"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -377,6 +391,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"bs58",
|
"bs58",
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"detee-shared",
|
||||||
"ed25519-dalek",
|
"ed25519-dalek",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"lazy_static",
|
"lazy_static",
|
||||||
@ -1565,18 +1580,18 @@ checksum = "3cb6eb87a131f756572d7fb904f6e7b68633f09cca868c5df1c4b8d1a694bbba"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde"
|
name = "serde"
|
||||||
version = "1.0.215"
|
version = "1.0.219"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "6513c1ad0b11a9376da888e3e0baa0077f1aed55c17f50e7b2397136129fb88f"
|
checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"serde_derive",
|
"serde_derive",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "serde_derive"
|
name = "serde_derive"
|
||||||
version = "1.0.215"
|
version = "1.0.219"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ad1e866f866923f252f05c889987993144fb74e722403468a4ebd70c3cd756c0"
|
checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
@ -1764,6 +1779,26 @@ dependencies = [
|
|||||||
"windows-sys 0.59.0",
|
"windows-sys 0.59.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror"
|
||||||
|
version = "2.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708"
|
||||||
|
dependencies = [
|
||||||
|
"thiserror-impl",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "thiserror-impl"
|
||||||
|
version = "2.0.12"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d"
|
||||||
|
dependencies = [
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "tinystr"
|
name = "tinystr"
|
||||||
version = "0.7.6"
|
version = "0.7.6"
|
||||||
|
@ -24,6 +24,9 @@ serde_json = "1.0.135"
|
|||||||
bs58 = "0.5.1"
|
bs58 = "0.5.1"
|
||||||
chrono = "0.4.39"
|
chrono = "0.4.39"
|
||||||
|
|
||||||
|
detee-shared = { git = "ssh://git@gitea.detee.cloud/testnet/proto", branch = "main" }
|
||||||
|
# detee-shared = { path = "../detee-shared" }
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
tonic-build = "0.12"
|
tonic-build = "0.12"
|
||||||
|
|
||||||
|
6
build.rs
6
build.rs
@ -1,6 +0,0 @@
|
|||||||
fn main() {
|
|
||||||
tonic_build::configure()
|
|
||||||
.build_server(true)
|
|
||||||
.compile_protos(&["vm.proto"], &["proto"])
|
|
||||||
.unwrap_or_else(|e| panic!("Failed to compile protos {:?}", e));
|
|
||||||
}
|
|
21
src/grpc.rs
21
src/grpc.rs
@ -11,25 +11,8 @@ use tokio_stream::{wrappers::ReceiverStream, StreamExt};
|
|||||||
use tonic::transport::Channel;
|
use tonic::transport::Channel;
|
||||||
|
|
||||||
pub mod snp_proto {
|
pub mod snp_proto {
|
||||||
tonic::include_proto!("vm_proto");
|
// tonic::include_proto!("vm_proto");
|
||||||
}
|
pub use detee_shared::snp::pb::vm::*;
|
||||||
|
|
||||||
impl From<snp_proto::NewVmResp> for snp_proto::VmDaemonMessage {
|
|
||||||
fn from(value: snp_proto::NewVmResp) -> Self {
|
|
||||||
snp_proto::VmDaemonMessage { msg: Some(snp_proto::vm_daemon_message::Msg::NewVmResp(value)) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<snp_proto::UpdateVmResp> for snp_proto::VmDaemonMessage {
|
|
||||||
fn from(value: snp_proto::UpdateVmResp) -> Self {
|
|
||||||
snp_proto::VmDaemonMessage { msg: Some(snp_proto::vm_daemon_message::Msg::UpdateVmResp(value)) }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<snp_proto::VmNodeResources> for snp_proto::VmDaemonMessage {
|
|
||||||
fn from(value: snp_proto::VmNodeResources) -> Self {
|
|
||||||
snp_proto::VmDaemonMessage { msg: Some(snp_proto::vm_daemon_message::Msg::VmNodeResources(value)) }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn register_node(config: &crate::config::Config) -> Result<Vec<VmContract>> {
|
pub async fn register_node(config: &crate::config::Config) -> Result<Vec<VmContract>> {
|
||||||
|
272
vm.proto
272
vm.proto
@ -1,272 +0,0 @@
|
|||||||
syntax = "proto3";
|
|
||||||
package vm_proto;
|
|
||||||
|
|
||||||
message Empty {
|
|
||||||
}
|
|
||||||
|
|
||||||
message Pubkey {
|
|
||||||
string pubkey = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
message AccountBalance {
|
|
||||||
uint64 balance = 1;
|
|
||||||
uint64 tmp_locked = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message VmContract {
|
|
||||||
string uuid = 1;
|
|
||||||
string hostname = 2;
|
|
||||||
string admin_pubkey = 3;
|
|
||||||
string node_pubkey = 4;
|
|
||||||
repeated uint32 exposed_ports = 5;
|
|
||||||
string public_ipv4 = 6;
|
|
||||||
string public_ipv6 = 7;
|
|
||||||
uint32 disk_size_gb = 8;
|
|
||||||
uint32 vcpus = 9;
|
|
||||||
uint32 memory_mb = 10;
|
|
||||||
string kernel_sha = 11;
|
|
||||||
string dtrfs_sha = 12;
|
|
||||||
string created_at = 13;
|
|
||||||
string updated_at = 14;
|
|
||||||
// total nanoLP cost per minute (for all units)
|
|
||||||
uint64 nano_per_minute = 15;
|
|
||||||
uint64 locked_nano = 16;
|
|
||||||
string collected_at = 17;
|
|
||||||
}
|
|
||||||
|
|
||||||
message MeasurementArgs {
|
|
||||||
// this will be IP:Port of the dtrfs API
|
|
||||||
// actually not a measurement arg, but needed for the injector
|
|
||||||
string dtrfs_api_endpoint = 1;
|
|
||||||
repeated uint32 exposed_ports = 2;
|
|
||||||
string ovmf_hash = 5;
|
|
||||||
// This is needed to allow the CLI to build the kernel params from known data.
|
|
||||||
// The CLI will use the kernel params to get the measurement.
|
|
||||||
repeated MeasurementIP ips = 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
message MeasurementIP {
|
|
||||||
uint32 nic_index = 1;
|
|
||||||
string address = 2;
|
|
||||||
string mask = 3;
|
|
||||||
string gateway = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
// This should also include a block hash or similar, for auth
|
|
||||||
message RegisterVmNodeReq {
|
|
||||||
string node_pubkey = 1;
|
|
||||||
string operator_wallet = 2;
|
|
||||||
string main_ip = 3;
|
|
||||||
string country = 4;
|
|
||||||
string region = 5;
|
|
||||||
string city = 6;
|
|
||||||
// nanoLP per unit per minute
|
|
||||||
uint64 price = 7;
|
|
||||||
}
|
|
||||||
|
|
||||||
message VmNodeResources {
|
|
||||||
string node_pubkey = 1;
|
|
||||||
uint32 avail_ports = 2;
|
|
||||||
uint32 avail_ipv4 = 3;
|
|
||||||
uint32 avail_ipv6 = 4;
|
|
||||||
uint32 avail_vcpus = 5;
|
|
||||||
uint32 avail_memory_mb = 6;
|
|
||||||
uint32 avail_storage_gb = 7;
|
|
||||||
uint32 max_ports_per_vm = 8;
|
|
||||||
}
|
|
||||||
|
|
||||||
message NewVmReq {
|
|
||||||
string uuid = 1;
|
|
||||||
string hostname = 2;
|
|
||||||
string admin_pubkey = 3;
|
|
||||||
string node_pubkey = 4;
|
|
||||||
repeated uint32 extra_ports = 5;
|
|
||||||
bool public_ipv4 = 6;
|
|
||||||
bool public_ipv6 = 7;
|
|
||||||
uint32 disk_size_gb = 8;
|
|
||||||
uint32 vcpus = 9;
|
|
||||||
uint32 memory_mb = 10;
|
|
||||||
string kernel_url = 11;
|
|
||||||
string kernel_sha = 12;
|
|
||||||
string dtrfs_url = 13;
|
|
||||||
string dtrfs_sha = 14;
|
|
||||||
uint64 price_per_unit = 15;
|
|
||||||
uint64 locked_nano = 16;
|
|
||||||
}
|
|
||||||
|
|
||||||
message NewVmResp {
|
|
||||||
string uuid = 1;
|
|
||||||
string error = 2;
|
|
||||||
MeasurementArgs args = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message UpdateVmReq {
|
|
||||||
string uuid = 1;
|
|
||||||
string admin_pubkey = 2;
|
|
||||||
uint32 disk_size_gb = 3;
|
|
||||||
uint32 vcpus = 4;
|
|
||||||
uint32 memory_mb = 5;
|
|
||||||
string kernel_url = 6;
|
|
||||||
string kernel_sha = 7;
|
|
||||||
string dtrfs_url = 8;
|
|
||||||
string dtrfs_sha = 9;
|
|
||||||
}
|
|
||||||
|
|
||||||
message UpdateVmResp {
|
|
||||||
string uuid = 1;
|
|
||||||
string error = 2;
|
|
||||||
MeasurementArgs args = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message DeleteVmReq {
|
|
||||||
string uuid = 1;
|
|
||||||
string admin_pubkey = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message BrainVmMessage {
|
|
||||||
oneof Msg {
|
|
||||||
NewVmReq new_vm_req = 1;
|
|
||||||
UpdateVmReq update_vm_req = 2;
|
|
||||||
DeleteVmReq delete_vm = 3;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
message DaemonStreamAuth {
|
|
||||||
string timestamp = 1;
|
|
||||||
string pubkey = 2;
|
|
||||||
repeated string contracts = 3;
|
|
||||||
string signature = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
message VmDaemonMessage {
|
|
||||||
oneof Msg {
|
|
||||||
DaemonStreamAuth auth = 1;
|
|
||||||
NewVmResp new_vm_resp = 2;
|
|
||||||
UpdateVmResp update_vm_resp = 3;
|
|
||||||
VmNodeResources vm_node_resources = 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
service BrainVmDaemon {
|
|
||||||
rpc RegisterVmNode (RegisterVmNodeReq) returns (stream VmContract);
|
|
||||||
rpc BrainMessages (DaemonStreamAuth) returns (stream BrainVmMessage);
|
|
||||||
rpc DaemonMessages (stream VmDaemonMessage) returns (Empty);
|
|
||||||
}
|
|
||||||
|
|
||||||
message ListVmContractsReq {
|
|
||||||
string admin_pubkey = 1;
|
|
||||||
string node_pubkey = 2;
|
|
||||||
string uuid = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message VmNodeFilters {
|
|
||||||
uint32 free_ports = 1;
|
|
||||||
bool offers_ipv4 = 2;
|
|
||||||
bool offers_ipv6 = 3;
|
|
||||||
uint32 vcpus = 4;
|
|
||||||
uint32 memory_mb = 5;
|
|
||||||
uint32 storage_gb = 6;
|
|
||||||
string country = 7;
|
|
||||||
string region = 8;
|
|
||||||
string city = 9;
|
|
||||||
string ip = 10;
|
|
||||||
string node_pubkey = 11;
|
|
||||||
}
|
|
||||||
|
|
||||||
message VmNodeListResp {
|
|
||||||
string operator = 1;
|
|
||||||
string node_pubkey = 2;
|
|
||||||
string country = 3;
|
|
||||||
string region = 4;
|
|
||||||
string city = 5;
|
|
||||||
string ip = 6; // required for latency test
|
|
||||||
repeated string reports = 7; // TODO: this will become an enum
|
|
||||||
uint64 price = 8; // nanoLP per unit per minute
|
|
||||||
}
|
|
||||||
|
|
||||||
message ExtendVmReq {
|
|
||||||
string uuid = 1;
|
|
||||||
string admin_pubkey = 2;
|
|
||||||
uint64 locked_nano = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message AirdropReq {
|
|
||||||
string pubkey = 1;
|
|
||||||
uint64 tokens = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message SlashReq {
|
|
||||||
string pubkey = 1;
|
|
||||||
uint64 tokens = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message Account {
|
|
||||||
string pubkey = 1;
|
|
||||||
uint64 balance = 2;
|
|
||||||
uint64 tmp_locked = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message RegOperatorReq {
|
|
||||||
string pubkey = 1;
|
|
||||||
uint64 escrow = 2;
|
|
||||||
string email = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message ListOperatorsResp {
|
|
||||||
string pubkey = 1;
|
|
||||||
uint64 escrow = 2;
|
|
||||||
string email = 3;
|
|
||||||
uint64 app_nodes = 4;
|
|
||||||
uint64 vm_nodes = 5;
|
|
||||||
uint64 reports = 6;
|
|
||||||
}
|
|
||||||
|
|
||||||
message InspectOperatorResp {
|
|
||||||
ListOperatorsResp operator = 1;
|
|
||||||
repeated VmNodeListResp nodes = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message ReportNodeReq {
|
|
||||||
string admin_pubkey = 1;
|
|
||||||
string node_pubkey = 2;
|
|
||||||
string contract = 3;
|
|
||||||
string reason = 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
message KickReq {
|
|
||||||
string operator_wallet = 1;
|
|
||||||
string contract_uuid = 2;
|
|
||||||
string reason = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
message BanUserReq {
|
|
||||||
string operator_wallet = 1;
|
|
||||||
string user_wallet = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
message KickResp {
|
|
||||||
uint64 nano_lp = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
service BrainCli {
|
|
||||||
rpc GetBalance (Pubkey) returns (AccountBalance);
|
|
||||||
rpc NewVm (NewVmReq) returns (NewVmResp);
|
|
||||||
rpc ListVmContracts (ListVmContractsReq) returns (stream VmContract);
|
|
||||||
rpc ListVmNodes (VmNodeFilters) returns (stream VmNodeListResp);
|
|
||||||
rpc GetOneVmNode (VmNodeFilters) returns (VmNodeListResp);
|
|
||||||
rpc DeleteVm (DeleteVmReq) returns (Empty);
|
|
||||||
rpc UpdateVm (UpdateVmReq) returns (UpdateVmResp);
|
|
||||||
rpc ExtendVm (ExtendVmReq) returns (Empty);
|
|
||||||
rpc ReportNode (ReportNodeReq) returns (Empty);
|
|
||||||
rpc ListOperators (Empty) returns (stream ListOperatorsResp);
|
|
||||||
rpc InspectOperator (Pubkey) returns (InspectOperatorResp);
|
|
||||||
rpc RegisterOperator (RegOperatorReq) returns (Empty);
|
|
||||||
rpc KickContract (KickReq) returns (KickResp);
|
|
||||||
rpc BanUser (BanUserReq) returns (Empty);
|
|
||||||
// admin commands
|
|
||||||
rpc Airdrop (AirdropReq) returns (Empty);
|
|
||||||
rpc Slash (SlashReq) returns (Empty);
|
|
||||||
rpc ListAllVmContracts (Empty) returns (stream VmContract);
|
|
||||||
rpc ListAccounts (Empty) returns (stream Account);
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user