<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>Mobilicorpus</title>
  
  <subtitle>幻影显形 | Keep Curiosity</subtitle>
  <link href="/atom.xml" rel="self"/>
  
  <link href="https://hyxxsfwy.github.io/"/>
  <updated>2018-05-01T16:00:33.000Z</updated>
  <id>https://hyxxsfwy.github.io/</id>
  
  <author>
    <name>hyxxsfwy</name>
    
  </author>
  
  <generator uri="http://hexo.io/">Hexo</generator>
  
  <entry>
    <title>对 ETH 与 EOS 未来发展的思考浅述（技术篇）</title>
    <link href="https://hyxxsfwy.github.io/2018/04/30/%E5%AF%B9-ETH-%E4%B8%8E-EOS-%E6%9C%AA%E6%9D%A5%E5%8F%91%E5%B1%95%E7%9A%84%E6%80%9D%E8%80%83%E6%B5%85%E8%BF%B0/"/>
    <id>https://hyxxsfwy.github.io/2018/04/30/对-ETH-与-EOS-未来发展的思考浅述/</id>
    <published>2018-04-30T04:08:20.000Z</published>
    <updated>2018-05-01T16:00:33.000Z</updated>
    
    <content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="引言">引言</h3><p>身为币圈一员，又是学计算机专业的，对目前打得火热的两大开源区块链项目 ETH 与 EOS 自然是会比较上心。二者的技术、理念、演化模式、未来前景，都应当是需要关注与思考的话题。</p><p>本文将尝试从技术层面对这两个项目进行综合对比分析。一家之言，仅供参考。</p><a id="more"></a><h3 id="github-项目生态分析">Github 项目生态分析</h3><p>Ethereum 项目主页：<a href="https://github.com/ethereum" title="https://github.com/ethereum" target="_blank" rel="noopener">https://github.com/ethereum</a></p><p>EOS 项目主页：<a href="https://github.com/EOSIO" title="https://github.com/EOSIO" target="_blank" rel="noopener">https://github.com/EOSIO</a></p><p>下面列表分析 ETH 和 EOS 两者的项目生态数据（截至 2018.05.01），同时引入币圈最成功的开源项目 Bitcoin 的数据作为对照。</p><ul><li>表 1：项目数据总览</li></ul><table><thead><tr><th style="text-align:left">项目名称</th><th style="text-align:center">关联的代码仓库数量</th><th style="text-align:center">项目公共成员</th><th style="text-align:left">协议实现核心分支数</th></tr></thead><tbody><tr><td style="text-align:left">Ethereum（以太坊）</td><td style="text-align:center">3663</td><td style="text-align:center">38</td><td style="text-align:left">2 (Go &amp; C++ 实现)</td></tr><tr><td style="text-align:left">EOS（柚子）</td><td style="text-align:center">71</td><td style="text-align:center">0</td><td style="text-align:left">1 (C++ 实现)</td></tr><tr><td style="text-align:left">Bitcoin（比特币）</td><td style="text-align:center">2840</td><td style="text-align:center">25</td><td style="text-align:left">1 (C++ 实现)</td></tr></tbody></table><hr><ul><li>表 2：核心仓库数据统计</li></ul><table><thead><tr><th style="text-align:left">仓库名称</th><th style="text-align:center">实现语言</th><th style="text-align:center"><em>开源协议</em></th><th style="text-align:center">星标</th><th style="text-align:center">Watch</th><th style="text-align:center">Fork</th><th style="text-align:center">贡献者</th><th style="text-align:center">发布版本</th><th style="text-align:center">社区计划项目数</th></tr></thead><tbody><tr><td style="text-align:left">ethereum/go-ethereum</td><td style="text-align:center">Go</td><td style="text-align:center">LGPL-3.0</td><td style="text-align:center">17118</td><td style="text-align:center">1753</td><td style="text-align:center">5429</td><td style="text-align:center">259</td><td style="text-align:center">130</td><td style="text-align:center">9</td></tr><tr><td style="text-align:left">ethereum/cpp-ethereum</td><td style="text-align:center">C++</td><td style="text-align:center">GPL-3.0</td><td style="text-align:center">3008</td><td style="text-align:center">525</td><td style="text-align:center">1893</td><td style="text-align:center">125</td><td style="text-align:center">228</td><td style="text-align:center">0</td></tr><tr><td style="text-align:left">EOSIO/eos</td><td style="text-align:center">C++</td><td style="text-align:center">MIT</td><td style="text-align:center">6461</td><td style="text-align:center">1069</td><td style="text-align:center">1517</td><td style="text-align:center">101</td><td style="text-align:center">43</td><td style="text-align:center">0</td></tr><tr><td style="text-align:left">bitcoin/bitcoin</td><td style="text-align:center">C++</td><td style="text-align:center">MIT</td><td style="text-align:center">31059</td><td style="text-align:center">3236</td><td style="text-align:center">18597</td><td style="text-align:center">537</td><td style="text-align:center">192</td><td style="text-align:center">8</td></tr></tbody></table><ul><li>注：GPL、LGPL 协议属于非商业化的强制开源协议，MIT 协议是允许项目后续向闭源、商业化发展的。详见这篇文章：<a href="http://www.ruanyifeng.com/blog/2011/05/how_to_choose_free_software_licenses.html" title="http://www.ruanyifeng.com/blog/2011/05/how_to_choose_free_software_licenses.html" target="_blank" rel="noopener">如何选择开源许可证？- 阮一峰的网络日志</a></li></ul><hr><ul><li>表 3：最近一个月项目开发活跃度</li></ul><table><thead><tr><th style="text-align:left">仓库名称</th><th style="text-align:center">活跃的 Pull 请求</th><th style="text-align:center">提交的更改数</th><th style="text-align:center">参与的开发者数</th></tr></thead><tbody><tr><td style="text-align:left">ethereum/go-ethereum</td><td style="text-align:center">82</td><td style="text-align:center">61</td><td style="text-align:center">32</td></tr><tr><td style="text-align:left">ethereum/cpp-ethereum</td><td style="text-align:center">48</td><td style="text-align:center">115</td><td style="text-align:center">7</td></tr><tr><td style="text-align:left">EOSIO/eos</td><td style="text-align:center">233</td><td style="text-align:center">760</td><td style="text-align:center">40</td></tr><tr><td style="text-align:left">bitcoin/bitcoin</td><td style="text-align:center">236</td><td style="text-align:center">252</td><td style="text-align:center">43</td></tr></tbody></table><p>注：这个指标可以直接到 Github 的仓库统计页面上去查看，有详尽的图表与数据展示。结论是，近一个月内，由于主网上线日期临近，EOS 项目开发的活跃程度明显高于 ETH 的两个核心项目。</p><ul><li><p>go-ethereum 近一个月仓库活动数据查看地址：<br><a href="https://github.com/ethereum/go-ethereum/pulse/monthly" title="https://github.com/ethereum/go-ethereum/pulse/monthly" target="_blank" rel="noopener">https://github.com/ethereum/go-ethereum/pulse/monthly</a></p></li><li><p>cpp-ethereum 近一个月仓库活动数据查看地址：<br><a href="https://github.com/ethereum/cpp-ethereum/pulse/monthly" title="https://github.com/ethereum/cpp-ethereum/pulse/monthly" target="_blank" rel="noopener">https://github.com/ethereum/cpp-ethereum/pulse/monthly</a></p></li><li><p>EOSIO/eos 近一个月仓库活动数据查看地址：<br><a href="https://github.com/ethereum/cpp-ethereum/pulse/monthly" title="https://github.com/ethereum/cpp-ethereum/pulse/monthly" target="_blank" rel="noopener">https://github.com/ethereum/cpp-ethereum/pulse/monthly</a></p></li><li><p>bitcoin/bitcoin 近一个月仓库活动数据查看地址：<br><a href="https://github.com/bitcoin/bitcoin/pulse/monthly" title="https://github.com/bitcoin/bitcoin/pulse/monthly" target="_blank" rel="noopener">https://github.com/bitcoin/bitcoin/pulse/monthly</a></p></li></ul><p>总结：无需对上述数据做过分解读，但从宏观事实出发，ETH 项目的开源生态建设显然优于 EOS。换句话说，没有了中本聪的 Bitcoin 还是 BTC，没有 V 神的 ETH 也还会是 ETH，但没有 BM 的 EOS，可能就不再是 EOS 了。</p><h3 id="共识算法优劣对比">共识算法优劣对比</h3><p>BTC 使用的共识算法是 POW（Proof of work，工作量证明）；<br>ETH 目前使用的共识算法是 POW + POS（Proof of Stake，股权证明）混合模式；<br>EOS 使用的共识算法是 DPOS（Delegated Proof of Stake，委任权益证明）。</p><p>这三种算法各有优劣，POW 模式稳定、游戏规则明确、潜在的人为影响风险最小，为人所诟病的缺陷就是矿场矿池对算力的垄断。POS 是软件模拟挖矿的方案，相对而言整个区块链就更容易被算法漏洞所影响，且账本分叉成本低廉，曾经闹得沸沸扬扬的 ETH 与 ETC 之争就是明证。DPOS 机制是 BM 对 POS 的“技术改进”，其本质上是将 ETH 面临的复杂动态多节点网络问题简化成了固定节点（21 + 100）的简单类静态分布式网络问题。对于程序开发而言，这种简化确实大大降低了开发难度，同时还能有效提高主链的处理能力（即取得较高的 TPS 值）。但区块链项目本来就存在一个“蒙代尔三角”难题：“高效率、去中心、安全性”三者形成一个不可能三角关系：任意系统无法同时满足此三种特性。比特币和以太坊是通过舍弃“高效率”来获得去中心和安全性，而 EOS 则通过 DPOS 机制选举 21 个超级节点，舍弃“去中心”与“安全性”，以“弱中心”方式追求“高效率”。</p><p>下表列出的是“按照区块链网络内置协议运作的话，三种算法各自可能面临的安全问题”：</p><ul><li>表 4，PoW、PoS、DPoS 安全性对比</li></ul><table><thead><tr><th style="text-align:left">攻击方法</th><th style="text-align:center">POW</th><th style="text-align:center">POS</th><th style="text-align:center">DPOS</th></tr></thead><tbody><tr><td style="text-align:left">短距离攻击（如贿赂攻击）</td><td style="text-align:center">/</td><td style="text-align:center">x</td><td style="text-align:center">/</td></tr><tr><td style="text-align:left">长距离攻击</td><td style="text-align:center">/</td><td style="text-align:center">x</td><td style="text-align:center">x</td></tr><tr><td style="text-align:left">币龄累计攻击</td><td style="text-align:center">/</td><td style="text-align:center">x</td><td style="text-align:center">x</td></tr><tr><td style="text-align:left">预计算攻击</td><td style="text-align:center">/</td><td style="text-align:center">x</td><td style="text-align:center">/</td></tr><tr><td style="text-align:left">分布式拒绝服务（DDos）</td><td style="text-align:center">/</td><td style="text-align:center">可能</td><td style="text-align:center">x</td></tr><tr><td style="text-align:left">女巫攻击（Sybil Attack）</td><td style="text-align:center">x</td><td style="text-align:center">x</td><td style="text-align:center">x</td></tr></tbody></table><p>注：详情参见这篇文章：<a href="https://daimajia.com/2017/09/14/pow-and-pos" title="https://daimajia.com/2017/09/14/pow-and-pos" target="_blank" rel="noopener">PoW，PoS，DPoS 综述</a></p><p>结论：从现有技术角度看，ETH 目前的 POW+POS 混合模式无疑是最佳选择。接下来，阐述得出该结论的原因。</p><h3 id="对共识算法机制的引申思考">对共识算法机制的引申思考</h3><p>由上表可知，技术上，POW 算法可以免疫绝大多数的攻击手法，而 POS 算法最易遭受攻击。然而，这里有一个大前提，就是攻击者是遵守“游戏规则”的，会在区块链自身设定的协议体系中找出漏洞并且尝试攻击。但实际上，没有这么傻的攻击者。打个比方，我知道小偷可能会撬门而入，所以安全防范措施就是换好的防盗门，加坚固的锁。殊不知，真正要来偷的都是走窗户和阳台，或者假扮外卖小哥入室抢劫，根本不会按套路出牌。在一个点对点的网络系统中，有效节点的数量决定了整个系统的健壮性。BTC、ETH 都是不限全节点数量的，主链网络安全又受到矿工们巨大算力的保护，所以可以长期稳定运行。但 EOS 的架构设计，不具备这个条件。</p><p>我们知道，EOS 的架构是 21 个超级节点负责提供整个主链所需的运算、存储、网络等硬件资源，而 100 个见证节点是“预备队”，平时只负责验证超级节点是否正常、有效的工作，只有当某个超级节点出现问题时，才有机会被选上成为新的超级节点。原本这是一个很优秀的主从备份设计，可以确保整个网络的稳定运行。可惜，当 EOS 的分红机制将超级节点设计成“会下金蛋的鸡”之后，事情就变质了。设想这样一个场景，我是某个见证节点的主人，每个月都花费不菲的成本去运行这个备份节点，眼见着超级节点躺着赚钱，自己这却只能跟着喝口汤。明明是一样的硬件配置，一样的设备开销，一样的运维费用，只因为你当初主网上线时选票拉的好了那么一点点，坐上了超级节点的宝座，从此就吃香的喝辣的，凭什么？按照游戏规则，见证节点作为备份，只有当某个超级节点宕机死掉之后，才有机会被选上代替这个超级节点的位置。100 个见证节点，如果大部分都对超级节点抱着“你赶紧死掉我好上位”的心态的话，我不知道有什么理由阻挡超级节点被恶意攻击。事实上，只要对某个超级节点暴露在外网、对主链提供服务的端口发动 TCP/IP 层的大流量 DDoS 攻击，这个超级节点的网络服务能力就一定会被瘫痪掉。几分钟后，这个一直处于无法响应通信状态的超级节点就会被票死，失去超级节点的资格。要是所有节点持有人都这么干，EOS 网络就没法工作了。</p><p>当然，出钱的资本方都不傻，这样自己玩死自己的蠢事不会去做。那这 100 个见证节点真的就会遵守规则，面对潜在的巨额利润毫不动心，乖乖排队等待不知何时才会落到自己头上的超级节点资格吗？主网还没上线，超级节点贿选的事情就已经发酵了，ETH 的 创始人 V 神还专门为此事写了一篇檄文：<a href="https://mp.weixin.qq.com/s/S5I0m_GIArNFUm4cKYS4sA" title="https://mp.weixin.qq.com/s/S5I0m_GIArNFUm4cKYS4sA" target="_blank" rel="noopener">V神谈EOS节点投票：我们必须绕开的阴影之地</a>。主网上线之后，121 个节点实际上就形成了一个利益共同体。当所有参与方都意识到自己既有毁灭对手的能力，又随时可能被对手所毁灭的时候，博弈的结果只能是联合起来，一起赚钱，一起割韭菜。但事情若走到这一步，EOS 这个区块链项目和某个大互联网公司的云计算平台还有什么区别呢？以后这 121 个节点中的大部分肯定都是跑在亚马逊 AWS 云服务器上的，我作为一个开发者，与其在各方利益纠葛不清的 EOS 系统内去费时费力的开发 DAPP，还不如直接用成熟的 AWS 系统，快速开发快速上线呢。</p><p>此外，有攻击超级节点动机的可不止那 100 个见证节点持有人。EOS 代币已经被炒到了一个高位，就是普通黑产，也有强烈的通过威胁攻击超级节点，来向超级节点持有人敲诈勒索大量加密货币的动机。目前全球各地天天专研 ETH 系统漏洞，指望盗币发财的黑客一大堆，攻防战早已打响，ETH 也在开源社区自身力量的驱动下不断的优化协议逻辑，修改代码 BUG。而 EOS 呢，主网都没上线，未知的考验还不知有多少。欲带皇冠，必承其重，EOS 这种先把泡泡吹起来，再去试探真假，把赌注压在六月主网上线之后一切顺利的做法，风险极高！</p><h3 id="一点补充分析">一点补充分析</h3><p>实际上，EOS 的预期已经被过度消耗了。项目八字还没一撇，就这样去爆炒，完全是资金盘操纵的手法。到时候主网上线，随便出点什么差错（这是大概率事件，一个新系统上线，其表现是几乎不可能完全符合预期的），就都是做空的动力。</p><p>我比较赞同<a href="https://zhuanlan.zhihu.com/p/35831536" title="歪理邪说：EOS 可能是个癌细胞……" target="_blank" rel="noopener">这篇文章</a>所提出的理论：</p><blockquote><p>区块链是什么？<br>区块链是比特币；<br>区块链是点对点的分布式的账本；<br>区块链是带智能合约的点对点的分布式账本；<br>区块链是生产关系；<br>区块链是一种社会思潮；<br>区块链是一种基因（X-gen）</p></blockquote><p>不错，区块链就像细胞中的 DNA。其核心价值，不在于主链有多么强大的而丰富的功能，而在于其像基因一样，去中心化，稳定，传承价值，同时具备一定的合约功能。而更为复杂的功能，就应该交给侧链、分支去实现，就像自然界发生的那样：基因转录出 RNA，RNA 表达出蛋白质，再由蛋白质去承担生命活动。我相信自然的选择，这才是区块链技术正确的进化方向。</p>]]></content>
    
    <summary type="html">
    
      &lt;h3 id=&quot;引言&quot;&gt;引言&lt;/h3&gt;
&lt;p&gt;身为币圈一员，又是学计算机专业的，对目前打得火热的两大开源区块链项目 ETH 与 EOS 自然是会比较上心。二者的技术、理念、演化模式、未来前景，都应当是需要关注与思考的话题。&lt;/p&gt;
&lt;p&gt;本文将尝试从技术层面对这两个项目进行综合对比分析。一家之言，仅供参考。&lt;/p&gt;
    
    </summary>
    
    
      <category term="区块链" scheme="https://hyxxsfwy.github.io/tags/%E5%8C%BA%E5%9D%97%E9%93%BE/"/>
    
      <category term="金融" scheme="https://hyxxsfwy.github.io/tags/%E9%87%91%E8%9E%8D/"/>
    
  </entry>
  
  <entry>
    <title>【学习笔记】厚朴中医学堂 - 痛经也有可能是心病</title>
    <link href="https://hyxxsfwy.github.io/2018/03/23/%E3%80%90%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E3%80%91%C2%96%E5%8E%9A%E6%9C%B4%E4%B8%AD%E5%8C%BB%E5%AD%A6%E5%A0%82-%E7%97%9B%E7%BB%8F%E4%B9%9F%E6%9C%89%E5%8F%AF%E8%83%BD%E6%98%AF%E5%BF%83%E7%97%85/"/>
    <id>https://hyxxsfwy.github.io/2018/03/23/【学习笔记】厚朴中医学堂-痛经也有可能是心病/</id>
    <published>2018-03-23T13:27:28.000Z</published>
    <updated>2018-03-25T16:00:33.000Z</updated>
    
    <content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="引言-心意相合-神思相安">引言 - 心意相合，神思相安</h3><blockquote><p>或曰：“以德报怨，何如？”<br>子曰：“何以报德？以直报怨，以德报德。”<br>　—— 《论语·宪问》</p></blockquote><blockquote><p>子曰：“吾十有五而志于学，三十而立，四十而不惑，五十而知天命，六十而耳顺，七十而<strong>从心所欲不逾矩</strong>。”<br>　——《论语·为政》</p></blockquote><p>心与意相合是个什么样的状态呢？抛却道儒间的门户之见，《论语》中的这两段就很好的诠释了“心与意相合”。</p><a id="more"></a><p>先做个名词解释。中医，或者说道家里讲的“心”为何，“意”又为何？</p><blockquote><p>心者，君主之官，神明出焉。 ——《黄帝内经·素问·<a href="https://ctext.org/huangdi-neijing/ling-lan-mi-dian-lun/zhs" title="https://ctext.org/huangdi-neijing/ling-lan-mi-dian-lun/zhs" target="_blank" rel="noopener">灵兰秘典论</a>》<br>五脏六腑之大主也，是精神之所舍也。 ——《黄帝内经·灵枢·<a href="https://ctext.org/huangdi-neijing/xie-ke/zhs" title="https://ctext.org/huangdi-neijing/xie-ke/zhs" target="_blank" rel="noopener">邪客篇</a>》</p></blockquote><p>中医所谓的“心”，并非单指心脏，而是指一个与人的精神、情志密切相关的系统，是五脏六腑的“君主”。用解刨学的观点看，“心”大致等于心脏+神经系统+内分泌系统的综合体；从心理学的角度看，心更类似于潜意识，是“灵魂”的代名词。</p><p>“意”则特指显性的“意识”，是后天习得的一系列东西，包括法律、道德、礼教、人情世故、利益考量等等。这些后天习得的内容必须一分为二的看待，那些有普世价值的，也就是与绝大多数人大脑中天生预装的操作系统相契合的东西，就是正确的，比如自由、民主、公正、法制、富强。而若以特定利益考量为目的强行灌输的“意”，就是糟粕、垃圾，比如天朝小学生守则里写有的“爱国等于爱党”、米帝如今风行的“政治正确”等。</p><p>徐文兵老师曾在二〇〇九年中国之声播出的《国学堂》节目中谈过，为人处世，最痛苦不过的就是心与意相违逆，身体里总有两个自己在掐架，长此以往，危矣！下面把这段音频放上来，读者听罢，可自行体悟“心与意”的关系：</p>        <div id="aplayer-jAnFMvTa" class="aplayer aplayer-tag-marker" style="margin-bottom: 20px;width:95%;">            <pre class="aplayer-lrc-content"></pre>        </div>        <script>          var ap = new APlayer({            element: document.getElementById("aplayer-jAnFMvTa"),            narrow: false,            autoplay: false,            showlrc: false,            music: {              title: "心与意的关系 - 20090523四气调神大论篇第十讲剪辑",              author: "徐文兵 梁冬",              url: "/aud/18.03/5.20090523四气调神大论篇第十讲剪辑.mp3",              pic: "",              lrc: ""            }          });          window.aplayers || (window.aplayers = []);          window.aplayers.push(ap);        </script><h3 id="正文-痛经也有可能是心病-学习笔记">正文 - “痛经也有可能是心病”学习笔记</h3><p>“痛经也有可能是心病”是厚朴中医学堂在沪江 CCTalk 上直播的“痛经的非药物外治法”网络课堂讲座的姊妹篇，全程录音长度 72 分钟，讲义同样只有一张 PPT。<br><em>注意</em>：这是一期从心理治疗层面入手，可能达到<strong>根治</strong>痛经的效果的节目。</p><p><img src="/imgs/18.03/%E5%8E%9A%E6%9C%B4%E4%B8%AD%E5%8C%BB%E5%AD%A6%E5%A0%82-%E7%97%9B%E7%BB%8F%E4%B9%9F%E6%9C%89%E5%8F%AF%E8%83%BD%E6%98%AF%E5%BF%83%E7%97%85-%E8%AE%B2%E5%BA%A7%E6%8F%90%E7%BA%B2.jpg" alt="“痛经也有可能是心病”讲座提纲" title="厚朴中医学堂-痛经也有可能是心病-讲座提纲"></p><h4 id="第一篇：导致痛经的心理因素">第一篇：导致痛经的心理因素</h4><ol><li>“求关注”的心理（因病获利）<ul><li>问题可能始于母女关系，发展于恋爱关系。根本原因还是缺爱、不安全感、渴望温暖。“一个人若愿意承受非常大的痛苦去获取一丝一点的温暖，则足以说明 Ta 对温暖渴求的迫切程度。”</li></ul></li></ol><ol start="2"><li>痛经成为一件“未竟之事”<ul><li>当痛经成为了一种“自我实现的预言”，“恐惧”与“潜意识的期盼”交织，“月经”与“痛”就成了一种绑定关系。心焦则气乱，最后便造成了“不痛反而不正常”的情形。</li></ul></li></ol><ol start="3"><li>与母亲的关系及女性身份认同<ul><li>与母亲的关系好吗？</li><li>对女性身份的认同感如何？</li><li>同性恋的人越来越多，绝大多数原因都是性别认知失调；</li><li>身心一体，长期的负面情志积累会导致身体上严重的疾病。</li></ul></li></ol><ol start="4"><li>精神压力<ul><li>生活或者工作环境导致的长期焦虑、不放松；</li><li>某次创伤性事件与痛经关联起来了，导致后续持久的痛经问题；</li><li>成年后的情感创伤，导致十二正经中“环阴气”的肝经、肾经行气不顺。“谈恋爱不仅走心，还走肾”，两性情感问题是与痛经直接相关的。</li></ul></li></ol><p>以下是这一篇的讲座录音：</p>        <div id="aplayer-pZyujVoA" class="aplayer aplayer-tag-marker" style="margin-bottom: 20px;width:95%;">            <pre class="aplayer-lrc-content"></pre>        </div>        <script>          var ap = new APlayer({            element: document.getElementById("aplayer-pZyujVoA"),            narrow: false,            autoplay: false,            showlrc: false,            music: {              title: "导致痛经的心理因素",              author: "文馨",              url: "/aud/18.03/6.痛经也有可能是心病-心理因素.mp3",              pic: "",              lrc: ""            }          });          window.aplayers || (window.aplayers = []);          window.aplayers.push(ap);        </script><h4 id="第二篇：对身体造成的影响">第二篇：对身体造成的影响</h4><ol><li><p>器质性的妇科疾病，如子宫内膜异位症、子宫息肉、子宫肌瘤、子宫腺肌症以及乳腺方面的疾病等；</p></li><li><p>气血两虚，肝气於滞，脸色蜡黄、长斑、长痘等。</p></li></ol><p>以下是这一篇的讲座录音：</p>        <div id="aplayer-lQvZwrgL" class="aplayer aplayer-tag-marker" style="margin-bottom: 20px;width:95%;">            <pre class="aplayer-lrc-content"></pre>        </div>        <script>          var ap = new APlayer({            element: document.getElementById("aplayer-lQvZwrgL"),            narrow: false,            autoplay: false,            showlrc: false,            music: {              title: "对身体造成的影响",              author: "文馨",              url: "/aud/18.03/7.痛经也有可能是心病-对身体造成的影响.mp3",              pic: "",              lrc: ""            }          });          window.aplayers || (window.aplayers = []);          window.aplayers.push(ap);        </script><h4 id="第三篇：心理疏导的方法">第三篇：心理疏导的方法</h4><ol><li>重塑自我认知<ul><li>欣赏自己，不必示弱；</li><li>自我关怀，不必求人；</li><li>在痛经的过程中，分散自己的注意力；</li><li>痛经的过程其实也是自我调整的机会，做积极的事，不要作。</li></ul></li></ol><ol start="2"><li>阴阳调和<ul><li>两性关系的调和；</li><li>更大范围上的“阴阳调和”，与自己、他人、周围环境、宇宙自然的调和，即道家所说的“<strong>法于阴阳，合于术数</strong>”<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup>。</li></ul></li></ol><ol start="3"><li>接受身份认同<ul><li>作为女性，对自我性别的认同感、自豪感；</li><li>真正的强大只能源自内心，温暖是求不来的，委曲求全的而来的温暖也不是温暖；</li><li>当情志创伤太重，仅凭自己走不出来的时候，不要死扛，应及时求助于专业人员。</li></ul></li></ol><p>以下是这一篇的讲座录音：</p>        <div id="aplayer-SkjKScMH" class="aplayer aplayer-tag-marker" style="margin-bottom: 20px;width:95%;">            <pre class="aplayer-lrc-content"></pre>        </div>        <script>          var ap = new APlayer({            element: document.getElementById("aplayer-SkjKScMH"),            narrow: false,            autoplay: false,            showlrc: false,            music: {              title: "心理疏导的方法",              author: "文馨",              url: "/aud/18.03/8.痛经也有可能是心病-心理疏导的方法.mp3",              pic: "",              lrc: ""            }          });          window.aplayers || (window.aplayers = []);          window.aplayers.push(ap);        </script><h4 id="第四篇：课堂答疑-回答学员的问题">第四篇：课堂答疑，回答学员的问题</h4><p>医案实例，答疑解惑。末尾提到点按膻中穴、揉小腹、坚持自我艾灸等外治法，上节课已有详述，可以复习一下。<br>以下是这一篇的讲座录音：</p>        <div id="aplayer-gwGlDnpg" class="aplayer aplayer-tag-marker" style="margin-bottom: 20px;width:95%;">            <pre class="aplayer-lrc-content"></pre>        </div>        <script>          var ap = new APlayer({            element: document.getElementById("aplayer-gwGlDnpg"),            narrow: false,            autoplay: false,            showlrc: false,            music: {              title: "课堂答疑&答学员问",              author: "文馨",              url: "/aud/18.03/9.痛经也有可能是心病-课堂答疑.mp3",              pic: "",              lrc: ""            }          });          window.aplayers || (window.aplayers = []);          window.aplayers.push(ap);        </script><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="fn1" class="footnote-item"><p>语出《黄帝内经·素问·<a href="https://ctext.org/huangdi-neijing/shang-gu-tian-zhen-lun/zhs" title="https://ctext.org/huangdi-neijing/shang-gu-tian-zhen-lun/zhs" target="_blank" rel="noopener">上古天真论</a>》<br>—— 上古之人，其知道者，<strong>法于阴阳，和于术数</strong>，食饮有节，起居有常，不妄作劳，故能形与神俱，而尽终其天年，度百岁乃去。今时之人不然也，以酒为浆，以妄为常，醉以入房，以欲竭其精，以耗散其真，不知持满，不时御神，务快其心，逆于生乐，起居无节，故半百而衰也。 <a href="#fnref1" class="footnote-backref">↩</a></p></li></ol></section>]]></content>
    
    <summary type="html">
    
      &lt;h3 id=&quot;引言-心意相合-神思相安&quot;&gt;引言 - 心意相合，神思相安&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;或曰：“以德报怨，何如？”&lt;br&gt;
子曰：“何以报德？以直报怨，以德报德。”&lt;br&gt;
　—— 《论语·宪问》&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;子曰：“吾十有五而志于学，三十而立，四十而不惑，五十而知天命，六十而耳顺，七十而&lt;strong&gt;从心所欲不逾矩&lt;/strong&gt;。”&lt;br&gt;
　——《论语·为政》&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;心与意相合是个什么样的状态呢？抛却道儒间的门户之见，《论语》中的这两段就很好的诠释了“心与意相合”。&lt;/p&gt;
    
    </summary>
    
      <category term="学习" scheme="https://hyxxsfwy.github.io/categories/%E5%AD%A6%E4%B9%A0/"/>
    
    
      <category term="教程" scheme="https://hyxxsfwy.github.io/tags/%E6%95%99%E7%A8%8B/"/>
    
      <category term="中医" scheme="https://hyxxsfwy.github.io/tags/%E4%B8%AD%E5%8C%BB/"/>
    
  </entry>
  
  <entry>
    <title>【学习笔记】厚朴中医学堂 - 痛经的非药物外治法</title>
    <link href="https://hyxxsfwy.github.io/2018/03/18/%E3%80%90%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E3%80%91%E5%8E%9A%E6%9C%B4%E4%B8%AD%E5%8C%BB%E5%AD%A6%E5%A0%82-%E7%97%9B%E7%BB%8F%E7%9A%84%E9%9D%9E%E8%8D%AF%E7%89%A9%E5%A4%96%E6%B2%BB%E6%B3%95/"/>
    <id>https://hyxxsfwy.github.io/2018/03/18/【学习笔记】厚朴中医学堂-痛经的非药物外治法/</id>
    <published>2018-03-18T08:43:31.000Z</published>
    <updated>2018-03-25T16:00:33.000Z</updated>
    
    <content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="引言-为什么我们还在-信中医">引言 - 为什么我们还在“信中医”</h3><blockquote><p><strong>面对现代医学无法给出明确有效治疗方案的病症，我们应当求助于遵守循证医学原理的传统中医。</strong><br>观点提炼于：<br>　——《太医来了》首席太医，丁香医生医学总监，田吉顺老师 <sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup><br>　——《天方烨谈》主讲，华大基因 CEO，尹烨老师<br>　—— 我的道家引路人，厚朴中医学堂堂主，徐文兵老师</p></blockquote><a id="more"></a><p>为什么“信中医”？答案很简单，信的不是中医，而是 <a href="https://baike.baidu.com/item/%E5%BE%AA%E8%AF%81%E5%8C%BB%E5%AD%A6/3288650" title="https://baike.baidu.com/item/%E5%BE%AA%E8%AF%81%E5%8C%BB%E5%AD%A6/3288650" target="_blank" rel="noopener">循证医学</a>（<a href="https://en.wikipedia.org/wiki/Evidence-based_medicine" title="https://en.wikipedia.org/wiki/Evidence-based_medicine" target="_blank" rel="noopener">Evidence-based Medicine</a>）。现代医学的边际之外，还有很多很多未解的医学难题。优秀的中医，可以通过多年的循证临床研究，凭借己身对“道”的理解，从另一个科学暂且未达的角度，（部分）解决这些难题。</p><p>话说，最近《黄帝内经》中关于十二时辰的子午流注学说都在基因的生物钟控层面被重新发现了，还有什么不可能的呢。<sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup> <sup class="footnote-ref"><a href="#fn3" id="fnref3">[3]</a></sup></p><p>中医，或者说循证医学，最大的缺点就是太个例化、对医者甚至病人都有很高的要求，且难以用双盲实验的手段大规模重复验证，这与工业文明的手法相悖。总之，这种缺点导致的事实就是绝大多数中医院校里培养出来的“中医”，都是庸医。于是，总的来说，中国目前的中医体系完全比不上条件、规则、方案都相对固定，可验证可重复的西医体系。何况，传统中医体系里，真正的大医，同时也应该是“有道高人”。这样的人，本就凤毛麟角啊。</p><p>可惜现代医学体系毕竟力有所限，很多时候遵守循证医学才是正途。所以，选择信中医，其实信的是那个有着多年循证经验的医者，比如徐文兵老师。（这里帮徐老师宣传一下，微信公众号<code>hopexuwenbing</code>，长达两学年的免费医道教学内容，干货满满；厚朴中医学堂淘宝店：<a href="https://hope-life.taobao.com/" title="https://hope-life.taobao.com/" target="_blank" rel="noopener">https://hope-life.taobao.com/</a>，十年五皇冠金牌老店，值得信赖，艾灸器、刮痧片等家用小部件一应俱全。）</p><p>鄙人于二〇〇九年在中国之声《国学堂》节目里听到梁冬和徐文兵老师讲《黄帝内经》，徐老师那精妙非常的讲解，令人颇有当头棒喝，茅塞顿开之感。始知华夏大地上的道家传承，从未断绝。而今九年时光匆匆，理论、经验、实修相互验证，益发明了“道”之所指。确实，宇宙之最不可理解之处，就在于它是可以被理解的。梁冬作为一个深受徐老师影响的经济媒体主持人，亦始终未曾放下对道家的研究。今年三月初，《天方烨谈》节目播出了尹烨与梁冬在《觉者》上关于“<a href="http://www.ximalaya.com/44841033/sound/74800237/" title="http://www.ximalaya.com/44841033/sound/74800237/" target="_blank" rel="noopener">意识如何影响生命</a>”的探讨，听罢可知，梁冬自己的修行也已经比九年前高了不止一筹。更难得的是，这期节目证实了我之前的一个猜测：华大基因的 CEO 尹烨老师，他绝对也能算道家的，是一路人。</p><p>从基因到意识，万法归宗，不论科学还是玄学，原来它们研究的都是宇宙真理，也就是那唯一的“道”。真理只有一个，“道”只有一条，人所能做的，也不过是用这短暂的一生不断去追寻罢了。</p><p>废话不多说，下面回归本文正题：</p><hr><h3 id="正文-痛经的非药物外治法-学习笔记">正文 - “痛经的非药物外治法”学习笔记</h3><p>“痛经的非药物外治法”是厚朴中医学堂在沪江 CCTalk 上直播的一期网络课堂讲座，全程录音长达 87 分钟，讲义倒是只有下面这一张 PPT。中医讲究口传心授，PPT 上列个纲要也就够了。</p><p><img src="/imgs/18.03/%E5%8E%9A%E6%9C%B4%E4%B8%AD%E5%8C%BB%E5%AD%A6%E5%A0%82-%E7%97%9B%E7%BB%8F%E7%9A%84%E9%9D%9E%E8%8D%AF%E7%89%A9%E5%A4%96%E6%B2%BB%E6%B3%95-%E8%AE%B2%E5%BA%A7%E6%8F%90%E7%BA%B2.jpg" alt="“痛经的非药物外治法”讲座提纲" title="厚朴中医学堂-痛经的非药物外治法-讲座提纲"></p><h4 id="第一篇：中医如何看待痛经">第一篇：中医如何看待痛经</h4><ol><li>痛经分类：原发性痛经和继发性痛经。两种情况的治疗方案是完全不同的。<ul><li>原发性痛经在临床上难以诊断出明确的病因，现代医学目前相对有效的治疗方案就是口服短效避孕药，嗯，典型的治标不治本；</li><li>继发性痛经通常由妇科的器质性病变所引起（如子宫内膜异位症、子宫肌瘤），这类必须先治好病症。</li></ul></li></ol><ol start="2"><li>对于非器质性病变的痛经，中医将其分为五个方面：<ul><li>肾气亏损型。这类属于虚症，肾气先天不足或者后天耗损过度所至，外治法以艾灸补益为主；</li><li>气血虚弱型。这类与单纯的肾气亏虚不同，已经到了虚不受补的状态，同是艾灸治疗，需要远端取穴，循序渐进；</li><li>气滞血於型。这类临床较多见，就是体内堵了不该有的东西。病因更多与“情志”相关，肝气不顺则易怒，实为心病外现之症。外治法，肝经区局部刮痧，艾灸膻中穴；</li><li>寒凝血於型。这类是寒症，临床患者偏年轻化，冷饮、碳酸饮料吃多了，或者冬季穿的太少，夏季空调吹太多，经年累月而成。外治法，每天坚持热水泡脚，最好是煮花椒水泡；膀胱经、冲脉等处刮痧祛寒毒，再辅以艾灸；</li><li>湿热蕴结型。表现为小腹倦痛，经期量多且长。外治法依然可用刮痧，以去湿热为主要目标。</li></ul></li></ol><p>以下是这一篇的讲座录音：</p>        <div id="aplayer-ictfOJgx" class="aplayer aplayer-tag-marker" style="margin-bottom: 20px;width:95%;">            <pre class="aplayer-lrc-content"></pre>        </div>        <script>          var ap = new APlayer({            element: document.getElementById("aplayer-ictfOJgx"),            narrow: false,            autoplay: false,            showlrc: false,            music: {              title: "中医如何看待痛经",              author: "关立双",              url: "/aud/18.03/1.中医如何看待痛经.mp3",              pic: "",              lrc: ""            }          });          window.aplayers || (window.aplayers = []);          window.aplayers.push(ap);        </script><h4 id="第二篇：外治法如何解决痛经">第二篇：外治法如何解决痛经</h4><ol><li>经前乳胀——乳腺按摩<ul><li>不要用不专业的手法瞎按摩，不但无益，反而有害；</li><li>好的按摩师手上应该有“气感”，会找到“关键点”；</li><li>情志变化的累积带来生理变化，会导致肋间隙的“千千结”，这些都需要通过“导引按跷”<sup class="footnote-ref"><a href="#fn4" id="fnref4">[4]</a></sup>的手法来打开；</li><li>自我按摩是可行的，但对“正常状态”的正确自我认知很重要。</li></ul></li></ol><ol start="2"><li>痛经的艾灸疗法<ul><li>艾灸的热度有穿透力，这是普通热水袋所不能比的；</li><li>灸法，光靠艾灸的热度暖起来是不够的，快速见效须得做到“<a href="https://baike.baidu.com/item/%E6%B0%94%E8%87%B3%E7%97%85%E6%89%80" title="https://baike.baidu.com/item/%E6%B0%94%E8%87%B3%E7%97%85%E6%89%80" target="_blank" rel="noopener">气至病所</a>”；<sup class="footnote-ref"><a href="#fn5" id="fnref5">[5]</a></sup></li><li>持之以恒，量的积累很重要；</li><li>双灸，远端取穴，如灸<a href="https://baike.baidu.com/item/%E8%B6%B3%E4%B8%89%E9%87%8C" title="https://baike.baidu.com/item/%E8%B6%B3%E4%B8%89%E9%87%8C" target="_blank" rel="noopener">足三里</a>；</li><li>单灸，就近取穴，灸<a href="https://baike.baidu.com/item/%E5%85%B3%E5%85%83" title="https://baike.baidu.com/item/%E5%85%B3%E5%85%83" target="_blank" rel="noopener">关元</a>、<a href="https://baike.baidu.com/item/%E5%AD%90%E5%AE%AB%E7%A9%B4" title="https://baike.baidu.com/item/%E5%AD%90%E5%AE%AB%E7%A9%B4" target="_blank" rel="noopener">子宫穴</a>或者直接灸痛点；</li><li>快速缓解疼痛的症状，可直接点按足三里；</li><li>补充单灸取穴的方法：<ul><li>气滞血於型，就近取穴之外，加灸<a href="https://baike.baidu.com/item/%E8%86%BB%E4%B8%AD" title="https://baike.baidu.com/item/%E8%86%BB%E4%B8%AD" target="_blank" rel="noopener">膻中</a>、<a href="https://baike.baidu.com/item/%E5%A4%AA%E5%86%B2/15418035" title="https://baike.baidu.com/item/%E5%A4%AA%E5%86%B2/15418035" target="_blank" rel="noopener">太冲</a>穴；</li><li>寒湿凝滞型，加灸<a href="https://baike.baidu.com/item/%E5%9C%B0%E6%9C%BA%E7%A9%B4" title="https://baike.baidu.com/item/%E5%9C%B0%E6%9C%BA%E7%A9%B4" target="_blank" rel="noopener">地机</a>穴；</li><li>气血虚弱型，加灸足三里；</li><li>肾气亏损型，加灸<a href="https://baike.baidu.com/item/%E5%A4%AA%E6%BA%AA/1569991" title="https://baike.baidu.com/item/%E5%A4%AA%E6%BA%AA/1569991" target="_blank" rel="noopener">太溪</a>穴。</li></ul></li></ul></li></ol><ol start="3"><li>月经期能否刮痧或者导引按跷<ul><li>正常情况下是不可以的；</li><li>面对急症、相对严重的疼痛等情况，则重症须下猛药，刮痧或按跷手法都是可取的，但必须谨慎小心；</li><li>经期不适合用手法，但行经前却是艾灸和导引按跷的良机。平时保养的效果可以在经期的流量和实际感觉中得到反馈。</li></ul></li></ol><ol start="4"><li>女性朋友应该注意的保养之道<ul><li>注意保暖，脚踝、小腿、腰腹都是容易受凉的部位；</li><li>经期少洗头，若不得不洗，做好保暖工作并及时吹干；</li><li>贴身衣物选纯棉的；</li><li>小偏方：醪糟蛋汤、红糖姜汤、粗盐袋热敷等；</li><li>止疼药除非逼不得已，否则别吃，会掩盖病症，造成依赖；</li><li>总结：知妄守常，No Zuo No Die</li></ul></li></ol><p>以下是这一篇的讲座录音：</p>        <div id="aplayer-cuVptylH" class="aplayer aplayer-tag-marker" style="margin-bottom: 20px;width:95%;">            <pre class="aplayer-lrc-content"></pre>        </div>        <script>          var ap = new APlayer({            element: document.getElementById("aplayer-cuVptylH"),            narrow: false,            autoplay: false,            showlrc: false,            music: {              title: "外治法如何解决痛经",              author: "关立双",              url: "/aud/18.03/2.外治法如何解决痛经.mp3",              pic: "",              lrc: ""            }          });          window.aplayers || (window.aplayers = []);          window.aplayers.push(ap);        </script><h4 id="第三篇：医案描述-分享几个临床病例">第三篇：医案描述，分享几个临床病例</h4><p>医案实例，文字难以尽述，此处直接上音频吧。只提几个要点：</p><ul><li>三十岁前人找病，三十岁后病找人；</li><li>本宇宙的基本法则——出来混，迟早是要还的；</li><li>减肥不能不吃主食，植物种子中蕴含着巨大的能量，是最好的补品；</li><li>了解自身，顺应自然。</li></ul><p>以下是这一篇的讲座录音：</p>        <div id="aplayer-ZJYLpBEE" class="aplayer aplayer-tag-marker" style="margin-bottom: 20px;width:95%;">            <pre class="aplayer-lrc-content"></pre>        </div>        <script>          var ap = new APlayer({            element: document.getElementById("aplayer-ZJYLpBEE"),            narrow: false,            autoplay: false,            showlrc: false,            music: {              title: "医案描述，分享几个临床病例",              author: "关立双",              url: "/aud/18.03/3.医案描述&病例分享.mp3",              pic: "",              lrc: ""            }          });          window.aplayers || (window.aplayers = []);          window.aplayers.push(ap);        </script><h4 id="第四篇：课堂答疑-回答学员的问题">第四篇：课堂答疑，回答学员的问题</h4><p>学员们的问题着实是千奇百怪……不做赘述了。</p><p>以下是这一篇的讲座录音：</p>        <div id="aplayer-VyiwhUbZ" class="aplayer aplayer-tag-marker" style="margin-bottom: 20px;width:95%;">            <pre class="aplayer-lrc-content"></pre>        </div>        <script>          var ap = new APlayer({            element: document.getElementById("aplayer-VyiwhUbZ"),            narrow: false,            autoplay: false,            showlrc: false,            music: {              title: "课堂答疑，回答学员的问题",              author: "关立双",              url: "/aud/18.03/4.课堂答疑&回答学员的问题.mp3",              pic: "",              lrc: ""            }          });          window.aplayers || (window.aplayers = []);          window.aplayers.push(ap);        </script><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="fn1" class="footnote-item"><p><a href="https://taiyilaile.com/123" title="https://taiyilaile.com/123" target="_blank" rel="noopener">《太医来了》第 123 期：再论中西医之争</a> <a href="#fnref1" class="footnote-backref">↩</a></p></li><li id="fn2" class="footnote-item"><p><a href="http://www.biodiscover.com/news/research/728601.html" title="http://www.biodiscover.com/news/research/728601.html" target="_blank" rel="noopener">意义重大！Science：基因也有“生物钟”，至少影响150种疾病</a> <a href="#fnref2" class="footnote-backref">↩</a></p></li><li id="fn3" class="footnote-item"><p><a href="http://www.ximalaya.com/44841033/sound/76127933/" title="http://www.ximalaya.com/44841033/sound/76127933/" target="_blank" rel="noopener">天方烨谈：基因也有生物钟！？</a> <a href="#fnref3" class="footnote-backref">↩</a></p></li><li id="fn4" class="footnote-item"><p><a href="http://www.cqvip.com/qk/93943x/200103/5364065.html" title="http://www.cqvip.com/qk/93943x/200103/5364065.html" target="_blank" rel="noopener">孟立. 导引, 按跷, 按摩, 推拿与手法. 按摩与导引,2001,(3):2-4</a> <a href="#fnref4" class="footnote-backref">↩</a></p></li><li id="fn5" class="footnote-item"><p><a href="http://www.cqvip.com/qk/95999x/200801/26380766.html" title="http://www.cqvip.com/qk/95999x/200801/26380766.html" target="_blank" rel="noopener">陈日新,康明非. 灸之要, 气至而有效. 中国针灸,2008,(1):44-46</a> <a href="#fnref5" class="footnote-backref">↩</a></p></li></ol></section>]]></content>
    
    <summary type="html">
    
      &lt;h3 id=&quot;引言-为什么我们还在-信中医&quot;&gt;引言 - 为什么我们还在“信中医”&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;面对现代医学无法给出明确有效治疗方案的病症，我们应当求助于遵守循证医学原理的传统中医。&lt;/strong&gt;&lt;br&gt;
观点提炼于：&lt;br&gt;
　——《太医来了》首席太医，丁香医生医学总监，田吉顺老师 &lt;sup class=&quot;footnote-ref&quot;&gt;&lt;a href=&quot;#fn1&quot; id=&quot;fnref1&quot;&gt;[1]&lt;/a&gt;&lt;/sup&gt;&lt;br&gt;
　——《天方烨谈》主讲，华大基因 CEO，尹烨老师&lt;br&gt;
　—— 我的道家引路人，厚朴中医学堂堂主，徐文兵老师&lt;/p&gt;
&lt;/blockquote&gt;
    
    </summary>
    
      <category term="学习" scheme="https://hyxxsfwy.github.io/categories/%E5%AD%A6%E4%B9%A0/"/>
    
    
      <category term="教程" scheme="https://hyxxsfwy.github.io/tags/%E6%95%99%E7%A8%8B/"/>
    
      <category term="中医" scheme="https://hyxxsfwy.github.io/tags/%E4%B8%AD%E5%8C%BB/"/>
    
  </entry>
  
  <entry>
    <title>【转】现代密码学实践指南【2015年】</title>
    <link href="https://hyxxsfwy.github.io/2017/04/15/%E3%80%90%E8%BD%AC%E3%80%91%E7%8E%B0%E4%BB%A3%E5%AF%86%E7%A0%81%E5%AD%A6%E5%AE%9E%E8%B7%B5%E6%8C%87%E5%8D%97-2015%E5%B9%B4/"/>
    <id>https://hyxxsfwy.github.io/2017/04/15/【转】现代密码学实践指南-2015年/</id>
    <published>2017-04-15T14:23:23.000Z</published>
    <updated>2018-03-18T16:00:33.000Z</updated>
    
    <content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><hr><p>本文介绍目前现代密码学的最先进技术，<br>前半部分主要翻译自  <a href="https://gist.github.com/tqbf/be58d2d39690c3b366ad" target="_blank" rel="noopener">《Cryptographic Right Answers》</a>，附上收集的资料，和byron个人的理解。</p><p>密码学理论艰深，概念繁多，本人知识水平有限，错误难免，如果您发现错误，请务必指出，非常感谢!</p><hr><p><strong>下文分类介绍在各种适用场景下，你应该使用的现代密码学算法</strong></p><a id="more"></a><h3 id="加密数据">加密数据</h3><p>按照优先级，应该选择:<br>(1)   首选 NaCl库，或者libsodium库，使用里面的crypto_secretbox()/crypto_secretbox_open() 函数<br>(2)   Chacha20-Poly1305 算法<br>(3)   AES-GCM 算法</p><p>适用场景:当你需要避免把明文数据在网络上传输的时候。</p><p>以上3种算法，都是AEAD类的算法，AEAD是2015年最好的选择。<br>其中的(2)和(3)在结构上类似：一个流加密模式的算法，配合一个多项式结构的MAC。<br>(2)是一个流加密算法，配合一个为通用cpu优化的MAC算法，<br>对密码学库的实现者来说，Poly1305也比GCM更容易安全地实现。<br>AES-GCM是工业标准(TLS目前主要用的就是AES-GCM)，现代CPU通常都有专门为AES-GCM设计的硬件指令，但是在没有硬件指令支持的CPU上(比如32位的arm)，(3)性能低于(2)。</p><p>此外，应该</p><ul><li>避免AES-CBC</li><li>避免AES-CTR</li><li>避免64bit块大小的块加密算法–(说的就是你–BlowFish)</li><li>避免OFB模式</li><li>不要使用RC4，RC4已经被攻破</li></ul><h3 id="对称密钥长度">对称密钥长度</h3><p>选择使用256bit长度的密钥</p><p>适用场景：只要你在使用密码学，你就应该注意<strong>对称密钥长度</strong></p><p>请记住：不要把对称加密（如AES）的key长度，和非对称加密(如RSA)的key长度搞混淆了，对称加密的key通常比非对称加密的key短多了。</p><p>下表对比了相同安全程度时，不同算法的密钥长度，单位:bit</p><table><thead><tr><th>Symmetric</th><th>ECC</th><th>DH/DSA/RSA</th></tr></thead><tbody><tr><td>80</td><td>163</td><td>1024</td></tr><tr><td>112</td><td>233</td><td>2048</td></tr><tr><td>128</td><td>283</td><td>3072</td></tr><tr><td>192</td><td>409</td><td>7680</td></tr><tr><td>256</td><td>571</td><td>15360</td></tr></tbody></table><p>此外，应该</p><ul><li>避免使用巨大key的算法(使用远大于256的key，只能说明使用者没有安全概念)</li><li>避免把多个加密算法串联叠加起来使用，这并没有什么卵用</li><li>避免128bit以下的key长度(比如，哥们求你别再提DES这种56bit密钥的古董了)</li></ul><h3 id="对称签名">对称签名</h3><p>应该选择 HMAC 类的算法</p><p>适用场景：安全加固一个API，如各种开放API的调用方认证</p><p>如果对一个API，你需要做认证(authenticating)，但是不需要做加密(encrypting)，记得千万不要自己发明算法，你自己发明的MAC算法基本都有安全漏洞，如果不信，请Google一下 &quot;长度扩展攻击&quot;<br><a href="http://en.wikipedia.org/wiki/Length_extension_attack" target="_blank" rel="noopener">长度扩展攻击</a><br><a href="http://netifera.com/research/flickr_api_signature_forgery.pdf" target="_blank" rel="noopener">Flickr的漏洞案例</a></p><p>同时，必须要注意的是，要使用一个<strong>常数时间字符串对比算法</strong>（这个地方和码农的常识完全相反，请务必留意）</p><p>此外，应该</p><ul><li>避免自行设计的“带密码的hash”结构，你的设计基本都是有安全漏洞的</li><li>避免HMAC-MD5，避免HMAC-SHA1，使用HMAC-SHA256, HMAC-SHA512等</li><li>避免复杂的多项式MAC</li><li>避免加密hash值的结构</li><li>避免CRC</li></ul><h3 id="hashing-hmac-算法">Hashing/HMAC 算法</h3><p>应该选择<a href="http://en.wikipedia.org/wiki/SHA-2" target="_blank" rel="noopener">SHA2</a>类的算法:: SHA-256, SHA-384, SHA-512, SHA-512/256</p><p>优先使用 SHA-512/256，SHA-512/256这个算法把 SHA-512 的512bit输出截短到256bit，避开了length extension 攻击。<br>同时，目前SHA-2是很安全可靠的，你不需要升级到SHA-3.</p><p>此外，应该</p><ul><li>避免SHA-1</li><li>避免MD5</li><li>避免MD6</li></ul><h3 id="随机id">随机ID</h3><p>应该使用256 bit的随机值</p><p>一定要使用 /dev/urandom，请认准这个</p><p>此外，应该</p><ul><li>避免用户空间的随机数生成器如:havaged,prngs,egd,等</li><li>避免/dev/random</li></ul><h3 id="密码处理">密码处理</h3><p>按照优先级顺序,选择：</p><ul><li>scrypt</li><li>bcrypt</li><li>如果以上2个都没有，那就用PBKDF2</li></ul><p>此外，应该</p><ul><li>避免直接SHA-2</li><li>避免直接SHA-1</li><li>避免直接MD5</li></ul><h3 id="非对称加密">非对称加密</h3><p>应该使用NaCl库</p><p>适用场景：当你需要加密消息，发给陌生人，并且对方异步接收消息，做离线解密时。这是一个很窄的应用案例，这种用法有个名字叫<em>电子信封(digital envelope)</em>，典型比如gpg加密文件后发送。</p><p>这条是几条之中最难做正确的，不要使用底层的密码学库，比如OpenSSL或者BouncyCastle。</p><p>你应该停止使用RSA，并且切换到椭圆曲线类体制，原因是：</p><ul><li>对RSA的攻击能力的进步 — 定义在传统质数域上的乘法运算(应用包括DH,DSA,ElGamal等)，要比椭圆曲线域上的乘法运算快得多。这是由于质数域上数域筛法（number field sieve,NFS）的进展，而在椭圆曲线域上，没有NFS这类算法。</li><li>RSA (和DH) 或迫使你考虑“向后兼容性”，而椭圆曲线体制没有这种兼容性包袱。TLS最近的几个安全漏洞，部分愿意也是由于这种向后兼容性，导致已经被破解的陈旧算法存在</li><li>RSA在一般场景中，都是直接用公钥做非对称加密，这种用法丧失了<strong>前向安全性(Perfect Forward Secrecy)</strong>。而椭圆曲线就不提倡，也很难这样使用，这样你就不会害死自己了。</li><li>在椭圆曲线体制下，保证正确性和安全性的重任，主要由密码学家承担，密码学家会提供一组曲线参数，在某一性能水平下，针对安全性和性能做优化。这样程序员不容易误用而害死自己。在RSA体制下，正好相反，程序员必须提供参数来保证正确性和安全性，就算是RSA-OAEP这种很好的设计，程序员也必须知道怎么提供参数，这样程序员很容易搞错。</li></ul><p>如果你必须使用RSA，一定要使用RSA-OAEP with SHA256，指数使用 65537</p><ul><li>避免 RSA-PKCS1v15</li><li>避免 ElGamal</li><li>避免 RSA</li></ul><h3 id="非对称签名">非对称签名</h3><p>应该使用NaCl，Ed25519，或者RFC6979</p><p>应用场景：如果你在设计一种新的比特币，或者一个给Ruby Gems或者Vagrant imges文件签名的系统，或者数字版权保护系统(DRM)，其中一系列的文件需要离线做认证；<br>或者你在设计一个加密消息传输层</p><p>上一条的内容在此处全部适用。</p><p>在10+年做付费软件安全评估的工作经历中，我只有屈指可数的几次，遇到使用RSA-PSS的用户，RSA-PSS是一个学术界的推荐算法。</p><p>过去10年，非对称签名最主要的应用场景是比特币，和前向安全的密钥协商（TLS协议里面的ECDHE）。<br>其中最主要的算法全都是基于椭圆曲线体制的。务必警惕新出现的使用RSA签名的系统，很有可能有问题。</p><p>在过去几年中，业界有一种趋势：放弃传统DSA签名，改为难以误用的<strong>确定性签名体制</strong>，其中的EdDSA(不要和ECDSA搞混了喂！)和RFC6979是最好的例子。这种趋势的主要是受到2010年索尼PlayStation 3的 ECDSA私钥被破解事件的影响，在这个案例中，索尼公司的码农错误地把一个随机数重复使用来做ECDSA签名，形成了漏洞，使得破解者据此直接把私钥算出来了。<strong>确定性签名体制</strong>在设计中不再依赖随机数生成器，因此彻底避开此类误用。所以你应该优先使用确定性签名体制。</p><ul><li>避免RSA-PKCS1v15，避免RSA，避免ECDSA，避免DSA</li><li>特别要避免常规的DSA和ECDSA</li></ul><h3 id="diffie-hellman-密钥交换">Diffie-Hellman 密钥交换</h3><p>应该使用NaCl，Curve25519，或者DH-2048</p><p>适用场景:<em>如果你在设计加密消息传输系统，并且无法使用固定对称密码</em></p><p>这是很棘手的一条，主要考量如下：</p><ul><li>如果你能使用NaCl库，那就使用NaCl库。你甚至不需要管NaCl是什么。</li><li>如果你能使用一个可信赖的第三方库，那就使用Curve25519，这是一条现代的ECDH曲线，有丰富的开源代码，性能经过高度优化，被彻底地安全分析过。并且Curve25519即将进入TLS 1.3版本标准。</li><li>但是绝对不要自己实现Curve25519，也绝对不要自己移植Curve25519的C代码</li><li>如果你不能使用第三方ECDH库，但是可以使用DH库，那就使用DH-2048，使用1个标准的2048 bit的群。</li><li>但是不要使用传统的DH，如果你需要协商DH参数，或者和其他实现互操作</li><li>如果你一定要做握手协商，或者和旧软件互操作，那么考虑使用NIST P-256, NIST P-256 有广泛的软件支持。</li><li>写死在代码里的DH-2048参数，比NIST P-256更安全。NIST P-256比协商出来的DH更安全。</li><li>但是，由于NIST P-256的实现有一些陷阱，所以一定要谨慎选择可信赖的，广泛使用使的第三方库</li><li>P-256 可能是NIST曲线中最安全的，不要使用P-224。</li></ul><p>DH（密钥协商）算法确实很难用，但是它很重要。</p><ul><li>避免，传统常规的 DH, SRP, J-PAKE 握手和协商</li><li>避开任何只使用了块加密算法和srand(time())的密钥协商模式（肯定有漏洞）</li></ul><h3 id="网站安全">网站安全</h3><p>应该使用OpenSSL，或者Google的BoringSSL，或者直接使用 AWS的 ELB</p><p>此处网站安全，指的是让网站支持HTTPS协议。<br>如果你不能把这个任务交给Amazon的云服务去做，把难题留给Amazon去解决，那么OpenSSL目前仍然是正确选择。</p><ul><li>避免不常见的TLS库，例如polarssl，GnuTLS，MatrixSSL等</li></ul><h3 id="客户端-服务器结构的应用程序的安全">客户端-服务器结构的应用程序的安全</h3><p>应该使用TLS</p><p>适用场景：如果你以为自己理解了前面关于公钥加密的介绍。。。</p><p>通常，在你设计了自己的RSA协议之后的1至18个月，你肯定会发现，你犯了某个错误，使你的协议没有任何安全性。<br>比如Salt Stack，Salt Stack的协议使用了 e=1 的RSA 公钥。。。</p><p>听起来，TLS有下面这些黑历史：</p><ul><li>The Logjam DH negotiation attack</li><li>The FREAK export cipher attack</li><li>The POODLE CBC oracle attack</li><li>The RC4 fiasco</li><li>The CRIME compression attack</li><li>The Lucky13 CBC padding oracle timing attack</li><li>The BEAST CBC chained IV attack</li><li>Heartbleed</li><li>Renegotiation</li><li>Triple Handshakes</li><li>Compromised CAs</li></ul><p>但是，你仍然应该使用TLS做传输协议，因为：</p><ul><li>这些漏洞中的大部分，仅仅是针对浏览器的，因为他们依赖受害者执行攻击者控制的JavaScript脚本，这些JavaScript脚本生成重复的明文，或特定的明文。</li><li>这些漏洞中的大部分，其影响都可以被减轻，只需要你在代码和配置里面写死 TLS v1.2, ECDHE，和 AES-GCM就行。这听起来很棘手，但是这远远没有你自己设计使用ECDHE和AES-GCM的传输协议棘手。</li><li>在一个自定义的传输协议的场景中，你并不需要依赖CA，你可以用一个自签名证书，嵌入到你的客户端里面。</li><li>不要自己设计加密传输协议，这是<strong>极其困难而易错的工程难题</strong></li><li>使用TLS，但是不要使用默认配置</li></ul><h3 id="在线备份">在线备份</h3><p>应该使用Tarsnap</p><hr><h3 id="名词解释">名词解释</h3><p>本文的内容比较新，相关中文资料极少，因此文中的名词对读者可能有点陌生，故byron这里介绍一下文中提到的一些名词：</p><ul><li><p>NaCl 库：<br><a href="http://nacl.cr.yp.to/" target="_blank" rel="noopener">http://nacl.cr.yp.to/</a><br>是密码学学术权威 Daniel J. Bernstein教授 设计的一个密码学算法库，2008年发开始公布。NaCl的特点是：api简洁而易用，高性能，高安全性，主要用于网络通信，加密，解密，签名等，NaCl提供了构建高层密码学工具的核心功能。</p></li><li><p>libsodium 库：<br><a href="https://download.libsodium.org/doc/" target="_blank" rel="noopener">https://download.libsodium.org/doc/</a><br>libsodium是对NaCl库的一个分支，进一步改进接口易用性，和可移植性。</p></li><li><p>AEAD :<br><a href="https://www.imperialviolet.org/2014/02/27/tlssymmetriccrypto.html" target="_blank" rel="noopener">https://www.imperialviolet.org/2014/02/27/tlssymmetriccrypto.html</a><br>AEAD的概念：<br>在通常的密码学应用中，Confidentiality  (保密) 用加密实现，Message authentication (消息认证) 用MAC实现。这两种算法的配合方式，引发了很多安全漏洞，过去曾经有3种方法：1. Encrypt-and-MAC  2.MAC-then-Encrypt 3.Encrypt-then-MAC ，后来发现，1和2都是有安全问题的，所以，2008年起，<br>逐渐提出了“用一个算法在内部同时实现cipher+MAC”的idea，称为AEAD(Authenticated encryption with additional data)。<br>在AEAD这种概念里，cipher+MAC 被 一个AEAD算法替换。<br><a href="http://en.wikipedia.org/wiki/Authenticated_encryption" target="_blank" rel="noopener">http://en.wikipedia.org/wiki/Authenticated_encryption</a></p></li><li><p>ChaCha20-poly1305 :<br>ChaCha20-poly1305是一种AEAD，提出者是Daniel J. Bernstein教授，针对移动互联网优化，目前Google对移动客户端的所有流量都使用ChaCha20-Poly1305</p></li><li><p>AES-GCM :<br>AES-GCM是一种AEAD，是目前TLS的主力算法，互联网上https流量的大部分依赖使用AES-GCM。<br>AES-GCM和ChaCha20-Poly1305的性能对比测试结果：</p></li></ul><blockquote><p>| Chip| AES-128-GCM speed| ChaCha20-Poly1305 speed|<br>| ------ | :-----: |  :-----: |<br>| OMAP 4460| 24.1 MB/s| 75.3 MB/s|<br>| Snapdragon S4 Pro|41.5 MB/s| 130.9 MB/s|<br>| Sandy Bridge Xeon (AESNI)|900 MB/s| 500 MB/s|</p></blockquote><ul><li><p>SHA2 :<br><a href="http://en.wikipedia.org/wiki/SHA-2" target="_blank" rel="noopener">http://en.wikipedia.org/wiki/SHA-2</a></p></li><li><p>Curve25519 :<br><a href="http://cr.yp.to/ecdh.html" target="_blank" rel="noopener">http://cr.yp.to/ecdh.html</a><br>Curve25519 是目前最高水平的 Diffie-Hellman函数，适用于广泛的场景，由Daniel J. Bernstein教授设计。由于NIST P-256的设计过程不透明，有来历不明的参数，被广泛怀疑有后门，所以设计了Curve25519，Curve25519的设计过程完全公开，没有任何来历不明的参数。<br>部署情况：<a href="http://ianix.com/pub/curve25519-deployment.html" target="_blank" rel="noopener">http://ianix.com/pub/curve25519-deployment.html</a></p></li><li><p>Ed25519 :<br><a href="http://ed25519.cr.yp.to/" target="_blank" rel="noopener">http://ed25519.cr.yp.to/</a><br>Ed25519 是一个数字签名算法，优点有：</p><ul><li>签名和验证的性能都极高， 一个4核2.4GHz 的 Westmere cpu，每秒可以验证 71000 个签名</li><li>安全性极高，等价于RSA约3000-bit</li><li>签名过程不依赖随机数生成器，不依赖hash函数的防碰撞性，没有时间通道攻击的问题</li><li>并且签名很小，只有64字节，公钥也很小，只有32字节。</li></ul><p>部署情况：<a href="http://ianix.com/pub/ed25519-deployment.html" target="_blank" rel="noopener">http://ianix.com/pub/ed25519-deployment.html</a></p></li><li><p>前向安全性：<br>前向安全性( Perfect Forward Secrecy )<br><a href="http://vincent.bernat.im/en/blog/2011-ssl-perfect-forward-secrecy.html" target="_blank" rel="noopener">http://vincent.bernat.im/en/blog/2011-ssl-perfect-forward-secrecy.html</a><br>前向安全性指的是，如果攻击者抓取并保存流量，那么将来私钥泄露后，攻击者也无法利用泄露的私钥解密这些流量。</p></li><li><p>Diffie-Hellman 密钥交换：<br><a href="http://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange" target="_blank" rel="noopener">http://en.wikipedia.org/wiki/Diffie–Hellman_key_exchange</a><br>在任何一本密码学教材里面都会重点介绍的</p></li><li><p>constant time compare :<br>针对Timing attack，<a href="http://en.wikipedia.org/wiki/Timing_attack" target="_blank" rel="noopener">http://en.wikipedia.org/wiki/Timing_attack</a> （这种攻击真是脑洞大开！）<br>当一个算法的运行时间和输入数据有关的时候，可以根据运行时间这一信息，破解出密钥等。<br>典型的，比如要验证一个对称签名，如果你用了C库里面的memcmp()，那你就会被timing attack方式攻击。<br>因此，涉及到密码学数据的memcmp，必须要用运行时间和输入无关的函数，比如OpenSSL库里面的CRYPTO_memcmp()</p></li></ul><hr><p>原文链接：<a href="https://gist.github.com/byronhe/232d22f1d3dcaa0a20cb" target="_blank" rel="noopener">https://gist.github.com/byronhe/232d22f1d3dcaa0a20cb</a></p>]]></content>
    
    <summary type="html">
    
      &lt;hr&gt;
&lt;p&gt;本文介绍目前现代密码学的最先进技术，&lt;br&gt;
前半部分主要翻译自  &lt;a href=&quot;https://gist.github.com/tqbf/be58d2d39690c3b366ad&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;《Cryptographic Right Answers》&lt;/a&gt;，附上收集的资料，和byron个人的理解。&lt;/p&gt;
&lt;p&gt;密码学理论艰深，概念繁多，本人知识水平有限，错误难免，如果您发现错误，请务必指出，非常感谢!&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;下文分类介绍在各种适用场景下，你应该使用的现代密码学算法&lt;/strong&gt;&lt;/p&gt;
    
    </summary>
    
      <category term="转载" scheme="https://hyxxsfwy.github.io/categories/%E8%BD%AC%E8%BD%BD/"/>
    
    
      <category term="翻墙" scheme="https://hyxxsfwy.github.io/tags/%E7%BF%BB%E5%A2%99/"/>
    
      <category term="密码学" scheme="https://hyxxsfwy.github.io/tags/%E5%AF%86%E7%A0%81%E5%AD%A6/"/>
    
  </entry>
  
  <entry>
    <title>搜集可用于 XX-Net 的高速 GGC IP 段</title>
    <link href="https://hyxxsfwy.github.io/2016/06/18/%E6%90%9C%E9%9B%86%E5%8F%AF%E7%94%A8%E4%BA%8EXX-Net%E7%9A%84%E9%AB%98%E9%80%9FGGC-IP%E6%AE%B5/"/>
    <id>https://hyxxsfwy.github.io/2016/06/18/搜集可用于XX-Net的高速GGC-IP段/</id>
    <published>2016-06-18T13:40:36.000Z</published>
    <updated>2018-03-18T16:00:33.000Z</updated>
    
    <content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="xx-net-简介">XX-Net 简介</h3><p>XX-Net 继承于 Goagent，实用之处在于它集成了自动扫描与检测可用的 GGC(Google Global Cache) IP 段功能，让基于 GAE 的翻墙方案得以长期稳定的坚持下去。项目主页：<a href="https://github.com/XX-net/XX-Net" target="_blank" rel="noopener">https://github.com/XX-net/XX-Net</a></p><a id="more"></a><h3 id="xx-net的安全性">XX-Net的安全性</h3><p>先下结论：XX-Net 不能用于匿名，但可以保证数据传输的安全。</p><p>下面详述：</p><ol><li>由于免费 GAE 应用无法使用 socket 接口，基于 GAE 的翻墙代理都要导入根证书，从而在本地完成对 https 流量的劫持、解密与转发，XX-Net 也不例外。由于 XX-Net 在首次启动时是在本地随机生成自签发证书的，只要这个唯一的本地证书不泄露，就不存在证书被盗用，进而遭受中间人攻击的风险。所以，如果有分享自用的 XX-Net 软件包给朋友使用的需求，请记得删除<code>data/gae_proxy</code>目录下的<code>CA.crt</code>根证书和<code>certs</code>目录。</li><li>XX-Net 本地客户端到 GAE 服务器的连接，默认检查扫描到 Goolge IP 的 https 证书，这是防蜜罐节点和墙的中间人攻击。所以，客户端到 GAE 服务器的连接是安全可靠的。</li><li>GAE 服务器到目标网站的连接，默认没用开启对 https 证书的检查，因为墙无法干扰到。为了加强安全性，可以手动开启：<br>定位到 XX-Net 所在目录下的<br><code>gae_proxy/local/gae_handler.py</code><br>文件，搜索<br><code>kwargs['validate'] = 0</code>，<br>将值改为<code>= 1</code>即可。<br>测试：开启服务端证书验证后，通过 XX-Net 代理访问<br><a href="https://goagent-cert-test.bamsoftware.com/" target="_blank" rel="noopener">https://goagent-cert-test.bamsoftware.com/</a>，<br>返回报错信息：<br><code>SSLCertificateError('Invalid and/or missing SSL certificate for URL: https://goagent-cert-test.bamsoftware.com/',), should validate=0 ?</code><br>这样一来，GAE服务器到目标网站的连接也可以确保安全。</li><li>关于匿名与隐私的问题，参见项目说明文档：<br><a href="https://github.com/XX-net/XX-Net/wiki/Anonymity-and-Security" target="_blank" rel="noopener">https://github.com/XX-net/XX-Net/wiki/Anonymity-and-Security</a><br>总之，如果传输、浏览特别敏感的信息，请使用 Tor，并学习如何匿名。而普通用户，只需要部署自己的 appid，且 appid 命名不要与现有网名相关，这就足够了。</li></ol><h3 id="扫描高速-ggc-ip-段">扫描高速 GGC IP 段</h3><p>XX-Net 保证其高可用性的核心技术就是扫描 GGC IP 段并维护动态的可用IP连接池。所以，指定的待扫描 GGC IP 段的质量就决定了 GAE 代理访问的速度。于是，问题的关键在于：如何发现高速稳定的 GGC IP 段。</p><ul><li><p>工具：checkiptools，项目主页：<a href="https://github.com/xyuanmu/checkiptools" target="_blank" rel="noopener">https://github.com/xyuanmu/checkiptools</a></p></li><li><p>过程：</p><ol><li>找寻目标国家，最好是与中国的国际出口线路有海底光缆直连的。比如台湾，日本，韩国，马来西亚。具体可以参考这个网站：<a href="http://www.submarinecablemap.com/" target="_blank" rel="noopener">http://www.submarinecablemap.com/</a></li><li>在 checkiptools 目录下，获取目标国家的全部 IPv4 地址段：</li></ol><figure class="highlight coq"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">wget -O- 'https://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest' | <span class="type">grep</span> ipv4 | <span class="type">grep</span> KR | <span class="type">awk</span> -F\| <span class="type">'&#123; printf</span>(<span class="string">"%s/%d\n"</span>, $<span class="number">4</span>, <span class="number">32</span>-log($<span class="number">5</span>)/log(<span class="number">2</span>)) &#125;' &gt; googleip.txt</span><br></pre></td></tr></table></figure><p>这个例子中，<code>grep KR</code>用到了韩国的 ISO 标准国家代码<code>KR</code>，所有的 ISO 标准国家代码参见 Wiki：<a href="https://zh.wikipedia.org/wiki/ISO_3166-1" target="_blank" rel="noopener">https://zh.wikipedia.org/wiki/ISO_3166-1</a></p><ol start="3"><li>开始扫描。Windows 下，直接双击运行<code>checkip.bat</code>，扫描目标国家的所有IP段，确认其是否为 GGC 服务器。扫描超时参数可以通过修改<code>python/checkip.py</code>文件里</li></ol><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">g_conntimeout = 5</span><br><span class="line">g_handshaketimeout = 7</span><br></pre></td></tr></table></figure><p>的值来自定义，单位为<code>s</code>，其他参数可参考代码注释自行调整。</p><ol start="4"><li>提取有效IP段。Windows下直接双击运行<code>!ptools.bat</code>，按照提示操作，选 2：<code>提取 ip_tmpok.txt 中有效IP的IP段, 并生成 ip_output.txt</code>，并设定延迟过滤阈值，如<code>400ms</code>。</li><li>将生成的 ip_output.txt 文件内容复制并在 XX-Net 的 Web 设置页面提交。待 XX-Net 扫描一段时间后，访问 Youtube 测速。如果确实高速稳定，则保留这些 GGC IP 段。</li></ol></li><li><p>PS：如果手头有 VPS 的，可以在 VPS 上开个300线程暴力扫描，再将得到的 GGC IP 段在本地网络用 checkiptools 检查一遍，得到靠谱的高速 GGC IP 段。</p></li></ul>]]></content>
    
    <summary type="html">
    
      &lt;h3 id=&quot;xx-net-简介&quot;&gt;XX-Net 简介&lt;/h3&gt;
&lt;p&gt;XX-Net 继承于 Goagent，实用之处在于它集成了自动扫描与检测可用的 GGC(Google Global Cache) IP 段功能，让基于 GAE 的翻墙方案得以长期稳定的坚持下去。项目主页：&lt;a href=&quot;https://github.com/XX-net/XX-Net&quot; target=&quot;_blank&quot; rel=&quot;noopener&quot;&gt;https://github.com/XX-net/XX-Net&lt;/a&gt;&lt;/p&gt;
    
    </summary>
    
      <category term="翻墙" scheme="https://hyxxsfwy.github.io/categories/%E7%BF%BB%E5%A2%99/"/>
    
    
      <category term="XX-Net" scheme="https://hyxxsfwy.github.io/tags/XX-Net/"/>
    
      <category term="翻墙" scheme="https://hyxxsfwy.github.io/tags/%E7%BF%BB%E5%A2%99/"/>
    
      <category term="Google" scheme="https://hyxxsfwy.github.io/tags/Google/"/>
    
  </entry>
  
  <entry>
    <title>【转】边信道攻击，从米特尼克传奇重现说起</title>
    <link href="https://hyxxsfwy.github.io/2016/06/01/%E3%80%90%E8%BD%AC%E3%80%91%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB%EF%BC%8C%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/"/>
    <id>https://hyxxsfwy.github.io/2016/06/01/【转】边信道攻击，从米特尼克传奇重现说起/</id>
    <published>2016-06-01T11:01:26.000Z</published>
    <updated>2016-06-17T16:00:33.000Z</updated>
    
    <content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>5月12日，在黑客大赛GeekPwn澳门站现场，来自美国加州大学钱志云团队的博士生曹跃现场展示了惊人的“远程任意TCP劫持连接技术”，重现了著名黑客米特尼克在互联网任意地方劫持任意用户的传奇。攻击的技术细节没有完全公开，但是根据GeekPwn的相关报道来看，曹跃同学是使用了一种被称为边信道（又称侧信道）攻击的技术完成了这一壮举。</p><p><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/01.jpg" alt></p><p>今天我们抛开这个深奥的漏洞，来谈下什么是边信道攻击。很多工业界的同学可能对这个学术界的热门术语并不是很熟悉。在密码学中，针对加密电子设备在运行过程中的时间消耗、功率消耗或电磁辐射之类的侧信道信息泄露而对加密设备进行攻击的方法被称为边信道攻击定时信息。这种攻击方式目前也已经被广泛的应用到密码学之外的安全技术领域。</p><h3 id="一个现实生活中的边信道攻击案例">一个现实生活中的边信道攻击案例</h3><p>几年前有过这样的一个报道：南京大学学生刘某在观看一段记者采访某互联网公司总裁周某的视频时突发奇想，利用视频中记者采访时的拨号声音还原出了周某手机号码。这个事情引起了网友的围观，并被周某在在微薄上证实确有其事。这个事件中刘同学使用的就是边信道攻击，通过记者视频中拨号的声音，对照每个号码按键声音的标准音，就可以精确的还原出真实的号码。</p><p><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/02.jpg" alt></p><p>在网络攻防中，边信道的思路实际已经有比较广泛的运用，比如通过电磁木马窃收物理隔离计算机信息、通过磁探头设备在Android和iOS设备上获取加密秘钥。相关的报道很多，这里不再一一赘述。</p><p><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/03.jpg" alt></p><h3 id="边信道攻击和应用安全">边信道攻击和应用安全</h3><p>在应用安全领域，时间信道进行攻击（Time attack，又称时序攻击）是一种比较常见的边信道攻击方式。根据应用软件的特性，我们可以构造不同的输入数据来观察程序执行某些流程耗时的差别，通过统计分析的方法来获取我们想要的信息。在现实生活中，张三晚上二十一点打隔壁老王家客厅座机，打10次有8次老王接的比平时慢，那么张三基本可以断定老王晚上睡觉的时间应该早于二十一点，这就是一种时序攻击。</p><p>2010年，Sebastian Schinzel在OWASP的一次会议上就做过题为《Side Channel Vulnerabilities on the Web - Detection and Prevention》的报告，里面介绍了一种基于应用程序流程执行差异的时序攻击模型并给出了防御方法。这里顺便多说一句，Sebastian Schinzel的研究领域非常广泛，OpenSSL的DROWN漏洞(水牢漏洞)也是这位国际友人发现并报告给官方的。</p><p><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/04.jpg" alt></p><p>在Black Hat 2013大会上，英国安全研究员Paul Stone就做过一个基于时间边信道攻击的报告，他利用基于JavaScript的时序攻击结合其它一些攻击策略，能够从目标用户浏览器上窃取信息。</p><p><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/05.jpg" alt></p><p>PHP应用程序中的字符串比较一直是时序攻击的重灾区，在找回密码等应用场景种均有可能存在此类安全隐患。大量知名的PHP开源应用程序都在这里栽倒过，比如piwik就在去年就发过补丁。</p><p><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/06.jpg" alt></p><p>这个坑也是源远流长，Ircmaxell对这个问题做过详细的分析。在比较两个字符是否一致的时候，首先PHP会做长度判断。如果字符长度不一样，就不用比下去了，这是一个时序攻击的利用点。</p><p><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/07.png" alt></p><p>然后，如果长度一样就用memcmp来比较了，这里我大PHP要接C语言的锅了</p><p><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/08.png" alt></p><p>可以看到这里本质是逐位比较的。我们可以构造如下的序列循环比较，记录下来每次尝试的时间。</p><p><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/09.png" alt></p><p>如果发现某个字符的时间比较长，基本就可以确定已经命中了这一位。固定住这一位后可以对下一位继续进行猜测。PHP为了解决这个问题，甚至专门提供了相关的安全函数。</p><p><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/10.png" alt></p><h3 id="网络安全的跨界合作">网络安全的跨界合作</h3><p>边信道攻击，作为一种在学术研究领域（特别是密码学领域）广为应用的攻防方式，在工业领域也发出了耀眼的光芒，体现了学术界和工业界在相互借鉴、认可和融合。</p><p>在过去的很多年中，国内学术界关于网络安全的研究和教学大多侧重于密码学领域。而在工业领域，大家则更侧重于系统漏洞和攻防实战。学术界和工业界的合作融合，相对比较少，看问题的角度，也有所差别。比如针对某一类攻击方法，从学术价值上看非常具有创新性，但是从工业界看却难有施展的场景，讨论起来的时候一言不合就只能拿酒说话了。</p><p>最近几年，情况有了很大的改变。一些有很强学术背景的牛人，在工业领域里取得了令人钦佩的成果，比如盘古团队的王铁磊和PaloAlto的屈波等超级大神。在密码学研究领域非常知名的上海交通大学loccs实验室甚至培养出了夺得过CTF赛事世界冠军的0ops团队。</p><p>在2015年底，清华段海新老师、复旦杨珉老师等活跃在网络安全学术和技术圈的研究人员发起了网络安全研究国际学术论坛（简称网安国际，InForSec，<a href="http://www.inforsec.org/" title="www.inforsec.org" target="_blank" rel="noopener">www.inforsec.org</a> ）。</p><p><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/11.jpg" alt></p><p>若干年后回首网络安全发展史，这可能是一个里程碑式的事件。InForSec通过组织一些活动，极大的促进了学术和工业的了解和交流。TSRC也在积极的为InForSec提供一些力所能及的支持，希望InForSec走的更远走的更好。</p><p>在未来的几年中，我们一定能够看到更多类似GeekPwn上边信道劫持TCP通信的精彩技术从学术界走向工业界。学术界发现问题、解决问题的方法能够给工业界的同学更多的启迪和思考，而工业界也能够给学术界提供更为广泛的战场。</p><hr><p>本文转载自腾讯安全应急响应中心官方微信公众号（tsrc_team）<br><img src="/imgs/16.06/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB-%E4%BB%8E%E7%B1%B3%E7%89%B9%E5%B0%BC%E5%85%8B%E4%BC%A0%E5%A5%87%E9%87%8D%E7%8E%B0%E8%AF%B4%E8%B5%B7/qrcode.png" alt><br>个人收藏，侵删。</p>]]></content>
    
    <summary type="html">
    
      
      
        &lt;link rel=&quot;stylesheet&quot; class=&quot;aplayer-secondary-style-marker&quot; href=&quot;\assets\css\APlayer.min.css&quot;&gt;&lt;script src=&quot;\assets\js\APlayer.min.js&quot; cla
      
    
    </summary>
    
      <category term="转载" scheme="https://hyxxsfwy.github.io/categories/%E8%BD%AC%E8%BD%BD/"/>
    
    
      <category term="信息安全" scheme="https://hyxxsfwy.github.io/tags/%E4%BF%A1%E6%81%AF%E5%AE%89%E5%85%A8/"/>
    
      <category term="边信道攻击" scheme="https://hyxxsfwy.github.io/tags/%E8%BE%B9%E4%BF%A1%E9%81%93%E6%94%BB%E5%87%BB/"/>
    
      <category term="Hack&amp;Security" scheme="https://hyxxsfwy.github.io/tags/Hack-Security/"/>
    
  </entry>
  
  <entry>
    <title>HaP 免流模式语法帮助文档</title>
    <link href="https://hyxxsfwy.github.io/2016/01/30/HaP-%E5%85%8D%E6%B5%81%E6%A8%A1%E5%BC%8F%E8%AF%AD%E6%B3%95%E5%B8%AE%E5%8A%A9%E6%96%87%E6%A1%A3/"/>
    <id>https://hyxxsfwy.github.io/2016/01/30/HaP-免流模式语法帮助文档/</id>
    <published>2016-01-30T05:45:28.000Z</published>
    <updated>2017-05-19T16:00:33.000Z</updated>
    
    <content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h2 id="1-配置参数">1. 配置参数</h2><p>本文是HaP核心的配置文件详解，比如<code>global</code>,<code>defaults</code>之类的能看到的配置语法，都可以在这里找到注释</p><h3 id="1-1-global">1.1 global</h3><p><code>global</code>在配置文件中，主要设置一些全局性的参数，起重要作用<br>一般建议不要修改，特别是pid文件地址，如果修改了可能会导致无法正常停止HaP核心</p><h4 id="1-1-1-daemon">1.1.1 daemon</h4><p>HaP核心运行方式为：后台运行</p><h4 id="1-1-2-user-group">1.1.2 user group</h4><p><code>user - group</code><br>设置HAP核心工作所属的用户和组</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置HAP核心工作的用户和组为:inet</span></span><br><span class="line">user inet</span><br><span class="line">group inet </span><br><span class="line"></span><br><span class="line"><span class="comment">###################################</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#设置HAP核心工作的用户和组为:root</span></span><br><span class="line">user root </span><br><span class="line">group root</span><br></pre></td></tr></table></figure><a id="more"></a><h4 id="1-1-3-maxconn">1.1.3 maxconn</h4><p>设置每个进程可用的最大连接数</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置每个进程可用的最大连接数20480</span></span><br><span class="line">maxconn 20480</span><br></pre></td></tr></table></figure><h4 id="1-1-4-chroot">1.1.4 chroot</h4><p>改变当前工作目录<br>一般不需要添加，所以在配置语法中这句是注释掉的，也不推荐使用，因为 pidfile 文件的路径是相对路径，这个会干扰 pidfile 文件的存放地址</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置工作目录为HaP的私有目录</span></span><br><span class="line">chroot /data/data/com.HaP.Byml/files</span><br><span class="line"></span><br><span class="line"><span class="comment">#/data/data/com.HaP.Byml/files目录</span></span><br><span class="line"><span class="comment">#就是HaP的私有目录</span></span><br></pre></td></tr></table></figure><h4 id="1-1-5-pidfile">1.1.5 pidfile</h4><p>haproxy的pid存放路径，启动进程的用户必须有权限访问此文件<br>不推荐修改这个地址，修改以后会干扰自带的HAP停止脚本</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置pidfile文件地址</span></span><br><span class="line">pidfile ./haproxy.pid </span><br><span class="line"></span><br><span class="line"><span class="comment">#上面的配置会使在配置文件相同的目录下创建pid文件</span></span><br><span class="line"><span class="comment">#及这就是相对目录，建议默认就这样</span></span><br></pre></td></tr></table></figure><h3 id="1-2-defaults">1.2 defaults</h3><p>默认的一个模块，一些超时和一些缺省值需要要设置的参数在这个模块设置</p><h4 id="1-2-1-timeout-connect">1.2.1 timeout connect</h4><p>超时参数：连接超时<br>如果一个连接超过了超时参数设置的值没有进行响应操作，就会自动断开连接，返回一个错误的报文</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置连接超时为：30000ms</span></span><br><span class="line">timeout connect 30000ms</span><br></pre></td></tr></table></figure><h4 id="1-2-2-timeout-client">1.2.2 timeout client</h4><p>超时参数：客户端超时<br>如果客户端超过了超时参数设置的值没有进行响应操作，就会自动断开连接，返回一个错误的报文</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置客户端超时为：300000ms</span></span><br><span class="line">timeout client 300000ms</span><br></pre></td></tr></table></figure><h4 id="1-2-3-timeout-server">1.2.3 timeout server</h4><p>超时参数：服务器端超时<br>如果服务器端超过了超时参数设置的值没有进行响应操作，就会自动断开连接，返回一个错误的报文</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设服务器端超时为：3000000ms</span></span><br><span class="line">timeout server 30000ms</span><br></pre></td></tr></table></figure><h4 id="1-2-4-stats">1.2.4 stats</h4><p>设置HaProxy的状态网页<br>由于有些模式修改过的请求，会干扰HAP核心的识别状态页面，所以推荐用默认透明模式进行访问状态页面</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置HaP核心的状态页面为/hap</span></span><br><span class="line">stats uri /hap</span><br></pre></td></tr></table></figure><p>在默认透明模式下访问<code>http://127.0.0.1:监听端口/hap</code> 就可以进入状态网页</p><h4 id="1-2-5-option-redispatch">1.2.5 option redispatch</h4><p>serverId对应的服务器挂掉后，强制定向到其他健康的服务器</p><h4 id="1-2-6-option-abortonclose">1.2.6 option abortonclose</h4><p>当服务器负载很高的时候，自动结束掉当前队列处理比较久的连接</p><h4 id="1-2-7-option-httpclose">1.2.7 option httpclose</h4><p>每次请求完毕后主动关闭HTTP通道<br>老版本的HAProxy不支持<code>keep-alive</code>模式 ，HAProxy会针对客户端的第一条请求的返回添加cookie并返回给客户端，客户端发送后续请求时会发送此cookie到HAProxy，HAProxy会针对此cookie分发到上次处理此请求的服务器上，如果服务器不能忽略此cookie值会影响处理结果。<br>要避免这种情况可配置此选项，防止产生多余的cookie信息。</p><h3 id="1-3-frontend">1.3 frontend</h3><p>前端配置，可以在里面进行请求方法过滤和拦截请求操作</p><h4 id="1-3-1-mode-http">1.3.1 mode http</h4><p><code>mode { tcp|http|health }</code>   设定启动的实例的协议类型<br>非对HAP核心了解的用户禁止修改，修改后可能导致无法上网</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置协议类型为http协议</span></span><br><span class="line">mode http</span><br></pre></td></tr></table></figure><h4 id="1-3-2-option-accept-invalid-http-request">1.3.2 option accept-invalid-http-request</h4><p>允许接受错误的HTTP请求<br>有些模式修改后，会使得核心识别为错误的请求，导致直接返回一个错误请求，无法上网。要避免，加上此选项就行。</p><h4 id="1-3-3-acl-http-g-p-s-method-get-post-https">1.3.3 acl http_g/p/s method GET/POST/HTTPS</h4><p><code>acl</code> 操作<br>上面的<code>http_g/p/s</code>会在后面用的，相当于<code>if</code>语句的条件</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#判断请求模式是否为GET</span></span><br><span class="line">acl http_g method GET</span><br><span class="line"><span class="comment">#如果为GET http_g就为true</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#判断请求模式是否为POST</span></span><br><span class="line">acl http_p method POST</span><br><span class="line"><span class="comment">#如果为GET http_p就为true</span></span><br><span class="line"></span><br><span class="line"><span class="comment">#判断请求模式是否为CONNECT(https)</span></span><br><span class="line">acl http_s method CONNECT</span><br><span class="line"><span class="comment">#如果为GET http_s就为true</span></span><br></pre></td></tr></table></figure><h4 id="1-3-4-use-backend-http-get-post-https-if-http-g-p-s">1.3.4 use_backend http-get/post/https if http_g/p/s</h4><p>如果<code>acl</code>操作的值为<code>true</code>,</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#如果http_g为true就使用http-get模块</span></span><br><span class="line">use_backend http-get if http_g</span><br><span class="line"></span><br><span class="line"><span class="comment">#如果http_p为true就使用http-post模块</span></span><br><span class="line">use_backend http-post if http_p</span><br><span class="line"></span><br><span class="line"><span class="comment">#如果http_s为true就使用https模块</span></span><br><span class="line">use_backend https if http_s</span><br></pre></td></tr></table></figure><h4 id="1-3-5-default-backend-https">1.3.5 default_backend https</h4><p>默认使用的模块，当请求方法非<code>get/post/https</code>时，就会启用</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置默认模块为:https</span></span><br><span class="line">default_backend https</span><br></pre></td></tr></table></figure><h2 id="2-请求处理语法">2. 请求处理语法</h2><h3 id="2-1-中文语法">2.1 中文语法</h3><p>添加中文语法的主要原因，是英文语法多多少少有些繁琐，不易写模式，而且很多友友都不懂英文语法，甚至看到英文就头疼。<br>添加中文语法对HaP的效率没有影响，最终的处理的都和英文语法一样。中文语法中的语句，都可以在英文语法里找到相同的作用的语法。<br>HaP是一款免费的软件，希望大家能尽量分享一些，多帮助些新人，这样才能发展HaP。</p><h4 id="2-1-1-添加一行">2.1.1 添加一行</h4><p>在请求中添加一行请求</p><ul><li><p>原型<br><code>请求 添加一行 hanme value</code></p></li><li><p>参数</p><ul><li>参数1：<code>hname</code> 必填，一行的行头名称</li><li>参数2：<code>value</code> 必填，一行的值，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在请求中添加一行：test: abc\r\n </span></span><br><span class="line">请求 添加一行 test abc</span><br></pre></td></tr></table></figure><h4 id="2-1-2-设置行值">2.1.2 设置行值</h4><p>设置一行的值</p><ul><li><p>原型<br><code>请求 设置行值 sanme value</code></p></li><li><p>参数</p><ul><li>参数1：<code>sname</code> 必填，需要设置的值得行名称</li><li>参数2：<code>value</code> 必填，一行的值 ，支持<code>%[xxx]</code>操作</li></ul></li></ul><p>在请求中，寻找<code>sname</code>行，如果存在就修改<code>sname</code>行的值，如果不存在就在请求结尾添加<code>sname</code>行，值为<code>value</code></p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置Host行的值为:10.0.0.172</span></span><br><span class="line">请求 设置行值 Host 10.0.0.172</span><br></pre></td></tr></table></figure><h4 id="2-1-3-设置行值2">2.1.3 设置行值2</h4><p>设置一行的值（与<code>设置行值</code>一致）</p><ul><li><p>原型<br><code>请求 设置行值2 sanme value</code></p></li><li><p>参数</p><ul><li>参数1：<code>sname</code> 必填，需要设置的值得行名称</li><li>参数2：<code>value</code> 必填，一行的值 ，支持<code>%[xxx]</code>操作</li></ul></li></ul><p>在请求中，寻找<code>sname</code>行，如果存在就修改<code>sname</code>行的值，如果不存在就在请求结尾添加<code>sname</code>行，值为<code>value</code></p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置Host行的值为:10.0.0.172</span></span><br><span class="line">请求 设置行值2 Host 10.0.0.172</span><br></pre></td></tr></table></figure><h4 id="2-1-4-删除一行">2.1.4 删除一行</h4><p>删除请求中的一行</p><ul><li><p>原型<br><code>请求 删除一行 danme</code></p></li><li><p>参数</p><ul><li>参数1：<code>dname</code> 必填，需要删除的行名称</li></ul></li></ul><p>会删除请求中的<code>dname</code>行</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#删除请求中的Host行</span></span><br><span class="line">请求 删除一行 Host</span><br></pre></td></tr></table></figure><h4 id="2-1-5-删除一行2">2.1.5 删除一行2</h4><p>删除请求中的一行（与<code>删除一行</code>一致）</p><ul><li><p>原型<br><code>请求 删除一行2 danme</code></p></li><li><p>参数</p><ul><li>参数1：<code>dname</code> 必填，需要删除的行名称</li></ul></li></ul><p>会删除请求中的<code>dname</code>行</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#删除请求中的Host行</span></span><br><span class="line">请求 删除一行2 Host</span><br></pre></td></tr></table></figure><h4 id="2-1-6-替换字符串">2.1.6 替换字符串</h4><p>替换请求中指定的字符串</p><ul><li><p>原型<br><code>请求 替换字符串 str1 str2</code></p></li><li><p>参数</p><ul><li>参数1：<code>str1</code> 必填，需要被替换的字符串，支持<code>%[xxx]</code>操作</li><li>参数2：<code>str2</code> 必填 ，需要替换的字符串</li></ul></li></ul><p>在请求中，把<code>str1</code>字符串替换为<code>str2</code>字符串</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#修改HTTP协议版本为:1.0</span></span><br><span class="line">请求 替换字符串 HTTP/1.1 HTTP/1.0</span><br><span class="line"></span><br><span class="line"><span class="comment">#把Host行替换成X-Online-Host行</span></span><br><span class="line">请求 替换字符串 \nHost: \nX-Online-Host:</span><br></pre></td></tr></table></figure><h4 id="2-1-7-之前添加">2.1.7 之前添加</h4><p>在请求中某一个字符串前面添加字符串</p><ul><li><p>原型<br><code>请求 之前添加 name str</code></p></li><li><p>参数</p><ul><li>参数1：<code>name</code> 必填，确定在哪一个字符串前面添加字符串</li><li>参数2：<code>str</code> 必填，需要添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li></ul><p>在请求中的的<code>name</code>字符串前添加<code>str</code>字符串</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在Host行前面添加一行：test,值为abc</span></span><br><span class="line">请求 之前添加 Host: test:\ abc\r\n</span><br></pre></td></tr></table></figure><h4 id="2-1-8-之后添加">2.1.8 之后添加</h4><p>在请求中指定字符串后面添加字符串</p><ul><li><p>原型<br><code>请求 之后添加 name str</code></p></li><li><p>参数</p><ul><li>参数1：<code>name</code> 必填，确定在哪个字符串后面添加字符串</li><li>参数2：<code>str</code> 必填，需要添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li></ul><p>在请求中的<code>name</code>行后面添加<code>str</code>字符串</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在首行下面添新的一行test 值为abc</span></span><br><span class="line">请求 之后添加 \n test:\ abc\r\n</span><br></pre></td></tr></table></figure><h4 id="2-1-9-行前添加">2.1.9 行前添加</h4><p>在请求中某一行前面添加字符串</p><ul><li><p>原型<br><code>请求 行前添加 name str</code></p></li><li><p>参数</p><ul><li>参数1：<code>name</code> 必填，确定在哪一行前面添加字符串</li><li>参数2：<code>str</code> 必填，需要添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li></ul><p>在请求中的的<code>name</code>行前添加<code>str</code>字符串</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在Host行前面添加一行：test,值为abc</span></span><br><span class="line">请求 行前添加 Host test:\ abc\r\n</span><br></pre></td></tr></table></figure><h4 id="2-1-10-行后添加">2.1.10 行后添加</h4><p>在请求中某一行后面添加字符串</p><ul><li><p>原型<br><code>请求 行后添加 name str</code></p></li><li><p>参数</p><ul><li>参数1：<code>name</code> 必填，确定在哪一行后面添加字符串</li><li>参数2：<code>str</code> 必填，需要添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li></ul><p>在请求中的的<code>name</code>行后面添加<code>str</code>字符串</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在Host行后面添加一行：test,值为abc</span></span><br><span class="line">请求 行后添加 Host test:\ abc\r\n</span><br></pre></td></tr></table></figure><h4 id="2-1-11-行值前添加">2.1.11 行值前添加</h4><p>在一行值的前面添加字符串</p><ul><li><p>原型<br><code>请求 行值前添加 name str</code></p></li><li><p>参数</p><ul><li>参数1：<code>name</code> 必填，确定在哪一行值的前面添加字符串</li><li>参数2：<code>str</code> 必填，需要添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li></ul><p>在请求中的的<code>name</code>的值前面添加添加<code>str</code>字符串</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在Host行值前面添加字符串：abc</span></span><br><span class="line">请求 行值前添加 Host abc</span><br><span class="line"><span class="comment">#如果Host行整行为:Host: wap.baidu.com\r\n</span></span><br><span class="line"><span class="comment">#那么使用上面的Host行就会变成：Host:abcwap.baidu.com\r\n</span></span><br><span class="line"><span class="comment">#这个时候Host行值的前面增加了abc，这就是'行值前添加'语法的作用</span></span><br></pre></td></tr></table></figure><h4 id="2-1-12-行值后添加">2.1.12 行值后添加</h4><ul><li><p>原型<br><code>请求 行值后添加 name str</code></p></li><li><p>参数</p><ul><li>参数1：<code>name</code> 必填，确定在哪一行值的后面</li><li>参数2：<code>str</code> 必填，需要添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在Host行值后面添加abc</span></span><br><span class="line">请求 行值后添加 Host abc</span><br><span class="line"><span class="comment">#如果Host行的整行为:Host: wap.baidu.com\r\n</span></span><br><span class="line"><span class="comment">#使用上面的语法后Host整行为：Host: wap.baidu.comabc\r\n</span></span><br><span class="line"><span class="comment">#这个时候Host行值后面添加了abc，这就是'行值后添加'语法的作用</span></span><br></pre></td></tr></table></figure><h4 id="2-1-13-url前添加">2.1.13 URL前添加</h4><ul><li><p>原型<br><code>请求 URL前添加 str</code></p></li><li><p>参数</p><ul><li>参数1：<code>str</code> 必填，需要添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在请求URL之前添加字符串str</span></span><br><span class="line">请求 URL前添加 str</span><br></pre></td></tr></table></figure><h4 id="2-1-14-url后添加">2.1.14 URL后添加</h4><ul><li><p>原型<br><code>请求 URL后添加 str</code></p></li><li><p>参数</p><ul><li>参数1：<code>str</code> 必填，需要添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">##在请求URL之后添加字符串str</span></span><br><span class="line">请求 URL后添加 str</span><br></pre></td></tr></table></figure><h4 id="2-1-15-删除网址http-host">2.1.15 删除网址<code>http://host</code></h4><ul><li><p>原型<br><code>请求 删除网址http://host null null</code></p></li><li><p>参数</p><ul><li>参数1： 可选，默认<code>null</code>即可</li><li>参数2： 可选，默认<code>null</code>即可</li></ul></li></ul><p>在请求的第一行通常是这样的<br><code>GET(method) http://wap.baidu.com/?from=xxx</code><br>由于某些特殊修改请求的方法，需要去掉请求中的<code>http://wap.baidu.com</code><br>所以出现了上面的语法，语法跟<code>mov-fhttp null null</code>作用一样</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#删除网址http://host</span></span><br><span class="line">请求 删除网址http://host null null</span><br></pre></td></tr></table></figure><h4 id="2-1-16-删除s-e">2.1.16 删除s_e</h4><ul><li><p>原型<br><code>请求 删除s_e start end</code></p></li><li><p>参数</p><ul><li>参数1：<code>start</code> 必填,开始字符</li><li>参数2：<code>end</code> 必填，结束字，支持<code>%[xxx]</code>操作符</li></ul></li></ul><p>删除<code>start</code>到<code>end</code>之间的字符，保留<code>end</code></p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#删除网址http://host</span></span><br><span class="line">请求 删除s_e http:// /</span><br><span class="line"><span class="comment">#上面的语句的作用就等于删除网址http://</span></span><br></pre></td></tr></table></figure><h4 id="2-1-17-删除s-e2">2.1.17 删除s_e2</h4><ul><li><p>原型<br><code>请求 删除s_e2 start end</code></p></li><li><p>参数</p><ul><li>参数1：<code>start</code> 必填，开始的字符</li><li>参数2：<code>end</code> 结束的字符串，支持<code>%[xxx]</code>操作</li></ul></li></ul><p>删除<code>start</code>到<code>end</code>的字符，删除<code>end</code>，跟<code>删除s_e</code>的区别就是<code>s_e</code>保留了<code>end</code>,这个语法删除了<code>end</code></p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#删除Host行</span></span><br><span class="line">请求 删除s_e2 Host \r\n</span><br><span class="line"><span class="comment">#上面的语法的意思是删除：以Host开头到以\r\n结尾的字符串，开头和结尾都删除</span></span><br></pre></td></tr></table></figure><h4 id="2-1-18-atob-a-b">2.1.18 atob a b</h4><p>主要用于转换行头（行头就是一行的名字，通常有<code>host行</code>的叫法，就是因为行头为<code>Host</code>）<br>如果a行存在，那么行头就替换成b行，b行不管存不存在都会被删除<br>如果a行的值为空，那么a行将会被删除，b行保留</p><ul><li><p>原型<br><code>请求 atob a b</code></p></li><li><p>参数</p><ul><li>参数1：<code>a</code> 必填，A行</li><li>参数2：<code>b</code> 必填，B行</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#X-Online-Host转Host</span></span><br><span class="line">请求 atob X-Online-Host Host</span><br></pre></td></tr></table></figure><h4 id="2-1-19-设置第一行-str">2.1.19 设置第一行 str</h4><p>自定义请求的第一行</p><ul><li><p>原型<br><code>请求 设置第一行 str</code></p></li><li><p>参数</p><ul><li>参数1：<code>str</code> 必填，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#具体事例 http://host转http://proxy_host</span></span><br><span class="line">请求 设置第一行 %[method]\ http://prxoy_host%[request_uri]\ HTTP/1.1\r\n</span><br><span class="line"><span class="comment">#%[method] 请求方法 GET/POST/CONNECT</span></span><br><span class="line"><span class="comment">#%[request_uri] 请求url 跟php的REQUEST_URI类似</span></span><br></pre></td></tr></table></figure><h4 id="2-1-20-设置行名-hdra-hdrb">2.1.20 设置行名 hdrA hdrB</h4><p>设置一行请求的行名</p><ul><li><p>原型<br><code>请求 设置行名 hdrA hdrB</code></p></li><li><p>参数</p><ul><li>参数1：`hdrA 需要被改名的请求行必填</li><li>参数1： 将要改为的行名</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#Host行改为T_Host行</span></span><br><span class="line">请求 设置行名 Host T_Host</span><br><span class="line"><span class="comment">#就把Host行的行名：Host改为了T_Host</span></span><br></pre></td></tr></table></figure><h3 id="2-2-英语语法">2.2 英语语法</h3><p>这里语法的作用都是同上面中文语法的<br>英文语法在后来的版本中对原来的语法进行优化和修复<br>在1.5版本后,set-header/2,del-header/2全部为自定义语法<br>这样做的目的是为了稳定性和安全性考虑</p><h4 id="2-2-1-add-header">2.2.1 add-header</h4><p>添加一行</p><ul><li><p>原型<br><code>http-request add-header h v</code></p></li><li><p>参数</p><ul><li><code>h</code>： 必填，需要添加的行</li><li><code>v</code>： 必填，需要添加行的值，支持<code>%[xxx]</code>操作</li></ul></li></ul><p>添加新的一行，行头为<code>h</code>，值为<code>v</code></p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#添加test行，值为abc</span></span><br><span class="line">http-request add-header test abc</span><br></pre></td></tr></table></figure><h4 id="2-2-2-set-header">2.2.2 set-header</h4><p>设置一行的值</p><ul><li><p>原型<br><code>http-request set-header h v</code></p></li><li><p>参数</p></li></ul><ul><li><code>h</code>： 必填，需要修改值的行</li><li><code>v</code>： 必填，需要修改的值，支持<code>%[xxx]</code>操作</li></ul><p>设置<code>h</code>行的值为<code>v</code>，不会修改位置</p><h4 id="2-2-3-set-header2">2.2.3 set-header2</h4><p>设置一行的值</p><ul><li><p>原型<br><code>http-request set-header2 h v</code></p></li><li><p>参数</p><ul><li><code>h</code>： 必填，需要修改值的行</li><li><code>v</code>： 必填，需要修改的值，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#设置Host行的值为10.0.0.172</span></span><br><span class="line">http-request set-header2 Host 10.0.0.172</span><br></pre></td></tr></table></figure><p>2.2.4 del-header<br>删除请求中的一行</p><ul><li><p>原型<br><code>http-request del-header h</code></p></li><li><p>参数</p><ul><li><code>h</code>： 必填，被删除的行头</li></ul></li></ul><p>删除请求中的<code>h</code>行</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#删除请求中的Host行</span></span><br><span class="line">http-request del-header Host</span><br></pre></td></tr></table></figure><p>2.2.5 del-header2</p><p>删除请求中的一行，与<code>del-heder</code>语法的区别就是此语法更稳当，<code>del-header</code>语法为开发语法</p><ul><li><p>原型<br><code>http-request del-header2 h</code></p></li><li><p>参数</p><ul><li><code>h</code>： 必填，被删除的行头</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#删除请求中Host行</span></span><br><span class="line">http-request del-header2 Host</span><br></pre></td></tr></table></figure><h4 id="2-2-6-add-replace-str-repalce">2.2.6 add-replace(str_repalce)</h4><p>替换请求中的字符串</p><ul><li><p>原型<br><code>http-request add-replace(str_replace) str1 str2</code></p></li><li><p>参数</p><ul><li><code>str1</code>： 必填，被替换的字符串，支持<code>%[xxx]</code>操作</li><li><code>str2</code>： 必填，替换的字符串</li></ul></li></ul><p>把请求中的<code>str1</code>字符串替换成<code>str2</code>字符串</p><p>示例</p><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#更改http协议版本为1.0</span></span><br><span class="line">http-request add-replace HTTP/1.1 HTTP/1.0</span><br></pre></td></tr></table></figure><h4 id="2-2-7-add-before">2.2.7 add-before</h4><p>在指定字符串前面添加字符串</p><ul><li><p>原型<br><code>http-request add-before name str</code></p></li><li><p>参数</p><ul><li><code>name</code>： 必填，定位在哪个字符串前面添加字符串</li><li><code>str</code>： 必填，需要添加的字符串 ，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#Host行前添加一行test,值为abc</span></span><br><span class="line">http-request add-before Host test:\ abc\r\n</span><br></pre></td></tr></table></figure><h4 id="2-2-8-add-after">2.2.8 add-after</h4><p>在指定字符串后面添加字符串</p><ul><li><p>原型<br><code>http-request add-after name str</code></p></li><li><p>参数</p><ul><li><code>name</code>： 必填，定位在哪个字符后面添加字符</li><li><code>str</code>： 必填，要添加的字符，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在首行下面添加一个Host 值为test</span></span><br><span class="line">http-rrequest add-after \n Host:\ test\r\n</span><br></pre></td></tr></table></figure><h4 id="2-2-9-add-lbefore">2.2.9 add-lbefore</h4><p>在指定行之前添加字符串</p><ul><li><p>原型<br><code>http-request add-lbefore h str</code></p></li><li><p>参数</p><ul><li><code>h</code>： 必填，在指定的行前</li><li><code>str</code>： 必填， 添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在Host行前添加新的一行test值为abc</span></span><br><span class="line">http-request add-lbeofore Host test:\ abc\r\n</span><br></pre></td></tr></table></figure><h4 id="2-2-10-add-lafter">2.2.10 add-lafter</h4><p>在指定行后添加字符串</p><ul><li><p>原型<br><code>http-request add-lafter h str</code></p></li><li><p>参数</p><ul><li><code>h</code>： 必填，在指定的行后</li><li><code>str</code>： 必填， 添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在Host行后添加新的一行:test行值为：abv</span></span><br><span class="line">http-request add-lafter Host test:\ abc\r\n</span><br></pre></td></tr></table></figure><h4 id="2-2-11-add-vbefore">2.2.11 add-vbefore</h4><p>在指定行后的值前面添加字符串</p><ul><li><p>原型<br><code>http-request add-vbefore h v</code></p></li><li><p>参数</p><ul><li><code>h</code>： 必填，确定在哪一行值的前面添加字符串</li><li><code>v</code>： 必填，添加的字符串 ，支持<code>%[xxx]</code>操作</li></ul></li></ul><p>在<code>h</code>行的值后面添加字符串<code>v</code></p><ul><li>示例</li></ul><figure class="highlight smali"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在Host行值前面添加字符串：abc</span></span><br><span class="line">http-request<span class="built_in"> add-vbefore </span>Host abc</span><br><span class="line"><span class="comment">#如果Host行整行为:Host: wap.baidu.com\r\n</span></span><br><span class="line"><span class="comment">#那么使用上面的Host行就会变成：Host:abcwap.baidu.com\r\n</span></span><br><span class="line"><span class="comment">#这个时候Host行值的前面增加了abc，这就是'add-hbefore'法的作用</span></span><br></pre></td></tr></table></figure><h4 id="2-2-12-add-vafter">2.2.12 add-vafter</h4><p>在指定行的值后面添加</p><ul><li><p>原型<br><code>http-request add-vafter h v</code></p></li><li><p>参数</p><ul><li><code>h</code>： 指定哪个行值后面添加字符串</li><li><code>v</code>： 需要添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在Host行值后面添加abc</span></span><br><span class="line">http-request add-vafter Host abc</span><br><span class="line"><span class="comment">#如果Host行的整行为:Host: wap.baidu.com\r\n</span></span><br><span class="line"><span class="comment">#使用上面的语法后Host整行为：Host: wap.baidu.comabc\r\n</span></span><br><span class="line"><span class="comment">#这个时候Host行值后面添加了abc</span></span><br></pre></td></tr></table></figure><h4 id="2-2-13-add-ubfore">2.2.13 add-ubfore</h4><p>在请求URL前面添加字符串</p><ul><li><p>原型<br><code>http-request add-ubefore str</code></p></li><li><p>参数</p><ul><li><code>str</code>： 添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在请求url前添加'http://bml.net'</span></span><br><span class="line">http-request ubefore http://byml.net</span><br></pre></td></tr></table></figure><h4 id="2-2-14-add-uafter">2.2.14 add-uafter</h4><p>在请求URL之后添加字符串</p><ul><li><p>原型<br><code>http-request add-uafter str</code></p></li><li><p>参数</p><ul><li><code>str</code>： 添加的字符串，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#在请求URL后面添加字符串?abc</span></span><br><span class="line">http-request add-uafter ?abc</span><br></pre></td></tr></table></figure><h4 id="2-2-15-atob-a-b">2.2.15 atob a b</h4><p>a行转b行</p><ul><li><p>原型<br><code>http-request atob a b</code></p></li><li><p>参数</p><ul><li><code>a</code>： a行</li><li><code>b</code>： b行</li></ul></li></ul><p>如果a行存在，b行存在，则会把b行删除，把a行的行头改成b<br>如果a行的值为空，则会删除a行，保留b行<br>如果a行不存在，则不会做任何处理</p><ul><li>示例</li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#X-Online-Host转Host</span></span><br><span class="line">http-request atob X-Online-Host Host</span><br></pre></td></tr></table></figure><p>####2.2.16 rep-hvalue<br>修改一行的值，如果不存在行就不添加</p><ul><li><p>原型<br><code>http-request rep-hvalue h v</code></p></li><li><p>参数</p><ul><li><code>h</code>： 修改值的行</li><li><code>v</code>： 需要修改成的值，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#修改host行的值为byml.net，如果不存在则不做任何处理</span></span><br><span class="line">http-request rep-havlue Host byml.net</span><br></pre></td></tr></table></figure><h4 id="2-2-17-mov-fhttp">2.2.17 mov-fhttp</h4><p>删除请求网址开头：<code>http://host</code></p><ul><li><p>原型<br><code>http-request mov-fhttp null null</code></p></li><li><p>参数</p><ul><li><code>null</code>： 默认即可</li><li><code>null</code>： 默认即可，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#使用例子</span></span><br><span class="line">http-request mov-fhttp null null</span><br></pre></td></tr></table></figure><h4 id="2-2-18-mov-se-s-e">2.2.18 mov-se s e</h4><p>删除以<code>s</code>开头到<code>e</code>结尾的字符串，保留<code>e</code></p><ul><li><p>原型<br><code>http-request mov-se s e</code></p></li><li><p>参数</p><ul><li><code>s</code>： 开始的字符串</li><li><code>e</code>： 结束的字符串，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#删除请求地址中的http://host</span></span><br><span class="line">http-request mov-se http:// /</span><br></pre></td></tr></table></figure><h4 id="2-2-19-mov-nse-s-e">2.2.19 mov-nse s e</h4><p>删除以<code>s</code>开头到<code>e</code>结尾的字符串，删除<code>e</code></p><ul><li><p>原型<br><code>http-request mov-nse s e</code></p></li><li><p>参数</p><ul><li><code>s</code>： 开始的字符串</li><li><code>e</code>： 结束的字符串，支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#删除Host行</span></span><br><span class="line">http-request mov-nse Host \r\n</span><br><span class="line"><span class="comment">#一行的结束标志是\r\n</span></span><br></pre></td></tr></table></figure><h4 id="2-2-20-set-req-fline-str">2.2.20 set-req-fline str</h4><p>自定义请求的第一行</p><ul><li><p>原型<br><code>http-request set-req-fline str</code></p></li><li><p>参数</p><ul><li><code>str</code>： 支持<code>%[xxx]</code>操作</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#http://host转http://proxy_host</span></span><br><span class="line">http-request set-req-fline %[method]\ http://proxy_host%[request_uri]\ HTTP/1.1\r\n </span><br><span class="line"><span class="comment">#%[method] 请求方法 GET/POST/CONNECT</span></span><br><span class="line"><span class="comment">#%[request_uri] 请求的url 跟php的REQUEST_URI类似</span></span><br></pre></td></tr></table></figure><h4 id="2-2-21-rn-header-hdra-hdrb">2.2.21 rn-header hdrA hdrB</h4><p>设置一行请求的行名</p><ul><li><p>原型<br><code>http-request rn-header hdrA hdrB</code></p></li><li><p>参数</p><ul><li><code>hdrA</code>： 被改名的请求行</li><li><code>hdrB</code>： 需要改为的名称</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#Host行改为T_Host</span></span><br><span class="line">http-request rn-header Host T_Host</span><br><span class="line"><span class="comment">#把Host行的请求名：Host 改为了T_Host</span></span><br></pre></td></tr></table></figure><h4 id="2-2-22-xhosttot">2.2.22 xhostTot</h4><p><code>Xhost</code>,<code>Host</code>（如果没有大写的，则自动查找小写）转换为<code>T_Host</code><br>如果<code>xhost</code>,<code>host</code>均存在<br>则以<code>xhost</code>优先，把<code>xhost</code>请求行名改为<code>T_Host</code><br>如果<code>host</code>行存在，<code>xhost</code>不存在<br>则以<code>host</code>行优先，把<code>host</code>行改为<code>T_Host</code>行</p><ul><li><p>原型<br><code>http-request xhostTot null null</code></p></li><li><p>参数</p><ul><li><code>null</code>： 无作用，但必须加</li><li><code>null</code>： 无作用，但必须加</li></ul></li><li><p>示例</p></li></ul><figure class="highlight makefile"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">http-request xhostTot null null</span><br></pre></td></tr></table></figure><h2 id="3-特殊用法">3.特殊用法</h2><h3 id="3-1-xxx-操作">3.1 <code>%[xxx]</code>操作</h3><p><code>%[xxx]</code>操作就相当于变量，到了核心就会被转换成这个变量存储的数据</p><h4 id="3-1-0-header-xxxx">3.1.0  <code>%[header(xxxx)]</code></h4><p>例如：<code>%[header(Host)]</code><br>就是取：Host行的值<br>这个语法为新增加语法，更适合编写模式</p><h4 id="3-1-1-url">3.1.1 <code>%[url]</code></h4><p>如果请求的第一行为：<code>GET http://byml.net/index.php HTTP/1.1\r\n</code><br>那么<code>%[url]</code>代表的是<code>http://byml.net/index.php</code></p><h4 id="3-1-2-request-uri">3.1.2 <code>%[request_uri]</code></h4><p>如果请求的第一行为：<code>GET http://byml.net/index.php?user=recall HTTP/1.1\r\n</code><br>那么<code>%[request_uri]</code>代表的是：<code>/index.php?user=recall</code></p><h4 id="3-1-3-req-hdr-xxx">3.1.3 <code>%[req.hdr(xxx)]</code></h4><p>例如：<code>%[req.hdr(Accept)]</code><br>就是取<code>Accept</code>行的值</p><p>如果是要取<code>Host</code>的值<br>推荐使用<code>%[host]</code>，这个是固定的，不会出现取值失败，自动停止等BUG</p><h4 id="3-1-4-method">3.1.4 <code>%[method]</code></h4><p>如果当前的请求方式为<code>GET</code><br>那么<code>%[method]</code>的值就是<code>GET</code></p><h4 id="3-1-5-req-ver">3.1.5 <code>%[req.ver]</code></h4><p><code>req.ver</code>是当前使用的HTTP协议的版本<br>如果请求是HTTP/1.1 <code>%[req.ver]</code>则为<code>1.1</code><br>如果请求是HTTP/1.0 <code>%[req.ver]</code>则为<code>1.0</code></p><h4 id="3-1-6-url-no-port">3.1.6 <code>%[url_no_port]</code></h4><p>如果<code>CONNECT</code>请求的第一行为<code>CONNECT byml.net:443 HTTP/1.1\r\n</code><br>那么<code>%[url_no_port]</code>代表<code>byml.net</code>，目前只推荐在<code>CONNECT</code>请求中使用</p><h4 id="3-1-7-host">3.1.7 <code>%[host]</code></h4><p>取<code>Host</code>行的值，解决<code>atob</code>后，<code>%[req.hdr(Host)]</code>取不到值的BUG</p><h4 id="3-1-8-t-host">3.1.8 <code>%[t_host]</code></h4><p>取<code>T_Host</code>行的值，可以先把<code>Host</code>字符串修改成<code>T_Host</code><br>这样就可以直接<code>%[t_host]</code>取到<code>Host</code>的值，而且只需要定义第一行就行了</p><h4 id="3-1-9-xhost">3.1.9 <code>%[xhost]</code></h4><p>取<code>X-Online-Host</code>行的值，固定搭配</p><h3 id="3-2-核心函数">3.2 核心函数</h3><h4 id="3-2-1-未完待续">3.2.1 未完待续</h4>]]></content>
    
    <summary type="html">
    
      &lt;h2 id=&quot;1-配置参数&quot;&gt;1. 配置参数&lt;/h2&gt;
&lt;p&gt;本文是HaP核心的配置文件详解，比如&lt;code&gt;global&lt;/code&gt;,&lt;code&gt;defaults&lt;/code&gt;之类的能看到的配置语法，都可以在这里找到注释&lt;/p&gt;
&lt;h3 id=&quot;1-1-global&quot;&gt;1.1 global&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;global&lt;/code&gt;在配置文件中，主要设置一些全局性的参数，起重要作用&lt;br&gt;
一般建议不要修改，特别是pid文件地址，如果修改了可能会导致无法正常停止HaP核心&lt;/p&gt;
&lt;h4 id=&quot;1-1-1-daemon&quot;&gt;1.1.1 daemon&lt;/h4&gt;
&lt;p&gt;HaP核心运行方式为：后台运行&lt;/p&gt;
&lt;h4 id=&quot;1-1-2-user-group&quot;&gt;1.1.2 user group&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;user - group&lt;/code&gt;&lt;br&gt;
设置HAP核心工作所属的用户和组&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;示例&lt;/li&gt;
&lt;/ul&gt;
&lt;figure class=&quot;highlight makefile&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;2&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;3&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;4&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;5&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;6&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;7&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;8&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;9&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;#设置HAP核心工作的用户和组为:inet&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;user inet&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;group inet &lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;###################################&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;comment&quot;&gt;#设置HAP核心工作的用户和组为:root&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;user root &lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;group root&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
    
    </summary>
    
      <category term="学习" scheme="https://hyxxsfwy.github.io/categories/%E5%AD%A6%E4%B9%A0/"/>
    
    
      <category term="免流" scheme="https://hyxxsfwy.github.io/tags/%E5%85%8D%E6%B5%81/"/>
    
      <category term="帮助" scheme="https://hyxxsfwy.github.io/tags/%E5%B8%AE%E5%8A%A9/"/>
    
      <category term="HAProxy" scheme="https://hyxxsfwy.github.io/tags/HAProxy/"/>
    
  </entry>
  
  <entry>
    <title>【转】如何在死线未至时，像死线已至那样高效？</title>
    <link href="https://hyxxsfwy.github.io/2016/01/16/%E3%80%90%E8%BD%AC%E3%80%91%E5%A6%82%E4%BD%95%E5%9C%A8%E6%AD%BB%E7%BA%BF%E6%9C%AA%E8%87%B3%E6%97%B6%EF%BC%8C%E5%83%8F%E6%AD%BB%E7%BA%BF%E5%B7%B2%E8%87%B3%E9%82%A3%E6%A0%B7%E9%AB%98%E6%95%88%EF%BC%9F/"/>
    <id>https://hyxxsfwy.github.io/2016/01/16/【转】如何在死线未至时，像死线已至那样高效？/</id>
    <published>2016-01-16T14:36:45.000Z</published>
    <updated>2016-02-09T16:00:33.000Z</updated>
    
    <content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>一张图说明一切：<br><img src="/imgs/16.01/%E4%BB%80%E4%B9%88%E6%98%AF%E4%B8%80%E4%B8%AA%E7%9C%9F%E6%AD%A3%E5%8F%AF%E6%89%A7%E8%A1%8C%E7%9A%84%E5%A5%BD%E8%AE%A1%E5%88%92.jpg" alt="什么是一个真正可执行的好计划" title="什么是一个真正可执行的好计划"></p><hr><p>倘若你是个脑力劳动者，做的工作无定规可循，不能简单重复，需要不断激荡脑力、解决问题、生产灵感、执行创意……很可能你会发现，自己的工作状态分为两种。</p><ul><li>一是虚掷模式。无人打扰，时间大段，身体康健睡眠充足，咖啡零食一应俱全，双显示器机械键盘，网络通畅电脑正常……然后？你摸鱼打混，聊天追文，悠然不觉长日将逝。</li><li>二是救火模式。没有一点点防备，一条死线就猝然“砰”一声砸到眼前。我怎么把这事忘得一干二净？你一边恼火，一边突然发现，不论环境如何，处处皆可工作。网络有如龟速？先读现有资料。电脑出了故障？手机打字足矣。夜半可以加班，车上可以路演，嘈杂周遭，也不能令你分心丝毫……咬牙冲过截止线，你终于长松口气，要是平常有这效率，怎需如今这般累个贼死？</li></ul><a id="more"></a><p>仍有余裕时不能自制，突发意外时，不得不透支未来资源来救急，而这种透支又让明天比今天更难捱，结果每天为着早该完成的事宜疲于奔命，一天比一天更难以自拔——一旦陷入这种“虚掷-救火”的循环陷阱，待办事项就往往越积越多，就像欠了高额债务的人，发现偿付欠款甚至利息越来越难。美国心理学家塞德希尔·穆来纳森（Sendhil Mullainathan）和埃尔德·沙菲尔（Eldar Shafir）共同撰写的《稀缺》一书解释说，在资源富足时，大脑固然会掉以轻心。在资源极度缺乏时，大脑却也不能做出明智抉择，反而会孤注一掷，饮鸩止渴。</p><p>怎么解决？ <strong>让大脑在“可控的稀缺”下工作。</strong> 更具体地说，不妨先把你计划中的工作时间大幅缩减，譬方说，将每天的计划内工作，严格限于三小时之内——别小看三小时，坐办公室的美国人，平均一天真正工作的时间大概才90分钟。</p><p>“决心做得更少”，却能帮你“实际做得更多”——只因你一开始梦想的“每周五天，每天八小时，始终保持死线来临前的高效”，根本是不可能做到的！未经严苛训练的大脑，不可能每天高效工作七小时。即使迫于极端压力而做到，也往往要付出透支的代价——透支其他未来项目的时间，透支自己的意志力，透支睡眠质量，乃至透支身心健康。救火模式正是如此。而内疚，自责，压力，焦虑，睡眠缺乏，没空休假，无暇与亲友相聚减压……救火时相伴而来的这些副产品，就像跑步时的额外负重，让你挣扎前行时，更加疲惫不堪。</p><p>想象如下场景，运动零基础的你决心开始慢跑，教练给了你这么一张健身计划：“每周跑五天，每天早上八点跑到中午十二点，休两小时，下午两点跑到六点，喔对了，记得负重十公斤。”</p><p>你的第一反应肯定是，这怎么可能！我根本跑不下来，估计十分钟后我就会在地上摊成一张肉饼。即使我拿出被狮子追时的意志力跑完一天，此后肯定也得卧床休息，没准还是在医院住院部卧床休息。</p><p>正常人不会给自己定这种健身计划，然而，年复一年，人们却给自己定这种工作计划。</p><p>最常见的错误，是计划时无余闲，将日程塞得满满当当，执行时则“弹性十足”——大脑一边因虚幻的“今日有八小时可供（高效）工作”而安于低效，一边还随时准备删改计划，扑去救火。</p><p>你需要做的，是 <strong>计划时有余闲，执行时无弹性</strong> 。是说服大脑“今天只有三小时可以工作”，让大脑悚然一惊，抖擞精神，像救火时那样目标明确，执行坚决。而日程表上留出的大量“余闲”，实际上是给你处理那些必然会出现的“突发状况”。如此，你就不至于因为各种“天降任务”而一次次推迟原定计划，导致最后主线任务反而挫折不断，难以进展。一个无法执行的计划，等于没有计划。而一个真正可执行的好计划，则一定会让你更高效。</p><hr><p>原文链接：<a href="http://songshuhui.net/archives/93667" target="_blank" rel="noopener">http://songshuhui.net/archives/93667</a></p>]]></content>
    
    <summary type="html">
    
      &lt;p&gt;一张图说明一切：&lt;br&gt;
&lt;img src=&quot;/imgs/16.01/%E4%BB%80%E4%B9%88%E6%98%AF%E4%B8%80%E4%B8%AA%E7%9C%9F%E6%AD%A3%E5%8F%AF%E6%89%A7%E8%A1%8C%E7%9A%84%E5%A5%BD%E8%AE%A1%E5%88%92.jpg&quot; alt=&quot;什么是一个真正可执行的好计划&quot; title=&quot;什么是一个真正可执行的好计划&quot;&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;倘若你是个脑力劳动者，做的工作无定规可循，不能简单重复，需要不断激荡脑力、解决问题、生产灵感、执行创意……很可能你会发现，自己的工作状态分为两种。&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;一是虚掷模式。无人打扰，时间大段，身体康健睡眠充足，咖啡零食一应俱全，双显示器机械键盘，网络通畅电脑正常……然后？你摸鱼打混，聊天追文，悠然不觉长日将逝。&lt;/li&gt;
&lt;li&gt;二是救火模式。没有一点点防备，一条死线就猝然“砰”一声砸到眼前。我怎么把这事忘得一干二净？你一边恼火，一边突然发现，不论环境如何，处处皆可工作。网络有如龟速？先读现有资料。电脑出了故障？手机打字足矣。夜半可以加班，车上可以路演，嘈杂周遭，也不能令你分心丝毫……咬牙冲过截止线，你终于长松口气，要是平常有这效率，怎需如今这般累个贼死？&lt;/li&gt;
&lt;/ul&gt;
    
    </summary>
    
      <category term="转载" scheme="https://hyxxsfwy.github.io/categories/%E8%BD%AC%E8%BD%BD/"/>
    
    
      <category term="GTD" scheme="https://hyxxsfwy.github.io/tags/GTD/"/>
    
      <category term="时间管理" scheme="https://hyxxsfwy.github.io/tags/%E6%97%B6%E9%97%B4%E7%AE%A1%E7%90%86/"/>
    
      <category term="拖延症" scheme="https://hyxxsfwy.github.io/tags/%E6%8B%96%E5%BB%B6%E7%97%87/"/>
    
  </entry>
  
  <entry>
    <title>Hexo Markdown 简明语法手册</title>
    <link href="https://hyxxsfwy.github.io/2016/01/15/Hexo-Markdown-%E7%AE%80%E6%98%8E%E8%AF%AD%E6%B3%95%E6%89%8B%E5%86%8C/"/>
    <id>https://hyxxsfwy.github.io/2016/01/15/Hexo-Markdown-简明语法手册/</id>
    <published>2016-01-15T12:19:32.000Z</published>
    <updated>2018-03-17T16:00:33.000Z</updated>
    
    <content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><h3 id="内容目录">内容目录</h3><p>在段落中填写 <code>[TOC]</code> 以显示全文内容的目录结构。</p><h3 id="文章头格式">文章头格式</h3><p><code>front-matter</code> 的基本格式示例如下：</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">---</span></span><br><span class="line"><span class="attr">title:</span> <span class="string">Hexo</span> <span class="string">Markdown-it</span> <span class="string">简明语法手册</span></span><br><span class="line"><span class="attr">date:</span> <span class="number">2016</span><span class="bullet">-01</span><span class="bullet">-15</span> <span class="number">20</span><span class="string">:19:32</span></span><br><span class="line"><span class="attr">tags:</span> <span class="string">[Markdown,LaTex,教程]</span></span><br><span class="line"><span class="attr">categories:</span> <span class="string">学习</span></span><br><span class="line"><span class="attr">toc:</span> <span class="literal">true</span></span><br><span class="line"><span class="attr">mathjax:</span> <span class="literal">true</span></span><br><span class="line"><span class="meta">---</span></span><br></pre></td></tr></table></figure><h3 id="斜体和粗体">斜体和粗体</h3><p>使用 <code>*</code> 和 <code>**</code> 表示斜体和粗体，格式如下：</p><figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="strong">*斜体*</span>， *<span class="strong">*粗体*</span><span class="strong">*</span></span><br></pre></td></tr></table></figure><p>渲染效果： 这是 <em>斜体</em>，这是 <strong>粗体</strong> 。</p><h3 id="分级标题">分级标题</h3><p>使用 <code>===</code> 表示一级标题，使用 <code>---</code> 表示二级标题，格式如下：</p><figure class="highlight asciidoc"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">这是一个一级标题</span><br><span class="line">============================</span><br><span class="line"></span><br><span class="line">这是一个二级标题</span><br><span class="line">--------------------------------------------------</span><br><span class="line"></span><br><span class="line">### 这是一个三级标题</span><br></pre></td></tr></table></figure><p>你也可以选择在行首加<code>#</code>号表示不同级别的标题 (H1-H6)，格式如下：</p><figure class="highlight clean"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># H1</span><br><span class="line">## H2</span><br><span class="line">### H3</span><br><span class="line">#### H4</span><br><span class="line">##### H5</span><br><span class="line">###### H6</span><br></pre></td></tr></table></figure><a id="more"></a><h3 id="分割线">分割线</h3><p>在单独的一行使用 <code>***</code> 或者 <code>---</code> 表示分割线</p><h3 id="删除线">删除线</h3><p>使用 ~~ 表示删除线<br><s>这是一段错误的文本。</s></p><h3 id="超链接">超链接</h3><p>插入文字超链接的格式如下 ：</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[<span class="string">链接文字</span>](<span class="link">链接地址 "链接标题"</span>)</span><br></pre></td></tr></table></figure><p>插入图片超链接的格式如下：</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">![<span class="string">图片说明</span>](<span class="link">图片链接 "图片标题"</span>)</span><br></pre></td></tr></table></figure><p>插入音频，使用插件<code>hexo-tag-aplayer</code>，语法如下：</p><figure class="highlight clojure"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&#123;% aplayer title author url [picture_url, narrow, autoplay, width:xx%, lrc:xxx] %&#125;</span><br></pre></td></tr></table></figure><p>详情参见：<a href="https://github.com/MoePlayer/hexo-tag-aplayer/blob/master/docs/README-zh_cn.md#%E4%BD%BF%E7%94%A8" title="https://github.com/MoePlayer/hexo-tag-aplayer/blob/master/docs/README-zh_cn.md#%E4%BD%BF%E7%94%A8" target="_blank" rel="noopener">hexo-tag-aplayer 中文使用文档</a></p><p>引用视频则直接插入<code>iframe</code>代码：</p><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">"/js/youtube-autoresizer.js"</span>&gt;</span><span class="undefined"></span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">iframe</span> <span class="attr">width</span>=<span class="string">"640"</span> <span class="attr">height</span>=<span class="string">"360"</span> <span class="attr">src</span>=<span class="string">"https://www.youtube.com/embed/HfElOZSEqn4"</span> <span class="attr">frameborder</span>=<span class="string">"0"</span> <span class="attr">allowfullscreen</span>&gt;</span><span class="tag">&lt;/<span class="name">iframe</span>&gt;</span></span><br></pre></td></tr></table></figure><hr><p>文字：<a href="https://hyxxsfwy.github.com" title="https://hyxxsfwy.github.com" target="_blank" rel="noopener">本博客链接</a></p><p>图片： <img src="/imgs/16.01/google_2015_logo_detail.png" alt="Google的logo" title="Google的logo"></p><p>视频：</p><script src="/js/youtube-autoresizer.js"></script><iframe width="640" height="360" src="https://www.youtube.com/embed/HfElOZSEqn4" frameborder="0" allowfullscreen></iframe>***<h3 id="注释">注释</h3><p>用 <code>\</code> 表示注释，<code>\</code> 后面的文字解析为纯文本格式。<br>渲染效果：<br>## 这不是二级标题</p><h3 id="引用">引用</h3><p>使用 <code>&gt;</code> 表示文字引用：</p><figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">&gt;</span><span class="bash"> 野火烧不尽，春风吹又生</span></span><br></pre></td></tr></table></figure><blockquote><p>野火烧不尽，春风吹又生</p></blockquote><h3 id="脚注">脚注</h3><p>使用 <code>[^1]</code> <code>[^1]:</code> 的脚注对来表示</p><figure class="highlight applescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">Here <span class="keyword">is</span> a footnote <span class="keyword">reference</span>,[^<span class="number">1</span>] <span class="keyword">and</span> another.[^longnote]</span><br><span class="line"></span><br><span class="line">[^<span class="number">1</span>]: Here <span class="keyword">is</span> <span class="keyword">the</span> footnote.</span><br><span class="line"></span><br><span class="line">[^longnote]: Here's one <span class="keyword">with</span> multiple blocks.</span><br><span class="line">    Subsequent <span class="built_in">paragraphs</span> are indented <span class="keyword">to</span> show <span class="keyword">that</span> they</span><br><span class="line">    belong <span class="keyword">to</span> <span class="keyword">the</span> previous footnote.</span><br></pre></td></tr></table></figure><p>Here is a footnote reference,<sup class="footnote-ref"><a href="#fn1" id="fnref1">[1]</a></sup> and another.<sup class="footnote-ref"><a href="#fn2" id="fnref2">[2]</a></sup></p><h3 id="列表与表格">列表与表格</h3><h4 id="无序列表">无序列表</h4><p>使用 *，+，- 表示无序列表。</p><figure class="highlight haml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">+ 无序列表项 一</span><br><span class="line">-<span class="ruby"> 子无序列表 一</span></span><br><span class="line"><span class="ruby">- 子无序列表 二</span></span><br><span class="line"><span class="ruby">* 子无序列表 三</span></span><br><span class="line"><span class="ruby">+ 无序列表项 二</span></span><br><span class="line"><span class="ruby">+ 无序列表项 三</span></span><br></pre></td></tr></table></figure><hr><ul><li>无序列表项 一<ul><li>子无序列表 一</li><li>子无序列表 二<ul><li>子无序列表 三</li></ul></li></ul></li><li>无序列表项 二</li><li>无序列表项 三</li></ul><hr><h4 id="有序列表">有序列表</h4><p>使用数字和点表示有序列表。</p><figure class="highlight lsl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 有序列表项 一</span><br><span class="line"><span class="number">1.</span> 子有序列表项 一</span><br><span class="line"><span class="number">2.</span> 子有序列表项 二</span><br><span class="line"><span class="number">2.</span> 有序列表项 二</span><br><span class="line"><span class="number">3.</span> 有序列表项 三</span><br></pre></td></tr></table></figure><hr><ol><li>有序列表项 一<ol><li>子有序列表项 一</li><li>子有序列表项 二</li></ol></li><li>有序列表项 二</li><li>有序列表项 三</li></ol><hr><h4 id="绘制表格">绘制表格</h4><p>绘制表格格式如下，<code>|</code> 控制分列，<code>-</code> 控制分行，<code>:</code> 控制对齐方式。</p><figure class="highlight gherkin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">|<span class="string"> Item     </span>|<span class="string"> Value     </span>|<span class="string"> Qty   </span>|</span><br><span class="line">|<span class="string"> :------- </span>|<span class="string"> --------: </span>|<span class="string"> :---: </span>|</span><br><span class="line">|<span class="string"> Computer </span>|<span class="string"> 1600 USD  </span>|<span class="string"> 5     </span>|</span><br><span class="line">|<span class="string"> Phone    </span>|<span class="string"> 12 USD    </span>|<span class="string"> 12    </span>|</span><br><span class="line">|<span class="string"> Pipe     </span>|<span class="string"> 1 USD     </span>|<span class="string"> 234   </span>|</span><br></pre></td></tr></table></figure><hr><table><thead><tr><th style="text-align:left">Item</th><th style="text-align:right">Value</th><th style="text-align:center">Qty</th></tr></thead><tbody><tr><td style="text-align:left">Computer</td><td style="text-align:right">1600 USD</td><td style="text-align:center">5</td></tr><tr><td style="text-align:left">Phone</td><td style="text-align:right">12 USD</td><td style="text-align:center">12</td></tr><tr><td style="text-align:left">Pipe</td><td style="text-align:right">1 USD</td><td style="text-align:center">234</td></tr></tbody></table><hr><h3 id="代码块">代码块</h3><h4 id="行内代码块">行内代码块</h4><p>使用 `codes` 表示行内代码块。</p><p>渲染效果： 让我们聊聊 <code>html</code> 。</p><h4 id="多行代码块">多行代码块</h4><figure class="highlight clean"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">这是用 ``` some codes ```表示的代码块（左侧无空格）；</span><br><span class="line">第二行；</span><br><span class="line">第三行。</span><br></pre></td></tr></table></figure><h4 id="加强的代码块">加强的代码块</h4><p>支持多种编程语言的语法高亮的显示，行号显示。</p><p>非代码示例：</p><figure class="highlight routeros"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ sudo apt-<span class="builtin-name">get</span> install vim-gnome</span><br></pre></td></tr></table></figure><p>Python 示例：</p><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">requires_authorization</span><br><span class="line"><span class="function"><span class="keyword">def</span> <span class="title">somefunc</span><span class="params">(param1=<span class="string">''</span>, param2=<span class="number">0</span>)</span>:</span></span><br><span class="line">    <span class="string">'''A docstring'''</span></span><br><span class="line">    <span class="keyword">if</span> param1 &gt; param2: <span class="comment"># interesting</span></span><br><span class="line">        <span class="keyword">print</span> <span class="string">'Greater'</span></span><br><span class="line">    <span class="keyword">return</span> (param2 - param1 + <span class="number">1</span>) <span class="keyword">or</span> <span class="keyword">None</span></span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">SomeClass</span>:</span></span><br><span class="line">    <span class="keyword">pass</span></span><br><span class="line"></span><br><span class="line"><span class="meta">&gt;&gt;&gt; </span>message = <span class="string">'''interpreter</span></span><br><span class="line"><span class="string"><span class="meta">... </span>prompt'''</span></span><br></pre></td></tr></table></figure><p>JavaScript 示例：</p><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment">* nth element in the fibonacci series.</span></span><br><span class="line"><span class="comment">* @param n &gt;= 0</span></span><br><span class="line"><span class="comment">* @return the nth element, &gt;= 0.</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">fib</span>(<span class="params">n</span>) </span>&#123;</span><br><span class="line">  <span class="keyword">var</span> a = <span class="number">1</span>, b = <span class="number">1</span>;</span><br><span class="line">  <span class="keyword">var</span> tmp;</span><br><span class="line">  <span class="keyword">while</span> (--n &gt;= <span class="number">0</span>) &#123;</span><br><span class="line">    tmp = a;</span><br><span class="line">    a += b;</span><br><span class="line">    b = tmp;</span><br><span class="line">  &#125;</span><br><span class="line">  <span class="keyword">return</span> a;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="built_in">document</span>.write(fib(<span class="number">10</span>));</span><br></pre></td></tr></table></figure><h3 id="latex-公式">LaTeX 公式</h3><p>数学公式的默认定界符是<code>$...$</code>和<code>\\(...\\)</code>（对于行内公式），以及<code>$$...$$</code>和<code>\\[...\\]</code>（对于块级公式）。<br>但是，如果你的文章内容中经常出现美元符号<code>$</code>,或者说你想将“$”用作美元符号而非行内公式的定界符，请在Hexo目录的_config.yml中添加：</p><figure class="highlight yaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">mathjax2:</span> <span class="literal">true</span></span><br></pre></td></tr></table></figure><p>而不是<code>mathjax: true</code>。 相应地，在需要使用数学公式的文章的<code>front-matter</code>中也添加<code>mathjax2: true</code>。</p><p>例如：</p><p>质能守恒方程: <code>$E = mc^2$</code>: $E = mc^2$</p><p>长度收缩：<code>$x' = {x - vt \over \sqrt{1 - {v^2 \over c^2}}}$</code>: $x’ = {x - vt \over \sqrt{1 - {v^2 \over c^2}}}$</p><p>表示块级公式：</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$$\Delta_A(\lambda)=\det(\lambda I-A)$$</span><br></pre></td></tr></table></figure><p>$$\Delta_A(\lambda)=\det(\lambda I-A)$$</p><p>或者：</p><figure class="highlight tex"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">\<span class="name">begin</span><span class="string">&#123;equation&#125;</span></span></span><br><span class="line"><span class="tag">\<span class="name">Delta</span></span>_A(<span class="tag">\<span class="name">lambda</span></span>)=<span class="tag">\<span class="name">det</span></span>(<span class="tag">\<span class="name">lambda</span></span> I-A),</span><br><span class="line"><span class="tag">\<span class="name">end</span><span class="string">&#123;equation&#125;</span></span></span><br></pre></td></tr></table></figure><p>\begin{equation}<br>\Delta_A(\lambda)=\det(\lambda I-A),<br>\end{equation}</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">\begin&#123;aligned&#125;</span><br><span class="line">\dot&#123;x&#125; &amp; = \sigma(y-x) \\\</span><br><span class="line">\dot&#123;y&#125; &amp; = \rho x - y - xz \\\</span><br><span class="line">\dot&#123;z&#125; &amp; = -\beta z + xy</span><br><span class="line">\end&#123;aligned&#125;</span><br></pre></td></tr></table></figure><p>（此处需注意换行符转义，多加一个<code>\</code>）</p><p>\begin{aligned}<br>\dot{x} &amp; = \sigma(y-x) \<br>\dot{y} &amp; = \rho x - y - xz \<br>\dot{z} &amp; = -\beta z + xy<br>\end{aligned}</p><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">\begin&#123;equation&#125;</span><br><span class="line">[a, b, c]=\left|</span><br><span class="line">\begin&#123;array&#125;&#123;ccc&#125;</span><br><span class="line">  a<span class="emphasis">_1&amp; a_</span>2  &amp; a_3  \\\</span><br><span class="line"> b<span class="emphasis">_1 &amp;b_</span>2   &amp; b_3  \\\</span><br><span class="line"> c<span class="emphasis">_1 &amp;c_</span>2   &amp;c_3   </span><br><span class="line">\end&#123;array&#125;</span><br><span class="line">\right|</span><br><span class="line">\end&#123;equation&#125;</span><br></pre></td></tr></table></figure><p>\begin{equation}<br>[a, b, c]=\left|<br>\begin{array}{ccc}<br>a_1&amp; a_2  &amp; a_3  \<br>b_1 &amp;b_2   &amp; b_3  \<br>c_1 &amp;c_2   &amp;c_3<br>\end{array}<br>\right|<br>\end{equation}</p><p>访问 <a href="http://meta.math.stackexchange.com/questions/5020/mathjax-basic-tutorial-and-quick-reference" target="_blank" rel="noopener">MathJax basic tutorial and quick reference</a> 参考更多使用方法。</p><hr class="footnotes-sep"><section class="footnotes"><ol class="footnotes-list"><li id="fn1" class="footnote-item"><p>Here is the footnote. <a href="#fnref1" class="footnote-backref">↩</a></p></li><li id="fn2" class="footnote-item"><p>Here’s one with multiple blocks.<br>Subsequent paragraphs are indented to show that they<br>belong to the previous footnote. <a href="#fnref2" class="footnote-backref">↩</a></p></li></ol></section>]]></content>
    
    <summary type="html">
    
      &lt;h3 id=&quot;内容目录&quot;&gt;内容目录&lt;/h3&gt;
&lt;p&gt;在段落中填写 &lt;code&gt;[TOC]&lt;/code&gt; 以显示全文内容的目录结构。&lt;/p&gt;
&lt;h3 id=&quot;文章头格式&quot;&gt;文章头格式&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;front-matter&lt;/code&gt; 的基本格式示例如下：&lt;/p&gt;
&lt;figure class=&quot;highlight yaml&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;2&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;3&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;4&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;5&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;6&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;7&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;8&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;meta&quot;&gt;---&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;attr&quot;&gt;title:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;Hexo&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;Markdown-it&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;简明语法手册&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;attr&quot;&gt;date:&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;2016&lt;/span&gt;&lt;span class=&quot;bullet&quot;&gt;-01&lt;/span&gt;&lt;span class=&quot;bullet&quot;&gt;-15&lt;/span&gt; &lt;span class=&quot;number&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;string&quot;&gt;:19:32&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;attr&quot;&gt;tags:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;[Markdown,LaTex,教程]&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;attr&quot;&gt;categories:&lt;/span&gt; &lt;span class=&quot;string&quot;&gt;学习&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;attr&quot;&gt;toc:&lt;/span&gt; &lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;attr&quot;&gt;mathjax:&lt;/span&gt; &lt;span class=&quot;literal&quot;&gt;true&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;meta&quot;&gt;---&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;h3 id=&quot;斜体和粗体&quot;&gt;斜体和粗体&lt;/h3&gt;
&lt;p&gt;使用 &lt;code&gt;*&lt;/code&gt; 和 &lt;code&gt;**&lt;/code&gt; 表示斜体和粗体，格式如下：&lt;/p&gt;
&lt;figure class=&quot;highlight asciidoc&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;&lt;span class=&quot;strong&quot;&gt;*斜体*&lt;/span&gt;， *&lt;span class=&quot;strong&quot;&gt;*粗体*&lt;/span&gt;&lt;span class=&quot;strong&quot;&gt;*&lt;/span&gt;&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;渲染效果： 这是 &lt;em&gt;斜体&lt;/em&gt;，这是 &lt;strong&gt;粗体&lt;/strong&gt; 。&lt;/p&gt;
&lt;h3 id=&quot;分级标题&quot;&gt;分级标题&lt;/h3&gt;
&lt;p&gt;使用 &lt;code&gt;===&lt;/code&gt; 表示一级标题，使用 &lt;code&gt;---&lt;/code&gt; 表示二级标题，格式如下：&lt;/p&gt;
&lt;figure class=&quot;highlight asciidoc&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;2&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;3&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;4&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;5&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;6&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;7&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;这是一个一级标题&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;============================&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;这是一个二级标题&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;--------------------------------------------------&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;### 这是一个三级标题&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
&lt;p&gt;你也可以选择在行首加&lt;code&gt;#&lt;/code&gt;号表示不同级别的标题 (H1-H6)，格式如下：&lt;/p&gt;
&lt;figure class=&quot;highlight clean&quot;&gt;&lt;table&gt;&lt;tr&gt;&lt;td class=&quot;gutter&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;1&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;2&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;3&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;4&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;5&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;6&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;td class=&quot;code&quot;&gt;&lt;pre&gt;&lt;span class=&quot;line&quot;&gt;# H1&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;## H2&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;### H3&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;#### H4&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;##### H5&lt;/span&gt;&lt;br&gt;&lt;span class=&quot;line&quot;&gt;###### H6&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/figure&gt;
    
    </summary>
    
      <category term="学习" scheme="https://hyxxsfwy.github.io/categories/%E5%AD%A6%E4%B9%A0/"/>
    
    
      <category term="Markdown" scheme="https://hyxxsfwy.github.io/tags/Markdown/"/>
    
      <category term="LaTex" scheme="https://hyxxsfwy.github.io/tags/LaTex/"/>
    
      <category term="教程" scheme="https://hyxxsfwy.github.io/tags/%E6%95%99%E7%A8%8B/"/>
    
  </entry>
  
  <entry>
    <title>Hello World</title>
    <link href="https://hyxxsfwy.github.io/2016/01/14/hello-world/"/>
    <id>https://hyxxsfwy.github.io/2016/01/14/hello-world/</id>
    <published>2016-01-14T07:21:32.000Z</published>
    <updated>2016-01-21T16:00:33.000Z</updated>
    
    <content type="html"><![CDATA[<link rel="stylesheet" class="aplayer-secondary-style-marker" href="\assets\css\APlayer.min.css"><script src="\assets\js\APlayer.min.js" class="aplayer-secondary-script-marker"></script><p>Welcome to <a href="https://hexo.io/" target="_blank" rel="noopener">Hexo</a>! This is your very first post. Check <a href="https://hexo.io/docs/" target="_blank" rel="noopener">documentation</a> for more info. If you get any problems when using Hexo, you can find the answer in <a href="https://hexo.io/docs/troubleshooting.html" target="_blank" rel="noopener">troubleshooting</a> or you can ask me on <a href="https://github.com/hexojs/hexo/issues" target="_blank" rel="noopener">GitHub</a>.</p><h2 id="quick-start">Quick Start</h2><h3 id="create-a-new-post">Create a new post</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo new <span class="string">"My New Post"</span></span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/writing.html" target="_blank" rel="noopener">Writing</a></p><h3 id="run-server">Run server</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo server</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/server.html" target="_blank" rel="noopener">Server</a></p><h3 id="generate-static-files">Generate static files</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo generate</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/generating.html" target="_blank" rel="noopener">Generating</a></p><h3 id="deploy-to-remote-sites">Deploy to remote sites</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ hexo deploy</span><br></pre></td></tr></table></figure><p>More info: <a href="https://hexo.io/docs/deployment.html" target="_blank" rel="noopener">Deployment</a></p>]]></content>
    
    <summary type="html">
    
      
      
        &lt;link rel=&quot;stylesheet&quot; class=&quot;aplayer-secondary-style-marker&quot; href=&quot;\assets\css\APlayer.min.css&quot;&gt;&lt;script src=&quot;\assets\js\APlayer.min.js&quot; cla
      
    
    </summary>
    
    
      <category term="Hello" scheme="https://hyxxsfwy.github.io/tags/Hello/"/>
    
  </entry>
  
</feed>
