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
38 changes: 20 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ The node uses the `common/service.proto` file messages for both protocols.
| `Stat` | Contains:<br/>- `name` (string): Stat name.<br/>- `type` (string): Stat type.<br/>- `link` (string): Link associated with the stat.<br/>- `value` (int64): Stat value. |
| `StatResponse` | Contains:<br/>- `stats` ([]Stat): List of stats. |
| `StatRequest` | Contains:<br/>- `name` (string): Name of the stat to request, user email or inbound \ outbound tag.<br/>- `reset` (bool) Whether to reset traffic stats. |
| `OnlineStatResponse` | Contains:<br/>- `email` (string): User's email.<br/>- `value` (int64): Online stat value. |
| `OnlineStatResponse` | Contains:<br/>- `name` (string): User's email.<br/>- `value` (int64): Online connection number. |
| `OnlineStatResponse` | Contains:<br/>- `name` (string): User's email.<br/>- `value` (map<string, int64>): Online stat value. |
| `BackendStatsResponse` | Contains:<br/>- `num_goroutine` (uint32): Number of goroutines.<br/>- `num_gc` (uint32): Number of garbage collections.<br/>- `alloc` (uint64): Allocated memory.<br/>- `total_alloc` (uint64): Total allocated memory.<br/>- `sys` (uint64): System memory.<br/>- `mallocs` (uint64): Number of mallocs.<br/>- `frees` (uint64): Number of frees.<br/>- `live_objects` (uint64): Number of live objects.<br/>- `pause_total_ns` (uint64): Total pause time in nanoseconds.<br/>- `uptime` (uint32): Uptime in seconds. |
| `SystemStatsResponse` | Contains:<br/>- `mem_total` (uint64): Total memory.<br/>- `mem_used` (uint64): Used memory.<br/>- `cpu_cores` (uint64): Number of CPU cores.<br/>- `cpu_usage` (double): CPU usage percentage.<br/>- `incoming_bandwidth_speed` (uint64): Incoming bandwidth speed.<br/>- `outgoing_bandwidth_speed` (uint64): Outgoing bandwidth speed. |
| `Users` | Contains:<br/>- `users` ([]User): List of users. |
Expand All @@ -102,23 +103,24 @@ The node uses the `common/service.proto` file messages for both protocols.
- Use `Authorization Bearer <session_id>` in the header for authentication with the **REST API**.
- Use `authorization Bearer <session_id>` in metadata for authentication with **gRPC**.

| gRPC | REST | Input | Output | Description |
|:-----------------------|:---------------------------|---------------|--------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `Start()` | `POST`,`/start` | `Backend` | `BaseInfoResponse` | This is the only method called before creating a connection. |
| `Stop()` | `PUT`,`/stop` | `Empty` | `Empty` | Stops the backend and deactivates the connection with the client. |
| `GetBaseInfo()` | `GET`,`/info` | `Empty` | `BaseInfoResponse` | Returns base info; can be used to check the connection between the node and client. |
| `GetLogs()` | `GET`,`/logs` | `Empty` | gRPC: (stream `Log`)<br/>REST API: (`SSE`) | This method is a `SSE` connection in the REST protocol, but in gRPC, it provides a stream connection. |
| `GetSystemStats()` | `GET`,`/stats/system` | `Empty` | `SystemStatsResponse` | Retrieves system statistics. |
| `GetBackendStats()` | `GET`,`/stats/backend` | `Empty` | `BackendStatsResponse` | Retrieves backend statistics. |
| `GetOutboundsStats()` | `GET`, `/stats/outbounds` | `StatRequest` | `StatResponse` | Retrieves outbound statistics. The `name` field in the request will be ignored. |
| `GetOutboundStats()` | `GET`,`/stats/outbound` | `StatRequest` | `StatResponse` | Retrieves statistics for a specific outbound. |
| `GetInboundsStats()` | `GET`,`/stats/inbounds` | `StatRequest` | `StatResponse` | Retrieves inbound statistics. The `name` field in the request will be ignored. |
| `GetInboundStats()` | `GET`,`/stats/inbound` | `StatRequest` | `StatResponse` | Retrieves statistics for a specific inbound. |
| `GetUsersStats()` | `GET`,`/stats/users` | `StatRequest` | `StatResponse` | Retrieves user statistics and resets traffic stats. The `name` field in the request will be ignored. |
| `GetUserStats()` | `GET`,`/stats/user` | `StatRequest` | `StatResponse` | Retrieves statistics for a specific user. |
| `GetUserOnlineStats()` | `GET`,`/stats/user/online` | `StatRequest` | `StatResponse` | Retrieves online statistics for a specific user. The `reset` field in the request will be ignored |
| `SyncUser()` | `PUT`,`/user/sync` | `User` | `Empty` | Adds/updates/removes a user in the core. To remove a user, ensure you send empty inbounds. Provides a stream in `gRPC` but must be called for each user in the `REST API`. |
| `SyncUsers()` | `PUT`,`/users/sync` | `Users` | `Empty` | Removes all old users and replaces them with the provided users. |
| gRPC | REST | Input | Output | Description |
|:-----------------------------|:------------------------------|---------------|--------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `Start()` | `POST`,`/start` | `Backend` | `BaseInfoResponse` | This is the only method called before creating a connection. |
| `Stop()` | `PUT`,`/stop` | `Empty` | `Empty` | Stops the backend and deactivates the connection with the client. |
| `GetBaseInfo()` | `GET`,`/info` | `Empty` | `BaseInfoResponse` | Returns base info; can be used to check the connection between the node and client. |
| `GetLogs()` | `GET`,`/logs` | `Empty` | gRPC: (stream `Log`)<br/>REST API: (`SSE`) | This method is a `SSE` connection in the REST protocol, but in gRPC, it provides a stream connection. |
| `GetSystemStats()` | `GET`,`/stats/system` | `Empty` | `SystemStatsResponse` | Retrieves system statistics. |
| `GetBackendStats()` | `GET`,`/stats/backend` | `Empty` | `BackendStatsResponse` | Retrieves backend statistics. |
| `GetOutboundsStats()` | `GET`, `/stats/outbounds` | `StatRequest` | `StatResponse` | Retrieves outbound statistics. The `name` field in the request will be ignored. |
| `GetOutboundStats()` | `GET`,`/stats/outbound` | `StatRequest` | `StatResponse` | Retrieves statistics for a specific outbound. |
| `GetInboundsStats()` | `GET`,`/stats/inbounds` | `StatRequest` | `StatResponse` | Retrieves inbound statistics. The `name` field in the request will be ignored. |
| `GetInboundStats()` | `GET`,`/stats/inbound` | `StatRequest` | `StatResponse` | Retrieves statistics for a specific inbound. |
| `GetUsersStats()` | `GET`,`/stats/users` | `StatRequest` | `StatResponse` | Retrieves user statistics and resets traffic stats. The `name` field in the request will be ignored. |
| `GetUserStats()` | `GET`,`/stats/user` | `StatRequest` | `StatResponse` | Retrieves statistics for a specific user. |
| `GetUserOnlineStats()` | `GET`,`/stats/user/online` | `StatRequest` | `OnlineStatResponse` | Retrieves online statistics for a specific user. The `reset` field in the request will be ignored |
| `GetUserOnlineIpListStats()` | `GET`,`/stats/user/online_ip` | `StatRequest` | `StatsOnlineIpListResponse` | Retrieves ip list statistics for a specific user. The `reset` field in the request will be ignored |
| `SyncUser()` | `PUT`,`/user/sync` | `User` | `Empty` | Adds/updates/removes a user in the core. To remove a user, ensure you send empty inbounds. Provides a stream in `gRPC` but must be called for each user in the `REST API`. |
| `SyncUsers()` | `PUT`,`/users/sync` | `Users` | `Empty` | Removes all old users and replaces them with the provided users. |

# Official library
We create some library's for you so make your job easier
Expand Down
3 changes: 2 additions & 1 deletion backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ type Backend interface {
GetSysStats(context.Context) (*common.BackendStatsResponse, error)
GetUsersStats(context.Context, bool) (*common.StatResponse, error)
GetUserStats(context.Context, string, bool) (*common.StatResponse, error)
GetStatOnline(context.Context, string) (*common.OnlineStatResponse, error)
GetUserOnlineStats(context.Context, string) (*common.OnlineStatResponse, error)
GetUserOnlineIpListStats(context.Context, string) (*common.StatsOnlineIpListResponse, error)
GetOutboundsStats(context.Context, bool) (*common.StatResponse, error)
GetOutboundStats(context.Context, string, bool) (*common.StatResponse, error)
GetInboundsStats(context.Context, bool) (*common.StatResponse, error)
Expand Down
14 changes: 12 additions & 2 deletions backend/xray/api/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,24 @@ func (x *XrayHandler) QueryStats(ctx context.Context, pattern string, reset bool
return resp, nil
}

func (x *XrayHandler) GetStatOnline(ctx context.Context, email string) (*common.OnlineStatResponse, error) {
func (x *XrayHandler) GetUserOnlineStats(ctx context.Context, email string) (*common.OnlineStatResponse, error) {
client := *x.StatsServiceClient
resp, err := client.GetStatsOnline(ctx, &command.GetStatsRequest{Name: email})
if err != nil {
return nil, err
}

return &common.OnlineStatResponse{Email: email, Value: resp.GetStat().Value}, nil
return &common.OnlineStatResponse{Name: email, Value: resp.GetStat().GetValue()}, nil
}

func (x *XrayHandler) GetUserOnlineIpListStats(ctx context.Context, email string) (*common.StatsOnlineIpListResponse, error) {
client := *x.StatsServiceClient
resp, err := client.GetStatsOnlineIpList(ctx, &command.GetStatsRequest{Name: email})
if err != nil {
return nil, err
}

return &common.StatsOnlineIpListResponse{Name: email, Ips: resp.GetIps()}, nil
}

func (x *XrayHandler) GetUsersStats(ctx context.Context, reset bool) (*common.StatResponse, error) {
Expand Down
8 changes: 6 additions & 2 deletions backend/xray/xray.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,12 @@ func (x *Xray) GetUserStats(ctx context.Context, email string, reset bool) (*com
return x.handler.GetUserStats(ctx, email, reset)
}

func (x *Xray) GetStatOnline(ctx context.Context, email string) (*common.OnlineStatResponse, error) {
return x.handler.GetStatOnline(ctx, email)
func (x *Xray) GetUserOnlineStats(ctx context.Context, email string) (*common.OnlineStatResponse, error) {
return x.handler.GetUserOnlineStats(ctx, email)
}

func (x *Xray) GetUserOnlineIpListStats(ctx context.Context, email string) (*common.StatsOnlineIpListResponse, error) {
return x.handler.GetUserOnlineIpListStats(ctx, email)
}

func (x *Xray) GetOutboundsStats(ctx context.Context, reset bool) (*common.StatResponse, error) {
Expand Down
Loading
Loading