Network 命令
rotifer network 命令运行一个点对点基因网络。已发布的 CLI 内置一个 libp2p 节点(libp2p 0.57),以后台守护进程方式运行。同一局域网里的节点通过 mDNS 互相发现;任何节点也可以通过 --bootstrap 地址加入。基因公告经 GossipSub 传播,基因记录存在 Kademlia DHT 里。
rotifer network status
Section titled “rotifer network status”显示 P2P 守护进程状态。
rotifer network status示例(守护进程运行中):
$ rotifer network status
── P2P Network Status ──
Status: ● Running PeerId: 12D3KooWA1b2c3d4e5f6... Listening: /ip4/192.168.0.103/tcp/9878/p2p/12D3KooWA1b2c3d4e5f6... Discovered peers: 2 Connected peers: 2 DHT peers: 2守护进程没有运行时,命令显示配置的监听端口和引导节点数量,并提示如何启动。
从下个版本起:
| 参数 | 说明 |
|---|---|
--state-file <path> | 从这个文件读守护进程的端口和令牌,而不是 ~/.rotifer/daemon.json(比如查看以服务账号运行的守护进程) |
status只读,不写任何文件。在从没启动过节点的机器上,它显示Node: not initialised: run 'rotifer network start' first。- 加全局
--json时,它把节点的各项计数以 JSON 输出,给脚本用:角色、连接、上限、拒绝次数、NAT、中继、gossip 和 DHT。不包含对端地址、PeerId 和评分。没有守护进程在运行时输出{"running":false},退出码为 1。
$ rotifer --json network status节选,节点用 --max-inbound 40 --max-pending 10 启动:
{ "running": true, "roles": { "relayServer": false }, "announcedAddrs": [], "connections": { "inbound": 0, "outbound": 0 }, "limits": { "inbound": 40, "outbound": 50, "pending": 10 }, "denials": { "inboundLimit": 0, "pendingInboundLimit": 0, "outboundLimit": 0, "memory": 0, "blocked": 0 }}完整输出还有 version、eventLoop、foreignPeersDropped、colocation、nat、relay、gossip 和 dht。
rotifer network start
Section titled “rotifer network start”以后台守护进程方式启动 P2P 节点。需要原生 libp2p 插件。
rotifer network start [--port <port>] [--host <addr>] [--bootstrap <addr...>] [--no-mdns]参数:
| 参数 | 默认值 | 说明 |
|---|---|---|
-p, --port <port> | 9878 | 监听端口 |
-H, --host <addr> | 127.0.0.1 | 监听接口:127.0.0.1(仅本机)或 0.0.0.0(其他机器可连) |
-b, --bootstrap <addr...> | 取自配置 | 引导节点的 multiaddr,可填多个;会覆盖配置文件 |
--no-mdns | mDNS 开 | 不在局域网里发现或广播(在不可信的 Wi-Fi 上使用);mDNS 只在 --host 不是本机回环地址时运行 |
从下个版本起:
| 参数 | 默认值 | 说明 |
|---|---|---|
--accept-p2p | 关 | 读过 rotifer network consent --show 之后,不经询问就允许本账号使用 P2P 网络 |
--foreground | 关 | 在当前进程里运行,不转到后台,给 systemd 这类服务管理器用;节点停止工作时以非 0 退出 |
--relay <addr...> | 无 | 在这个中继上保留一个位置(multiaddr 以 /p2p/<PeerId> 结尾),让 NAT 后面的节点能连到本节点 |
--relay-server | 关 | 为其他节点充当中继。不加 --announce 时,中继服务照样启动,但不对外公布(relay.advertising: false),也不接受任何预约;要做公共中继,需加 --announce /ip4/<公网 IP>/tcp/<端口> |
--announce <addr...> | 无 | 本节点的公网地址,只接受 /ip4/<公网 IPv4>/tcp/<端口> |
--max-inbound <n> | 50 | 已建立的入站连接最多几条 |
--max-pending <n> | 20 | 握手中的连接最多几条,入站出站合计 |
示例:
$ rotifer network start --host 0.0.0.0 --port 9878
── Starting P2P Daemon ──
PeerId: 12D3KooWA1b2c3d4e5f6... Listen host: 0.0.0.0 PID: 48213 Bootstrap peers: 0 LAN discovery (mDNS): on
✓ P2P daemon running in the background. ℹ 'rotifer network status' shows the reachable multiaddr — give it to other nodes as --bootstrap局域网发现。 用 --host 0.0.0.0 启动的节点通过 mDNS 发现局域网里的其他节点,不需要 --bootstrap。用默认的 --host 127.0.0.1 时 mDNS 不开(显示 LAN discovery (mDNS): off (loopback only));--no-mdns 在任何接口上都会关掉它。
连接其他节点。 节点可以经中继或打洞建立连接,并限制连接数和内存用量。它会尽量保持 8 条主动拨出、对端由自己选定的连接,不再那么依赖谁连进来。没有连上任何引导节点时,它会马上重拨一个,失败后逐次拉长间隔。重启时只拨回真正连上过的对端,不再拨听说过的每个地址,所以只要连上过一个对端,重启时就不必再给 --bootstrap。
首次同意(从下个版本起)。 一个账号第一次 network start 时,先打印节点会连到哪里、对端能看到什么(就是 rotifer network consent --show 打印的那段文字),然后问 Allow P2P networking for this account? [y/N]。直接回车=不同意。不同意时什么都不保存,连节点密钥也不生成:
Not started. P2P networking stays off; nothing was saved.脚本、CI 和其他不在终端里的运行,以及加了 --json 的运行,一律不问:在记下同意之前,它们不连接任何地方,直接以退出码 1 结束:
$ rotifer network start < /dev/null✗ P2P networking needs your consent first → Nothing was started and no connection was made. Run 'rotifer network start' in a terminal to read what it connects to and allow it, or pass --accept-p2p if you have read it (rotifer network consent --show prints the text).先用 rotifer network consent --show 读那段文字,再加一次 --accept-p2p,或者运行 rotifer network consent --accept。用 --accept-p2p 时,那段文字写到 stderr,日志里会留下同意了什么。同意按账号记录,之后再启动就不再问。
中继和连接上限(从下个版本起)。 --relay 填一个中继的地址:可以是官方节点之一,也可以是你自己运行的节点:
# 经中继(官方节点或你自己运行的节点)连到本节点rotifer network start --relay /ip4/<relay-ip>/tcp/9878/p2p/<relay-PeerId>
# 在有公网 IPv4 地址的机器上:为其他节点充当中继rotifer network start --host 0.0.0.0 --relay-server --announce /ip4/<public-ip>/tcp/9878加了 --relay-server 或 --announce,其他节点也可以主动连到本节点(提示原文:With —relay-server or —announce, other nodes can also connect to this node on their own.)。--announce 只接受 /ip4/<公网 IPv4>/tcp/<端口>:填域名、内网地址或保留地址会被拒绝,守护进程不启动,原因写在 ~/.rotifer/daemon.log。--max-inbound 和 --max-pending 必须是 1 及以上的整数;network status --json 显示实际生效的上限。
交给服务管理器运行(从下个版本起)。 --foreground 让节点在当前进程里运行,给 systemd 之类用。用 Ctrl-C 或 SIGTERM 停止。服务没有终端,所以要先用 --accept-p2p 或 rotifer network consent --accept 记下同意。
守护进程在后台运行:用 rotifer network status 查看,用 rotifer network stop 关闭。启动不起来时看 ~/.rotifer/daemon.log。配置保存在 ~/.rotifer/network.json。
rotifer network stop
Section titled “rotifer network stop”停止 P2P 守护进程。
rotifer network stoprotifer network consent
Section titled “rotifer network consent”从下个版本起提供。查看、给出或撤回本账号对 P2P 网络的同意。
rotifer network consent --show | --accept | --revoke | --status一次只能给一个参数:
| 参数 | 说明 |
|---|---|
--show | 打印节点会连到哪里、对端能看到什么 |
--accept | 记下同意,但不启动节点(会打印所同意的那段文字) |
--revoke | 撤回同意,并停掉正在运行的节点;节点密钥和记住的对端保留 |
--status | 是否已记下同意、对应哪一版说明、从什么时候起 |
示例(--show,在从没启动过节点的账号上): 这段是 CLI 的原样输出,保留英文。
$ rotifer network consent --showP2P networking is off for this account. Starting the node turns it on.
The node will connect to: - bootstrap peers from -b or ~/.rotifer/network.json (now: 0) - relay nodes from --relay, used to reach nodes behind NAT - peers it met on earlier runs, saved in ~/.rotifer/peers.json (now: 0) - peers that those nodes introduce - devices on your local network, only with a non-loopback --host and without --no-mdns - rotifer.dev, only to fetch the public keys that check other nodes' certificatesThere is no public Rotifer network yet. With no peers configured, the node connects to nothing.
Every peer it connects to can see: - your IP address - this node's ID, (made when the node first starts), kept in ~/.rotifer/identity.pem - the gene announcements this node receives and forwardsWith --relay-server or --announce, other nodes can also connect to this node on their own.It sends gene metadata (names, IDs, versions), never gene code or the inputs and outputs of a run.
Stop the node: rotifer network stopWithdraw this consent: rotifer network consent --revoke数字和节点 ID 在命令运行时按本账号的实际情况填入。--show 只读,不会生成节点密钥。
示例(--status):
$ rotifer network consent --status P2P consent: not givenℹ Read it with 'rotifer network consent --show'; allow with 'rotifer network start' or --accept.
$ rotifer network consent --status P2P consent: given Notice version: 1 Since: 2026-11-24T03:07:56.925Z How: flagHow 是 prompt(在 network start 时回答了 y)、flag(--accept-p2p)或 command(consent --accept)。加全局 --json 时,--status 输出 {"consented":false,"noticeVersion":null,"acceptedAt":null,"source":null},或填好值的同样几个字段。
撤回: --revoke 删除同意记录并停掉正在运行的节点。节点密钥(~/.rotifer/identity.pem)和记住的对端保留,所以之后再 network start 会重新询问,回来时仍是同一个节点。
$ rotifer network consent --revoke✓ P2P consent withdrawn.ℹ The running P2P node was stopped.ℹ The node key (~/.rotifer/identity.pem) and remembered peers are kept.以后的版本如果改了说明文字,说明的版本号会升,所有人都会被重新询问一次。
rotifer network peers
Section titled “rotifer network peers”列出运行中的守护进程发现的节点。
rotifer network peers示例:
$ rotifer network peers
── Discovered Peers ──
#1 /ip4/192.168.0.107/tcp/9878/p2p/12D3KooWB7c8d9...
1 peer(s) discovered还没有节点连上时,命令显示 No peers discovered yet.
rotifer network received
Section titled “rotifer network received”显示本节点从其他节点收到的基因公告。需要守护进程正在运行。
rotifer network received示例:
$ rotifer network received
── Received Gene Announcements ──
grammar-checker@1.0.0 writing.grammar · Native · v2:3f9a1c0b7e2d… · from 12D3KooWB7c8d9…
1 announcement(s) received ℹ Names and versions are labels claimed by the publisher; the gene ID is derived from the content.只有在本节点已连接并订阅时,其他节点发出的公告才会出现在这里。名称和版本是发布者自己声称的标签;基因 ID 由内容算出。
rotifer network announce <gene-name>
Section titled “rotifer network announce <gene-name>”通过运行中的守护进程公告一个本地基因。读取当前项目的 genes/<gene-name>/;这个基因必须能算出 v2 基因 ID。
rotifer network announce <gene-name>公告走两条路:
- Gossip:已连接并订阅的节点会收到,在
rotifer network received里列出。 - DHT:基因记录存进 DHT,其他节点可以按 v2 基因 ID 查到。守护进程每 12 小时重发一次,已公告的基因清单在守护进程重启后仍保留。要停止,用
rotifer network withdraw。
示例:
$ rotifer network announce grammar-checker
── Gene Announcement ──
✓ Announced 'grammar-checker' Gene ID (v2): v2:3f9a1c0b7e... Gossip: published (2 connected peers subscribe) DHT record: sent to 2 nodes, 2 acknowledged (an acknowledgement does not prove the record was kept) Provider record: published (the protocol reports no count and no acknowledgement) Read-back: readable from 2 other nodes还没有 DHT 节点时,DHT record 一行显示 not sent: no DHT peers yet。上面那条网络地址提醒在本节点第一次公告时显示一次,rotifer network announce --help 里始终都有。
rotifer network search <query>
Section titled “rotifer network search <query>”同时搜索 Rotifer Cloud 和 P2P 网络。
rotifer network search <query><query> 是关键词,或者一个 v2 基因 ID(v2:<64 位十六进制>):
- 关键词匹配本节点从其他节点听到的公告的名称和领域,同时并行搜一次 Rotifer Cloud。
- v2 基因 ID 到 DHT 里查。Rotifer Cloud 查不了 v2 ID,所以这时跳过 Cloud。
- DHT 从不按关键词搜。 两张列表不合并。
示例:
$ rotifer network search grammar
Gene Search "grammar"
Rotifer Cloud (1) grammar-checker@1.0.0 writing.grammar · Native · by rotifer · reputation 0.82P2P network (1) heard from other nodes · whether any is the same gene as a Cloud result is unknown v2:3f9a1c… 1 registered account grammar-checker@1.0.0 writing.grammar · Native from 12D3KooWB7c8… (registered) ℹ The two lists are not merged: Cloud search results don't carry a v2 gene ID, so one gene can appear in both. ℹ Name, domain, fidelity and version are each publisher's own claim. The gene ID itself is only checked when the content is fetched.P2P 结果按基因 ID 分组,按发布它的已注册账号数排序;发布者给同一个基因的标签不一致时,结果里会标出 ! publishers disagree on …。名称、领域、fidelity 和版本都是各发布者自己的声明,基因 ID 本身只在取回内容时才校验。
- P2P 这一侧有 3 秒时限;碰到时限或候选数上限时,命令会提示结果可能不完整。
- 守护进程没运行时只显示 Cloud 列表,并提示运行
rotifer network start。 - 连不上 Rotifer Cloud 时只显示 P2P 结果。两边都没有回应时,命令以退出码 1 结束。
rotifer network withdraw <gene>
Section titled “rotifer network withdraw <gene>”停止公告一个基因:不再重发,本节点也不再提供它。
rotifer network withdraw <gene><gene> 是基因名或 v2 基因 ID。守护进程没运行时,只会把它从重发清单里删掉。
撤回做不到的事: 其他节点不会收到删除通知:它们存下的副本在收到后 24 小时内过期;从 gossip 听到公告的节点最长还能在 48 小时内列出它。
节点密钥: 记录的有效时间窗只约束单条声明,约束不了被盗的节点密钥:谁拿着密钥,谁就能一直签名。密钥泄露时请轮换(删除 ~/.rotifer/identity.pem 后重启)。
rotifer network attest
Section titled “rotifer network attest”为本节点申请一张注册证明证书,把节点和你的 Rotifer Cloud 账号关联起来。证书默认关闭。
rotifer network attest enable [--accept-public-pseudonym]rotifer network attest statusrotifer network attest renewrotifer network attest disable| 子命令 | 作用 |
|---|---|
enable | 开启证书并为本节点申请一张 |
status | 显示本节点的证书 |
renew | 立即续签。运行中的守护进程会在剩余不足 48 小时时自动续签 |
disable | 不再携带和续签证书 |
运行 enable 之前:需先 rotifer login。登录后,在一个节点上第一次运行 enable 时,会先列出你要同意的内容,征求同意后才开启:
- 你的节点会和一个账号假名关联公开,Cloud 能反查到你的账号。
- 证书 7 天内失效;节点在线时会在剩余不足 48 小时时自动续签。
- 账号被封禁或证书被吊销时,吊销公布后约 24 小时内,其他节点不再接受这张证书。没有公布吊销时,证书到期即失效,最长为签发后 7 天。
非交互运行时(在脚本里,或加了 --json),enable 不会询问,除非加 --accept-public-pseudonym,否则不开启任何东西。
续签:运行中的守护进程每 10 分钟检查一次证书,剩余不足 48 小时时续签。续签失败时继续使用当前证书,一小时后重试,并在 status 里显示。
disable 删除本节点保存的证书。已签发的证书不会作废:它在到期前一直有效,最长为上次续签后 7 天。
节点密钥变了:新密钥对网络来说是一个新节点,需要自己的证书:status 显示 Key changed,enable 会重新征求同意。旧证书不会作废,到期前(最长 7 天)对旧密钥仍然有效,拿到旧密钥的人可以继续用;旧密钥可能泄露时,请联系 Rotifer 团队吊销旧节点。
rotifer network status 也会显示证书,多一行 Certificate。
JSON 输出:加 --json 时,每个子命令输出一份 JSON。成功时是 { ok: true, action, attestation, daemon, notices }。attestation 不包含证书本身;status 的 daemon 是 running 或 not_running,其他子命令的 daemon 是 loaded、cannot_load 或 not_running。失败时是 { ok: false, action, error: { code, message, fix } },退出码为 1。
$ rotifer network attest status --json{ "ok": true, "action": "status", "attestation": { "state": "off", "peerId": null, "issuedAt": null, "expiresAt": null, "expiresInSeconds": null, "autoRenew": false, "lastRenewalAttemptAt": null, "lastRenewedAt": null, "lastFailure": null }, "daemon": "not_running", "notices": []}$ rotifer network attest renew --json{ "ok": false, "action": "renew", "error": { "code": "POR_NOT_ENABLED", "message": "Certificates are not enabled on this node.", "fix": "Run 'rotifer network attest enable' first." }}节点怎么保护自己
Section titled “节点怎么保护自己”- 其他节点的记录先检查再存,每个发布者和总量各有上限。反复违规的节点会被暂时屏蔽。
- 只有使用 Rotifer DHT 的节点才能加入。 其他 libp2p 节点不会被加进本节点的 DHT。
- 没有注册校验器的 topic 上的 gossip 一律忽略;节点也拒绝在自己没注册的 topic 上发布。
- 注册证明。 心跳可以带上 Rotifer Cloud 签发的注册证明,其他节点会核验并用于互相打分。节点用
rotifer network attest申请证明;签发证明的云端部分在 rotifer-playground 仓库里,但没有部署。
Rotifer 项目运行两台公共节点,一台在 Hetzner,一台在 Vultr。两台是同一个运营方(Rotifer 官方),都兼作引导节点和中继。
| 云服务商 | 地址 |
|---|---|
| Hetzner | /ip4/5.222.20.175/tcp/9878/p2p/12D3KooWSAW5s7pFZeyfjtYzL8oUJHX3pL73LJrv14o6Sbg8NQp8 |
| Vultr | /ip4/45.76.147.10/tcp/9878/p2p/12D3KooWPWUb6EieuaSjYx7Mu51tv2yKr5p4MGCCQiX5XyuPT6yi |
CLI 不会自己去连它们:你不启动节点,P2P 就不开;bootstrap_peers 默认也是空的。要用它们,启动时把两条地址都传进去:
rotifer network start -b /ip4/5.222.20.175/tcp/9878/p2p/12D3KooWSAW5s7pFZeyfjtYzL8oUJHX3pL73LJrv14o6Sbg8NQp8 /ip4/45.76.147.10/tcp/9878/p2p/12D3KooWPWUb6EieuaSjYx7Mu51tv2yKr5p4MGCCQiX5XyuPT6yi一个账号第一次启动时,节点连任何地方之前会先征求你的同意(见 rotifer network consent)。
-b 只管这一次运行:它替换配置里的列表,不会写进配置。想每次都用官方节点,先停掉节点,再把两条地址写进 ~/.rotifer/network.json 的 bootstrap_peers。第一次 network start 之后才有这个文件(见配置):
"bootstrap_peers": [ "/ip4/5.222.20.175/tcp/9878/p2p/12D3KooWSAW5s7pFZeyfjtYzL8oUJHX3pL73LJrv14o6Sbg8NQp8", "/ip4/45.76.147.10/tcp/9878/p2p/12D3KooWPWUb6EieuaSjYx7Mu51tv2yKr5p4MGCCQiX5XyuPT6yi"]之后不带 -b 的 rotifer network start 就会连它们。想让 NAT 后面的节点也能经它们连到你,再加 --relay 和同样两条地址,节点会在每台上保留一个中继位置。
你连上的每个节点(包括这两台)都能看到你的 IP 地址和本节点的 PeerId。rotifer network consent --show 列出对端能看到的全部内容。
在同一网络的几台机器之间观察一个基因如何传播:
- 在每台机器上用可连的接口启动节点:
rotifer network start --host 0.0.0.0。节点通过 mDNS 互相发现,rotifer network peers会列出它们。从下个版本起,每台机器第一次启动时会征求同意:回答y,或者读过rotifer network consent --show后加--accept-p2p。 - 在任意一台机器上公告一个基因:
rotifer network announce <gene-name>。 - 在其他机器上,
rotifer network received会列出它,rotifer network search <gene-name>会在P2P network下显示它。
如果 mDNS 关了或被拦(比如加了 --no-mdns,或网络丢弃组播),就经一个节点加入:用 rotifer network status 记下它的 multiaddr,再用 rotifer network start --host 0.0.0.0 --bootstrap /ip4/<seed-ip>/tcp/9878/p2p/<seed-PeerId> 启动其他节点。
网络配置保存在 ~/.rotifer/network.json:
{ "node_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "listen_port": 9878, "bootstrap_peers": [], "enabled": false}bootstrap_peers 默认为空,你不填,节点就不连任何引导节点。可以填 /ip4/<ip>/tcp/<port>/p2p/<PeerId> 格式的 multiaddr,比如官方节点或你自己运行的节点;也可以在启动时传 --bootstrap,它在这一次运行里替换这个列表。
node_id 是本地配置标识;status / start 显示的 libp2p PeerId 才是其他节点在 --bootstrap multiaddr 里要用的。
从下个版本起,同意记录与这个文件分开存放,在 ~/.rotifer/p2p/consent.json(只有你能读)。它记下同意的是哪一版说明、什么时候、怎么同意的、用的哪个 CLI 版本;不记 IP 地址、PeerId 或主机。记录缺失或读不出来,一律当作没有同意,也没有任何环境变量能代替它。要撤回,请用 rotifer network consent --revoke,不要手动删文件,这样正在运行的节点也会一起停。
| 能力 | 状态 |
|---|---|
| 节点证书 | 签发服务还没有开放——rotifer network attest enable 会说明这一点,不会开启任何东西 |
| 在 DHT 上按关键词搜索 | 不支持——关键词匹配听到的公告和 Rotifer Cloud;DHT 只按 v2 基因 ID 查 |