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