Files
2024-12-18 21:16:43 +08:00

85 lines
25 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>实现原理 | 中微子代理</title>
<meta name="generator" content="VuePress 1.9.2">
<link rel="icon" href="/neutrino-proxy/img/favicon.ico">
<meta name="description" content="一个基于Netty的开源内网穿透神器">
<meta name="keywords" content="vuepress,theme,blog,vdoing">
<meta name="theme-color" content="#11a8cd">
<meta name="referrer" content="no-referrer-when-downgrade">
<link rel="preload" href="/neutrino-proxy/assets/css/0.styles.b79d758c.css" as="style"><link rel="preload" href="/neutrino-proxy/assets/js/app.26329228.js" as="script"><link rel="preload" href="/neutrino-proxy/assets/js/2.bcc017ba.js" as="script"><link rel="preload" href="/neutrino-proxy/assets/js/32.ebdd578e.js" as="script"><link rel="prefetch" href="/neutrino-proxy/assets/js/10.aefeccb2.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/11.83da976e.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/12.28575ea2.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/13.2bc54ade.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/14.239eae84.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/15.9c7084a5.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/16.db6de795.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/17.5a8480e4.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/18.9d247656.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/19.9da31ccd.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/20.3ad6f2c9.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/21.e3560148.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/22.eb77dd26.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/23.6aa343b0.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/24.7e68c2e7.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/25.de1c1c00.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/26.a9272eda.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/27.d61af734.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/28.7dfe2be6.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/29.ec35ef30.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/3.31c9497d.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/30.43ea93fb.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/31.3d915a65.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/33.32f5fccd.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/34.9942da58.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/35.cf7271d2.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/36.9bd0c33b.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/37.71c8b009.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/38.7632b8b0.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/39.5140c9f6.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/4.3e10c61a.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/40.40facdf8.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/5.26fb3e34.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/6.526bfcbe.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/7.df78e3fb.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/8.e3e55472.js"><link rel="prefetch" href="/neutrino-proxy/assets/js/9.cc059fee.js">
<link rel="stylesheet" href="/neutrino-proxy/assets/css/0.styles.b79d758c.css">
</head>
<body class="theme-mode-light">
<div id="app" data-server-rendered="true"><div class="theme-container sidebar-open have-rightmenu"><header class="navbar blur"><div title="目录" class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/neutrino-proxy/" class="home-link router-link-active"><img src="/neutrino-proxy/img/logo.png" alt="中微子代理" class="logo"> <span class="site-name can-hide">中微子代理</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/neutrino-proxy/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="文档" class="dropdown-title"><a href="/neutrino-proxy/pages/793dcb/" class="link-title">文档</a> <span class="title" style="display:none;">文档</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/neutrino-proxy/pages/793dcb/" class="nav-link">快速上手</a></li><li class="dropdown-item"><!----> <a href="/neutrino-proxy/pages/793dcc/" class="nav-link">后台操作指南</a></li></ul></div></div><div class="nav-item"><a href="/neutrino-proxy/pages/5d571c/" class="nav-link">案例</a></div><div class="nav-item"><a href="/neutrino-proxy/pages/1ab20b/" class="nav-link">支持</a></div><div class="nav-item"><a href="/neutrino-proxy/pages/ff3519/" class="nav-link">更新记录</a></div><div class="nav-item"><a href="https://gitcode.com/dromara/neutrino-proxy" target="_blank" rel="noopener noreferrer" class="nav-link external">
GitCode
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://gitee.com/dromara/neutrino-proxy" target="_blank" rel="noopener noreferrer" class="nav-link external">
Gitee
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <a href="https://github.com/dromara/neutrino-proxy" target="_blank" rel="noopener noreferrer" class="repo-link">
Github
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav></div></header> <div class="sidebar-mask"></div> <div class="sidebar-hover-trigger"></div> <aside class="sidebar" style="display:none;"><!----> <nav class="nav-links"><div class="nav-item"><a href="/neutrino-proxy/" class="nav-link">首页</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="文档" class="dropdown-title"><a href="/neutrino-proxy/pages/793dcb/" class="link-title">文档</a> <span class="title" style="display:none;">文档</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/neutrino-proxy/pages/793dcb/" class="nav-link">快速上手</a></li><li class="dropdown-item"><!----> <a href="/neutrino-proxy/pages/793dcc/" class="nav-link">后台操作指南</a></li></ul></div></div><div class="nav-item"><a href="/neutrino-proxy/pages/5d571c/" class="nav-link">案例</a></div><div class="nav-item"><a href="/neutrino-proxy/pages/1ab20b/" class="nav-link">支持</a></div><div class="nav-item"><a href="/neutrino-proxy/pages/ff3519/" class="nav-link">更新记录</a></div><div class="nav-item"><a href="https://gitcode.com/dromara/neutrino-proxy" target="_blank" rel="noopener noreferrer" class="nav-link external">
GitCode
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><a href="https://gitee.com/dromara/neutrino-proxy" target="_blank" rel="noopener noreferrer" class="nav-link external">
Gitee
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div> <a href="https://github.com/dromara/neutrino-proxy" target="_blank" rel="noopener noreferrer" class="repo-link">
Github
<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></nav> <ul class="sidebar-links"><li><a href="/neutrino-proxy/pages/1ab20b/" class="sidebar-link">个人赞赏</a></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>贡献指南</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/neutrino-proxy/pages/a3f096/" class="sidebar-link">如何贡献</a></li><li><a href="/neutrino-proxy/pages/2f674a/" class="sidebar-link">项目结构</a></li><li><a href="/neutrino-proxy/pages/dd027d/" aria-current="page" class="active sidebar-link">实现原理</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header level2"><a href="/neutrino-proxy/pages/dd027d/#指令通道-cmdchannel" class="sidebar-link">指令通道(CmdChannel)</a></li><li class="sidebar-sub-header level2"><a href="/neutrino-proxy/pages/dd027d/#用户访问通道-visitorchannel" class="sidebar-link">用户访问通道(VisitorChannel)</a></li><li class="sidebar-sub-header level2"><a href="/neutrino-proxy/pages/dd027d/#被代理服务的实际通道-realserverchannel" class="sidebar-link">被代理服务的实际通道(RealServerChannel)</a></li><li class="sidebar-sub-header level2"><a href="/neutrino-proxy/pages/dd027d/#代理数据传输的通道-proxychannel" class="sidebar-link">代理数据传输的通道(ProxyChannel)</a></li><li class="sidebar-sub-header level2"><a href="/neutrino-proxy/pages/dd027d/#_1、服务连接阶段" class="sidebar-link">1、服务连接阶段</a></li><li class="sidebar-sub-header level2"><a href="/neutrino-proxy/pages/dd027d/#_2、用户连接阶段" class="sidebar-link">2、用户连接阶段</a></li><li class="sidebar-sub-header level2"><a href="/neutrino-proxy/pages/dd027d/#_3、实际被代理服务连接阶段" class="sidebar-link">3、实际被代理服务连接阶段</a></li><li class="sidebar-sub-header level2"><a href="/neutrino-proxy/pages/dd027d/#_4、代理通道连接阶段" class="sidebar-link">4、代理通道连接阶段</a></li><li class="sidebar-sub-header level2"><a href="/neutrino-proxy/pages/dd027d/#_5、数据传输阶段" class="sidebar-link">5、数据传输阶段</a></li></ul></li></ul></section></li><li><section class="sidebar-group depth-0"><p class="sidebar-heading"><span>赞赏公示</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/neutrino-proxy/pages/acdf0a/" class="sidebar-link">2024年</a></li><li><a href="/neutrino-proxy/pages/cded59/" class="sidebar-link">2023年</a></li></ul></section></li></ul> </aside> <div><main class="page"><div class="theme-vdoing-wrapper "><div class="placeholder"></div> <!----> <div class="content-wrapper"><div class="right-menu-wrapper"><div class="right-menu-margin"><div class="right-menu-title">目录</div> <div class="right-menu-content"></div></div></div> <h1><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAAXNSR0IArs4c6QAABGpJREFUSA3tVVtoXFUU3fvOI53UlmCaKIFmwEhsE7QK0ipFEdHEKpXaZGrp15SINsXUWvBDpBgQRKi0+KKoFeJHfZA+ED9KKoIU2gYD9UejTW4rVIzm0VSTziPzuNu1z507dibTTjL4U/DAzLn3nL3X2o91ziX6f9wMFdh6Jvbm9nNSV0msViVO6tN1Rm7NMu2OpeJ9lWBUTDxrJbYTS0hInuwciu9eLHlFxCLCZEk3MegsJmZ5K/JD6t7FkFdEvGUo1g7qJoG3MHImqRIn8/nzY1K9UPKKiJmtnUqHVE3Gbuay6vJE/N2FEmuxFjW2nUuE0yQXRRxLiTUAzs36zhZvOXJPdX850EVnnLZkB8prodQoM5JGj7Xk2mvC7JB8tG04Ef5PiXtG0UtxupRQSfTnBoCy554x18yJHI6I+G5Eru4LHmPJZEQsrvPUbMiA8G/WgMK7w7I+ez7++o2ANfbrjvaOl1tFMs+htG3IrZH9/hDX1Pr8Tc0UvH8tcX29KzAgIGcEkINyW5BF9x891hw6VYqgJHEk0huccS7vh3C6gTiODL+26huuBtbct8eZnqLML8PkxGYpuPZBqtqwkSjgc4mB5gbgig5i+y0UDK35LMxXisn9xQtK+nd26gTIHsHe/oblK/b29fUmN/8Y+9jAQrnBp56m1LcDlDp9irKTExSKduXJVWSqdBMA08pEJnEIOB3FPPMybu/oeV8zFeYN3xx576Q6RH+VmplE4ncQV5v+5rzSoyOU7PuEAg8g803PwBJ0CExno/jcMbN8tONYeOmHiuUNryvm3fRUy4tMPVLdAGkUhNWuggGrJcXPv+ouCjz0MKUHz1J2/E8IC9nqTabcxgaBYM0hPhD5Y65FsbxRQKxCQrDjDctW7PUM3HuZunFyifSAqEfuzCp48Il24luWUWZoyJCaPR82jE0+kFA643wRFVni4RYSq3ohJO2pZ7B5dO4xkDWbEpossJPLSrPjYID8rS2UHTlvyNxqIGsg674XJJ7vnh5L7PNwC4hh2sjCI96mzszOTpxLF0T7l88Yz7lAuK6OnL8gXLOnTvpzSb22YG8W7us3jSebFHeeqnXRG1vt+MoUM84LQIBmMsCTAcOauTh0T0l0neQK7m2bLMt2mGxU3HYssS0J2cdv5wljlPsrIuZLAG/2DOZIXgCYT8uMGZN+e2kSirfxZOPCsC0f24nTZzspnVn9VePS1Z5vubmAGGXG8ZFno9Hel0yfA5ZPhF7Dh972BQJ2qCpgH67lmWtBYbvk6sz02wjky2vXyz0XErP/kFB619js1BtwfOV4OPRqOQBjy3Qbk18vigUPPSD5ceHnwck7W9bhAqZdd7SuG7w4/P2F/GaJh8c7e9qgow+Q7cGBo+98WsLkuktFqiZabtXuQTu/Y5ETbR0v7tNSFnvrmu6pjdoan2KjMu8q/Hmj1EfCO2ZGfEIbIXKUlw8qaX9/b2oeSJmFksSeT/Fn0V3nSypChh4Gjh74ybO9aeZ/AN2dwciu2/MhAAAAAElFTkSuQmCC">实现原理<!----></h1> <div class="page-slot page-slot-top">
<div class="wwads-cn wwads-horizontal page-wwads" data-id="136"></div>
<style>
.page-wwads{
width:100%!important;
min-height: 0;
margin: 0;
}
.page-wwads .wwads-img img{
width:80px!important;
}
.page-wwads .wwads-poweredby{
width: 40px;
position: absolute;
right: 25px;
bottom: 3px;
}
.wwads-content .wwads-text, .page-wwads .wwads-text{
height: 100%;
padding-top: 5px;
display: block;
}
</style>
</div> <div class="theme-vdoing-content content__default"><h1 id="代理实现中涉及的几类channel"><a href="#代理实现中涉及的几类channel" class="header-anchor">#</a> 代理实现中涉及的几类Channel</h1> <h2 id="指令通道-cmdchannel"><a href="#指令通道-cmdchannel" class="header-anchor">#</a> 指令通道(CmdChannel)</h2> <ul><li>该channel负责维护客户端与服务端之间的指令通讯,由客户端启动后向服务端发起连接请求,服务端验证license成功后连接建立。</li> <li>服务端维护第一个CmdChannel的映射表,key为licenseId。服务端可以根据licenseId,向指定的客户端指令通道发布指令。</li> <li>该通道建立完成后,服务端会将该license授权的外网映射端口打开,等待用户访问。正常情况下,只要客户端不下线,该通道一直可用。</li> <li>然后服务端维护第二个CmdChannel的映射表,key为服务端外网端口。服务端可以根据指定的外网端口,向指定的客户端指令通道发布指令。</li></ul> <h2 id="用户访问通道-visitorchannel"><a href="#用户访问通道-visitorchannel" class="header-anchor">#</a> 用户访问通道(VisitorChannel)</h2> <ul><li>该channel负责维护访问者与服务端端口之间的通讯,由访问者向服务端映射的外网端口发起请求开始建立,具体断开时机由实际的被代理的
协议决定。</li> <li>如HTTP/1.0下,用户向该端口发起请求,响应结束后,该通道随之关闭,下一次发起请求后,重新建立新的连接。</li> <li>该连接建立后,服务端会向该外网端口映射的指令通道发送<code>Connect</code>指令,传输该外网端口需要代理的内网信息,
如:<code>127.0.0.1:3306</code></li></ul> <h2 id="被代理服务的实际通道-realserverchannel"><a href="#被代理服务的实际通道-realserverchannel" class="header-anchor">#</a> 被代理服务的实际通道(RealServerChannel)</h2> <ul><li>该channel负责维护客户端与实际被代理服务之间的通讯,当客户端接收到服务端的<code>Connect</code>指令后,客户端便会建立该通道。</li></ul> <h2 id="代理数据传输的通道-proxychannel"><a href="#代理数据传输的通道-proxychannel" class="header-anchor">#</a> 代理数据传输的通道(ProxyChannel)</h2> <ul><li>该channel负责完成内网被代理服务与代理服务端之间的数据转发任务。</li> <li>每个客户端维护一个<code>ProxyChannel</code>的缓存队列,需要时从该队列中取,当取不到时,直接新建一个<code>ProxyChannel</code>返回。
当一个<code>ProxyChannel</code>实例用完后,需要归还到缓存队列中(<code>ProxyChannel</code>收到<code>DisConnect</code>指令时)。</li> <li><code>RealServerChannel</code>建立完成后,就会获取相关联的<code>ProxyChannel</code>,并与其绑定。设置<code>RealServerChannel</code>
可读状态。然后通过<code>ProxyChannel</code>向服务端发送<code>Connect</code>指令。</li></ul> <h1 id="代理实现流程"><a href="#代理实现流程" class="header-anchor">#</a> 代理实现流程</h1> <h2 id="_1、服务连接阶段"><a href="#_1、服务连接阶段" class="header-anchor">#</a> 1、服务连接阶段</h2> <ul><li>1.1、客户端根据是否需要使用SSL,选择对应的服务端端口发起连接,建立<code>CmdChannel</code></li> <li>1.2、客户端根据用户输入或配置文件获取<code>license</code>,并携带<code>license</code>通过<code>CmdChannel</code>向服务端发送<code>Auth</code>指令。</li> <li>1.3、服务端通过<code>CmdChannel</code>接收到来自客户端的<code>Auth</code>指令。若验证<code>license</code>有效,则建立<code>licenseId</code><code>CmdChannel</code>的映射缓存、
外网端口与<code>CmdChannel</code>的映射缓存。并启动服务端代理端口,等待用户连接。</li></ul> <h2 id="_2、用户连接阶段"><a href="#_2、用户连接阶段" class="header-anchor">#</a> 2、用户连接阶段</h2> <ul><li>2.1、用户向服务端代理的外网端口发起请求,服务端建立<code>VisitorChannel</code></li> <li>2.2、根据外网端口查找<code>CmdChannel</code>,若不存在有效的<code>CmdChannel</code>,则关闭该<code>VisitorChannel</code>。否则,
设置<code>VisitorChannel</code>为不可读,并携带内网映射信息(如:<code>127.0.0.1:3306</code>)通过<code>CmdChannel</code>向客户端发送<code>Connect</code>指令。</li></ul> <h2 id="_3、实际被代理服务连接阶段"><a href="#_3、实际被代理服务连接阶段" class="header-anchor">#</a> 3、实际被代理服务连接阶段</h2> <ul><li>3.1、客户端通过<code>CmdChannel</code>接收到服务端的<code>Connect</code>指令。拿到需要代理的内网IP、端口号,向实际被
代理服务发起连接请求,若连接失败,则通过<code>CmdChannel</code>向服务端发送<code>DisConnect</code>指令。建立<code>RealServerChannel</code>成功,设置<code>RealServerChannel</code>为不可读
状态,并进入4.1阶段</li></ul> <h2 id="_4、代理通道连接阶段"><a href="#_4、代理通道连接阶段" class="header-anchor">#</a> 4、代理通道连接阶段</h2> <ul><li>4.1、客户端通过<code>ProxyChannelQueue</code>获取或新建一个<code>ProxyChannel</code>,并将<code>RealServerChannel</code><code>ProxyChannel</code>进行绑定。</li> <li>4.2、客户端通过<code>ProxyChannel</code>向服务端发送<code>Connect</code>指令。</li> <li>4.3、服务端通过<code>ProxyChannel</code>通道收到来自客户端的<code>Connect</code>指令后,将<code>ProxyChannel</code>与对应的<code>VisitorChannel</code>进行绑定,并
设置<code>VisitorChannel</code>为可读状态。</li></ul> <h2 id="_5、数据传输阶段"><a href="#_5、数据传输阶段" class="header-anchor">#</a> 5、数据传输阶段</h2> <ul><li>5.1、服务端通过<code>VisitorChannel</code>收到来自用户的请求数据,然后找到<code>VisitorChannel</code>绑定的<code>ProxyChannel</code>
通过<code>ProxyChannel</code>发送<code>Transfer</code>指令,并携带用户请求数据。</li> <li>5.2、客户端通过<code>ProxyChannel</code>收到来自服务端的<code>Transfer</code>指令,取出用户请求数据。找到<code>ProxyChannel</code>绑定的<code>RealServerChannel</code>,
通过<code>RealServerChannel</code>向被代理服务写入用户请求数据。</li> <li>5.3、客户端通过<code>RealServerChannel</code>收到被代理服务响应的数据,找到<code>RealServerChannel</code>绑定的<code>ProxyChannel</code>
通过<code>ProxyChannel</code>向服务端发送<code>Transfer</code>指令,并携带响应数据。</li> <li>5.4、服务端通过<code>ProxyChannel</code>收到来自客户端的<code>Transfer</code>指令,找到<code>ProxyChannel</code>绑定的<code>VisitorChannel</code>
通过<code>VisitorChannel</code>向用户端写入响应数据。</li></ul></div></div> <div class="page-edit"><!----> <!----> <div class="last-updated"><span class="prefix">上次更新:</span> <span class="time">2023/10/26, 13:41:02</span></div></div> <div class="page-nav-wapper"><div class="page-nav-centre-wrap"><a href="/neutrino-proxy/pages/2f674a/" class="page-nav-centre page-nav-centre-prev"><div class="tooltip">项目结构</div></a> <a href="/neutrino-proxy/pages/acdf0a/" class="page-nav-centre page-nav-centre-next"><div class="tooltip">2024年</div></a></div> <div class="page-nav"><p class="inner"><span class="prev">
<a href="/neutrino-proxy/pages/2f674a/" class="prev">项目结构</a></span> <span class="next"><a href="/neutrino-proxy/pages/acdf0a/">2024年</a>
</span></p></div></div></div> <!----></main></div> <div class="footer"><div class="icons"><a href="mailto:[email protected]" title="发邮件" target="_blank" class="iconfont icon-youjian"></a><a href="https://gitee.com/dromara/neutrino-proxy" title="Gitee" target="_blank" class="iconfont icon-gitee"></a><a href="https://github.com/aoshiguchen/neutrino-proxy" title="Github" target="_blank" class="iconfont icon-github"></a></div>
Theme by
<a href="https://github.com/xugaoyi/vuepress-theme-vdoing" target="_blank" title="本站主题">Vdoing</a>
| Copyright © 2023-2024
<span>傲世孤尘 | MIT License</span></div> <div class="buttons"><div title="返回顶部" class="button blur go-to-top iconfont icon-fanhuidingbu" style="display:none;"></div> <div title="去评论" class="button blur go-to-comment iconfont icon-pinglun" style="display:none;"></div> <div title="主题模式" class="button blur theme-mode-but iconfont icon-zhuti"><ul class="select-box" style="display:none;"><li class="iconfont icon-zidong">
跟随系统
</li><li class="iconfont icon-rijianmoshi">
浅色模式
</li><li class="iconfont icon-yejianmoshi">
深色模式
</li><li class="iconfont icon-yuedu">
阅读模式
</li></ul></div></div> <!----> <!----> <!----></div><div class="global-ui"></div></div>
<script src="/neutrino-proxy/assets/js/app.26329228.js" defer></script><script src="/neutrino-proxy/assets/js/2.bcc017ba.js" defer></script><script src="/neutrino-proxy/assets/js/32.ebdd578e.js" defer></script>
</body>
</html>