sdlan/API.md
2025-05-12 11:54:24 +08:00

189 lines
3.1 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# SDLAN API交互文档
## 检测客户端版本
```text
url: /api/upgrade
method: post
params:
client_id: string
version: int
channel: string // 客户端的渠道信息
return:
{"result": {
"upgrade_type": 0, // 升级类型0: 不升级1: 普通升级2: 强制升级
"upgrade_prompt": "升级提升语"
"upgrade_address": "升级提升语"
}}
{"error": {"code": 1, "message": "错误描述"}}
```
## SDL主动请求的接口
### 1. 获取全部的可用网络信息
```text
url: /api/get_all_networks
method: get
return:
{"result": [8, 9, 10]}
{"error": {"code": 1, "message": "错误描述"}}
```
### 2. 获取单个网络信息
```text
url: /api/get_network?id=:id
method: get
return:
{"result":
{
"id": 1,
"name": "网络1",
"ipaddr": "192.168.0.1/24",
"owner_id": 1234,
"disabled_clients": ["client_id_xyz", "client_id_xyz1"]
}
}
{"error": {"code": 1, "message": "错误描述"}}
```
### 3.token校验
```text
url: /api/auth_token
method: post
params:
client_id: string
token: string,
version: int // 当前客户端版本
return:
{"result":
{
"network_id": 8,
"upgrade_type": 0, // 升级类型0: 不升级1: 普通升级2: 强制升级
"upgrade_prompt": "升级提升语"
"upgrade_address": "升级提升语"
}
}
{"error": {"code": 1, "message": "错误描述"}}
code = 1, Token does not exists
code = 2, Client Connection Disable
```
### 4.设置节点的状态
```text
url: /api/set_node_status
method: post
params:
client_id: string
network_id: int,
ip_addr: string,
status: 0 | 1, // 0: 离线1 在线
return:
{"result": "success"}
```
### 5. 节点流量汇报(每分钟汇报一次,单位为字节数)
```text
url: /api/flow_report
method: post
params:
client_id: string
network_id: int,
forward_num: int,
p2p_num: int,
inbound_num: int
return:
{"result": "success"}
```
## 管理平台请求SDLAN
### 网络管理接口
#### 1. 创建新网络
```text
url: /network/create
method: post
params:
id: int
return:
{"result": "success"}
{"error": {"code": 1, "message": "错误描述"}}
```
#### 2. 更新网络信息
```text
url: /network/reload
method: post
params:
id: int
return:
{"result": "success"}
{"error": {"code": 1, "message": "错误描述"}}
```
#### 3. 删除网络
```text
url: /network/delete
method: post
params:
id: int
return:
{"result": "success"}
{"error": {"code": 1, "message": "错误描述"}}
```
### 客户端节点管理
#### 1. 禁用节点
```text
url: /node/disable
method: post
params:
network_id: int
client_id: int
return:
{"result": "success"}
{"error": {"code": 1, "message": "错误描述"}}
```
#### 2. 迁移到新网络
```text
url: /node/move
method: post
params:
client_id: int
to_network_id: int
timeout: int
return:
{"result": "success"}
{"error": {"code": 1, "message": "错误描述"}}
```