V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
fffonion
V2EX  ›  NGINX

用 OpenResty 写了一个 SNI 代理

  •  
  •   fffonion ·
    fffonion · 2016-06-06 04:51:22 +08:00 · 5284 次点击
    这是一个创建于 2874 天前的主题,其中的信息可能已经有所发展或是发生改变。

    功能类似于dlundquist/sniproxy

    推荐 OpenResty 加上 stream 模块和 ngx_stream_lua_module 模块。在 1.9.15.1 上测试通过。

    测了一下比 nginx 的 stream 模块直接转发 443 速度低 20%。转发的部分现在还很 low ,需要读 TLS 的头取得包长度,然后一次性读完之后给对面。不知道各位有啥好的建议不。

    Github→ https://github.com/fffonion/lua-resty-sniproxy.git

    16 条回复    2016-08-13 20:46:07 +08:00
    ericFork
        1
    ericFork  
       2016-06-06 06:04:52 +08:00
    excited. +1s
    fcicq
        2
    fcicq  
       2016-06-06 06:24:04 +08:00
    赞.
    ```
    wait(
    spawn(_upl, self),
    spawn(_dwn, self)
    )
    ```
    能不能直接换成 port forwarding?
    49
        3
    49  
       2016-06-06 06:53:31 +08:00 via iPhone
    绝赞!
    fcicq
        4
    fcicq  
       2016-06-06 06:56:30 +08:00
    好像没有这个能力. 只能去求一个类似 nodejs 的 xxx.pipe(yyy) 的 api 了, 直接挂在 read_event_handler 和 write_event_handler 上.
    在这个 api 没有做出来之前可以把 send 和 receive 的字节数都去掉, 收到多少发多少.
    fffonion
        5
    fffonion  
    OP
       2016-06-06 08:09:22 +08:00
    @fcicq
    收到多少发多少好像不行? send 和 receive 在一个轻线程里是同步的
    fcicq
        6
    fcicq  
       2016-06-06 08:34:17 +08:00
    @fffonion 可以直接调用 sock:receive() 而不需要 len 参数吧?
    fffonion
        7
    fffonion  
    OP
       2016-06-06 09:29:35 +08:00
    @fcicq 不加参数的话是相当于`'*l'`,读到换行符为止
    fcicq
        8
    fcicq  
       2016-06-06 09:37:44 +08:00
    @fffonion 写死 4096 如何?
    fffonion
        9
    fffonion  
    OP
       2016-06-06 11:13:22 +08:00
    @fcicq 这样碰到一些小包可能会堵住吧?
    如果有像 go 里面的 channel 一样的东西就好了
    fcicq
        10
    fcicq  
       2016-06-06 11:16:11 +08:00
    @fffonion 那请问 echo server, socks5 server 都应该怎么写?
    fffonion
        11
    fffonion  
    OP
       2016-06-06 12:34:28 +08:00
    @fcicq 这种我觉得要么是头上带长度然后 receive(length),要么有分隔符的 receiveuntil(分隔符)?个人感觉 openresty 的 socket 得用同步的思想来写
    mengskysama
        12
    mengskysama  
       2016-06-06 13:10:07 +08:00 via iPhone
    春哥说正则有 jo 参数(
    fffonion
        13
    fffonion  
    OP
       2016-06-06 13:16:27 +08:00
    @mengskysama 好我去加一个
    wujunze
        14
    wujunze  
       2016-06-06 14:24:54 +08:00
    mark
    shanliang
        15
    shanliang  
       2016-06-06 23:58:18 +08:00
    mark
    fengjianxinghun
        16
    fengjianxinghun  
       2016-08-13 20:46:07 +08:00 via iPhone
    自己改源码包装个 ioctl 出来得 fd buf 长度
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3623 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 10:28 · PVG 18:28 · LAX 03:28 · JFK 06:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.