進階
I2P Integration
深入了解 Bitcoin Core 的 I2P(Invisible Internet Project)整合,增強網路隱私。
10 分鐘
什麼是 I2P?
I2P(Invisible Internet Project)是一個匿名網路層,類似於 Tor,但採用不同的架構。 Bitcoin Core 從 v22.0 開始支持 I2P,提供額外的網路隱私選項。
I2P vs Tor
| 特性 | I2P | Tor |
|---|---|---|
| 路由類型 | 大蒜路由 | 洋蔥路由 |
| 連接方向 | 雙向隧道 | 單向電路 |
| 地址格式 | .b32.i2p | .onion |
| 延遲 | 較高 | 較低 |
| 適用場景 | 內部服務 | 出口流量 |
設置 I2P
安裝 I2P Router
# Ubuntu/Debian - 安裝 i2pd(C++ 實現)
sudo apt-get install i2pd
# 或使用官方 Java 實現
# 下載:https://geti2p.net/en/download
# macOS
brew install i2pd
# 啟動 i2pd
sudo systemctl start i2pd
sudo systemctl enable i2pd
# 檢查狀態
sudo systemctl status i2pd
# 確認 SAM 端口運行(預設 7656)
ss -tlnp | grep 7656 配置 i2pd
# /etc/i2pd/i2pd.conf
# 啟用 SAM(Simple Anonymous Messaging)接口
# Bitcoin Core 使用 SAM 與 I2P 通訊
[sam]
enabled = true
address = 127.0.0.1
port = 7656
# 隧道配置
[ntcp2]
enabled = true
published = true
[ssu2]
enabled = true
published = true 配置 Bitcoin Core
# bitcoin.conf
# I2P SAM 代理地址
i2psam=127.0.0.1:7656
# 接受 I2P 入站連接
i2pacceptincoming=1
# 可選:只使用 I2P(最大隱私)
# onlynet=i2p
# 可選:同時使用多個網路
# onlynet=i2p
# onlynet=onion
# onlynet=ipv4
# Debug 日誌
debug=i2p 注意: 首次連接 I2P 網路需要一些時間來建立隧道。請耐心等待。
驗證連接
# 檢查網路資訊
bitcoin-cli getnetworkinfo
# 輸出中應該看到 I2P 網路
{
"networks": [
{
"name": "ipv4",
"limited": false,
"reachable": true
},
{
"name": "i2p",
"limited": false,
"reachable": true,
"proxy": "127.0.0.1:7656",
"proxy_randomize_credentials": false
}
],
"localaddresses": [
{
"address": "ukeu3k5oycgaauneqgtnvselmt4yemvoilkln7jpvamvfx7dnkdq.b32.i2p",
"port": 0,
"score": 4
}
]
}
# 查看 I2P 連接的節點
bitcoin-cli getpeerinfo | jq '.[] | select(.network == "i2p") | {addr, network}'
# 查看本地 I2P 地址
bitcoin-cli getnetworkinfo | jq '.localaddresses[] | select(.address | endswith(".b32.i2p"))' 技術架構
I2P 連接流程:
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Bitcoin Core │────▶│ I2P Router │────▶│ I2P Network │
│ │ │ (i2pd/i2p) │ │ │
│ - SAM Client │ │ - SAM Server │ │ - 隧道路由 │
│ - Port 7656 │ │ - 隧道管理 │ │ - 加密傳輸 │
└─────────────────┘ └─────────────────┘ └─────────────────┘
│
▼
┌─────────────────┐
│ 遠端 Bitcoin │
│ Node │
│ xxx.b32.i2p │
└─────────────────┘
地址格式:
Base32 編碼的 256-bit 目的地雜湊
例如:ukeu3k5oycgaauneqgtnvselmt4yemvoilkln7jpvamvfx7dnkdq.b32.i2p // SAM 協議簡化實現
interface SAMSession {
// 創建會話
async createSession(style: 'STREAM'): Promise;
// 連接到遠端目的地
async connect(destination: string): Promise;
// 接受入站連接
async accept(): Promise<{socket: Socket, from: string}>;
}
// Bitcoin Core 使用 SAM 3.1 協議
class I2PConnection {
private samSocket: Socket;
async connect(destination: string): Promise {
// HELLO VERSION
await this.send('HELLO VERSION MIN=3.1 MAX=3.1\n');
// SESSION CREATE
await this.send('SESSION CREATE STYLE=STREAM ID=Bitcoin...\n');
// STREAM CONNECT
await this.send(`STREAM CONNECT ID=Bitcoin DESTINATION=${destination}\n`);
}
} 隱私考慮
優點
- • IP 地址完全隱藏
- • 抗流量分析
- • 分散式網路
- • 雙向隧道更高效
考慮事項
- • 延遲較高
- • I2P 節點較少
- • 初始連接慢
- • 需要額外運行 i2pd
最大隱私配置
# bitcoin.conf - 最大隱私模式
# 只使用匿名網路
onlynet=i2p
onlynet=onion
# I2P 配置
i2psam=127.0.0.1:7656
i2pacceptincoming=1
# Tor 配置
proxy=127.0.0.1:9050
listen=1
# 禁用 DNS
dnsseed=0
dns=0
# 手動添加種子節點
addnode=xxx.b32.i2p
addnode=yyy.onion 故障排除
# 檢查 i2pd 是否運行
pgrep -a i2pd
# 檢查 SAM 端口
ss -tlnp | grep 7656
# 查看 i2pd 日誌
sudo journalctl -u i2pd -f
# 查看 Bitcoin Core I2P 日誌
tail -f ~/.bitcoin/debug.log | grep -i i2p
# 常見錯誤:
# "SAM session failed" - i2pd 未運行或 SAM 未啟用
# "I2P not reachable" - 隧道尚未建立,等待幾分鐘
# 重啟服務
sudo systemctl restart i2pd
bitcoin-cli stop && sleep 5 && bitcoind 常見問題
- 1. 無法連接:確認 i2pd 運行並啟用 SAM
- 2. 節點很少:I2P 網路上的 Bitcoin 節點有限,正常現象
- 3. 延遲高:I2P 設計優先考慮隱私而非速度
總結
- ✓ 隱私增強:隱藏真實 IP 地址
- ✓ SAM 協議:透過 i2pd 的 SAM 接口連接
- ✓ 補充 Tor:可與 Tor 同時使用增加多樣性
- ⚠ 注意:延遲較高,節點較少
已複製連結