Skip to content

Commit

Permalink
chore: udpate api defination
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma233 committed Aug 15, 2024
1 parent 125b499 commit 444924b
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 126 deletions.
315 changes: 310 additions & 5 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ futures = "0.3.30"
hex = "0.4.3"
libp2p = { version = "0.53.2", features = ["tokio", "macros", "yamux", "noise", "tcp", "request-response", "relay"] }
prost = "0.13.1"
reqwest = { version = "0.12.5", features = ["json", "rustls-tls"] }
serde = { version = "1.0.207", features = ["derive"] }
thiserror = "1.0.60"
tokio = { version = "1.37.0", features = ["rt-multi-thread"] }
tokio-util = "0.7.11"
Expand Down
6 changes: 1 addition & 5 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
fn main() -> Result<(), Box<dyn std::error::Error>> {
let protos = [
"proto/auth_v1.proto",
"proto/command_v1.proto",
"proto/tunnel_v1.proto",
];
let protos = ["proto/command_v1.proto", "proto/tunnel_v1.proto"];
tonic_build::configure()
.protoc_arg("--experimental_allow_proto3_optional")
.compile(&protos, &["proto"])?;
Expand Down
89 changes: 0 additions & 89 deletions examples/authserver.rs

This file was deleted.

21 changes: 0 additions & 21 deletions proto/auth_v1.proto

This file was deleted.

2 changes: 1 addition & 1 deletion proto/command_v1.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package command.v1;
package org.dephy.pproxy.command.v1;

message AddPeerRequest {
string multiaddr = 1;
Expand Down
2 changes: 1 addition & 1 deletion proto/tunnel_v1.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
syntax = "proto3";
package tunnel.v1;
package org.dephy.pproxy.tunnel.v1;

enum TunnelCommand {
TUNNEL_COMMAND_UNSPECIFIED = 0;
Expand Down
42 changes: 40 additions & 2 deletions src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,41 @@
pub mod proto {
tonic::include_proto!("auth.v1");
use serde::Deserialize;

pub struct AuthClient {
local_id: libp2p::PeerId,
endpoint: reqwest::Url,
client: reqwest::Client,
}

#[derive(Deserialize)]
struct AuthClientResponse {
data: bool,
}

impl AuthClient {
pub fn new(local_id: libp2p::PeerId, endpoint: reqwest::Url) -> AuthClient {
AuthClient {
local_id,
endpoint,
client: reqwest::Client::new(),
}
}

pub async fn is_valid(&self, token: &str) -> Result<bool, reqwest::Error> {
let url = self.endpoint.join("access-control").unwrap();
let params = [
("device", self.local_id.to_string()),
("token", token.to_string()),
];

let response = self
.client
.get(url)
.query(&params)
.send()
.await?
.json::<AuthClientResponse>()
.await?;

Ok(response.data)
}
}
2 changes: 1 addition & 1 deletion src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use tonic::Status;
use crate::PProxyHandle;

pub mod proto {
tonic::include_proto!("command.v1");
tonic::include_proto!("org.dephy.pproxy.command.v1");
}

pub struct PProxyCommander {
Expand Down
2 changes: 1 addition & 1 deletion src/tunnel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::CommandNotifier;
use crate::PProxyCommand;

pub mod proto {
tonic::include_proto!("tunnel.v1");
tonic::include_proto!("org.dephy.pproxy.tunnel.v1");
}

pub struct TunnelServer {
Expand Down

0 comments on commit 444924b

Please sign in to comment.