klzgrad / naiveproxy

Make a fortune quietly
BSD 3-Clause "New" or "Revised" License
6.68k stars 884 forks source link

Create CDN compatible Websocket tunnels #390

Closed grimpenmire closed 1 year ago

grimpenmire commented 2 years ago

I've looked through existing issues, and I know the current view of the maintainers for using naiveproxy behind a CDN. However, I want to make a new argument for this.

For the past couple of months, I've been setting up and maintaining proxy servers for people in Iran (mainly v2ray based ones). The folks in Iran are in the rather unique and unfortunate position that they have their access to the global Internet shut down at critical times (like when there are mass protests, as there has been in the last two months).

Crucially, the data centers inside the country still have Internet access even when residential and mobile customers do not. So what we've been doing is setting up TLS based proxy servers and put them behind a CDN inside the country. This has been a saving grace for us, and that's how we've managed to keep people connected.

So I'm trying to see if this can be made to work with naiveproxy. I know naiveproxy uses CONNECT tunnels which are not supported by CDNs. So we need a workaround, like for example using an HTTP upgrade mechanism. I might want to try to get a stab at it myself if the maintainers are not interested in doing it, but I'd appreciate any pointers and ideas. I'm also interested to know if you'd still be against the idea given our use case.

triggered96 commented 1 year ago

What about grpc? some CDN providers like cloudflare have the ability for connecting to upstream (proxy server) on gRPC. something like this:

User <---HTTP/2 ---> CDN <---- gRPC ----> Proxy Server < ---- > Free Internet

Don't hold illusions that it can be realized, it is impossible in naiveproxy.

ghost commented 1 year ago

So, is it possible to use any CDN??Not limited to websocket. Can we add a fake header before the real trans data? such as GET /resource/xxxxxxxxxx-key. let the cdn think you are requesting a normal resource.

triggered96 commented 1 year ago

So, is it possible to use any CDN??Not limited to websocket. Can we add a fake header before the real trans data? such as GET /resource/xxxxxxxxxx-key. let the cdn think you are requesting a normal resource.

The author believes that adding faux websocket support itself is not realistic, because faux websocket does not reuse the websocket framework. If the framework is reused, the naive project needs to be greatly modified, and in actual tests, the efficiency is far lower than http2. After my own test, I also agree with the author's idea. So don't even think about adding websocket to naiveproxy.

triggered96 commented 1 year ago

The built-in websocket framework of chromium is itself a prototype and has not actually been deepened. After all, chromium did not expect that someone would use the chromium source code to modify it into httpproxy. Remarks: Chrome or chromium initiates websocket usually through javascript, so if you want to integrate the websockt high-efficiency framework, you have to integrate v8, which will greatly deform the naive code, and c++ is not as easy to implement as go, because The chromium source code structure itself has limitations.

ghost commented 1 year ago

So, is it possible to use any CDN??Not limited to websocket. Can we add a fake header before the real trans data? such as GET /resource/xxxxxxxxxx-key. let the cdn think you are requesting a normal resource.

The author believes that adding faux websocket support itself is not realistic, because faux websocket does not reuse the websocket framework. If the framework is reused, the naive project needs to be greatly modified, and in actual tests, the efficiency is far lower than http2. After my own test, I also agree with the author's idea. So don't even think about adding websocket to naiveproxy.

I don't mean to add websocket, but any request format to let the CDN to carry for us,just like get the index.html page

grimpenmire commented 1 year ago

Well, websocket is pretty much the only thing we can use to pass through CDNs, because CDNs don't support CONNECT tunnels that naive uses.

triggered96 commented 1 year ago

So, is it possible to use any CDN??Not limited to websocket. Can we add a fake header before the real trans data? such as GET /resource/xxxxxxxxxx-key. let the cdn think you are requesting a normal resource.

The author believes that adding faux websocket support itself is not realistic, because faux websocket does not reuse the websocket framework. If the framework is reused, the naive project needs to be greatly modified, and in actual tests, the efficiency is far lower than http2. After my own test, I also agree with the author's idea. So don't even think about adding websocket to naiveproxy.

I don't mean to add websocket, but any request format to let the CDN to carry for us,just like get the index.html page

As @grimpenmire pointed out, CDNs don't support CONNECT tunnels, which can only be carried over requests based on GET, POST, or HEAD. If you want to use a CDN to pass CONNECT requests back to the origin server, your idea won't work. I also mentioned earlier why Naive doesn't consider faux-websocket for ws communication, and in reality, the performance of faux-websocket is far worse than that of http/2. If you want to truly use ws, it is recommended to use other tools as naive may not be suitable for you.