› 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 · Jun 6, 2016 · 6626 views
    This topic created in 3822 days ago, the information mentioned may be changed or developed.

    功能类似于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 replies  •  2016-08-13 20:46:07 +08:00
    ericFork
    ericFork
    Jun 6, 2016
    1
    excited. +1s
    fcicq
    fcicq
    Jun 6, 2016
    2
    赞.
    ```
    wait(
    spawn(_upl, self),
    spawn(_dwn, self)
    )
    ```
    能不能直接换成 port forwarding?
    49
    49
    Jun 6, 2016 via iPhone
    3
    绝赞!
    fcicq
    fcicq
    Jun 6, 2016
    4
    好像没有这个能力. 只能去求一个类似 nodejs 的 xxx.pipe(yyy) 的 api 了, 直接挂在 read_event_handler 和 write_event_handler 上.
    在这个 api 没有做出来之前可以把 send 和 receive 的字节数都去掉, 收到多少发多少.
    fffonion
    fffonion
    OP
    Jun 6, 2016
    5
    @fcicq 嗯
    收到多少发多少好像不行? send 和 receive 在一个轻线程里是同步的
    fcicq
    fcicq
    Jun 6, 2016
    6
    @fffonion 可以直接调用 sock:receive() 而不需要 len 参数吧?
    fffonion
    fffonion
    OP
    Jun 6, 2016
    7
    @fcicq 不加参数的话是相当于`'*l'`,读到换行符为止
    fcicq
    fcicq
    Jun 6, 2016
    8
    @fffonion 写死 4096 如何?
    fffonion
    fffonion
    OP
    Jun 6, 2016
    9
    @fcicq 这样碰到一些小包可能会堵住吧?
    如果有像 go 里面的 channel 一样的东西就好了
    fcicq
    fcicq
    Jun 6, 2016
    10
    @fffonion 那请问 echo server, socks5 server 都应该怎么写?
    fffonion
    fffonion
    OP
    Jun 6, 2016
    11
    @fcicq 这种我觉得要么是头上带长度然后 receive(length),要么有分隔符的 receiveuntil(分隔符)?个人感觉 openresty 的 socket 得用同步的思想来写
    mengskysama
    mengskysama
    Jun 6, 2016 via iPhone
    12
    春哥说正则有 jo 参数(
    fffonion
    fffonion
    OP
    Jun 6, 2016
    13
    @mengskysama 好我去加一个
    jinfeng333
    jinfeng333
    Jun 6, 2016
    14
    mark
    shanliang
    shanliang
    Jun 6, 2016
    15
    mark
    fengjianxinghun
    fengjianxinghun
    Aug 13, 2016 via iPhone
    16
    自己改源码包装个 ioctl 出来得 fd buf 长度
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   884 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 311ms · UTC 22:19 · PVG 06:19 · LAX 14:19 · JFK 17:19
    ♥ Do have faith in what you're doing.