————-kiểm tra thêm nội dung————–
Tài liệu API I2PControl
I2PControl là một API JSON-RPC 2.0 được tích hợp sẵn với I2P router (từ phiên bản 0.9.39). Nó cho phép giám sát và điều khiển router đã được xác thực thông qua các yêu cầu JSON có cấu trúc.
Mật khẩu mặc định:
itoopie— đây là mật khẩu gốc từ nhà máy và nên được thay đổi ngay lập tức để đảm bảo bảo mật.
1. Tổng quan & Truy cập
| Implementation | Default Endpoint | Protocol | Enabled by Default | Notes |
|---|---|---|---|---|
| Java I2P (2.10.0+) | http://127.0.0.1:7657/jsonrpc/ | HTTP | ❌ Must be enabled via WebApps (Router Console) | Bundled webapp |
| i2pd (C++ implementation) | https://127.0.0.1:7650/ | HTTPS | ✅ Enabled by default | Legacy plugin behavior |
2. Định dạng JSON-RPC
Tất cả các yêu cầu đều tuân theo cấu trúc JSON-RPC 2.0:
{
"jsonrpc": "2.0",
"id": "1",
"method": "MethodName",
"params": {
/* named parameters */
}
}
Một phản hồi thành công bao gồm trường result; khi thất bại, một đối tượng error sẽ được trả về:
{
"jsonrpc": "2.0",
"id": "1",
"result": { /* data */ }
}
hoặc
{
"jsonrpc": "2.0",
"id": "1",
"error": {
"code": -32001,
"message": "Invalid password"
}
}
3. Luồng Xác thực
Yêu cầu (Xác thực)
curl -s -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "Authenticate",
"params": {
"API": 1,
"Password": "itoopie"
}
}' \
http://127.0.0.1:7657/jsonrpc/
Phản hồi thành công
{
"jsonrpc": "2.0",
"id": "1",
"result": {
"Token": "a1b2c3d4e5",
"API": 1
}
}
Bạn phải bao gồm Token đó trong tất cả các yêu cầu tiếp theo trong params.
4. Phương thức & Điểm cuối
4.1 RouterInfo
Lấy dữ liệu telemetry chính về router.
Ví dụ Yêu cầu
curl -s -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "2",
"method": "RouterInfo",
"params": {
"Token": "a1b2c3d4e5",
"i2p.router.version": "",
"i2p.router.status": "",
"i2p.router.net.status": "",
"i2p.router.net.tunnels.participating": "",
"i2p.router.net.bw.inbound.1s": "",
"i2p.router.net.bw.outbound.1s": ""
}
}' \
http://127.0.0.1:7657/jsonrpc/
Các Trường Phản Hồi (result) Theo tài liệu chính thức (GetI2P): - i2p.router.status (String) — trạng thái có thể đọc được - i2p.router.uptime (long) — mili giây (hoặc chuỗi cho i2pd cũ hơn) :contentReference[oaicite:0]{index=0} - i2p.router.version (String) — chuỗi phiên bản :contentReference[oaicite:1]{index=1} - i2p.router.net.bw.inbound.1s, i2p.router.net.bw.inbound.15s (double) — băng thông đến theo B/s :contentReference[oaicite:2]{index=2} - i2p.router.net.bw.outbound.1s, i2p.router.net.bw.outbound.15s (double) — băng thông đi theo B/s :contentReference[oaicite:3]{index=3} - i2p.router.net.status (long) — mã trạng thái số (xem enum bên dưới) :contentReference[oaicite:4]{index=4} - i2p.router.net.tunnels.participating (long) — số lượng tunnel tham gia :contentReference[oaicite:5]{index=5} - i2p.router.netdb.activepeers, fastpeers, highcapacitypeers (long) — thống kê peer của netDB :contentReference[oaicite:6]{index=6} - i2p.router.netdb.isreseeding (boolean) — có đang thực hiện reseed hay không :contentReference[oaicite:7]{index=7} - i2p.router.netdb.knownpeers (long) — tổng số peer đã biết :contentReference[oaicite:8]{index=8}
Enum Mã Trạng Thái (i2p.router.net.status)
| Code | Meaning |
|---|---|
| 0 | OK |
| 1 | TESTING |
| 2 | FIREWALLED |
| 3 | HIDDEN |
| 4 | WARN_FIREWALLED_AND_FAST |
| 5 | WARN_FIREWALLED_AND_FLOODFILL |
| 6 | WARN_FIREWALLED_WITH_INBOUND_TCP |
| 7 | WARN_FIREWALLED_WITH_UDP_DISABLED |
| 8 | ERROR_I2CP |
| 9 | ERROR_CLOCK_SKEW |
| 10 | ERROR_PRIVATE_TCP_ADDRESS |
| 11 | ERROR_SYMMETRIC_NAT |
| 12 | ERROR_UDP_PORT_IN_USE |
| 13 | ERROR_NO_ACTIVE_PEERS_CHECK_CONNECTION_AND_FIREWALL |
| 14 | ERROR_UDP_DISABLED_AND_TCP_UNSET |
4.2 GetRate
Được sử dụng để lấy các chỉ số tốc độ (ví dụ: băng thông, tỷ lệ thành công tunnel) trong một khoảng thời gian nhất định.
Ví dụ Yêu cầu
curl -s -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "3",
"method": "GetRate",
"params": {
"Token": "a1b2c3d4e5",
"Stat": "bw.combined",
"Period": 60000
}
}' \
http://127.0.0.1:7657/jsonrpc/
Phản hồi mẫu
{
"jsonrpc": "2.0",
"id": "3",
"result": {
"Rate": 12345.67
}
}
4.3 RouterManager
Thực hiện các hành động quản trị.
Các tham số / phương thức được phép - Restart, RestartGraceful - Shutdown, ShutdownGraceful - Reseed, FindUpdates, Update :contentReference[oaicite:10]{index=10}
Ví dụ Request
curl -s -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "4",
"method": "RouterManager",
"params": {
"Token": "a1b2c3d4e5",
"Restart": true
}
}' \
http://127.0.0.1:7657/jsonrpc/
Phản hồi thành công
{
"jsonrpc": "2.0",
"id": "4",
"result": {
"Restart": null
}
}
4.4 NetworkSetting
Lấy hoặc thiết lập các tham số cấu hình mạng (cổng, upnp, chia sẻ băng thông, v.v.)
Ví dụ Request (lấy giá trị hiện tại)
curl -s -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "5",
"method": "NetworkSetting",
"params": {
"Token": "a1b2c3d4e5",
"i2p.router.net.ntcp.port": null,
"i2p.router.net.ssu.port": null,
"i2p.router.net.bw.share": null,
"i2p.router.net.upnp": null
}
}' \
http://127.0.0.1:7657/jsonrpc/
Phản Hồi Mẫu
{
"jsonrpc": "2.0",
"id": "5",
"result": {
"i2p.router.net.ntcp.port": "1234",
"i2p.router.net.ssu.port": "5678",
"i2p.router.net.bw.share": "50",
"i2p.router.net.upnp": "true",
"SettingsSaved": true,
"RestartNeeded": false
}
}
Lưu ý: các phiên bản i2pd trước 2.41 có thể trả về các kiểu số thay vì chuỗi — client nên xử lý cả hai. :contentReference[oaicite:11]{index=11}
4.5 Cài đặt Nâng cao
Cho phép thao tác các tham số bên trong router.
Ví dụ Yêu cầu
curl -s -H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": "6",
"method": "AdvancedSettings",
"params": {
"Token": "a1b2c3d4e5",
"Set": {
"router.sharePercentage": "75",
"i2np.flushInterval": "6000"
}
}
}' \
http://127.0.0.1:7657/jsonrpc/
Ví dụ Phản hồi
{
"jsonrpc": "2.0",
"id": "6",
"result": {
"Set": {
"router.sharePercentage": "75",
"i2np.flushInterval": "6000"
}
}
}
5. Mã Lỗi
Mã Lỗi Chuẩn JSON-RPC2
| Code | Meaning |
|---|---|
| -32700 | JSON parse error |
| -32600 | Invalid request |
| -32601 | Method not found |
| -32602 | Invalid parameters |
| -32603 | Internal error |
| Code | Meaning |
|---|---|
| -32001 | Invalid password provided |
| -32002 | No authentication token presented |
| -32003 | Authentication token doesn't exist |
| -32004 | The provided authentication token was expired and will be removed |
| -32005 | The version of the I2PControl API used wasn't specified, but is required to be specified |
| -32006 | The version of the I2PControl API specified is not supported by I2PControl |
6. Sử dụng & Các phương pháp tốt nhất
- Luôn bao gồm tham số
Token(trừ khi đang xác thực). - Thay đổi mật khẩu mặc định (
itoopie) khi sử dụng lần đầu. - Đối với Java I2P, đảm bảo webapp I2PControl được kích hoạt qua WebApps.
- Chuẩn bị cho những biến đổi nhỏ: một số trường có thể là số hoặc chuỗi, tùy thuộc vào phiên bản I2P.
- Ngắt dòng các chuỗi trạng thái dài để hiển thị thân thiện hơn.