Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,34 @@ jobs:
name: pony-api
path: target/release/api

build-auth:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Install latest rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
default: true
override: true

- name: Update apt package index
run: sudo apt-get update

- name: Install protobuf-compiler
run: sudo apt-get install -y protobuf-compiler

- name: Build API
run: cargo build --release --bin auth --no-default-features

- name: Upload API binary
uses: actions/upload-artifact@v4
with:
name: pony-auth
path: target/release/auth

collect-binaries:
runs-on: ubuntu-latest
needs: [build-agent, build-api]
Expand Down Expand Up @@ -111,6 +139,12 @@ jobs:
name: pony-api
path: collected/api

- name: Download auth
uses: actions/download-artifact@v4
with:
name: pony-auth
path: collected/auth

- name: Upload combined binaries
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pony"
version = "0.1.48"
version = "0.2.0"
edition = "2021"
build = "build.rs"

Expand Down Expand Up @@ -36,7 +36,7 @@ prost = { version = "0.13" }
prost-derive = { version = "0.13" }
rand = "0.8"
reqwest = { version = "0.12", features = ["json"] }
rkyv = { version = "0.7", features = ["std", "alloc", "validation", "uuid"] }
rkyv = { version = "0.7", features = ["std", "alloc", "validation", "uuid", ] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
serde_urlencoded = "0.7"
Expand Down Expand Up @@ -80,6 +80,10 @@ path = "src/bin/agent/main.rs"
name = "api"
path = "src/bin/api/main.rs"

[[bin]]
name = "auth"
path = "src/bin/auth/main.rs"

[[bin]]
name = "utils"
path = "src/bin/utils.rs"
Expand Down
12 changes: 12 additions & 0 deletions dev/dev.sql
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,17 @@ ADD COLUMN bonus_days INTEGER DEFAULT NULL;



ALTER TABLE subscriptions
ALTER COLUMN refer_code SET NOT NULL;

ALTER TABLE subscriptions
ADD CONSTRAINT subscriptions_refer_code_unique UNIQUE (refer_code);


ALTER TYPE proto ADD VALUE 'hysteria2';

ALTER TABLE connections ADD COLUMN token UUID DEFAULT NULL;

ALTER TABLE inbounds ADD COLUMN h2 JSONB DEFAULT NULL;


4 changes: 2 additions & 2 deletions dev/user-state.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ <h3>Subscriptions</h3>
const ul = document.createElement('ul');
data.forEach(item => {
const li = document.createElement('li');
li.textContent = item;
li.textContent = ` ${item} `;
ul.appendChild(li);
});
connsElement.appendChild(ul);
Expand All @@ -266,7 +266,7 @@ <h3>Subscriptions</h3>
data.forEach(sub => {
const li = document.createElement('li');
li.textContent =
`ID: ${sub.id}, expires: ${sub.expires_at}, deleted: ${sub.is_deleted}, ref:_by ${sub.referred_by}`;
`ID: ${sub.id}, expires: ${sub.expires_at}, deleted: ${sub.is_deleted}, ref_by: ${sub.referred_by}`;
ul.appendChild(li);
});
subsElement.appendChild(ul);
Expand Down
68 changes: 54 additions & 14 deletions src/bin/agent/core/http.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use async_trait::async_trait;
use pony::http::requests::ConnTypeParam;
use pony::Tag;
use reqwest::Client as HttpClient;
use reqwest::StatusCode;
use reqwest::Url;

use pony::http::requests::NodeRequest;
use pony::http::requests::NodeType;
use pony::http::requests::NodeTypeParam;
use pony::ConnectionBaseOp;
use pony::NodeStorageOp;
use pony::SubscriptionOp;
Expand All @@ -15,11 +15,12 @@ use super::Agent;

#[async_trait]
pub trait ApiRequests {
async fn register_node(
async fn register_node(&self, _endpoint: String, _token: String) -> Result<()>;
async fn get_connections(
&self,
_endpoint: String,
_token: String,
node_type: NodeType,
endpoint: String,
token: String,
proto: Tag,
last_update: Option<u64>,
) -> Result<()>;
}
Expand All @@ -31,11 +32,11 @@ where
C: ConnectionBaseOp + Send + Sync + Clone + 'static,
S: SubscriptionOp + Send + Sync + Clone + 'static,
{
async fn register_node(
async fn get_connections(
&self,
endpoint: String,
token: String,
node_type: NodeType,
proto: Tag,
last_update: Option<u64>,
) -> Result<()> {
let node = {
Expand All @@ -46,6 +47,51 @@ where
.clone()
};

let env = node.env;

let conn_type_param = ConnTypeParam {
proto: proto,
last_update: last_update,
env: env,
};

let mut endpoint_url = Url::parse(&endpoint)?;
endpoint_url
.path_segments_mut()
.map_err(|_| PonyError::Custom("Invalid API endpoint".to_string()))?
.push("connections");
let endpoint_str = endpoint_url.to_string();

let res = HttpClient::new()
.get(&endpoint_str)
.query(&conn_type_param)
.header("Content-Type", "application/json")
.header("Authorization", format!("Bearer {}", token))
.send()
.await?;

let status = res.status();
let body = res.text().await?;
if status.is_success() {
log::debug!("Connections Request Accepted: {:?}", status);
Ok(())
} else {
log::error!("Connections Request failed: {} - {}", status, body);
Err(PonyError::Custom(
format!("Connections Request failed: {} - {}", status, body).into(),
))
}
}

async fn register_node(&self, endpoint: String, token: String) -> Result<()> {
let node = {
let mem = self.memory.read().await;
mem.nodes
.get_self()
.expect("No node available to register")
.clone()
};

let mut endpoint_url = Url::parse(&endpoint)?;
endpoint_url
.path_segments_mut()
Expand All @@ -58,11 +104,6 @@ where
Err(e) => log::error!("Error serializing node '{}': {}", node.hostname, e),
}

let node_type_param = NodeTypeParam {
node_type: Some(node_type),
last_update,
};

let node_request = NodeRequest {
env: node.env.clone(),
hostname: node.hostname.clone(),
Expand All @@ -77,7 +118,6 @@ where

let res = HttpClient::new()
.post(&endpoint_str)
.query(&node_type_param)
.header("Content-Type", "application/json")
.header("Authorization", format!("Bearer {}", token))
.json(&node_request)
Expand Down
Loading
Loading