Skip to content

PasteFerry (隔空贴): clipboard and file sync across macOS, Windows and Linux. Direct-first, end-to-end encrypted. Optional official access: no server to host. Independent self-hosting remains available.

18.3 KB
Raw Blame
<!doctype html>
<html lang="zh-CN">
<head>
  <meta charset="utf-8">
  <script>
    (function () {
      if (location.hostname !== "baiyuze.github.io") return;
      var prefix = /^\/(?:pasteferry|copysync)(?=\/|$)/.exec(location.pathname);
      if (!prefix) return;
      var path = location.pathname.slice(prefix[0].length) || "/";
      location.replace("https://pasteferry.cc" + path + location.search + location.hash);
    })();
  </script>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>工作原理:直连、多出口探测与出问题时的处理 — 隔空贴</title>
  <meta name="description" content="复制之后发生了什么,两台电脑怎么连上,连不上怎么办。">
  <link rel="canonical" href="https://pasteferry.cc/how/">
  <link rel="alternate" hreflang="zh-CN" href="https://pasteferry.cc/how/">
  <link rel="alternate" hreflang="zh-TW" href="https://pasteferry.cc/zh-tw/how/">
  <link rel="alternate" hreflang="zh-HK" href="https://pasteferry.cc/zh-hk/how/">
  <link rel="alternate" hreflang="en" href="https://pasteferry.cc/en/how/">
  <link rel="alternate" hreflang="ja" href="https://pasteferry.cc/ja/how/">
  <meta name="theme-color" content="#141416">
  <meta property="og:type" content="article">
  <meta property="og:site_name" content="隔空贴">
  <meta property="og:title" content="工作原理:直连、多出口探测与出问题时的处理 — 隔空贴">
  <meta property="og:description" content="复制之后发生了什么,两台电脑怎么连上,连不上怎么办。">
  <meta property="og:url" content="https://pasteferry.cc/how/">
  <meta property="og:image" content="https://pasteferry.cc/assets/og.png">
  <meta property="og:locale" content="zh_CN">
  <meta name="twitter:card" content="summary_large_image">
  <link rel="icon" href="../assets/favicon.svg?v=df696024d8" type="image/svg+xml">
  <link rel="icon" href="../assets/favicon-32.png?v=8e9afa506d" sizes="32x32" type="image/png">
  <link rel="apple-touch-icon" href="../assets/apple-touch-icon.png?v=bcbf406cb8">
  <link rel="stylesheet" href="../assets/site.css?v=dbae55d27c">
  <script>document.documentElement.classList.add("js");if (!/Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent)) document.documentElement.classList.add("pc");</script>
</head>
<body>
  <a class="skip" href="#main">跳到正文</a>

  <header class="bar">
    <div class="wrap">
      <a class="brand" href=".././" aria-label="隔空贴首页"><img src="../assets/icon.svg?v=65a69999e0" alt="" width="26" height="26">隔空贴</a>
      <nav aria-label="页面导航">
        <a href="../features/">功能</a>
        <a class="mid" href="../start/">快速开始</a>
        <a class="wide" href="../start/#server">连接方式</a>
        <a href="../download/">下载</a>
        <details class="menu">
          <summary aria-label="更多页面" class="current"><span>更多</span><svg class="chev" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m3 4.5 3 3 3-3"/></svg></summary>
          <ul>
            <li class="narrow"><a href="../start/">快速开始</a></li>
            <li class="narrow"><a href="../start/#server">连接方式</a></li>
            <li><a href="../themes/">主题教程</a></li>
            <li><a href="./" aria-current="page">工作原理</a></li>
            <li><a href="../security/">安全与隐私</a></li>
            <li><a href="../faq/">常见问题</a></li>
            <li><a href="../feedback/">讨论与反馈</a></li>
            <li class="sep" role="separator"></li>
            <li><a href="https://github.com/baiyuze/pasteferry/blob/main/CHANGELOG.md">更新记录</a></li>
            <li class="narrow-gh"><a href="https://github.com/baiyuze/pasteferry">GitHub</a></li>
          </ul>
        </details>
        <a class="gh" href="https://github.com/baiyuze/pasteferry" data-gh-stars aria-label="在 GitHub 上给隔空贴点 Star"><svg class="gh-mark" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z"/></svg><span class="gh-label">Star</span><span class="gh-count" hidden><svg class="gh-star" viewBox="0 0 16 16" aria-hidden="true"><path fill="currentColor" d="M8 .25a.75.75 0 01.673.418l1.882 3.815 4.21.612a.75.75 0 01.416 1.279l-3.046 2.97.719 4.192a.751.751 0 01-1.088.791L8 12.347l-3.766 1.98a.75.75 0 01-1.088-.79l.72-4.194L.818 6.374a.75.75 0 01.416-1.28l4.21-.611L7.327.668A.75.75 0 018 .25z"/></svg><b></b></span></a>
        <details class="lang">
          <summary aria-label="语言:简体中文"><svg viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.4" aria-hidden="true"><circle cx="10" cy="10" r="7.25"/><path d="M2.75 10h14.5M10 2.75c-2.1 2-3.1 4.4-3.1 7.25s1 5.25 3.1 7.25M10 2.75c2.1 2 3.1 4.4 3.1 7.25s-1 5.25-3.1 7.25"/></svg><span>简体中文</span><svg class="chev" viewBox="0 0 12 12" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m3 4.5 3 3 3-3"/></svg></summary>
          <ul>
            <li><a href="../how/" hreflang="zh-CN" lang="zh-CN" data-lang="zh" aria-current="page">简体中文</a></li>
            <li><a href="../zh-tw/how/" hreflang="zh-TW" lang="zh-TW" data-lang="zh-tw">繁體中文(台灣)</a></li>
            <li><a href="../zh-hk/how/" hreflang="zh-HK" lang="zh-HK" data-lang="zh-hk">繁體中文(香港)</a></li>
            <li><a href="../en/how/" hreflang="en" lang="en" data-lang="en">English</a></li>
            <li><a href="../ja/how/" hreflang="ja" lang="ja" data-lang="ja">日本語</a></li>
          </ul>
        </details>
      </nav>
    </div>
  </header>

  <main id="main">
    <section class="hero guide-hero">
      <div class="wrap">
        <p class="crumb"><a href=".././">隔空贴</a></p>
        <h1 class="display">工作原理</h1>
        <p class="lede">复制之后发生了什么,两台电脑怎么连上,连不上怎么办。</p>
      </div>
    </section>

    <section class="section" aria-labelledby="flow-title">
      <div class="wrap">
        <h2 id="flow-title">按下复制之后</h2>
        <p class="intro">文字、图片、文件都走同一条路。</p>
        <ol class="flow">
          <li><h3>发现</h3><p>后台服务察觉剪贴板变了。</p></li>
          <li><h3>传输</h3><p>文字和 50 MB 以内的文件马上发过去,更大的先发一条记录。</p></li>
          <li><h3>粘贴</h3><p>另一台存到本地再放进剪贴板,粘贴出来就是真实的文件。</p></li>
        </ol>
      </div>
    </section>

    <section class="section" id="diagram" aria-labelledby="how-title">
      <div class="wrap">
        <h2 id="how-title">隔空贴的连接方式</h2>
        <p class="intro">同一网络里直接找到对方;不在一个网络时,由服务器牵线后尽量直连,连不上才中转。内容始终加密。</p>
        <figure class="diagram">
          <svg viewBox="0 0 960 400" role="img" aria-labelledby="diagram-title diagram-desc">
            <title id="diagram-title">隔空贴的连接方式</title>
            <desc id="diagram-desc">电脑 A 与电脑 B 之间是 WebRTC 直连;两台电脑都通过信令连到服务器;直连失败时,数据经服务器的 TURN 中转。</desc>
            <rect class="d-box" x="360" y="24" width="240" height="96" rx="14"/>
            <text class="d-title" x="480" y="64" text-anchor="middle">信令与中转服务</text>
            <text class="d-sub" x="480" y="92" text-anchor="middle">信令、STUN、TURN 中转</text>
            <path class="d-sig" d="M140 210V58H360"/>
            <path class="d-sig" d="M820 210V58H600"/>
            <path class="d-relay" d="M196 210V100H360"/>
            <path class="d-relay" d="M764 210V100H600"/>
            <text class="d-note" x="210" y="50">信令:交换连接信息</text>
            <text class="d-note" x="210" y="128">中转:只在直连不通时</text>
            <rect class="d-box" x="40" y="210" width="240" height="120" rx="14"/>
            <text class="d-title" x="160" y="262" text-anchor="middle">Mac</text>
            <text class="d-sub" x="160" y="290" text-anchor="middle">在这里复制</text>
            <rect class="d-box" x="680" y="210" width="240" height="120" rx="14"/>
            <text class="d-title" x="800" y="262" text-anchor="middle">Mac、Windows 或 Linux</text>
            <text class="d-sub" x="800" y="290" text-anchor="middle">在这里粘贴</text>
            <path class="d-direct" d="M280 270H680"/>
            <text class="d-label" x="480" y="256" text-anchor="middle">WebRTC 直连,DTLS 加密</text>
            <text class="d-note" x="480" y="298" text-anchor="middle">数据只在两台电脑之间传</text>
            <g class="d-legend" transform="translate(40 372)">
              <path class="d-direct" d="M0 0H28"/><text x="38" y="5">数据(直连)</text>
              <path class="d-relay" d="M210 0H238"/><text x="248" y="5">数据(中转,备用)</text>
              <path class="d-sig" d="M470 0H498"/><text x="508" y="5">信令</text>
            </g>
          </svg>
          <ul class="points diagram-text">
            <li><strong>WebRTC 直连,DTLS 加密</strong> 数据只在两台电脑之间传</li>
            <li><strong>信令与中转服务</strong> 信令、STUN、TURN 中转</li>
            <li>中转:只在直连不通时</li>
          </ul>
        </figure>
      </div>
    </section>

    <section class="section" id="multi-uplink" aria-labelledby="multi-title">
      <div class="wrap">
        <h2 id="multi-title">公司网络也能直连</h2>
        <p class="intro">多出口的公司网络以前只能中转。隔空贴会探出每个出口,让对方逐个尝试。</p>
        <div class="cols">
          <div>
            <h3>做了什么</h3>
            <ul class="points">
              <li><strong>共用一个端口。</strong>所有连接走同一个 UDP 端口。</li>
              <li><strong>探测每个出口。</strong>同时问 7 台服务器,有几个出口就拿到几个地址。</li>
              <li><strong>全部告诉对方。</strong>对方逐个尝试,对上的那个就能连通。</li>
              <li><strong>空闲时再试直连。</strong>先用中转保证能用,空闲时再换成直连。</li>
            </ul>
          </div>
          <div>
            <h3>用真实的网络拓扑测试</h3>
            <p class="small">每次提交代码都会在模拟的网络里自动跑一遍。</p>
            <div class="table-scroll">
              <table>
                <thead><tr><th scope="col">场景</th><th scope="col">结果</th></tr></thead>
                <tbody>
                <tr><td>单出口 ↔ 家用路由器</td><td>直连</td></tr>
                <tr><td>两个出口,旧版本(对照)</td><td>中转</td></tr>
                <tr><td>四个出口 ↔ 家用路由器</td><td>直连</td></tr>
                <tr><td>两个出口 ↔ 两个出口</td><td>直连</td></tr>
                <tr><td>两个出口 ↔ 端口随机分配的 NAT</td><td>中转</td></tr>
                <tr><td>一开始打不通,之后网络恢复</td><td>先中转,随后直连</td></tr>
                <tr><td>没有服务器,同一网段</td><td>直连</td></tr>
                <tr><td>没有服务器,两个网段之间被隔离</td><td>连不上</td></tr>
                </tbody>
              </table>
            </div>
            <p class="small">实测:公司 4 个出口的 Mac 和家里的 Mac,以前中转 0.6 MB/s,现在直连。</p>
            <p class="small">细节见<a href="../design/nat-traversal.html">技术方案</a>。</p>
          </div>
        </div>
      </div>
    </section>

    <section class="section" id="fallbacks" aria-labelledby="fallback-title">
      <div class="wrap">
        <h2 id="fallback-title">出问题的时候</h2>
        <p class="intro">常见的情况,都有处理。</p>
        <dl class="fallbacks">
          <div><dt>同一网络里找不到对方</dt><dd>配对时填上对方的地址,之后会记住。</dd></div>
          <div><dt>打不通直连</dt><dd>经服务器中转,内容同样加密。</dd></div>
          <div><dt>对方睡眠或断网</dt><dd>醒来后自动重连。</dd></div>
          <div><dt>传文件时断开</dt><dd>连上后从断点接着传。</dd></div>
          <div><dt>文件名在 Windows 上不合法</dt><dd>换成全角字符,名字照样看得懂。</dd></div>
          <div><dt>复制的是密码</dt><dd>Windows 上密码管理器复制的内容会被跳过。</dd></div>
        </dl>
      </div>
    </section>

    <section class="section" id="specs" aria-labelledby="specs-title">
      <div class="wrap">
        <h2 id="specs-title">技术规格</h2>
        <div class="table-scroll">
          <table class="specs">
            <tbody>
            <tr><th scope="row">版本</th><td>2.10.1,<time datetime="2026-11-07">2026 年 11 月 7 日</time>发布</td></tr>
            <tr><th scope="row">Mac 客户端</th><td>macOS 13 Ventura 及以上;Apple 芯片与 Intel 芯片各有一个安装包,约 25 MB,不需要 Rosetta;也有两种芯片通用的版本,约 47 MB</td></tr>
            <tr><th scope="row">Windows 客户端</th><td>Windows 10 与 Windows 11,x64;按用户安装,不需要管理员权限;安装包约 23 MB</td></tr>
            <tr><th scope="row">Linux 客户端</th><td>x64 与 ARM64;.deb(Debian、Ubuntu 等)或 tar.gz(其他发行版),约 22 MB;需要 X11 桌面,或者带 XWayland 的 Wayland 桌面(GNOME、KDE 等默认都带);GTK 3</td></tr>
            <tr><th scope="row">服务器</th><td>用「服务」或在同一网络里都不需要。自建的话,支持 Linux x86_64/ARM64、macOS 与 Windows 10/11 x64。</td></tr>
            <tr><th scope="row">界面语言</th><td>简体中文、繁體中文(台灣、香港)、English、日本語,默认跟随系统,可在设置里切换</td></tr>
            <tr><th scope="row">同步的内容</th><td>纯文本、带格式的文本、图片与截图、文件、文件夹,可以按类型关闭</td></tr>
            <tr><th scope="row">传输</th><td>WebRTC 数据通道,直连优先,打不通时经 TURN 中转;同一网络里经 mDNS 发现、UDP 8788 交换连接信息;多出口网络逐个探测每个出口;文件以 tar + zstd 流式打包</td></tr>
            <tr><th scope="row">加密与身份</th><td>DTLS 端到端加密;设备身份为 Ed25519 密钥;信令消息逐条签名</td></tr>
            <tr><th scope="row">配对</th><td>6 位配对码,5 分钟内有效,字符集去掉了 0/O、1/I 等易混字符;配对时人工核对安全指纹</td></tr>
            <tr><th scope="row">自动同步上限</th><td>默认 50 MB,可在 1 MB 到 1 GB 之间调整</td></tr>
            <tr><th scope="row">隔空传送</th><td>发给一台设备,不限大小,文件和整个文件夹都行;局域网里走加密的 TCP 通道(两端需 2.5.1),用不了时退回 WebRTC;外网和中转用 WebRTC;断了接着传,每个文件用 SHA-256 校验。Mac 发 1 GB 到 Linux 虚拟机实测 144.3 MB/s,实际速度看网络和硬盘。</td></tr>
            <tr><th scope="row">好友</th><td>F 开头的 7 位好友码,经局域网或「服务」交换,可以核对安全码;好友之间只能互发文件和图片,可附 200 字以内的备注,每批都要对方接受;好友看不到你的剪贴板、复制记录和设备;收到的文件去掉可执行权限,Mac 上加隔离标记;两端需 2.6 或更新</td></tr>
            <tr><th scope="row">记录保留</th><td>默认 3 天,可在 1 小时到 30 天之间调整,到期自动清理</td></tr>
            <tr><th scope="row">实测速度</th><td>局域网直连传输 20 MB 文件约 330 毫秒,校验和一致</td></tr>
            <tr><th scope="row">技术栈</th><td>后台服务与服务器用 Go(Windows 上纯 Go 调用 Win32,Linux 上纯 Go 走 X11 协议),界面用 Flutter(三个系统共用一套代码),消息定义用 Protocol Buffers</td></tr>
            <tr><th scope="row">许可</th><td><a href="https://github.com/baiyuze/pasteferry/blob/main/LICENSING.md">GNU AGPL-3.0</a></td></tr>
            </tbody>
          </table>
        </div>
      </div>
    </section>
  </main>

  <footer class="footer">
    <div class="wrap">
      <p>隔空贴以 GNU AGPL-3.0 开源。</p>
      <nav aria-label="页脚链接">
        <a href="https://github.com/baiyuze/pasteferry/releases">所有版本</a>
        <a href="https://github.com/baiyuze/pasteferry/blob/main/CHANGELOG.md">更新记录</a>
        <a href="https://pasteferry.cc/design/nat-traversal.html">技术方案</a>
        <a href="https://github.com/baiyuze/pasteferry/blob/main/LICENSING.md">许可说明</a>
        <a href="https://github.com/baiyuze/pasteferry/issues">反馈问题</a>
        <a href="../privacy/">隐私说明</a>
        <a href="../feedback/">讨论与反馈</a>
      </nav>
      <nav aria-label="语言">
        <a href="../how/" hreflang="zh-CN" lang="zh-CN" data-lang="zh" aria-current="page">简体中文</a>
        <a href="../zh-tw/how/" hreflang="zh-TW" lang="zh-TW" data-lang="zh-tw">繁體中文(台灣)</a>
        <a href="../zh-hk/how/" hreflang="zh-HK" lang="zh-HK" data-lang="zh-hk">繁體中文(香港)</a>
        <a href="../en/how/" hreflang="en" lang="en" data-lang="en">English</a>
        <a href="../ja/how/" hreflang="ja" lang="ja" data-lang="ja">日本語</a>
      </nav>
    </div>
  </footer>

  <script src="../assets/site.js?v=fb60f6e5ce" defer></script>
  <script src="/assets/analytics.js?v=e2777f714d" defer></script>
  <script type="module" src="https://static.cloudflareinsights.com/beacon.min.js" data-cf-beacon='{"token": "7ee226baf4a949a397c4bfd69a9e7461"}'></script>
</body>
</html>