<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Croath Liu on Medium]]></title>
        <description><![CDATA[Stories by Croath Liu on Medium]]></description>
        <link>https://medium.com/@croath?source=rss-a23cd5271080------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*g-G95XPrllsueCNyGyKtig.jpeg</url>
            <title>Stories by Croath Liu on Medium</title>
            <link>https://medium.com/@croath?source=rss-a23cd5271080------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 19:36:10 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@croath/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[BNS 比特币域名服务 & 支撑 BNS 的去中心化网络 Rings Network 解析]]></title>
            <link>https://medium.com/@croath/bns-%E6%AF%94%E7%89%B9%E5%B8%81%E5%9F%9F%E5%90%8D%E6%9C%8D%E5%8A%A1-%E6%94%AF%E6%92%91-bns-%E7%9A%84%E5%8E%BB%E4%B8%AD%E5%BF%83%E5%8C%96%E7%BD%91%E7%BB%9C-rings-network-%E8%A7%A3%E6%9E%90-85fb1c7e6102?source=rss-a23cd5271080------2</link>
            <guid isPermaLink="false">https://medium.com/p/85fb1c7e6102</guid>
            <category><![CDATA[btc]]></category>
            <category><![CDATA[bn]]></category>
            <category><![CDATA[ring-network]]></category>
            <category><![CDATA[chords]]></category>
            <category><![CDATA[decentralization]]></category>
            <dc:creator><![CDATA[Croath Liu]]></dc:creator>
            <pubDate>Wed, 22 Feb 2023 07:56:32 GMT</pubDate>
            <atom:updated>2023-02-22T08:03:20.045Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uRncjOpIQspM-YPkXbjsuA.png" /><figcaption>Rings Network</figcaption></figure><h3>概述</h3><h4>BNS 是什么</h4><p><a href="https://bns.org/">BNS (Bitcoin Name Service)</a> 是一种基于区块链的域名服务系统，称为 Bitcoin Name Service，它是一个可跨链的统一域名系统，兼容目前和未来的所有公有链。BNS 持有者可以使用以 <em>.btc </em>结尾的 BNS 域名在各种区块链地址中进行支付、聊天、视频游戏以及数据流传输，同时也是一个完全免费和主权个人的域名系统。</p><h4>Rings Network 是什么</h4><p><a href="https://ringsnetwork.io/">Rings Network</a> 是为了实现上述目的而设计的 P2P 网络。Rings Network <strong>不是公链</strong>，也不同于现有的区块链系统，可以看作是整个区块链系统的基础设施。它虽然不是公链，但是在它的基础上可以构建公链，也可以构建仅基于去中心化网络而不基于区块链的应用。它可以打通以太网络和 Solana 等不同公链的地址交互，使不同公链上的人能够一起进行聊天、游戏、视频传输、文件传输以及原子交换。BNS 则是 Rings Network 的 DID（数字身份）系统。</p><p>开发者可以使用 Rings Network 构建基于 P2P 网络的应用程序。Rings Network 利用 <a href="https://en.wikipedia.org/wiki/Chord_(peer-to-peer)">Chord 算法</a> 构建了一个轻量级的分布式哈希表（DHT, Distributed Hash Table），可以支持最多 2¹⁶⁰ 个节点的在线运行。这样，我们可以使用 Rings Network 实现分布式存储和去中心化 Web（dWeb）。Rings Network 网络还允许创建隐藏的服务，以提供匿名和隐私。此外，DHT 可以查找网络中的节点，这些节点可用于不同类型的路由和通信。</p><p>如果你了解 <a href="https://github.com/nostr-protocol/nostr">Nostr</a>，那么其实 Rings Network 和 Nostr 都属于去中心化网络，只是设计哲学和实现方式有所不同，Rings Network 中没有专职的 relay（转发节点）概念</p><h4>BNS 和 Rings Network 有什么关系</h4><p><strong>去中心化网络中更高效的域名解析</strong></p><p>因为 Rings Network 是一个去中心化的网络，它不需要依赖于中心化的服务器或第三方，从而避免了数据的单点故障、数据的安全和隐私的问题。由于 Rings Network 的 P2P 网络架构和冗余分布的节点系统，它可以提供更快、更稳定和更安全的域名解析服务。因此，在 Rings Network 上使用 BNS 域名服务可以为用户提供更好的体验和更高效的域名解析。</p><p>目前 BNS 的基础合约是部署在 Ethereum 上的，未来将基于 Ethereum 上 BNS 域名注册合约进行同步，在 Rings Network 中实现 dDNS（去中心化域名解析服务）功能。</p><p><strong>增加用户的控制权和所有权</strong></p><p>BNS 采取的是<strong>免费注册</strong>和<strong>免费续期</strong>机制。这可以显著提高用户的控制权和所有权，因为这意味着用户不需要频繁支付昂贵的续期费用，也不需要担心域名注册商收回域名。用户在注册完域名后就可以拥有这个域名，并且在续期时不需要再支付任何费用。用户知道这个域名永远属于他们，而不是由发行商不断收费才能使用。</p><p>和我们常见的 ERC20(FT) 以及 ERC721(NFT) 一样，你购买了某代币或者 NFT，则理所应当该资产应当永久属于你控制，这也是区块链金融和资产和中心化金融和资管的不同之处，你不再受银行等机构控制你的财产。</p><p>那么域名服务理所应当也是这样的，在去中心化的世界里没有人可以声明自己拥有了某个根域名就可以持续向用户收费才能使用其上注册域名。域名的本质还是资产，只不过是一个「资产化的名字」，你拥有了，那么就应该永远属于你。</p><p>续期（而不是续费）机制是为了防止长期未使用的域名沉没，同样也是免费的。</p><p><strong>去中心化的网站和应用的身份</strong></p><p>BNS 可以独立地将开发者的去中心化网站和去中心化应用的名称映射到对应的公钥地址，使得用户可以通过易于记忆的域名来访问网站和应用，而不需要记住复杂的公钥地址。因此，BNS 可以为去中心化的网站和应用提供独特的身份，并为用户提供更直接的访问途径。当然没有域名的情况下，你也可以通过公钥找到对方，进行网站访问、应用使用、直接发送私信等。</p><h3>BNS 的特点</h3><h4>开放使用</h4><p>除赠予行业内初期用户一些少量域名外，BNS 项目方<strong>不保留</strong>任何域名。3 位数及以下的域名将延后开放注册，3 位以上的所有域名均开放注册。</p><h4>免费注册与续期</h4><p>免费注册，免费续期，除 Ethereum 网络收取的 gas 费用之外，BNS 项目方不收取任何费用。</p><h4>版税收入与回购</h4><p>BNS 将上线各大 NFT 交易市场方便用户进行二级交易，二级市场交易可能会收取少量版税或不收取版税，额度将取决于社区投票结果。</p><p>倘若收取版税，官方将预计使用版税收入的 50% ~ 100%（后期百分比取决于社区投票结果）将用于对 Rings Network 的代币进行回购。</p><h3>BNS 与 Rings Network 代币经济</h3><h4>持有 BNS 并在 Rings Network 上挖矿</h4><p>持有 BNS 域名可以参与挖矿，Rings Network 采用的是浏览器挖矿方式。官方网站上有详细的关于挖矿逻辑的技术文档，有兴趣的可以去阅读：</p><p><a href="https://bns.org/zh/#mining">BNS 挖矿机制</a></p><h4>为 Rings Network 的生态和 Token 创造价值</h4><p>在 Rings Network 上开启浏览器节点并挖矿的同时，也可以为网络做出卓越贡献，方式包括但不限于：</p><ol><li>基于浏览器的跨链域名P2P通讯（例如，以太坊上域名和 Aptos 域名、BNS 域名、BNB 域名之间可以在不同链间聊天）。</li><li>基于浏览器的去中心化前端导航（例如，用户可以在我们的网站/插件上直接访问 Tornado Cash）。</li><li>正在开发的是一个基于原子交换和 P2P 的去中心化交易系统。由于 Rings Network 提供的状态通道，原子交换变得像使用 Uniswap 一样简单，这将带来颠覆式的交易模式的创新。</li></ol><p>参与挖矿的人数越多，节点数便越多。这和普通的中心化应有是相反的，中心化应用随着用户数量增加单节点压力会越来越大服务会越来越不稳定，Rings Network 的网络特性是节点数越多连接越稳定速度越快，所以更多人参与会使 Rings Network 更强壮可用性更强。</p><h3>Rings Network 深入探讨</h3><h4>Rings Network 的定义</h4><p><strong>点对点网络</strong></p><p>点对点网络（peer-to-peer 或 P2P）又称对等网络，是去中心化、依靠用户群（peers）交换信息的互联网体系，它的作用在于，减低以往网路传输中的节点，以降低资料遗失的风险。</p><p>与有中心服务器的中央网络系统不同，对等网络的每个用户端既是一个节点，也有服务器的功能，任何一个节点无法直接找到其他节点，必须依靠其户群进行信息交流。</p><blockquote>关于点对点网络和中心化网络的差异，以及 Rings Network 和 Nostr 的区别，可以参考我之前写的这篇文章：</blockquote><p><a href="https://medium.com/@croath/%E5%8E%BB%E4%B8%AD%E5%BF%83%E5%8C%96%E7%82%B9%E5%AF%B9%E7%82%B9%E7%BD%91%E7%BB%9C%E7%AE%80%E5%8F%B2-%E7%8E%B0%E4%BB%A3%E5%8E%BB%E4%B8%AD%E5%BF%83%E5%8C%96%E7%BD%91%E7%BB%9C-nostr-%E5%92%8C-ringsnetwork-8283bb60923b">去中心化点对点网络简史 | 现代去中心化网络 #Nostr 和 #RingsNetwork</a></p><p><strong>Rings Network 的去中心化网络设计</strong></p><p>Rings Network 使用的是 Chord 环状网络，所有节点依次列成一个环，然后通过算法控制，各个节点也会和环上其他节点建立若干个链接，当某个链接断开时（例如节点退出或网络断开），算法会控制不影响其他节点运行而重新组成环和建立新的链接。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/990/1*92H5Crbdvf-gQpCXFc26Gw.png" /><figcaption>来自 Rings Network 白皮书 Network Layer 章节的 Chord 网络结构图</figcaption></figure><h4>Rings Network 的特点</h4><p><strong>面向浏览器用户</strong></p><p>Rings Network 从第一行代码开始就优先考虑浏览器可用性，全节点服务可以<strong>完整地运行在浏览器</strong>中而非 SDK 调用中心化节点的方式，换言之你在浏览器中加载的 Rings Network 节点和程序员在服务器上运行的节点是<strong>完全对等、功能完全相同的</strong>。这点和现有的区块链节点或其他去中心化网络的连接方式上是有很大不同的。</p><p>目前尚无其他网络可以做到此种体验，因为其他类型的网络使用了太多只有服务器上才能开启的特性，这使得他们开发浏览器版本的应用变得十分困难。例如我们常见的数据库、连接池、加密解密方式、数据存储模块等，大多数网络都是使用服务器上专用的解决方案进行集成，而 Rings Network 则是选择浏览器和服务器均支持的方式进行开发。</p><p>想象一下如果你基于 Rings Network 开发了一个新型区块链，那么他将没有所有 RPC 节点的概念，因为你打开网页的那一刻，你的网页本身也就成为了节点。</p><p><strong>连接方式</strong></p><p>Rings Network 节点间是基于 <a href="https://en.wikipedia.org/wiki/WebRTC">WebRTC</a> 的，节点间可以进行 p2p 连接。WebRTC 较多应用在视频流或语音流场景中，例如直播、直播播放、在线会议等。WebRTC 本身也是对 p2p 友好的，它无需得到你具体的 IP 地址和端口的组合，以及在这个端口上运行好监听服务才能开启使用，两台分别在不同内网的浏览器页面即可轻松互相连接，这也是我们所熟知的 HTTP 请求无法办到的。</p><p>此处连接方式上可以看得出 Rings Network 在设计上有很强的指向性 — — 为 web 服务。浏览器目前是大家主流的互联网交互方式，脱离浏览器的 app 则会受到例如 App Store 或 Google Play 等中心化组织的审核审查，所以本身可运行在浏览器中、连接方式被浏览器默认支持是非常重要的。WebRTC 在浏览器中进行高效、并行连接，或进行流式数据传输。</p><p><strong>可扩展性和效率</strong></p><p>Rings Network 网络中没有中心节点，所有节点在整个网络中具有相同的角色。都可独立工作，亦可帮助其他节点转发消息。任何节点加入网络或突然从网络中断开均不影响网络稳定性，所有节点均可随时随地加入或离开不会造成网络不可用级别的抖动，经过测试如果有 50% 的连接突然断开，网络可用性仍可以达到 97% 以上。这都归功于 Chord 网络结构的优秀设计，也正是这种特性造就了 Rings Network 极强的可扩展性。</p><p>数据分布存储在 Rings Network DHT 的各个节点上，而不是像 Ethereum 网络一样你搭建节点时需要同步好 1T 的全节点数据才能开始使用。在 Rings Network 中当你需要查询数据时，你会直接向全网发起查询而非查询本地的数据存储，寻址算法会迅速找到离你最近的存储该数据的一个或几个节点，并将该数据返回给你。你甚至不需要直接连接到那个节点，中继节点（每一个节点都是中继节点）即可转发结果给你。</p><p>目前 DHT 中存储的数据较少，仅包含各个节点的连接信息。你不能向通用 DHT 中写入额外的数据。但是如果你想要构建区块链或需要存储的去中心化应用时，未来你可以自由声明自己的子网（Sub-Ring）进行数据存储或要求全量数据同步，加入该子网的用户便可以享受到自定义数据存储和读取的特性。</p><p><strong>服务整合</strong></p><p>开发者可以方便地将各种去中心化或中心化服务整合到 Rings Network 节点中，甚至无需阅读源码即可实现这一点。你只需要运行类似如下的代码：</p><pre>rings service register &lt;name&gt;</pre><p>该服务器上或浏览器上的节点即可向全网告知当前节点可以提供某项服务了。</p><p>举例说明，我们已经有一个 ipfs 的服务了，那么以上述方式进行服务注册时，该节点即可转发 ipfs 的内容，格式即为 ipfs rpc 中定义的格式。当其他用户打开浏览器并选择查询 ipfs 服务时即可找到多个注册了 ipfs 服务的节点并从多节点中直接获取 ipfs 的内容。</p><p>类似地，Ethereum Node RPC 也可以通过这一行代码开放给整个 Rings Network 使用。</p><p>不仅仅是上述的去中心化服务，甚至我们很多熟知的中心化服务也可以这样在网络中提供，例如：MySQL，Proxy，Redis 等。你甚至可以使用网络上提供 pytorch api 的 Rings 节点进行分布式地 AI 训练/推断服务。</p><h4>使用 Rings Network 的好处</h4><p><strong>增加安全性和隐私</strong></p><p>Rings Network 中可以开启强制转发功能和转发层数设定，这代表着你不从任何节点直接获取数据（避免对方定位你），转发层数越多，速度越慢，隐蔽性越强。转发层数越少，速度越快，隐蔽性越弱。你可以根据自己的需求进行分应用的调整，例如在游戏或聊天场景使用默认设置以求最高效率。在邮件或隐私交易场景中设置较高隐私级别来躲避流量追踪。</p><p><strong>统一身份 DID</strong></p><p>Rings Network 中使用 ECDSA 椭圆曲线映射私钥，这代表则无论你在使用任何一条链的私钥，都可以使用该链的钱包进行签名并使用这个身份作为你在 Rings Network 中的统一身份，这样也就可以让不同区块链的用户共同在一个去中心化网络中进行交互。</p><p>当你拥有了 BNS 域名后，更短更好记忆的 .btc 短域名则是更优方案，他可以解析到你在任何链的地址，方便用户间互相寻找而不用关心对方在什么链。</p><p><strong>临时性的加密数据通道</strong></p><p>任何两个节点都可以建立一个短时间内加密的数据通道，基于这个数据通道双方可以方便地交换各种信息，包括 <a href="https://academy.binance.com/zh/articles/atomic-swaps-explained">原子交换</a> 中的 secret 和 hash 等，并且双方都可以不用了解具体的交换和验证细节，这使得很多原本需要大量专业知识才能做到的事情变得简单起来了，例如原子交换、跨链去中心化无金库桥、跨链 NFT 交易、去中心化 NFT OTC 平台、闪电网络等。</p><h3>相关阅读</h3><p>去中心化点对点网络简史：</p><p><a href="https://medium.com/@croath/%E5%8E%BB%E4%B8%AD%E5%BF%83%E5%8C%96%E7%82%B9%E5%AF%B9%E7%82%B9%E7%BD%91%E7%BB%9C%E7%AE%80%E5%8F%B2-%E7%8E%B0%E4%BB%A3%E5%8E%BB%E4%B8%AD%E5%BF%83%E5%8C%96%E7%BD%91%E7%BB%9C-nostr-%E5%92%8C-ringsnetwork-8283bb60923b">去中心化点对点网络简史 | 现代去中心化网络 #Nostr 和 #RingsNetwork</a></p><p>Rings Network 白皮书：</p><ol><li>Rings 网络白皮书 <a href="https://raw.githubusercontent.com/RingsNetwork/whitepaper/master/rings.pdf">https://raw.githubusercontent.com/RingsNetwork/whitepaper/master/rings.pdf</a></li><li>BNS 白皮书 <a href="https://raw.githubusercontent.com/RingsNetwork/whitepaper/master/bns.pdf">https://raw.githubusercontent.com/RingsNetwork/whitepaper/master/bns.pdf</a></li><li>BNS 与 Rings Network 节点抵押挖矿白皮书 <a href="https://raw.githubusercontent.com/RingsNetwork/whitepaper/master/pos.pdf">https://raw.githubusercontent.com/RingsNetwork/whitepaper/master/pos.pdf</a></li></ol><p>Rings Network 官网：</p><p><a href="https://ringsnetwork.io/">Rings Network - The Communication Layer of web3</a></p><p>BNS 官网：</p><p><a href="https://bns.org/">BNS - Bitcoin Name Service</a></p><p>Rings Network 源码：</p><p><a href="https://github.com/RingsNetwork/rings-node">GitHub - RingsNetwork/rings-node: Rings is a structured peer-to-peer network implementation using WebRTC, Chord algorithm, and full WebAssembly (WASM) support.</a></p><p>Twitter:</p><p><a href="https://twitter.com/RingsNetworkio">https://twitter.com/RingsNetworkio</a> | <a href="https://twitter.com/bnsbtc">https://twitter.com/bnsbtc</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85fb1c7e6102" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[低成本体验生成 AI 小姐姐照片]]></title>
            <link>https://medium.com/@croath/%E4%BD%8E%E6%88%90%E6%9C%AC%E4%BD%93%E9%AA%8C%E7%94%9F%E6%88%90-ai-%E5%B0%8F%E5%A7%90%E5%A7%90%E7%85%A7%E7%89%87-85ffa7c13cd7?source=rss-a23cd5271080------2</link>
            <guid isPermaLink="false">https://medium.com/p/85ffa7c13cd7</guid>
            <category><![CDATA[stable-diffusion]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[ai]]></category>
            <category><![CDATA[lora]]></category>
            <category><![CDATA[chatgpt]]></category>
            <dc:creator><![CDATA[Croath Liu]]></dc:creator>
            <pubDate>Sat, 18 Feb 2023 16:47:57 GMT</pubDate>
            <atom:updated>2023-02-19T05:05:37.528Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qFk6hlXpLn4uHySw3lqd3Q.png" /><figcaption>来自 <a href="https://twitter.com/auditore_k">auditore_k</a> 生成的照片</figcaption></figure><h3>前言</h3><p>近期 AI 领域被 ChatGPT 又带火起来了，ChatGPT 如此庞大的训练语料和参数数量是一般人难以进行实践的，我一直关注 Stable Diffusion 的发展，同时也知道无论是能力还是财力，我个人其实是不容易做出属于自己的很特别的模型，但是对这方面一直有兴趣，所以即使没有能力做训练（train），也想体验使用其他人模型创造一些内容（inference）。</p><p>这里先介绍两个网站，对于有能力探寻更深入的人会有所帮助：</p><blockquote><a href="https://huggingface.co/">https://huggingface.co/</a> ，Hugging Face 上有很多数据集可以用来做训练，也可以基于其他人共享的数据集进行训练，比自己找数据要方便很多，也有 auto train 功能，可以使用他们付费的服务进行训练。也可以创建 space 来快速给一个训练好的模型生成 API 接口，方便以服务的形式开放给他人使用或者让自己的其他服务调用。有了这些功能深度学习工程师便可以更专注于深度学习本身，而不用特别关注训练数据的来源或者如何部署机器进行训练、回测以及接口化。</blockquote><blockquote><a href="https://civitai.com/">https://civitai.com/</a> CivitAI 主要是模型分享以及社区，用户会在其他人的模型下面回复通过这个模型生成的样本，以及生成时的参数和 seed，方便我们调试其他人模型时可以参考已有的输出进行快速尝试，不然可能会一直觉得自己生成的不够好。</blockquote><h3>ChilloutMix &amp; LoRA</h3><p>首先，我选用的基础模型是 <a href="https://civitai.com/models/6424/chilloutmix">https://civitai.com/models/6424/chilloutmix</a> ，这个模型擅长于生成亚洲女性特征的图片。</p><p>其次，选择一个自己顺眼的 LORA 训练模型。LoRA（Low-Rank Adaptation of Large Language Models）粗略地讲就是利用少量的图像来对 AI 进行额外学习训练，并在一定程度上控制结果。</p><p>流程上也比较简单，就是基于 ChilloutMix 的训练结果和你自己准备的数据集来进行二次训练，目的是最终输出的内容既具有原始 ChilloutMix 的能力，又更倾向你提供的数据的特征。</p><p>这里我尝试了三个 LORA 模型：</p><ul><li><a href="https://civitai.com/models/7448/korean-doll-likeness">Korean Doll Likeness | Stable Diffusion LORA | Civitai</a></li><li><a href="https://civitai.com/models/7716/taiwan-doll-likeness">Taiwan Doll Likeness | Stable Diffusion LORA | Civitai</a></li><li><a href="https://civitai.com/models/10135/japanese-doll-likeness">Japanese Doll Likeness | Stable Diffusion LORA | Civitai</a></li></ul><p>他们本质上没有区别，但是因为二次训练集的差别，三个模型输出的内容特征分别倾向于：韩国女性、台湾女性、日本女性。当然你也可以生成中国女性、越南女性、二次元女性等等专属的模型，甚至去训练二次元图像或 NSFW 图像。每一种模型都有自己的特长，LoRA 的目的就是各具所长地进行输出而不是一个通用模型。</p><h3>搭建环境</h3><p>这里我以 Taiwan Doll Likeness 为例来叙述使用方法。</p><p>我们打开 Taiwan Doll Likeness 模型的页面，会看到页面右边有一个 ▶️ 按钮：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/910/1*8qA5fcXt82El1ES07epDwg.png" /><figcaption>Taiwan Doll Likeness 页面右侧的 ▶️ 按钮</figcaption></figure><p>点开之后显示的是可以用哪些软件进行 inference（推断）：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a5ic-nlbGZA1x1Mb9y-UHg.png" /><figcaption>软件可用性</figcaption></figure><p>这里我们发现可用的只有一个，就是 Automatic 1111 Web UI (Local)。意思就是你要先配置好 Automatic 1111 Web UI 这个软件，然后它是运行在你本地的，而不是一个服务。</p><p>下面不可用的服务意思是这个模型没有提供支持下列服务的方式，可以简单认为互不兼容的意思。</p><blockquote>如果你不具备基础的编程能力（例如安装软件环境或配置服务器等），你可以不用看这一章的内容了，上面图中最后一个软件是 Draw Things，这个软件在 macOS 和 iOS 上都可以下载到，你可以选择例如 <a href="https://civitai.com/models/3950/art-and-eros-aeros-a-tribute-to-beauty">https://civitai.com/models/3950/art-and-eros-aeros-a-tribute-to-beauty</a> 支持 Draw Things 运行的模型，就可以不用写代码就可以通过界面交互的方式在软件里去尝试。当然 ChilloutMix 也是支持 Draw Things 的。</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H2nZQujGCQiLRccca8YlGQ.png" /><figcaption>我使用 Draw Things 来生成的一张图片</figcaption></figure><h3>租用服务器</h3><p>如果你已经选择好要运行软件的机器了，可以跳过这一章。</p><p>如果你用的电脑没有额外的显卡，或者在用不带外接显卡的苹果设备，抑或网络条件较差，那么强烈建议你租用一台有显卡的服务器进行尝试，这样会在下载和生成的时候节约大量的时间。</p><blockquote>我自用的 MacBook Pro 配有 M1 Pro 8 核心 CPU 和 16GB ram，生成图片的速度很慢，大概生成 steps 在 20 左右的低清晰度图片需要 5–10 分钟。而在一台共享 GPU 的服务器上 10s 之内可以完成。</blockquote><p>如果你不知道如何选择服务器，这里我推荐 <a href="https://www.vultr.com/?ref=6981435">Vultr</a> 的服务器，相对其他大厂商而言 Vultr 页面配置简单，价格也相对低廉，在小厂商中也是少有的提供 GPU 服务器的厂商。而且支持虚拟货币和支付宝支付，没有国际信用卡的朋友用起来也方便。</p><p>你可以使用我的邀请链接注册 Vultr，这样我们都可以获得 $10 的抵扣额度：</p><p><a href="https://www.vultr.com/?ref=6981435">SSD VPS Servers, Cloud Servers and Cloud Hosting</a></p><p>创建服务器时选择 Cloud GPU 并选择 NVIDIA A40 系列：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jrdM5rs4ssJUSTOVEgjtjg.png" /><figcaption>Cloud GPU + A40</figcaption></figure><p>选择 1/6 GPU 和 8GB 显存的版本，这种配置是我对比下来性价比最高的。记得关掉自动备份的开关，每个月可以省 $42。这样的花平均一天的成本就是 $7，我只开了几个小时，总共花费 $2 就可以进行非常完整的体验了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NPtEN3g0bTpwWsyKUKdyTw.png" /><figcaption>记得关闭自动备份</figcaption></figure><h3>配置环境</h3><p>先打开 <a href="https://github.com/AUTOMATIC1111/stable-diffusion-webui">https://github.com/AUTOMATIC1111/stable-diffusion-webui</a> 根据项目介绍 Automatic Installation on Linux 这一章节在服务器上进行安装，安装过程比较简单，不会出现什么意外的错误，但是记得不要用 root 用户进行安装，如果创建 sudo 权限用户请自行搜索。</p><p>安装完之后先不要运行，项目需要在启动阶段加载一个模型否则启动不了。</p><p>在 ChilloutMix 页面右侧找到下载按钮，取得下载地址后在服务器上进行下载，模型大小 3.97GB 大概几分钟时间可以下载好，下载好的模型请放置在stable-diffusion-webui 项目下的 models/Stable-diffusion/ 目录下，并确认下载好的文件名结尾为 .ckpt。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XF3-roYkr2b6cjLqWa8_NQ.png" /><figcaption>下载 ChilloutMix</figcaption></figure><p>同样的，前往 Taiwan Doll Likeness 页面下载模型，并放置在 models/Lora/ 目录下，也请确认扩展名为 .safetensors。</p><p>模型都下载好后，就可以运行 webui.sh 启动软件了。启动起来的服务监听在 127.0.0.1，我通过 cloudflared 进行 tunnel 转发以便在外部访问，当然你也可以通过 webui.sh 的 listen 参数让他监听在 0.0.0.0 以便可以通过 IP 地址直接访问，或者通过配置 nginx 进行转发也是可行的，具体过程此处不赘述。</p><p>当你看到如下提示时就代表启动成功了：</p><pre>Running on local URL:  http://127.0.0.1:7860</pre><h3>安装插件</h3><p>在浏览器中打开相应地址，切换到 Extensions 标签页面的 Install from URL，并输入 <a href="https://github.com/civitai/sd_civitai_extension">https://github.com/civitai/sd_civitai_extension</a> 点击 Install 安装 CivitAI 提供的插件，安装成功后切换回 Installed 页面点击 Apply and restart UI 重新加载。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tCJYVHgpxD5eGZt0emyg2A.png" /><figcaption>安装 CivitAI 提供的插件</figcaption></figure><h3>开始生成图片</h3><p>第一步：确认左上角已经加载了 ChilloutMix 模型：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/728/1*7xdyixzlCmQx1NZu2uxFsg.png" /></figure><p>第二步：在右侧找到这个按钮，点击之后左侧会展开一些新的元素</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/712/1*2HC3T8Iw3r8UeJiCHx-Qyg.png" /></figure><p>第三步：在左侧展开的标签中点击 Lora，并选择我们刚下载好的模型：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8OL-IixwXIqbq3AfDzYiUw.png" /></figure><p>第四步：点击之后你会看到左侧有了变化，prompt 中自动多了一行文字，代表使用 taiwanDollLikeness 这个模型：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iaw9rwo9fxKfHFxkhypqSA.png" /></figure><p>我直接输入 a girl，点击右侧的 Generate 尝试生成：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*WtbYerfmpPoHL1cYbJVXjQ.png" /></figure><p>此时无论在页面上还是在命令行窗口中都可以看到生成进度和预期完成时间：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P1rWYKBwXm0b41zeSNUFTg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*y5S-ACrshZUxognlCFDFnQ.png" /></figure><p>生成完成后的图片是这样的，很容易看出来不太尽如人意，不只是不好看的问题，甚至有些不像一个人类。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*3DRtZvsN4L7jaOKlAR6dCw.png" /></figure><h3>参数调优</h3><p>首先我们先调优生成的关键词，如果不知道如何选取关键词可以去官方页面的官方样例或回复中别人生成的样例中点击一张你喜欢的风格的图片，看看哪张图片是用什么关键词生成的，例如这张：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3lcp0XVO7dGTKsZclpQPrQ.png" /><figcaption>一张其他用户生成的图片和参数</figcaption></figure><p>此处 Prompt 代表你想要生成的元素，而 Negative prompt 代表你想要避免出现的元素，我们就先复制这张图片的参数进行生成。</p><blockquote>⚠️ 注意：复制时候要注意不要全复制了，从模型文件后面开始复制，图中的生成使用的是 &lt;lora:taiwanDollLikeness_v10:0.66&gt;，而我使用的是 &lt;lora:taiwanDollLikeness_v10:1&gt;，注意灵活使用。</blockquote><p>同时我们也发现该图片使用的 sampler 是 DPM++ SKE Karras，这也是比较推荐的一个效果不错的 sampler，我们也把 sampler 改成同样的。相应地，也将 CFG scale 和 Steps 参数和该图片使用的参数对齐。（Steps 越多，生成效果越好，生成速度越慢），改好的界面如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6aJe_Bf87NpBqEJK3yJD6Q.png" /></figure><blockquote>⚠️ 注意：不建议改 Seed，seed 的意思是该次生成的「路线」，代表一定指向性的特征，我们不需要和那张样例图片的感觉一模一样，所以我选择不改 seed。</blockquote><p>这次时间会比上次久一点，但效果好了不少：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*KgnoSF_XGurtIFSZSrzEnw.png" /></figure><p>不过图片还是有点模糊，因为我们生成的图片是 512x512 大小的。生成更高清晰度的图片不要直接调节图片大小，这样会让生成的速度变慢许多，最好的方式是仍然使用 AI 让我们对模糊的图片进行自动放大：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yIkLOnHs8R45qdVAd4wCGg.png" /></figure><p>勾选 Hires. fix 选项，Hires steps 可以调节为 10–20 中的数值，并确定 Upsacle by 值为 2，这样就可以在生成出 512x512 的图片后将其放大为 1024x1024。我们再生成一次试试：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*Mgu7-EgP1KypNGLhSueLnQ.png" /></figure><p>效果好多了。</p><p>关于参数方面该模型的作者已经在页面中详细介绍了如何调整参数才能获得较好的效果，大家要仔细读一下，比自己乱尝试要高效（但是自己乱尝试很好玩）：</p><pre>Things to note if you&#39;ve used my other LORAs: -<br>1. It has more variation, and less consistent in making the same types of faces, it is easier to have more facial expressions due to this.<br>2. Different LORA weight control would easily change the face variation.<br><br>Explanation:<br>1. This is a LORA trained for sd1.5, the trigger words are &#39;girl&#39; and &#39;woman&#39;, or you could control the weight with LORA taiwanDollLikeness_v10 prompt.<br><br>2. This LORA works extremely well with ChilloutMix and potentially any other photorealistic models, including nsfw models.<br><br>3. Works okay when used together with PureErosFace but you must know how to control the weights properly.<br>https://civitai.com/models/4514/pure-eros-face<br><br>5. May also work together with &#39;ulzzang-6500&#39; but weight control is a must.<br>https://civitai.com/models/8109/ulzzang-6500-korean-doll-aesthetic<br><br>6. Try to use hires fix with around 10-20 hires steps, latent upscaling (bicubic antialiased), denoising strength between 0,4-0.7, its given the best results by far.<br><br>7. Higher resolution also helps when creating further subjects, hires fix helps greatly with this too.|<br><br>8. Best samplers are DPM++ SDE Karras, Euler a, DPM2 a Karras and DPM++ SDE<br><br>Caution:<br>1. Recommended weights for txt2img - 0.5-0.8<br>2. Recommended weights for img2img - 0.4-0.8</pre><h3>Prompt</h3><p>掌握了这些技巧大家就可以生成自己喜欢的图片了，但是可能会发现其中有一个点很困难，就是初学者如何选择 prompt。AI 从业者会形象地将 prompt 和 negative prompt 称为「咒语」并将这种生成过程称为「咒语吟唱」。你的吟唱越精确，咒语细节越多，最终生成的图片就越符合你的想象。</p><p>如果你不知道如何生成这些咒语，那么我有几种方法可能会对你有一些启发：</p><h4>Prompt Hero</h4><p>访问 <a href="https://prompthero.com/">https://prompthero.com/</a> 在顶部菜单选择 Stable Diffusion，在搜索框中输入 girl 关键词（或者任何你想要的关键词），在搜索结果中找到自己喜欢的风格，就可以复制这张图片的 prompt 进行尝试了。类似的网站有很多大家可以自行找一下。当然在 CivitAI 上去找 prompt 也是很好的方式。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LTTDOit9i8MNGj1islofIA.png" /></figure><h4>ChatGPT</h4><p>使用 ChatGPT 进行关键词生成也是很好的方式，特别是对英文表示很好的朋友会很有帮助，请 ChatGPT 帮助你去生成你想要的 prompt：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a4uvTTrjueP-MYNfvnfNkQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5uZ6cY8fTYPtCJAMzlSLdQ.png" /></figure><h4>Clip Interrogator</h4><p>如果你有想要模仿风格的照片，也可以把这张照片传进 clip interrogator 中，这个 AI 会帮助你提取关键词。很多人都自己实现了 clip interrogator，你也可以用这个网站直接使用：</p><p><a href="https://replicate.com/pharmapsychotic/clip-interrogator">Replicate</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DdGsq2crKRCGmtXYCpL2EA.png" /></figure><h3>我生成的一些图片</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*Mgu7-EgP1KypNGLhSueLnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*lmAj9rHwppKc7ALW_nzEYw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*KSU4VOePJWI30kAjkEBaIg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/864/1*IUM4UmJ0KFg7PVFq-qhBag.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*dZobuRi4kDz605CvbPLKnQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*SDH-EMne1RpmIJjjGp3oJA.png" /></figure><h3>手指好奇怪！</h3><p>Stable Diffusion 一个非常常见的问题就是人类的关节、手指乱掉了，例如这样：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/0*YWSGfQ7Gn4hqN_k1" /><figcaption>手指混乱</figcaption></figure><p>或者这样：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/368/1*YiwiqbEQQ-DoWWWl7GP5Bw.png" /><figcaption>关节或人体结构混乱</figcaption></figure><p>目前暂时没有太好的解决方法，但是我们可以巧妙地绕过去，例如：</p><ol><li>要求图片生成时不要露出手来</li><li>添加 negative 关键词，例如：extra fingers</li><li>添加关键词，例如：5 fingers per hand</li><li>多生成几次</li></ol><p>在网上也看到过一些 AI 模特的手指和关节都非常正常，其中有几个原作者也明确表示了有人工进行后期图片优化。</p><p>相信这个问题不久也可以得到解决。</p><h3>NSFW</h3><p>估计大家已经开始玩起来了，甚至开始生成 NSFW 图片来对 AI 进行更全面的能力测试（满足自己奇怪的性癖），但是却发现效果始终不好。原因很简单啦，上述这些模型是生成正常的照片的，所以训练集中色情元素本身就没有很多，自然发挥不佳。寻找专门的 porn 模型进行尝试会效果更好。</p><p>如果你喜欢 ChilloutMax 的人脸和身材效果，可以喂给它一些你喜欢的 porn 元素的图片来生成特定的（满足自己奇怪的性癖）色情照片。</p><p>但记得不要做违法的事情（例如在不合适的场合传播色情照片、使用特定的人类去生成他的色情照片、生成儿童色情等）。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=85ffa7c13cd7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Brief History of Decentralized Peer-to-Peer Networks | Modern Decentralized Networks #Nostr and…]]></title>
            <link>https://medium.com/@croath/a-brief-history-of-decentralized-peer-to-peer-networks-modern-decentralized-networks-nostr-and-58fe6db9699a?source=rss-a23cd5271080------2</link>
            <guid isPermaLink="false">https://medium.com/p/58fe6db9699a</guid>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[p2p]]></category>
            <category><![CDATA[nostr]]></category>
            <category><![CDATA[ring-network]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Croath Liu]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 14:09:02 GMT</pubDate>
            <atom:updated>2023-02-03T14:09:02.681Z</atom:updated>
            <content:encoded><![CDATA[<h3>A Brief History of Decentralized Peer-to-Peer Networks | Modern Decentralized Networks #Nostr and #RingsNetwork</h3><h3>What is peer-to-peer network?</h3><p>Peer-to-peer network, also known as P2P network, is a decentralized Internet system that relies on groups of users (peers) to exchange information, and its role is to reduce the number of nodes in previous network transmissions to reduce the risk of data loss.<br>Unlike a centralized network system with a central server, each user end of a peer-to-peer network is both a node and a server, and any node cannot directly find other nodes and must rely on its user group for information exchange.</p><h4>Classification of peer-to-peer networks</h4><p>According to the degree of centralization, peer-to-peer networks can be classified into three main categories.</p><h3>General P2P</h3><ul><li>Nodes act as both client and server sides.</li><li>There is no central server.</li><li>There is no central router.</li></ul><p>Bitcoin network, BitTorrent network, and eDonkey network (eDonkey, eMule, ed2k) all belong to the general type of P2P, each node can act as both client and server, it does not have a center, no one node can control the whole network, each node’s function, and authority are reciprocal.</p><h3>The special type of P2P</h3><ul><li>There is a central server that keeps the information about the nodes and responds to requests for this information.</li><li>Nodes are responsible for publishing this information (since the central server does not save files), letting the central server know what files they want to share, and letting nodes that need it to download their shareable resources.</li><li>Routing endpoints use addresses, which are referenced by a set of indexes to obtain absolute addresses.</li></ul><p>The early version of the Napster network was a special type of P2P network, where a group of high-performance central servers kept directory information about the resources shared by all active peers in the network. When a file needs to be queried, a peer sends a file query request to a central server. After the central server performs the corresponding search and query, it returns a list of peers’ address information that matches the query requirements. After receiving the reply, the query-initiating peer will select the peer based on information such as network traffic and latency, establish a connection with the appropriate peer, and start the file transfer.</p><h3>Hybrid P2P</h3><ul><li>Skype is a hybrid P2P network, where user information and chat messages are stored in a centralized server.</li></ul><p>Skype is a hybrid P2P network where user information and chat messages are stored in a centralized server, and when users transfer files directly, Skype clients can initiate a direct connection between them without going through the server, allowing direct file transfer between clients.</p><h3>History of Peer-to-Peer Networks</h3><h3>1969 — ARPANET</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*00jxvqchdCqWGDBx" /><figcaption>ARPANET Technology Architecture Diagram</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/0*B7dtjFMNSE1QqF1S" /><figcaption>APRANET Access Interface</figcaption></figure><p>ARPANET (Advanced Research Projects Agency Network), the world’s first operational packet-switching network developed by the U.S. Defense Advanced Research Projects Agency, is the originator of the global Internet.</p><p>Instead of a C/S (Cilent-Server) structure, the hosts of ARPANET treat each other as peer computer nodes.</p><h3>1979 — Usenet</h3><p>Designed by Duke graduate students Tom Truscott and Jim Ellis in 1979 and released in 1980, Usenet contains numerous newsgroups, which are web collections of newsgroups (as opposed to the traditional term, news, which refers to communication, information) and their messages, and is like an early reddit, a forum for users to gather.</p><p>Usenet predates the World Wide Web by a decade and is known as the “poor man’s Appa Web”.</p><p>When a user posts an article, it is stored on a server according to the Usenet hierarchy (newsgroup), and it is initially viewable only on the news server used by that user. Each news server exchanges articles with other servers (“news feeds”). This is P2P messaging, where articles are copied from one server to another and can eventually reach every server in the network, allowing newsgroup messages to be stored in a distributed manner on a large number of computers around the world. Each server contains all the content of the articles, and the servers operate independently of each other to synchronize the articles.</p><p>AOL stopped using Usenet in 2005, and in May 2010, Duke University, which had been using Usenet for more than 30 years, shut down its In May 2010, Duke University, which had been using Usenet for more than 30 years, shut down its Usenet servers, citing low usage and rising costs.</p><h3>1999 — Napster</h3><p>Napster is a soft ware that provides an online music service, originally founded as an archive sharing service by John Fanning, Shawn Fanning and Sean Parker.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CfOICggKGMhUoQyl" /><figcaption>Sean Parker, Mark’s investor in the movie “The Social Network”</figcaption></figure><p>Users can download Napster clients for free and then download MP3 files from others while acting as a server themselves for others to download.</p><p>Napster has a central server that provides file directory services to all users. When a client wants to download music, he needs to go to this central server to find out which clients have the music, and then connect directly to that machine to download it. (Special type of P2P network described above)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*X_FFyxAI4RKByCYk" /><figcaption>Napster operating interface</figcaption></figure><p>Napster was the first widely used peer-to-peer music sharing service that dramatically impacted the way people, especially college students, used the Internet. It made it easy to share MP3 songs among music lovers, but it also drew accusations of mass copyright infringement from the audio-visual community. Although the service was discontinued by court order, it paved the way for the expansion of other peer-to-peer file-sharing programs such as Kazaa, Limewire and BearShare, and made it increasingly difficult to control this form of file-sharing. Today Napster is primarily a paid service, and the popularity and repercussions of the free Napster have made it a legendary symbol in the computer and entertainment industries.</p><h3>2000 — Gnutella</h3><p>Unlike Napster, which is a semi-centralized network, the Gnutella network is fully distributed. Its initial popularity stemmed from the threat of Napster being shut down in early 2001 due to a legal dispute. The growing number of users also exposed a number of flaws in the initial version of the protocol, and in early 2001, various versions of the protocol (initially implemented as proprietary closed-source client software) allowed for increased scalability of Gnutella. Unlike the previous protocol, which treated each user node as a user as well as a server, the improved protocol treated certain users as “ultrapeers” that routed search requests and responses for all users connected to them.</p><h3>2000 年 — Freenet</h3><p>Freenet is a content publishing and communication platform designed to defend against content censorship. Famous platforms such as The Pirate Bay, Wikileaks, and Silk Road are all based on Freenet.</p><p>The inherent nature of P2P makes it naturally censorship-resistant, allowing the content of its platform to be permanently stored in nodes and not easily deleted or blocked from all nodes at once, and it can be said that the release of Freenet officially opened the era of the dark web.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/0*h9mYaUE87iNzjH7w" /><figcaption>Drugs, Hallucinogens, Controlled Substances, and More Explicitly Priced in Bitcoin on the Silk Road</figcaption></figure><h3>2001— Bittorrent</h3><p>The BitTorrent protocol (BT for short, commonly known as BitTorrent, BT Download) is a network protocol program used for file sharing in peer-to-peer networks.</p><p>BitTorrent protocol downloads are characterized by the fact that the more people download, the more bandwidth is made available and the faster the download speed. At the same time, the more users have the complete file, the longer the “lifetime” of the file.</p><p>The seed file is essentially a text file that contains both Tracker information and file information; Tracker information is mainly the address of the Tracker server used in BT downloads and the settings for the Tracker server, while file information is generated based on a calculation of the target file, which is encoded according to the BitTorrent protocol’s The file information is generated by calculating the target file, and the result is encoded according to the Bencode rules in the BitTorrent protocol.</p><p>BitTorrent later introduced Distributed Hash Technology (DHT), a distributed storage method that is significantly more efficient than flood query technology. Without the need for a server, each client is responsible for a small area of routing and for storing a small portion of the data, thus enabling the addressing and storage of the entire DHT network. With BT download software that supports this technology, users do not need to be connected to a Tracker in order to download, as the software will find and communicate with other users in the DHT network who are downloading the same file and start the download task. The obvious benefit of this technology is that it greatly reduces the burden on the Tracker (or even eliminates the need for it). Communication between users can be created more quickly (especially if they are not connected to the Tracker).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/0*4zR8-b2ePdAYoN_I" /><figcaption>BitTorrent 的客户端之一</figcaption></figure><h3>2009 — Bitcoin</h3><p>Bitcoin (BTC) is a cryptocurrency based on decentralization, using peer-to-peer network with consensus initiative, open source code, and blockchain as the underlying technology. Bitcoin was published by Satoshi Nakamoto (screen name, Satoshi Nakamoto) on October 31, 2008, and the Genesis block was born on January 3, 2009.</p><p>Bitcoin combines P2P peer-to-peer networking technology and cryptographic principles to maintain the security and reliability of the issuance system. Unlike a central network system with a central server, there is no central server in a P2P network; each user side is both a node and a server, and no node can directly find other nodes, but must rely on its household group for information exchange. Bitcoin uses the following 3 mechanisms to solve the problem of finding other nodes when running for the first time.</p><p>By default, the client running Bitcoin joins an IRC chat channel and is informed of the IP addresses and ports of the other clients joining the channel. The name of the channel and the name of the IRC chat server are written in the Bitcoin software.</p><p>Some “well-known” bitcoin nodes are also written into the software in case the IRC chat service feature is inaccessible for any reason.</p><p>IP addresses of other clients running Bitcoin can be added manually.</p><p>Instead of running the 3 mechanisms described above, once a node is connected to a Bitcoin node, the message sent will contain the addresses of other nodes in the peer-to-peer P2P network, and the other nodes will be found directly through their anonymous user base. The combination of P2P technology with nodes spread throughout the Internet and cryptographic principles ensures that the Bitcoin distribution system cannot be monitored, isolated, or compromised by governments, organizations, or hackers, thus guaranteeing the reliability and anonymity of the system. Denial of service style (DDoS) and other attacks that target Bitcoin exchange centers are the same as attacking or shutting down the networks of traditional currency exchanges without theoretically affecting their currency issuance and use.</p><h3>2012 — Diaspora</h3><p>Diaspora positions itself as an open source personal web server and decentralized social network, and after raising $200,000 on Kickstarter in 2010, the project was officially launched and a beta version was quickly released, followed by a stable community version in 2012. Facebook is a centralized platform where users only need a web browser to use it, while Diaspora requires a dedicated download of its own program client, which makes it harder to promote. In addition, some people don’t really care about the privacy issues that come with a centralized platform.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pZptJqxN7wKmB2Ij" /><figcaption>Diaspora</figcaption></figure><h3>Summary</h3><p>In the 50+ years since 1969, P2P networks have evolved from expensive to inexpensive, from proprietary (music) to general purpose (files, websites), and diversified, with virtual currencies, privacy networks, open public resources, and other directions, and the exploration of pass-through incentives for usage.</p><p>But P2P networks are still not mainstream. The development of network infrastructure over the past 20 years has enabled ordinary individuals to access high-speed broadband networks, and each web host in a large server room can even serve users with 10,000 megabytes of bandwidth, giving rise to a new generation of information dissemination and entertainment options. People are enjoying the convenience and fun of centralized services, and the need for decentralization and peer-to-peer is not so important in the context of the Web 2.0 era.</p><p>But P2P technology itself has not been abandoned and is even serving the Internet behind the scenes.</p><h3>Web 2.0 Peer-to-Peer in the Big Internet Era</h3><h3>P2P CDN Edge Acceleration</h3><h4>CDN</h4><p>A Content Delivery Network (CDN) is a system of interconnected computer networks over the Internet that uses servers closest to each user to deliver music, pictures, videos, applications, and other files to users faster and more reliably. to provide high-performance, scalable, and low-cost delivery of network content to users.</p><p>For example, a small forum site has only one server with a bandwidth of 10M. 10M of bandwidth is fully capable of providing data transfer services for hundreds of online forum users at the same time. However, after the forum added the function of uploading images, the 10M bandwidth was overwhelmed, and each image ranged from several hundred K to several tens of M. More than 90% of the bandwidth was used to transfer the images, which themselves did not change, and each user saw the same image. The user loading speed also starts to slow down. This is where CDN technology comes to the rescue. CDN technology helps webmasters store images on servers around the world so that users in California only get the content of the post and the address of the image from the forum server when they visit the forum, and the image is transferred to the user’s computer from a local server in California. By analogy, users in France can also get the image from a local server in France. Users around the world are loading images from the nearest server, users are loading faster, and the forum’s server bandwidth load is reduced.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*J68LQ2Nh0gwI8nac" /><figcaption>CDN Network Architecture</figcaption></figure><h4>Edge Nodes</h4><p>The “California local servers” and “French servers” that store and serve images in the above example are called “edge nodes” in a CDN network.</p><p>Edge nodes can serve not only static files (images, music, videos, and other unchanging resources) but also dynamic content. For example, we want to add an anti-theft watermark to each image with the username and IP of the logged-in user, so that the source can be marked to prevent users from stealing the image and sending it to other sites, so that each user sees a different image with a different watermark when they visit. The service can also run on the edge node, where the code to add the watermark is written on the edge node, and the watermark is provided to the user directly when the user visits. The function of edge nodes to provide dynamic computing services is called edge computing.</p><h4>P2P CDN Converged Acceleration</h4><p>When we access large files, the bandwidth of the CDN edge nodes may not be enough for users either, so many service providers are starting to offer P2P CDN converged acceleration services, which are used by streaming providers such as Youtube to enable users to play HD videos without latency.</p><p>Dark Fiber refers to the tendency of operators to lay more fiber when laying fiber for a city. For example, they expect this building to use 1TB of broadband in the future but will lay 10TB of bandwidth capacity equipment and fiber in the ground. Because the cost of fiber optic laying is mainly from digging the ground to digging the wall to bury the line, just like your home renovation line, opening a wall is only more reason to lay. Although 1TB of bandwidth is sufficient for current use, with the increase in the number of users, user demand, and Internet service upgrades, operators expect to use 10 TB of bandwidth in the coming period of time may be used. Just as we were using 10M broadband a decade ago, most of us are now using 100M+ broadband networks. Laying redundant bandwidth in advance can reduce the cost of future construction.</p><p>Google has purchased a lot of dark fiber rights and secondary sale rights from carriers. They use this dark fiber bandwidth to accelerate YouTube video playback. For example, when you load a video of 100M in size, the CDN can no longer carry that kind of content on a single node (because many users may be requesting large files on the CDN node at the same time), but there may be 10 small Youtube servers connected to dark fiber in your city that are caching the video, and YouTube starts using those 10 nodes YouTube starts using these 10 nodes to establish a P2P connection with your PC over dark fiber, and each server sends you a 10M video. Overall these 10 servers use very little bandwidth and traffic, and you get 100M of video files instantly, which improves your playback experience. Because the traffic is on the dark fiber network, it doesn’t take up public bandwidth and doesn’t affect the Internet experience of other users in the area, so it’s a double whammy.</p><p>Nowadays, dark fiber and its secondary sales are almost snapped up, and some vendors have released a profit-sharing model of bandwidth-sharing service, which is to install bandwidth-sharing software on personal routers, computers, or smart devices, start them up at idle time, use personal smart devices as caching nodes, perform P2P resource sharing services to other users in need, and get a share of the profits.</p><h3>P2P direct connection in centralized clients</h3><p>While not every service provider has the financial and technical resources of Google to use dark fiber, smaller software providers can still enhance the user experience with P2P technology.</p><p>I’m sure you’ve all experienced that when you and a colleague are sitting in the same building (on the same intranet), you can transfer files to each other on Skype or other chat software much faster than you can transfer files to a customer who is not in the same area. Because Skype finds out that you are in the same intranet, your file transfer doesn’t need to go to the Internet, but establish a direct peer-to-peer connection, communicating through the building’s router, and you can transfer it directly. Half of the bandwidth of the intranet is very large, so even a file of several G sizes can be transferred in a few tens of seconds.</p><p>The same scenario applies to WANs, where users in the same neighborhood, city, and ISP P2P direct connection to transfer files is usually much faster than going through a centralized server on the Internet.</p><p>Although these software are generally centralized and do not work without a central server, the integration of P2P in these features greatly improves the user experience.</p><p>With all the talk about #Nostr recently, I’d like to take this opportunity to discuss a less discussed topic, the structured and peer-to-peer nature of decentralized networks, using #Nostr and Rings Network as examples to illustrate some of the similarities and differences.</p><h3>Nostr &amp; Rings Network</h3><h4>1⃣️ centralized, decentralized, hybrid</h4><p>We all know about centralized networks, like Twitter, where the operator can decide whether to remove or change user data, and if it stops operating or bans users, everyone’s virtual assets (content) will then disappear.</p><p>The most widely known decentralized networks are Bitcoin and Ether, where no matter which node goes offline, the content security of the network is not affected and transmission security and consistency is guaranteed by cryptographic algorithms rather than human intervention.<br>Mastodon is a hybrid network that is more centralized in nature.</p><h4>2⃣️ Nostr Network Architecture</h4><p>Nostr is a decentralized network in a way, but I prefer to call it a hybrid network, but a more decentralized one.</p><p>Each user is an independent client, the client is only connected to the relay, and the relay can be considered as a forwarding node in its literal sense. relay and relay can be connected to each other, but only if they know each other’s address, for the relay does not know the address is not connected, only through the help of other relays forwarding. A client can also connect multiple relays, so the overall addressing and communication efficiency will be improved.</p><p>I know these are already clichés, but if you are not an expert in this field, it is difficult to understand, you can imagine the Nostr network as a mobile network.</p><p>The client is the phone, the relay is the base station (signal tower), the phone (client) can connect to one or more towers (relay), if you can not connect to any tower, you can not send and receive information.<br>The towers of course need to be connected to each other so that they can form a communication network. A tower may be connected to one or several other towers, so that there is an alternative when one of the connections is not working, and multiple connections ensure the shortest possible reach to the phone you are looking for. A tower is in most cases connected to hundreds or thousands of handsets, while a handset is usually connected to only a single-digit number of towers, a structure we call a star network (star topology). Multiple base stations are combined to form an extended star network. This is the basic network structure of Nostr.</p><h4>3⃣️ Rings Network Architecture</h4><p>The Rings Network uses a Chord ring network, where all nodes are sequentially listed into a ring, and then each node is controlled by an algorithm that also establishes several links with other nodes on the ring. When a link is broken (e.g., the node drops out or the network is disconnected), the algorithm controls the re-formation of the ring and the establishment of new links without affecting the operation of other nodes.</p><h4>4⃣️ Differences</h4><p>Various network structures have their own advantages and disadvantages, and basically there is no essential difference between the best and the worst, but the optimal solution is to use the right network structure based on the usage scenario and the problem being solved. Here we talk about the differences between the two in some common scenarios.</p><h4>Connection method</h4><p>The connection between the Nostr client and relay is WebSocket based and does not allow p2p connections. The Rings Network nodes are WebRTC-based, and p2p connections are allowed between nodes.</p><p>The connection method here shows that both networks are designed with a strong orientation towards web services. Browsers are now the dominant way to interact with the Internet, and apps that are not browser-based are subject to scrutiny by centralized organizations such as the App Store or Google Play, so it is very important that they run in browsers and that the connectivity is supported by browsers by default. Whether it’s WebSocket or WebRTC, it’s a good choice for efficient, parallel connections in the browser, or for streaming data.</p><p>Meanwhile, Rings Network chooses to connect in a p2p fashion, which is necessarily not as efficient as the central node cluster bandwidth state of the Nostr star network, but will be better in terms of connectivity. The two decentralized networks have different trade-offs in terms of data transmission efficiency and connectivity.</p><h4>Node Roles</h4><p>There are central nodes (clusters) in the Nostr network that are responsible for maintaining the state of the entire network; there is no central node in the Rings Network, and all nodes have the same role in the entire network.</p><p>If a malicious node is present in the network, neither network can be attacked by phishing or fake messages, because both are encrypted with algorithms that guarantee the reliability of each message. However, when the purpose of the malicious node is to listen, track, and deliberately not deliver the message location, a malicious client in the Nostr network will not have much impact, but a malicious relay will cause network failure or user privacy exposure; in the Rings Network, a carefully choreographed Chord id malicious node may also achieve the purpose of listening and tracking by controlling a certain number of malicious nodes. In Rings Network, a carefully orchestrated Chord id node may also control a certain number of malicious nodes for listening and tracking purposes, but it is not likely to cause network failure or unavailability.</p><h4>Data Storage</h4><p>In the Nostr network, data is stored in relay nodes; in the Rings Network, data is stored in various nodes throughout the network, but for now, the Rings Network DHT has no content beyond node connection information and uses any third party for storage in the form of a glue protocol.</p><p>Nostr’s design is more in line with the existing blockchain node format, but not all relays persist all messages, which is a balanced solution in terms of cost and efficiency. The Rings Network does not have such functionality, and relying on third parties provides developers with more flexible options and reduces the difficulty of development, but also discards the functionality of the network itself.</p><h4>Data Query</h4><p>In the Nostr network, data queries need to go through the central node; in the Rings Network, data queries can be made through any node in the ring network. Therefore, in most cases, the Nostr query throughput is higher, while the query is more centralized, and the performance requirements of the relay nodes and network requirements are higher, while the average query throughput of Rings Network is lower, but it does not receive a single point of exit from the network and cause data loss.</p><h4>Reliability</h4><p>The reliability of Nostr network depends on the reliability of relay node, if the central node fails, the whole network will be affected; the reliability of Rings Network is higher, even if one or more nodes fail, the whole network can still work normally.</p><p>When a single point of failure is encountered, it mainly depends on the properties of the failure point. in Nostr network, if the failure point occurs on the relay node, a large number of clients will be affected, and if multiple relay nodes fail earlier, the network may split into several parts, or even the whole network is down. Rings Network performs better with a single point of failure because the nodes are peer-to-peer and maintain over 95% availability even when 50% of the nodes fail.</p><h4>Efficiency</h4><p>The efficiency of Nostr network may be limited by the central node, and the query and storage of data need to go through the central node; the efficiency of Rings Network is higher, and the query and storage of data can be done through any node.</p><p>In Nostr network, as the network grows, the ratio of the number of clients to the number of relays is less prone to blockage if the ratio is always balanced, but if the number of clients increases dramatically and the number and quality of relays do not keep up with the speed of network development, paralysis may occur. However, in an ideal situation, the overall transmission efficiency is high and the speed is fast, but even in this case, as the number of packets in the network increases dramatically, it is easy to cause a DDOS-like message storm that may bring down the entire network.</p><p>Rings Network, on the contrary, if the number of nodes increases dramatically, the network efficiency and transmission quality will be improved, theoretically the more nodes the better the connectivity, and the corresponding multi-point transmission will also reflect the bandwidth effect; while if the number of nodes is small, remote nodes may not get a good experience. However, as the number of nodes increases homeopathically leading to an increase in the volume of messages, the possibility of message storms is very low because of point-to-point transmission.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=58fe6db9699a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[去中心化点对点网络简史 | 现代去中心化网络 #Nostr 和 #RingsNetwork]]></title>
            <link>https://medium.com/@croath/%E5%8E%BB%E4%B8%AD%E5%BF%83%E5%8C%96%E7%82%B9%E5%AF%B9%E7%82%B9%E7%BD%91%E7%BB%9C%E7%AE%80%E5%8F%B2-%E7%8E%B0%E4%BB%A3%E5%8E%BB%E4%B8%AD%E5%BF%83%E5%8C%96%E7%BD%91%E7%BB%9C-nostr-%E5%92%8C-ringsnetwork-8283bb60923b?source=rss-a23cd5271080------2</link>
            <guid isPermaLink="false">https://medium.com/p/8283bb60923b</guid>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[p2p]]></category>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[nostr]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Croath Liu]]></dc:creator>
            <pubDate>Fri, 03 Feb 2023 13:35:42 GMT</pubDate>
            <atom:updated>2023-02-03T14:11:26.012Z</atom:updated>
            <content:encoded><![CDATA[<h3>什么是点对点网络？</h3><p>点对点网络（peer-to-peer 或 P2P）又称对等网络，是去中心化、依靠用户群（peers）交换信息的互联网体系，它的作用在于，减低以往网路传输中的节点，以降低资料遗失的风险。</p><p>与有中心服务器的中央网络系统不同，对等网络的每个用户端既是一个节点，也有服务器的功能，任何一个节点无法直接找到其他节点，必须依靠其户群进行信息交流。</p><h3>点对点网络的分类</h3><p>根据中心化程度，点对点网络可以分为三大类：</p><h3>一般型 P2P</h3><ul><li>节点同时作为客户端和服务器端。</li><li>没有中心服务器。</li><li>没有中心路由器。</li></ul><p>比特币（Bitcoin）网络、BitTorrent 网络、eDonkey 网络（电驴，电骡，ed2k）均属于一般型 P2P，每一个节点均可以作为客户端和服务端，它没有一个中心，没有任何一个节点能够控制整个网络，每一个节点的功能和权限都是对等存在的。</p><h3>特殊型 P2P</h3><ul><li>有一个中心服务器保存节点的信息并对请求这些信息的要求做出响应。</li><li>节点负责发布这些信息（因为中心服务器并不保存文件），让中心服务器知道它们想共享什么文件，让需要它的节点下载其可共享的资源。</li><li>路由终端使用地址，通过被一组索引引用来获取绝对地址</li></ul><p>早期的 Napster 网络属于特殊型 P2P 网络，一群高性能的中央服务器保存着网络中所有活动对等计算机共享资源的目录信息。当需要查询某个文件时，对等机会向一台中央服务器发出文件查询请求。中央服务器进行相应的检索和查询后，会返回符合查询要求的对等机地址信息列表。查询发起对等机接收到应答后，会根据网络流量和延迟等信息进行选择，和合适的对等机建立连接，并开始文件传输。</p><h3>混合型 P2P</h3><ul><li>同时含有一般型 P2P 和特殊型 P2P 的特点。</li></ul><p>Skype 属于混合型 P2P 网络，用户信息和聊天信息存储在中心化服务器中，当用户直接进行文件传输时，Skype 客户端之间又可以发起直连，不通过服务器，允许客户端之间直接传递文件。</p><h3>点对点网络发展史</h3><h3>1969 年 — ARPANET</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/0*00jxvqchdCqWGDBx" /><figcaption>ARPANET 技术架构图</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/490/0*B7dtjFMNSE1QqF1S" /><figcaption>APRANET 访问界面</figcaption></figure><p>ARPANET（Advanced Research Projects Agency Network，阿帕网），是美国国防高级研究计划局开发的世界上第一个运营的数据包交换网络，是全球互联网的鼻祖。</p><p>阿帕网的主机之间视彼此为对等的计算机节点，而非 C/S（Cilent-Server） 结构。</p><h3>1979 年 — Usenet</h3><p>1979年杜克大学的研究生汤姆·特拉斯科特与吉姆·埃利斯设计出来 Usenet，并于1980年发布。Usenet 包含众多新闻组，它是新闻组（异于传统，新闻指交流、信息）及其消息的网络集合，他就像早期的 reddit，是用户聚集的论坛。</p><p>Usenet 比万维网的诞生早了十年，被称为“穷人的阿帕网”。</p><p>当用户发布文章时，根据所分 Usenet 层级（新闻组）存储在服务器，它一开始仅在该用户使用的新闻服务器上可以浏览。 每个新闻服务器与其他服务器（“新闻源”）交换文章。这种方式就是 P2P 信息传输，文章从一个服务器复制到另一个服务器 ，最终可以传达到网络中的每个服务器，新闻组消息得以被分布式存储于全球大量的计算机中。每一台服务器都包涵所有的文章内容，服务器之间独立运行，同步文章。</p><p>从 90 年代开始，用户便不断上传体积庞大的非文本类内容（色情图片、软件等），自此开始 Usenet 的服务器在流量和存储空间上开始呈现爆炸趋势。AOL 于 2005 年停止使用 Usenet。2010年5月，早在30多年前就开始使用 Usenet 的杜克大学关闭了它的 Usenet 服务器，其理由是使用率低且成本不断上升。</p><h3>1999 年 — Napster</h3><p>Napster 是一种提供线上音乐服务的软体，最初由约翰·范宁、肖恩·范宁和西恩·帕克共同创立的档案共享服务。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*CfOICggKGMhUoQyl" /><figcaption>电影《社交网络》中 Mark 的投资人 Sean Parker</figcaption></figure><p>用户可以免费下载Napster客户端，然后从别人那里下载MP3文件，同时自己也作为一台服务器，供别人下载。</p><p>Napster有一台中心服务器，向所有用户提供文件目录服务，客户想下载音乐时，需要先到这台中心服务器上查询哪些客户端拥有这首音乐，然后直连到那台机器下载。（上文所述特殊型 P2P 网络）</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*X_FFyxAI4RKByCYk" /><figcaption>Napster 操作界面</figcaption></figure><p>Napster 是第一个被广泛应用的点对点音乐共享服务，它极大幅度地影响了人们，特别是对于大学生使用互联网的方式。而它的出现，也使得音乐爱好者间共享MP3歌曲变得容易，却也因此招致了影音界对其大规模侵权行为的指责。尽管在法庭的责令下该服务已经终止，但它却为其他点对点文件共享程序 — — 如 Kazaa，Limewire 和 BearShare — — 的拓展铺好了路，且对这种方式的文件共享的控制，亦变得愈加困难。如今 Napster 以经营付费服务为主，而免费的 Napster 的流行和回响使其在电脑界和娱乐业里成为一个传奇的象征。</p><h3>2000 年 — Gnutella</h3><p>与半中心化网络的 Napster 不同，Gnutella 网络是完全分布式的。其最初的流行是源于 2001 年早期 Napster 由于法律纠纷而被关闭的威胁。不断增长的用户也使得该协议的最初版本暴露了不少缺陷。2001年早期，各种不同版本的协议（最初以专有闭源客户软件形式实现）使得 Gnutella 的扩展性得到了增强。与先前的协议将每一个用户节点都当作用户以及服务器不同，改进过的协议将某些用户当作”超节点”（ultrapeer），其为与之连接的所有用户路由搜索请求及回应。</p><h3>2000 年 — Freenet</h3><p>Freenet 是一个内容发布和沟通平台，专为抵御内容审查而设计。海盗湾、维基解密、丝绸之路等著名平台都是基于 Freenet 的。</p><p>P2P 本身的特性使其具有天然的抗审查特性，其平台的内容得以在节点中永久保存且不容易一次性删除或屏蔽所有节点，可以说 Freenet 的发布正式开启了暗网时代。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/0*h9mYaUE87iNzjH7w" /><figcaption>毒品、致幻剂、管制药品等在丝绸之路上以比特币明码标价</figcaption></figure><h3>2001年 — Bittorrent</h3><p>BitTorrent 协议（简称 BT，俗称比特洪流、BT 下载）是用在对等网络中文件分享的网络协议程序。</p><p>BitTorrent协议下载的特点是，下载的人越多，提供的带宽也越多，下载速度就越快。同时，拥有完整文件的用户也会越来越多，文件的“寿命”也就越长。</p><p>种子文件本质上是文本文件，包含 Tracker 信息和文件信息两部分。Tracker 信息主要是BT下载中需要用到的 Tracker 服务器的地址和针对 Tracker 服务器的设置，文件信息是根据对目标文件的计算生成的，计算结果根据 BitTorrent 协议内的 Bencode 规则进行编码。</p><p>后来 BitTorrent 引入了分布式哈希技术（ DHT ），相比泛洪查询技术，DHT效率显著提升。DHT 全称为分布式哈希表（Distributed Hash Table），是一种分布式存储方法。在不需要服务器的情况下，每个客户端负责一个小范围的路由，并负责存储一小部分数据，从而实现整个 DHT 网络的寻址和存储。使用支持该技术的 BT 下载软件，用户无需连上 Tracker 就可以下载，因为软件会在DHT网络中寻找下载同一文件的其他用户并与之通讯，开始下载任务。这种技术好处十分明显，就是大大减轻了 Tracker 的负担（甚至不需要）。用户之间可以更快速创建通讯（特别是与 Tracker 连接不上的时候）。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/916/0*4zR8-b2ePdAYoN_I" /><figcaption>BitTorrent 的客户端之一</figcaption></figure><h3>2009 年 — Bitcoin</h3><p>比特币（英语：Bitcoin，缩写：BTC）是一种基于去中心化，采用点对点网络与共识主动性，开放源代码，以区块链作为底层技术的加密货币，比特币由中本聪（网名，Satoshi Nakamoto）于 2008 年10月31日发表论文，2009 年 1 月 3 日，创世区块诞生。</p><p>比特币结合 P2P 对等网络技术和密码学原理，来维持发行系统的安全可靠性。与有中心服务器的中央网络系统不同，在 P2P 网络中无中心服务器，每个用户端既是一个节点，也有服务器的功能，任何一个节点都无法直接找到其他节点，必须依靠其户群进行信息交流。比特币使用以下 3 种机制，来解决初次运行时，查找其他节点的问题。</p><p>在默认情况下，运行比特币的用户端加入一个IRC聊天通道，并可以获知加入该通道的其他用户端的IP地址和端口。该通道的名称和IRC聊天服务器的名称被写在了比特币软件中。</p><p>一些“知名的”比特币节点也被编写在软件中，以防IRC聊天服务功能因故无法访问。</p><p>可以手动添加运行比特币的其他用户端的 IP 地址。</p><p>现在不需要运行上述 3 个机制，一旦连接到比特币的某个节点，在发送的信息中，就会包含对等网络 P2P 其他节点的地址，直接通过其匿名用户群来找到其他节点。节点遍布整个互联网的 P2P 技术和密码学原理相结合，确保了比特币发行系统无法被政府、组织、或黑客监控、隔离、或破坏，从而保障了系统的可靠性和匿名性。拒绝服务式（DDoS）以及其他攻击，其目标都是针对比特币交易中心，这和攻击或关闭传统货币交易所的网络，理论上不影响其货币发行和使用一样。</p><h3>2012 年 — Diaspora</h3><p>Diaspora 将自己定位为开源的个人 Web 服务器和去中心化的社交网络。2010 年在 Kickstarter 上筹资 $200,000 后，项目正式成立，并迅速发布了一个测试版本，到了2012年，稳定的社区版才算正式发布。Diaspora 的目标之一就是替代 Facebook。Facebook 是一个集中式的平台，用户使用它时，只需要一台 Web 浏览器即可，而Diaspora 是需要专门下载自己的程序客户端的，这也使得推广起来比较难。另外，有的人其实根本不关心集中式平台带来的隐私问题。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pZptJqxN7wKmB2Ij" /><figcaption>Diaspora</figcaption></figure><h3>总结</h3><p>自 1969 年以来的 50 多年时间里，P2P 网络由从昂贵走向廉价，由专用（音乐）逐渐走向通用（文件、网站），多元化程度也得以发展，虚拟货币、隐私网络、开放公共资源等等方向层出不穷，使用方式也开始进行通证激励式的探索。</p><p>但 P2P 网络仍非主流。近 20 年来网络基础设施的发展使得普通个人能够接入高速宽带网络，大型机房里每个虚拟主机甚至都可以通过万兆的带宽为用户提供服务，这催生了一系列新生代信息传播方式和娱乐途径。互联网人在产品模式上都探索空间大大增加，人们在尽情享受中心化服务带来的便捷与乐趣，去中心化和点对点的需求在 Web2.0 时代大力发展的背景下也显得不那么重要了。</p><p>但 P2P 技术本身并没有被抛弃，甚至还在幕后为互联网服务着。</p><h3>Web2.0 大互联网时代的点对点</h3><h3>P2P CDN 边缘加速</h3><h4>CDN</h4><p>内容分发网络（英语：Content Delivery Network 或Content Distribution Network，缩写：CDN）是指一种透过互联网互相连接的电脑网络系统，利用最靠近每位用户的服务器，更快、更可靠地将音乐、图片、视频、应用程序及其他文件发送给用户，来提供高性能、可扩展性及低成本的网络内容传递给用户。</p><p>例如某小型论坛网站只有一台服务器，其带宽为 10M，10M 的带宽完全可以为几百名在线的论坛用户同时提供数据传输服务。但论坛加入上传图片功能后，10M 的带宽就不堪重负了，每张图片几百 K 至几十 M 不等，90% 以上的带宽被用来传输图片，而这些图片本身是不会变化的，每个用户看到的都是相同的图片。用户加载速度也开始变慢了。此时 CDN 技术就来帮忙了，CDN 技术帮助网站主把图片存储在全世界各地的服务器上，加州的用户访问论坛时只从论坛服务器拿到帖子正文内容和其中的图片地址，而图片是从加州本地的某个服务器上传输到用户计算机的。类比法国的用户也可以从法国本地的服务器上拿到该图片。全世界的用户都在从距离自己最近的服务器加载图片，用户的加载速度变快了，论坛的服务器带宽负载也下降了。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*J68LQ2Nh0gwI8nac" /><figcaption>CDN 网络结构</figcaption></figure><h4>边缘节点</h4><p>上述例子中的存储和提供图片的「加州本地服务器」和「法国服务器」即被称作CDN 网络中的「边缘节点」。</p><p>边缘节点不仅能提供静态文件（图片、音乐、视频等不变的资源）服务，也能提供动态内容的服务。例如我们想要每一张图片加上防盗水印，水印内容为登录用户的用户名和 IP，这样可以标记来源，防止用户盗取图片发到其他网站，因此每个用户访问时看到的都是带有不同水印的图片。该服务也可以运行在边缘节点上，在边缘节点上写好加水印的代码，在用户访问时直接加好水印提供给用户。边缘节点提供动态计算服务的功能就叫做边缘计算。</p><h4>P2P CDN 融合加速</h4><p>当我们访问大型文件时，CDN 边缘节点的带宽可能也不足够用户使用，此时很多服务商开始提供 P2P CDN 融合加速服务。Youtube 等流媒体服务商就是使用此技术让用户能够无延迟播放高清视频的。</p><p>暗光纤（Dark Fiber）是指运营商在为城市铺设光纤的时候，倾向于多铺一些。比如它们预计这个楼未来也就用 1TB 的宽带，但会在地下铺 10TB 带宽容量的设备和光纤。因为光纤铺设的成本主要来自挖地挖墙埋线，就和你家装修走线一样，开一次墙只有多铺的道理。虽然 1TB 的带宽足够目前使用，但随着用户数量的增加、用户需求的增加、互联网服务的升级，运营商预计未来一段时间内可能会用到 10 TB 的带宽。就像十年前我们都在用 10M 的宽带，但是现在大多在用 100M 以上的宽带网络了。提前铺设好冗余带宽可以降低未来施工的费用。</p><p>而这部分暗光纤带宽在目前来说是闲置的。Google 在运营商手中购买了大量的暗光纤使用权和二次售卖权。他们把这些暗光纤的带宽用来加速 YouTube 视频播放。例如当你加载一个大小为 100M 的视频时，原本 CDN 单个节点已经无法承载这样的内容加速了（因为同时可能有很多用户都在请求 CDN 节点上的大文件），但你所在的城市可能有10台 接入了暗光纤的 Youtube 小型服务器都缓存了这个视频，YouTube 便开始使用这 10 台节点和你的个人电脑通过暗光纤建立 P2P 连接，每台服务器向你发送 10M 大小的视频。从整体上来看这 10 台服务器都仅使用了很小的带宽和流量，而你却能够瞬间获得 100M 的视频文件，播放体验得到了提升。因为流量走的是暗光纤网络，没有占用公共带宽，不会影响该区域内其他用户的上网体验，可谓一举两得。</p><p>现如今暗光纤及其二次销售几乎被抢购一空，部分厂商发布了分润模式的带宽共享服务，即在个人路由器、电脑或智能设备上安装带宽共享软件，在闲时启动，使用个人智能设备作为缓存节点，对其他有需要对用户进行 P2P 的资源共享服务，并获得利润分成。</p><h3>中心化客户端中的 P2P 直连</h3><p>虽然不是每个服务商都拥有 Google 的财力和技术水平能够使用暗光纤，但小型软件服务商仍然能够通过 P2P 技术提升用户体验。</p><p>想必大家都有这样的体验：当你和同事坐在同一个楼宇（同一内网中）时，你们在 Skype 或其他聊天软件中互传文件时的速度比你给不在同一地区的客户传输文件的速度要快得多。因为 Skype 发现你们在同一内网中，于是你们的文件传输就不需要走 Internet，而是直接建立点对点的连接，通过楼宇的路由器沟通，就可以直接传递了，而内网的带宽一半是非常大的，所以即便是几个 G 大小的文件也可以在几十秒钟之内传输完毕。</p><p>同样的场景也适用与广域网中，同一片社区，同一个城市，同一个 ISP 中的用户 P2P 直连传递文件通常要比经过互联网中心化服务器传输要快很多。</p><p>虽然这些软件普遍都是中心化的，脱离了中心服务器便无法运作，但是还是在这些功能上整合了 P2P，极大提升了用户体验。</p><p>最近大家都在讨论 #Nostr ，我也借此讨论一个比较少有人讨论的话题，去中心化网络的结构化和点对点特性，以 #Nostr 和 Rings Network 举例来阐述一些异同点。</p><h3>Nostr 和 Rings Network</h3><h4>1⃣️ 中心化，去中心化，混合式</h4><p>中心化网络大家都了解，像 Twitter 这样，运营者可以决定是否删除更改用户数据，如果停止运营或封禁用户，大家的虚拟资产（内容）便随之消失。</p><p>去中心化网络里最广为人知的就是比特币和以太坊，无论哪个节点下线都不影响网络的内容安全，传输安全和一致性通过加密算法保证而非人工干预。</p><p>混合式当前比较著名的就是 Mastodon，各个服务器之间可以相关联，不同服务器的用户可以相联系，但若某个服务器停止工作，用户的账户也便不复存在。Mastodon 在混合式网络里是偏中心化属性强一点的。</p><h4>2⃣️ Nostr 网络结构</h4><p>Nostr 在某种程度上来说是去中心化网络，但是我更愿意表述其为混合式网络，但是是去中心化程度较高的那种。Nostr 的拓扑结构大体上是这样的：</p><p>每个用户都是独立的客户端，客户端只和 relay 相连接，relay 如其字面上意义可以认为是转发节点。relay 和 relay 之间可以互相连接，但是前提是互相之间知道对方的地址，对于不知道地址的 relay 是连接不到的，只能通过其他 relay 帮助转发。一个客户端也可以连接多个 relay，这样整体上寻址和通信的效率也会提升上来。</p><p>我知道这些已经是老生常谈了，但是如果你不是这个领域的专家，理解起来有困难，大家可以把 Nostr 网络想象为移动网络：</p><p>客户端就是手机，relay 就是基站（信号塔），手机（客户端）可以连接一个或多个信号塔（relay），如果连接不到任何信号塔，也就无法发送和接收信息。</p><p>信号塔之间当然也需要互相连接，这样才能组成一张通讯网。一个信号塔可能会连接一个或几个其他信号塔，当其中某个连接不畅的时候可以有备选，多个连接也能保证最短到达需要寻找的手机。一个信号塔大多数情况下连接了成百上千的手机，而一个手机通常只会连接到个位数的信号塔，我们称这种结构为星型网络（星型拓扑）。多个基站联合起来组成了扩展式的星型网络。这就是 Nostr 的基本网络结构。</p><h4>3⃣️ Rings Network 网络结构</h4><p>Rings Network 使用的是 Chord 环状网络，所有节点依次列成一个环，然后通过算法控制，各个节点也会和环上其他节点建立若干个链接，当某个链接断开时（例如节点退出或网络断开），算法会控制不影响其他节点运行而重新组成环和建立新的链接。</p><h4>4⃣️ 差异对比</h4><p>各种网络结构组成都各有优势和劣势，基本上不存在本质上的优良之分，而是基于使用场景和所解决的问题采用合适的网络结构才是最优方案。这里我们谈一下两者在一些常见场景下的处理差异：</p><h4>连接方式</h4><p>Nostr 客户端和 relay 之间的连接是基于 WebSocket 的，不允许 p2p 连接。而 Rings Network 节点间是基于 WebRTC 的，节点间可以进行 p2p 连接。</p><p>此处连接方式上可以看得出两个网络在设计上都有很强的指向性 — — 为 web 服务。浏览器目前是大家主流的互联网交互方式，脱离浏览器的 app 则会受到例如 App Store 或 Google Play 等中心化组织的审核审查，所以本身可运行在浏览器中、连接方式被浏览器默认支持是非常重要的。无论 WebSocket 还是 WebRTC，在浏览器中进行高效、并行连接，或进行流式数据传输，都是很好的选择。</p><p>与此同时，Rings Network 选择了 p2p 的方式进行连接，在传输效率上必然没有 Nostr 星型网络的中心节点群带宽状态好，但是连通性上会更胜一筹。两种去中心化网络在数据传输效率和连通性上有所不同取舍。</p><h4>节点角色</h4><p>Nostr 网络中存在中心节点（群），它们负责维护整个网络的状态；Rings Network 网络中没有中心节点，所有节点在整个网络中具有相同的角色。</p><p>如果网络中有恶意节点存在，两种网络均不会被钓鱼或虚假消息攻击，因为两者都是经过加密算法保证每一条消息的可靠性。但是当恶意节点的目的是监听、追踪、蓄意不传递消息位置时，在 Nostr 网络中，恶意的客户端不会造成太大影响，但是恶意的 relay 则会造成网络故障或用户隐私暴露；在 Rings Network 中，精心编排的 Chord id 恶意节点也有可能通过控制一定数量的恶意节点达成监听和追踪的目的，但是不容易造成网络故障或不可用。</p><h4>数据存储</h4><p>Nostr 网络中，数据存储在 relay 节点；Rings Network 网络中，数据分布存储在整个网络中的各个节点，不过目前而言 Rings Network 的 DHT 暂且没有节点连接信息以外的内容，以胶水协议形式使用任意第三方进行存储。</p><p>Nostr 这种设计更偏向现有区块链的节点形式，但并非所有 relay 都对所有消息进行持久化，是一种在成本和效率中有所兼顾的方案。而 Rings Network 本身没有这种功能，依赖第三方在形式上为开发者提供了更多灵活的选择、降低了开发难度，不过同时也舍弃了网络本身的功能。</p><h4>数据查询</h4><p>Nostr 网络中，数据查询需要经过中心节点；Rings Network 网络中，数据查询可以通过环状网络中的任意节点进行。因此大多数情况下 Nostr 查询吞吐量较高，而查询较为中心化，relay 节点性能要求、网络要求均较高，Rings Network 平均查询吞吐量则较低，但是不会收到单点退出网络而造成数据丢失。</p><h4>可靠性</h4><p>Nostr 网络的可靠性取决于 relay 节点的可靠性，如果中心节点故障，整个网络将受到影响；Rings Network 网络的可靠性较高，即使一个或多个节点故障，整个网络仍然能够正常工作。</p><p>当遭遇单点故障时，主要取决于故障点属性。Nostr 网络中，如果故障点发生在 relay 节点上，大量客户端将受到影响，如果多个 relay 节点遭遇故障，可能会造成网络分裂成几部分，甚至整个网络瘫痪。而 Rings Network 遭遇单点故障时则表现较好，因为各个节点关系对等，即使 50% 节点遭遇故障仍能保持 95% 以上的可用性。</p><h4>效率</h4><p>Nostr 网络的效率可能受到中心节点的限制，数据的查询和存储都需要经过中心节点；Rings Network 网络的效率较高，数据的查询和存储都可以通过任意节点进行。</p><p>Nostr 网络中随着网络的发展壮大，客户端数量和 relay 数量的比值如果一直较为均衡，则不容易出现堵塞，但如果客户端数量剧增而 relay 数量和质量没有跟上网络发展的速度，瘫痪的情况则有可能发生。不过在理想状态下，整体传输效率较高，速度也较快，但是即使在这种情况下，随着网络中消息包数量剧增，很容易造成类似 DDOS 效果的消息风暴出现，可能会拖垮整个网络。</p><p>Rings Network 网络则相反，如果节点数量剧增，则网络效率和传输质量会有所提升，理论上节点越多连通性越好，相应的多点传输带来的带宽效应也会体现；而如果节点数量较少，偏僻节点则可能无法获得很好的体验。但随着节点数量增加顺势导致的消息量增加时，因为点对点传输的缘故，消息风暴出现的可能性非常低。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8283bb60923b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[日本人真的说过「花姑娘大大的有」这种话吗]]></title>
            <link>https://medium.com/@croath/%E6%97%A5%E6%9C%AC%E4%BA%BA%E7%9C%9F%E7%9A%84%E8%AF%B4%E8%BF%87-%E8%8A%B1%E5%A7%91%E5%A8%98%E5%A4%A7%E5%A4%A7%E7%9A%84%E6%9C%89-%E8%BF%99%E7%A7%8D%E8%AF%9D%E5%90%97-b4afff05cc2d?source=rss-a23cd5271080------2</link>
            <guid isPermaLink="false">https://medium.com/p/b4afff05cc2d</guid>
            <dc:creator><![CDATA[Croath Liu]]></dc:creator>
            <pubDate>Thu, 13 Feb 2020 08:09:34 GMT</pubDate>
            <atom:updated>2020-02-13T08:09:34.987Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*sAry60rRQg9v91Ih.jpg" /></figure><p>中国影视作品、特别是抗日战争系列作品中，常出现侵华日军和中国人说一些奇怪的话，甚至有些场景中中国人也会和日本军人说这样的语言，比方说：</p><p>「花姑娘大大的有」<br>「你的什么的干活」<br>「我的良民的干活」</p><p>我最开始以为是丑化侵华日军的手法，或者是因为侵华日军说不好中文而说出的一种奇怪的语言。但是随着看的抗日剧越来越多，我开始有一种疑问：如果这些语言是编剧杜撰的，为什么所有作品中的语法都差不多？难道不应该每个编剧有自己的杜撰语法结构吗？更深层的疑问也到了我脑海中：听了几句这种语言之后，我好像掌握了这种语言的特征，甚至能自己造几个看起来还算像样的句子：</p><p>「我的食堂的去，吃饭的干活。」</p><p>不用我说，想必所有人都能理解这句话的意思，虽然是我自己造的句。这是不是很神奇？我们听了几句蹩脚的汉语，就能感受出其中错误的汉语语法，然后还能造句，甚至其他也听过类似语言的人都能看懂！</p><p>其实这种语言真的存在，它叫「协和语」，也有其语法和语义规则；回到本文标题顺便也做个解答：日本人还真说过「花姑娘大大的有」这句话，真不是抗日剧编剧杜撰的。</p><h3>协和语是什么</h3><p>来自维基百科的解释：</p><blockquote>协和语是曾经使用于日本影响下的中国东北地区的一种日语和汉语混杂的皮钦语（混杂语言），其主要存在时期自清末日俄战争后至 1945 年满洲国灭亡。<br>指代“通行于满洲地区的日中混杂语”这一概念的名称很多，例如日满混淆语、沿线官话等。现在较常使用的“协和语”一名的可考用法最早出现在1948年的中文报纸，在满洲国存在的时代并未发现中文或日文材料如此称呼。</blockquote><p>（后文我会再解释「皮钦语」，这里理解为混杂语言就可以了。）</p><p>「满洲国」指的是日本建立的傀儡政权，中华民国政府和中华人民共和国政府均不承认满洲国的地位，所以均称其为「伪满洲国」，但其本名是「满洲国」或「大满洲帝国」（下文中如若涉及到这几种不同称呼均代表满洲国，请不要做意识形态方面的恶意推断，本文不带有作者个人政治倾向）。</p><p>满洲国在哪呢？看这张图：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*FTQ7BXzFuQb2xQCq.jpg" /></figure><p>得到这样的解释之后我们大体上有了一个印象，就是协和语应该在目前我们所说的中国「东北地区」流行过。但协和语这个名字是 1948 年才真正见于文学作品的，在那之前大多被称作「日支合弁語」「日満合弁語」「中日合弁語」「日満親善語」或「沿線官話」（南满洲铁道沿线的官话）。</p><p>无论叫它什么吧，说的都是这种汉语和日语混杂而形成的新语言，而这种语言最早在 1924 年就有记载了，沿用至 1945 年左右，至少有 20 年的使用时间，所以其语法和语义上经过前后人的丰富和完善，也形成了自己的一套体系。因为取自汉语和日语，所以这就是为什么汉语母语者随便听两句也能说个大概的原因。</p><p>伪满是多民族共融地区，那么大家应该说什么语言呢？当时伪满的口号是「五族协和，王道乐土」，五族是满洲国主要的五大民族，指的是汉族、蒙古族、朝鲜族（当地朝鲜族和朝鲜人）、满族、大和民族（日本人），其中汉族人占 83%，满族和蒙古族占 15%，朝鲜人和日本人占 2% 左右。</p><p>这样的一种人民组成形态中，因为日本人是统治阶层，所以 1934 年开始满洲国小学教育开始加入日语课程，1938 年汉语、日语、蒙古语成为满洲国国语，日语是小学必修课，汉语和蒙古语是二选一的选修课。</p><p>虽然因为同化教育的原因，很多当地人都会说日语，但是更普遍的中国人还是说汉语的，所以要和当下最普通的中国人交流，汉语是必要的，这也是协和语产生的历史背景，当然也是协和语主要发音是汉语发音的原因。</p><h3>基本的协和语语法</h3><p>基本的语法比较简单，这里简单介绍几种：</p><p><strong>疑问句，核心词汇：か（读作类似 ka 的发音）</strong></p><p>学过日语的同学看到这里会比较熟悉，因为日语的疑问句句尾就是「か」。没学过日语的同学也不用怕，因为学起来非常简单，比方说这句：</p><blockquote>你的知道か — 你知道吗？<br>一个多少钱か — 一个多少钱？</blockquote><p>简单吧，好像就是把「吗」换成了「か」，或者把没有汉语疑问词的句尾加上了「か」。读法也非常简单，汉语的部分就按照汉语读，最后那个か就读 ka。</p><p><strong>表示存在、完成、断定的句子</strong></p><p>句尾加个「有」就可以了。</p><blockquote>花姑娘大大的有 — 这里有漂亮的姑娘。（花姑娘其实指慰安妇或者军妓）<br>他死了的有 — 他死了。</blockquote><p>简单吧，读法上也很简单，「有」就是汉语读音。</p><p><strong>「的」字</strong></p><p>你的我的他的，（你的有时候也用作「你呀」）人称代词你我他。汉语不是黏着语，所以有时候出于语音节奏的原因，要加一个「的」字，比方说：</p><blockquote>你呀這個的いくらか — 你这个东西卖多少钱？<br>你的快快的干活的好 — 你快点工作。</blockquote><p>第二句话如果做中文语法分析的话，第二个「快快的」应该是「快快地」，但是协和语中没有这种区别。</p><p><strong>ある 表示断定，读音 a ru 类似：啊撸</strong></p><p>在协和语中 ある 不但表示日语中的 ある，还可以代替 である／です／だ，就是全简化成 ある 了。后来这种现象也像 long time no see 一样传回日本去了，一部分日本人也这么说话。</p><p>《银魂》中神乐口头禅就是 ある，这就是一种典型的刻板印象，因为日本人觉得中国人讲日语总是总是喜欢把各种词语都像协和语一样用 ある 代替，所以塑造这种中国元素的动漫形象就给她配上这种口头禅了。</p><h3>词汇的交融</h3><p>虽然说日语汉字来源于中文，但还是有很多汉语词汇是日语没有的，比方说上文提到的「快快的」（快快地）就是汉语词的转化。类似的词还有：</p><blockquote>明白（日語：みんぱい minbai）表示明白或了解。<br>死了（日語：すーら sūra） ：意思是死亡。<br>勞駕，老駕（日語：ろーじゃ rōja）：辛苦了，勞駕。<br>…</blockquote><p>他们除了日常词汇当然也学了一些民间词汇：</p><blockquote>屄（ぴー，pī，女性器，売春妇）</blockquote><p>和我们学英语一样，正经的没学几句，一旦你周围有英语母语者，那你学脏话的速度肯定突飞猛进。日本军人也不例外，说脏话也比较多：</p><blockquote>マーラカピー（妈的屄）- 这种脏话在日本军队中比较盛行<br>朝鮮ピー（朝鲜屄）- 抢来的朝鲜姑娘，他们这样称呼朝鲜慰安妇<br>ピーヤ（屄屋）- 妓院</blockquote><p>虽说日语本身脏话甚少，但是人性本身就没有太大的差别，他们学会了脏话之后也会说的如此顺口，歧视意味也比较强，中文中应该没有人把妓院叫做屄屋之类的，中国女性和朝鲜女性一度被物化成一个女性器官而已。</p><p>这些词汇组成的语言当时也被称作 兵隊シナ語，军队支那语，因为支那含有贬义色彩所以后来更广泛地被称作「军队中国语」。</p><p>除了汉语折射到日语的词汇，日语也有很多词汇被以音译的形式引入到汉语中，举几个常见的例子：</p><blockquote>八嘎/八格牙路 — 馬鹿，假名：ばか，baka，笨蛋、混账的意思<br>米西米西 — 飯々 meshimeshi，吃饭的意思<br>哟西 — よし，表示好<br>哈依 — はい，表示肯定的回答</blockquote><p>这些词汇想必大家在影视作品中都有听到过，都是日语词汇的音译，这些词语日本人没有找到对应的中文词语就直接用了日语，时间长了中国人也会跟着说，便于交流。</p><p>双向词汇互通的过程中也产生了一些非常奇妙的词汇，在翻译角度可以说做到了信达雅的程度：</p><p>轱辘马 — クルマ，日语读音是 kuruma，听起来和「轱辘马」很像，意思就是汽车。当时中国少有的汽车，汽车大多是日本人带来的，他们叫 kuruma，中国人就也叫它轱辘马，非常形象，带四个轱辘的自己会跑的马。</p><h3>日常表现形式</h3><p>除了影视作品中一句两句的短句，协和语又如何组成长段的书面语言呢？这里摘录《满洲农业概况》中的一小段：</p><blockquote>人生所需要的衣、食、住一切物品、无一不可以大豆供给的、福特汽车王曾经讲过「完全用大豆制成而实用豆油驱驰的汽车，不久就可以出现了」、由这句话也就可以窥知大豆的用处伟大了，大豆有以上广泛的用处、所以在将来发展上有莫大期待的。</blockquote><p>口语化的表示也有：</p><blockquote>明天的你的快々的起來、你的起來的我的に起來說話</blockquote><p>虽然有语法和特定结构，但是其实整个就是一个混乱的状态。</p><p>更多关于协和语的语法，如果有兴趣，可以参考一些文献，比如四宫爱子的《「日支合辦語」の研究》等。</p><h3>伪中国语</h3><p>伪中国语是近些年的一个新名词，主要是 Twitter 上一些日本用户发表的文字，他们去掉了日语的假名，通篇全部使用汉字表达，形成一种奇怪的语言，其本身的语法是不通的，纯娱乐化的一个东西。我在 Twitter 上随便搜了一些贴出来让大家观摩一下：</p><blockquote>今日君伪中国语勉强乎？<br>伪中国语、日本人娱乐而造。今仆(僕)伪中国语以言、大变感异(異)。<br>此语古中国语与日本语之语法合契、其勉强、感趣有。中国人此语理解较易。<br>- <a href="http://twitter.com/_Lazy_Rabbit_">@_Lazy_Rabbit_</a></blockquote><blockquote>我日视群，群友变态言，非常惧<br>群的主、管理如视，管理希望<br>谢谢茄子<br>- <a href="http://twitter.com/xlymuxdy">@xlymuxdy</a></blockquote><blockquote>课业準備中，本当煩，牛乳飲用想。<br>- <a href="http://twitter.com/Licht_CAO">@Licht_CAO</a></blockquote><p>对话：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/386/0*zHEHQtzuA-rWqM95.jpg" /></figure><p>甚至还有专门的表情包：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/734/0*ca_KXZHh3FqJSf9K.jpg" /></figure><p>近期日本商店为中国顾客也打出了伪中国语的标语：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/0*NaUcCRtKP4J3k5qc.jpg" /></figure><h3>只有日语和汉语的混合吗</h3><p>当然不是。前文提过的皮钦语（Pidgin）指的就是两门或多门语言混合产生的新语言。这里大家最了解的恐怕就是上海的洋泾浜了：</p><blockquote>— 來是康姆（khaonm / come）去是谷（koh / go），廿四洋鈿吞的福（thentihfoh / twenty-four）。<br> — 是叫也司（yasy / yes）勿叫諾（noh / no），如此如此沙咸沙（soghaeso / so and so）。<br> — 真嶄實貨佛立谷（vahlihkoh / very good），靴叫蒲脫（buthah / boot）鞋叫靴（shiu / shoe）。<br> — 洋行買辦江擺渡（kaonpadu / comprador），小火輪叫司汀巴（sythinpo / steamer）。<br> — 翹梯（thi / tea）翹梯請吃茶，雪堂（shihdaon / sit down）雪堂請儂坐。<br> — 烘山芋叫撲鐵禿（phohthihthah / potato），東洋車子力克靴（lihkhahshiu / rickshaw）。<br> — 打屁股叫班蒲曲（paebutshoh / bamboo chop），混帳王八蛋風爐（daefonlu / daffy low）。<br> — 那摩溫（namouuen / number one）先生是阿大，跑街先生殺老夫（saehlaufu / shroff）。<br> — 麥克（mahkhah / mark）麥克鈔票多，畢的生司（pihtihsansy / empty cents）當票多。<br> — 紅頭阿三開潑度（khephahdu / keep door），自家兄弟勃拉茶（bahladzo / brother）。<br> — 爺要發茶（fahdzo / father）娘賣茶（madzo / mother），丈人阿伯發音落（fahinloh / father-in-law）。</blockquote><p>苗族的语言和其他语言混合之后新诞生了一种语言叫做：猫家话。<br>青海东部的五屯人自创的五屯话则混合了汉语、藏语、蒙语。<br>东北官话也有大量词汇来自于满语，比如：「撒么」满文转写sabumbi，是看见的意思。</p><p>除了汉语方言之外，其他地方也有大量的皮钦语存在的情况。语言是随着使用者的迁徙、融合、共通发生着改变，所以随着新词汇广泛地使用，随时都可能有新的皮钦语产生。</p><p>网络用语和汉语的混合、emoji 和其他语言的混合都算是现代皮钦语，例如：</p><p><strong>感觉自己像一个SB。</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b4afff05cc2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[小程序生成图片分享朋友圈]]></title>
            <link>https://medium.com/@croath/%E5%B0%8F%E7%A8%8B%E5%BA%8F%E7%94%9F%E6%88%90%E5%9B%BE%E7%89%87%E5%88%86%E4%BA%AB%E6%9C%8B%E5%8F%8B%E5%9C%88-12d5226e3331?source=rss-a23cd5271080------2</link>
            <guid isPermaLink="false">https://medium.com/p/12d5226e3331</guid>
            <category><![CDATA[微信小程序]]></category>
            <category><![CDATA[chrome]]></category>
            <category><![CDATA[puppeteer]]></category>
            <dc:creator><![CDATA[Croath Liu]]></dc:creator>
            <pubDate>Wed, 23 Oct 2019 09:21:04 GMT</pubDate>
            <atom:updated>2020-10-20T13:45:00.667Z</atom:updated>
            <content:encoded><![CDATA[<h3>小程序生成图片分享朋友圈</h3><p>小程序开发者都希望自己的小程序得以广泛传播，因为不少小程序都设计了很多转发激励行为，但分享小程序到朋友圈（或其他外部平台）一直是一个难题。一个常见的方案就是生成分享海报、分享图片。但生成分享图片在技术上却也是一个难题。</p><h3>技术选型</h3><p>目前常用技术方案基本分为三种：</p><ol><li>使用 canvas 绘图并生成</li><li>使用后端绘图库进行绘制，返回给小程序端</li><li>使用服务端开一个浏览器进行 HTML 渲染，并截图返回给小程序端</li></ol><p>第一种方案：要求较高，canvas 和纯 html 布局相去甚远，零基础学习<strong>成本较高</strong>，而且在不同的微信浏览器中效果<strong>不可预期</strong>，想短时间内做出精美可控的生成图片不容易。实操的时候发现了一个非常麻烦的事情：网络图片或者 base64 图片都无法直接在 canvas 里渲染显示，要先下载好传进去。</p><p>第二种方案：后端库可以完成较为简单的需求，但字体加载、阴影、圆角、透明等方案效果需要精调，如果文字需要截断或动态伸缩长度时并不容易处理。图片的截取和伸缩自适应也不灵活。而且选用这种方案相当于需要把 UI 布局的工作丢给后端工程师去解决，这不是他们擅长的范围，效果未必会好。</p><p>第三种方案：页面的绘制方面，<strong>纯前端技术即可完成</strong>，难度低，完成度高，但是需要在后端起一个 node 服务开启 puppeteer 去控制服务端 Chrome 浏览器。这种方案的缺点就是<strong>成本太高</strong>，我们和业界同行都测算过，结果差不多：4 核 16G 的服务器生成图片的 QPS 大概只有 10–20，相当于一秒钟较差情况只能生成 10 张图片，这对于突发的大量分享需求并不能满足，而且这种配置的服务器，不能部署其他服务，只跑这个服务就会用尽大部分资源。</p><p>费用上：只单单算 5M 带宽的服务器费用一个月就要 700+ 人民币，流量和图片托管费用另算。此方案的最小化实现：至少需要 1 核 2G 的服务器才能较为顺畅地完成一次顺利截图，但是还是要处理浏览器无响应假死等情况，较为复杂。但综合来看，这种方案是效果最好最为灵活的。</p><h3>快海报小程序分享图生成服务</h3><p>快海报 <a href="https://kuaihaibao.com/">kuaihaibao.com</a> 是专门提供小程序分享海报生成服务的，技术上用的就是上面所述的第三种方案，但是只需要调用他的 API 就可以完成，不需要开发者维护 puppeteer 和 headless Chrome，而且成本较低，一张分享图的最低生成成本是 0.033 元。</p><p>其实真正集成到自己的服务中时，平均成本要比这个低，因为有些生成的图片的二维码，如果不带用户个人信息（不给分享的用户返利）时，可以生成一次之后永久缓存起来，其他用户再分享同一个东西都用缓存好的图片，综合成本就降下来了。</p><p>算一下成本：</p><ul><li>比方说一个刚起步的小程序日活 5000（对于刚起步的小程序其实已经很高了吧）</li><li>假设有 5% 的用户生成分享图</li><li>也就是每天生成 250 张分享图，一个月会生成 7500 张分享图</li></ul><p>这样的话每个月成本就是 75元人民币左右，相比 700+ 人民币的服务器成本省太多了。这是测算比较高的指标，而且是完全不应用缓存方案的情况。</p><p>如果你的小程序还处于冷启动的阶段：</p><ul><li>日活 500</li><li>假设有 5% 的用户生成分享图</li><li>也就是每天生成 25 张分享图，一个月会生成 750 张分享图</li></ul><p>每月成本 7.5 元。比 1 核 2G 的最小化自部署方案也要便宜。但带来的收益是无穷的，750 张分享图发到朋友圈，每张分享图 1000 受众浏览，一个月就是将近 750000 人次分享受众。</p><h3>调用 API</h3><p>首先去 <a href="https://kuaihaibao.com/">https://kuaihaibao.com/</a> 注册账号，验证邮箱激活之后，其实就可以先测试用了，每个账号有 100 次测试额度，测试生成的图片带水印。</p><p>网站左侧的 [文档] 页面能找到集成文档，非常简单，一共就只有一个核心 API，通过 HTTP 调用的。</p><p>先在【开发】-&gt;【设置】中激活 token</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/0*TNs7aphZnHaZnjyZ" /></figure><p>然后打开 【开发】-&gt;【模板】中，找到自己喜欢的模版。因为我只想生成一个简单的分享图片，所以最简单的方式就是使用网站内置的模版，内置模板目前有 8 款，应该能满足大部分小程序的需求了，抽奖、打卡、图文、文字、电商都有，改一改文案和图片就可以了。</p><p>我选了这个抽奖模板：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*qZtuT9HLCqHLpzcZ" /></figure><p>按照 <a href="https://kuaihaibao.com/doc/docs/template/kzccda95.html">https://kuaihaibao.com/doc/docs/template/kzccda95.html </a>文档描述的 JSON 改成我需要的：</p><pre>{<br>  &quot;backgroundColor&quot;: &quot;#fafafa&quot;,<br>  &quot;backgroundImage&quot;: &quot;&quot;,<br>  &quot;user&quot;: {<br>    &quot;avatar&quot;: &quot;https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/girl_2.jpg&quot;,<br>    &quot;nickname&quot;: &quot;我是测试账号&quot;,<br>    &quot;color&quot;: &quot;#666&quot;<br>  },<br>  &quot;tip&quot;: &quot;邀请你来抽奖&quot;,<br>  &quot;qrcode&quot;: &quot;https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/sample_qr_0.png&quot;,<br>  &quot;records&quot;: [<br>    {<br>      &quot;title&quot;: &quot;一等奖&quot;,<br>      &quot;desc&quot;: &quot;2019 年 11 月 16 日 10:00 开奖&quot;,<br>      &quot;image&quot;: &quot;https://s3.cn-northwest-1.amazonaws.com.cn/res.weiyidan.com/production/10000002/4109f8e51a8f43b9816dbc8fe636e22a.jpeg&quot;<br>    }<br>  ],<br>  &quot;brand&quot;: &quot;我的测试抽奖小程序&quot;,<br>  &quot;slogan&quot;: &quot;快来和我一起抽吧！&quot;,<br>  &quot;metaColor&quot;: &quot;#999&quot;<br>}</pre><p>然后打开 Terminal 做一次请求试试：</p><pre>curl -X &quot;POST&quot; &quot;https://api.kuaihaibao.com/services/screenshot&quot; \<br>     -H &#39;Authorization: Bearer 这里写你自己的 token&#39; \<br>     -H &#39;Content-Type: application/json; charset=utf-8&#39; \<br>     -d /pre&gt;{<br>  &quot;template&quot;: &quot;kzccda95&quot;,<br>  &quot;data&quot;: {<br>    &quot;qrcode&quot;: &quot;https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/sample_qr_0.png&quot;,<br>    &quot;records&quot;: [<br>      {<br>        &quot;title&quot;: &quot;一等奖&quot;,<br>        &quot;desc&quot;: &quot;2019 年 11 月 16 日 10:00 开奖&quot;,<br>        &quot;image&quot;: &quot;https://s3.cn-northwest-1.amazonaws.com.cn/res.weiyidan.com/production/10000002/4109f8e51a8f43b9816dbc8fe636e22a.jpeg&quot;<br>      }<br>    ],<br>    &quot;tip&quot;: &quot;邀请你来抽奖&quot;,<br>    &quot;slogan&quot;: &quot;快来和我一起抽吧！&quot;,<br>    &quot;metaColor&quot;: &quot;#999&quot;,<br>    &quot;brand&quot;: &quot;我的测试抽奖小程序&quot;,<br>    &quot;backgroundImage&quot;: &quot;&quot;,<br>    &quot;backgroundColor&quot;: &quot;#fafafa&quot;,<br>    &quot;user&quot;: {<br>      &quot;avatar&quot;: &quot;https://khb-sample.oss-cn-shanghai.aliyuncs.com/sample/girl_2.jpg&quot;,<br>      &quot;nickname&quot;: &quot;我是测试账号&quot;,<br>      &quot;color&quot;: &quot;#666&quot;<br>    }<br>  }<br>}&#39;</pre><p>返回了结果：</p><pre>{<br>  &quot;success&quot;: true,<br>  &quot;data&quot;: {<br>    &quot;name&quot;: &quot;iPhone 5&quot;,<br>    &quot;image&quot;: &quot;https://khb-test-oss.oss-cn-shanghai.aliyuncs.com/screenshot/4fa63f2a3605cbdece90c659cbccea619d9cf9fa?x-oss-process=style/test_watermark&quot;<br>  }<br>}</pre><p>打开图片地址看看：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*5CasflZ-TAUag3up" /></figure><p>速度很快，图片很漂亮，只是中间带水印，充值后成为付费用户，再生成的图片水印就自动取掉了。</p><h3>后端集成</h3><p>这里参考快海报官方给的最佳实践的逻辑参考图：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zaYK3zQV_bViQ9h1" /></figure><p>所以后端只需要做一件事，就是提供一个 API 给客户端用，这个 API 被调用的时候去请求快海报的服务器，再把结果返回给小程序就好了。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=12d5226e3331" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Catalina macOS 10.15 下 CGO 不能运行的解决方案]]></title>
            <link>https://medium.com/@croath/catalina-macos-10-15-%E4%B8%8B-cgo-%E4%B8%8D%E8%83%BD%E8%BF%90%E8%A1%8C%E7%9A%84%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88-5b580140b45a?source=rss-a23cd5271080------2</link>
            <guid isPermaLink="false">https://medium.com/p/5b580140b45a</guid>
            <category><![CDATA[catalina]]></category>
            <category><![CDATA[go]]></category>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[golang]]></category>
            <dc:creator><![CDATA[Croath Liu]]></dc:creator>
            <pubDate>Sun, 13 Oct 2019 09:55:54 GMT</pubDate>
            <atom:updated>2019-10-13T09:55:54.379Z</atom:updated>
            <content:encoded><![CDATA[<p>如果提示：</p><pre># crypto/x509<br>share/go/src/crypto/x509/root_cgo_darwin.go:16:10: fatal error: &#39;CoreFoundation/CoreFoundation.h&#39; file not found<br>#include &lt;CoreFoundation/CoreFoundation.h&gt;<br>         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~</pre><p>或：</p><pre>fatal error: ‘stdio.h’ file not found</pre><p>首先应该安装最新稳定版的 Xcode，安装完毕后打开运行，会提示安装 Command Line Tools，或运行：</p><pre>xcode-select --install</pre><p>此时运气好问题就会消失了，如果仍然提示 CoreFoundation .h 找不到，应按照以下方案依次运行：</p><ol><li>重启，按住 Command+R 进入 恢复模式，在恢复模式中启动 terminal，输入：</li></ol><pre>csrutil disable</pre><p>2. 重启之后，运行：</p><pre>sudo mount -uw /	# 根目录挂载为可读写</pre><p>3. link 如下几个目录</p><pre>cd /System/Library/Frameworks/CoreFoundation.framework<br>ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Headers Headers<br>ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/CoreFoundation.framework/Modules Modules<br>cd /System/Library/Frameworks/Security.framework<br>ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Headers Headers<br>ln -s /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks/Security.framework/Modules Modules</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5b580140b45a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[macOS 快速在英文与常见输入法之间切换]]></title>
            <link>https://medium.com/@croath/macos-%E5%BF%AB%E9%80%9F%E5%9C%A8%E8%8B%B1%E6%96%87%E4%B8%8E%E5%B8%B8%E8%A7%81%E8%BE%93%E5%85%A5%E6%B3%95%E4%B9%8B%E9%97%B4%E5%88%87%E6%8D%A2-de07d9a4b1f3?source=rss-a23cd5271080------2</link>
            <guid isPermaLink="false">https://medium.com/p/de07d9a4b1f3</guid>
            <category><![CDATA[input-methods]]></category>
            <category><![CDATA[shortcuts]]></category>
            <category><![CDATA[macos]]></category>
            <dc:creator><![CDATA[Croath Liu]]></dc:creator>
            <pubDate>Tue, 17 Oct 2017 03:39:32 GMT</pubDate>
            <atom:updated>2017-10-17T03:39:32.217Z</atom:updated>
            <content:encoded><![CDATA[<p>我日常有五个常用输入法：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mfZCj5uxIPtaOS6jRCM7nA.png" /><figcaption>英文 / 简体拼音 / 繁體拼音 / 平假名 / 片假名</figcaption></figure><p>日常使用时有几个常见需求：</p><ol><li>在非英文输入法中输入长度不会太长的英文词组</li><li>在非英文与英文输入法之间快速切换</li></ol><p>第一个问题其实还算容易解决了，在简体拼音和繁體拼音的情况下还好了，默认敲 Caps Lock 键就可以长短输入英文了。但是有一个缺点，就是在日文输入法情况下却不好用了，无论如何都不能很方便地进行来回切换，只能手动切换。</p><p>第二个问题平时还好，但是会遇到一些不太好的场景，比方说我从简体切换到繁體，又切换回简体，系统就会将这两个切换作为 ⌘+Space 的缓存。所以就不是很方便去快速切换到英文。但是两个非英文输入法间频繁互相切换的需求是比较少的，相反是某个非英文输入法和英文输入法之间频繁切换比较多，所以我并不想要这种「智能缓存」。</p><p>首先，我看了一下输入法的配置界面：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PDrNBlGT5kSRtp2Lf7kLAQ.png" /></figure><p>快捷键中并没有此功能，找来找去，发现了这个配置：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8CJgnWRDJ9IrJO1VLYnjAQ.png" /></figure><p>迅速勾选☑️！问题完美解决！</p><p>这样会让 Caps Lock 不切换输入法而快速输入英文的功能失效，但是可以迅速切换到英文输入法，再按一次还会回来。不但解决了问题 2，而且还顺带解决了问题 1 中日文输入法无法方便输入英文的问题。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=de07d9a4b1f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[简单 CNN 解决手写汉字错别字识别问题]]></title>
            <link>https://medium.com/@croath/%E7%AE%80%E5%8D%95-cnn-%E8%A7%A3%E5%86%B3%E6%89%8B%E5%86%99%E6%B1%89%E5%AD%97%E9%94%99%E5%88%AB%E5%AD%97%E8%AF%86%E5%88%AB%E9%97%AE%E9%A2%98-f502c21d1747?source=rss-a23cd5271080------2</link>
            <guid isPermaLink="false">https://medium.com/p/f502c21d1747</guid>
            <category><![CDATA[汉字]]></category>
            <category><![CDATA[cnn]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[tensorflow]]></category>
            <dc:creator><![CDATA[Croath Liu]]></dc:creator>
            <pubDate>Fri, 15 Sep 2017 03:54:05 GMT</pubDate>
            <atom:updated>2017-09-15T03:54:05.789Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>项目背景</strong></h3><p>项目起源于公司的 AI Contest，背景缩略如下：</p><blockquote>在字体业务中，创造新字体是一项重要的工作。在创造一种新字体时，我们首先会确定新字体的规格，并指定一个基准的汉字集合(通常有8877个常用汉字)，并请设计师来对每一个汉字按照字体规格来手写汉字；之后，会对每一个手写的汉字进行<strong>检查</strong>，找到其中的错字(比如少笔画、多笔画等等)，并请设计师修正。这其中的<strong>检查</strong>步骤，目前是人工在做，通常要消耗大量的人工(目前每种字体大约为两人天)。我们期望，利用技术手段，实现检查步骤的自动化，自动识别手写错字。</blockquote><p>这个问题首先想到的是 Tutorial 中的 MNIST 问题，所以尝试用同样的思路解决。但是有几点区别，所以细节处理上要做一些改变。</p><p>首先观察一下训练样本，大概是这样的一些样本：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/64/1*dC1Y0jQ6KY_b2RUo-kmJPg.png" /><figcaption>uni4e0e_与.png</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/64/1*wLcIjjzThxlk-ly6iFsfaA.png" /><figcaption>uni4e01_丁.png</figcaption></figure><p>图片会以这样的格式命名： &quot;uni&quot;+汉字unicode+&quot;_&quot; 汉字+&quot;.png&quot;</p><p>错误的样本如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/64/1*1m2kW_waWCZgySRUZFOWrA.png" /><figcaption>uni4E4C_乌.png</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/64/1*AMh6idumgyvCV0rQYKLyng.png" /><figcaption>uni4E4E_乎.png</figcaption></figure><p>实际为「鸟」</p><p>错误标记为「乌」</p><p>实际为「平」</p><p>错误标记为「乎」</p><p>错误样本基本分为两类：</p><ol><li>把一个字写成了一个字</li><li>搞错汉字构成，写了一个不存在的字</li></ol><p>简单说就是「错别字」 分开的「错字」和「别字」。</p><h3>数据预处理</h3><p>首先训练用样本图片的大小是不一致的，长宽比也是不一致的，需要进行预处理。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DFHaoj79CAgoyhOtpWvkug.png" /><figcaption>举例说明，左侧字需要左右补白，右侧字需要上下补白</figcaption></figure><p>预处理的方式我选择对图片进行归一尺寸成正方形，如果有长方形的图片则对短边进行补白（原图背景为白色前景为黑色）。当然也可以选择直接进行拉伸图片为正方形。我个人觉得拉伸方案不够好，因为像「一」这样的汉字会被拉成一个黑色的正方形，「丨」（笔画，竖）也会被拉成黑色的正方形，辨识起来会非常困难。一个更直观的例子如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/810/1*1_9FtX8lLJh3Xh8baggohg.png" /></figure><p>「汨罗江」的<strong>「汨」</strong>和「汩汩泉涌」的<strong>「汩」</strong>，如果只是简单拉伸，也很难进行辨识。类似的情况还有「日」和「曰」，这种情况并不罕见，而且可以说是属于日常手写错别字中概率比较高的别字范围。</p><p>所以最后选用填充空白的方案进行图片预处理。</p><p>做完填充之后还有一个问题，就是每幅图片尺寸不一，有的长宽上千 pixels，有的几百。大尺寸可以较好地保留原始特征，但会明显减缓学习速度，所以需要挑选尽可能小、又要满足能够足以展现特征的尺寸。我选择了一个比较复杂的字，繁体的「变」-&gt;「變」，并在 PhotoShop 中输入这个字并不断调整大小，观察尺寸，最后发现 64x64 的大小已经足以展现复杂汉字的足够特征了：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/657/1*x2qMM817ZtksZ724XmIFgw.png" /></figure><p>我使用 ImageMagick 进行图片预处理，代码如下：</p><blockquote>find -name “*.png” | xargs -I{} \</blockquote><blockquote>convert {} -resize 64x64 +antialias \</blockquote><blockquote>-gravity center -extent 64x64 {}</blockquote><p>两步预处理进行之后的图片样式大体如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/558/1*ILEPOZ2A6HG0kBBqX3Xc0g.png" /></figure><p>继而和同事讨论中又遇到一个问题，我是先处理了所有样本生成了新样本集，同事则在运行时进行处理，类似的训练方法同事的训练过程相对较慢。其实原因也比较简单：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*owk-xfwBIwrYVhOdwU41xQ.png" /></figure><p>如果每张图片都在加载入内存时才进行补白和缩放操作，势必要占用很多运行时间，但是如果最开始先切好图片，之后的训练就只是训练了，会节省很多时间。</p><h3>CNN</h3><p>网络层比较简单，在 Tensorboard 中展现的可视化网络如下：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1MSuF2mHrGEBWymno3e3bg.png" /></figure><p>关键建层的代码也比较简单，没有过多复杂的操作：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q_A4DGOUbUwPB2f-gwy0Nw.png" /></figure><p>最后模型大小为 307.8M，只做了默认的简单量化之后缩减为 77M，识别正确率能够达到 99% 以上。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/746/1*NlUqXq3rnfJmUcHIVX33VA.png" /><figcaption>一些识别输出，可以看到「汨」和「汩」是可以完美分辨的</figcaption></figure><p>代码全在 <a href="https://github.com/croath/han">https://github.com/croath/han</a> ，README 中有更完善的使用方法，我的模型文件在 <a href="https://drive.google.com/file/d/0B-noE_nG9ncQY0ZZd29HWnNsUDQ/view?usp=sharing">https://drive.google.com/file/d/0B-noE_nG9ncQY0ZZd29HWnNsUDQ/view?usp=sharing</a> 可以下载。</p><p>训练样本也可以自己生产，项目中 dump_ttf.sh 可以通过输入的 ttf 字体文件自动生成所需训练样本和测试样本，使用时不必去网上费力寻找样本，自己生成即可。</p><p>有任何问题可以给我发邮件 Croath.Liu+medium@gmail.com 一起讨论。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f502c21d1747" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mac 再次中毒了]]></title>
            <link>https://medium.com/@croath/mac-%E5%86%8D%E6%AC%A1%E4%B8%AD%E6%AF%92%E4%BA%86-e0c34c390055?source=rss-a23cd5271080------2</link>
            <guid isPermaLink="false">https://medium.com/p/e0c34c390055</guid>
            <category><![CDATA[macos]]></category>
            <category><![CDATA[virus]]></category>
            <dc:creator><![CDATA[Croath Liu]]></dc:creator>
            <pubDate>Tue, 27 Jun 2017 06:41:41 GMT</pubDate>
            <atom:updated>2017-09-11T07:20:15.171Z</atom:updated>
            <content:encoded><![CDATA[<p>Mac 再次中毒了</p><p>今天 Mac 再次中毒了。</p><p>昨晚应约出去吃晚饭，Mac 就放在公司没有拿走，刚好在编译 tensorflow。今天上班打开浏览器，浏览器开始不停地蹦广告，Safari 和 Chrome 都一样。Ad click 的第一跳基本上是从 media-serving.com 出去的。搜了一下相关域名，都被引导去了下载 Windows 杀毒软件的博客，我怀疑这些博客也是这次广告病毒攻击计划中的一环，关掉了博客自己想办法。</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/1*MD4CaaqO39DgyONny7fd7w.png" /><figcaption>广告页面之一</figcaption></figure><p>先打开 Surge Dashboard 看一下网络请求，是从一个本地端口的服务代理走的第一次 redirect，试着向该端口主动请求，无果。试了触发几次广告，发现本地端口的服务是使用时启动，使用完立刻关闭的。高明。配合 Surge 发现了奇怪的进程在配合这件事：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JduYhrEx1jVGcUwZYkEEkQ.png" /><figcaption>就是这个 overwave</figcaption></figure><p>其实之前也遇到过一次类似的病毒攻击，不过当时在美国参加 WWDC，太忙了没空理就删了病毒进程放那了。（我甚至怀疑是在 WWDC 会场染上的病毒），上次是这个进程：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w99newVMtN96RpFjrwsUAw.png" /><figcaption>非常聪明，每次换个名字</figcaption></figure><p>这次是： /Library/overwave/overwave</p><p>尝试 kill，会自启动，和上次完全一样的。去看自 daemons：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*4pnYvvnJNklv11_rRn5tgA.png" /></figure><p>无果，咨询了一下原来 /Users/xxx/Library 下也有 LaunchAgents，在那里找到了 overwave 的 plist。删掉，然后删除 overwave，kill 进程，done。</p><p>kill 之前查了一下 Console 看日志，非常恐怖，记录了我每一次应用使用和浏览器浏览：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tFKUjV6JdEGBoFEiVVVPsA.png" /></figure><p>看了一下进程是凌晨 05:21 启动的，去看了一下 syslog：</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nhqHaCjkfgzJd1W_ZJBfpw.png" /><figcaption>这里很蹊跷</figcaption></figure><p>所以明显是有另外的服务写了这个 plist 进去。</p><p>至此为止，病毒处理完毕，但是并未彻底解决问题，或者说某天可能（一定）要复发。留下的疑点有三：</p><ol><li>为什么浏览器会经由我未配置的本地代理去请求网络？（我只使用 Surge 走系统代理链接远程代理翻墙）</li><li>到底是哪个 process 创建了 daemon plist 文件，目前没有日志文件能寻踪</li><li>如何预防此类病毒？（除了不安装来源不明的程序，但有时候有一些小开发工具很难第一时间判断其安全性）</li></ol><p>2017 年 9 月 11 日，再次中毒，这次和往次一样，process 又改了名字。照旧没有找到任何线索，总之先删除了病毒再看。无奈中只能挨个看进程名字看到哪个奇怪就去搜一搜。</p><p>看了一会进城太多了，后来想想它是有 root 权限的，只看 root 就好了。root 进程有很多认识的，syslogd WindowServer 等等，可以排除很多，最后剩下了十几个不认识的进程，挨个去搜吧。最终找到了这个：immora 广告病毒。</p><p>Google 搜到这个 thread： <a href="https://discussions.apple.com/thread/7950393">https://discussions.apple.com/thread/7950393</a></p><p>Daemon 在 /Library/LaunchDaemons/com.apple.immora.plist ，删掉，再删掉 /Library/immora。此次中毒事件算是告于段落。</p><p>另外，我非常怀疑这个病毒是 MacKeeper 放的，因为经常被引导到 MacKeeper 的下载页面，并提示系统已中毒让我下载修复。唉，外国人也不老实。</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e0c34c390055" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>