Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同时添加对HTTP+SOCSK的监听(实测有效) #479

Closed
triggered96 opened this issue Mar 18, 2023 · 15 comments
Closed

同时添加对HTTP+SOCSK的监听(实测有效) #479

triggered96 opened this issue Mar 18, 2023 · 15 comments

Comments

@triggered96
Copy link

triggered96 commented Mar 18, 2023

我尝试在源码上进行一些幅度的修改,可以达到 HTTP+SOCSK的监听。

效果如下:

[0318/101509.061990:INFO:naive_proxy_bin.cc(279)] MAP www.example.com:443 xx.xx.xx.xx.xx:443
[0318/101509.099174:INFO:naive_proxy_bin.cc(112)] Proxying via https://www.example.com
[0318/101509.112288:INFO:naive_proxy_bin.cc(365)] SOCKS proxy listening at 0.0.0.0:1088
[0318/101509.112464:INFO:naive_proxy_bin.cc(379)] HTTP proxy listening at 0.0.0.0:1089
[0318/101524.933872:INFO:naive_connection.cc(235)] Connection 1 to fonts.gstatic.com:443
root@Ubuntu:~# lsof -i:1088
COMMAND     PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
naive   1546751 root   17u  IPv4 64161991      0t0  TCP *:1088 (LISTEN)
root@Ubuntu:~# lsof -i:1089
COMMAND     PID USER   FD   TYPE   DEVICE SIZE/OFF NODE NAME
naive   1546751 root   18u  IPv4 64161992      0t0  TCP *:1089 (LISTEN)
naive   1546751 root   19u  IPv4 64226094      0t0  TCP Ubuntu:1089->192.168.1.10:61938 (ESTABLISHED)
root@Ubuntu:~# 
int result = server_socket->ListenWithAddressAndPort(
      params.listen_addr, params.listen_port, kListenBackLog);
  if (result != net::OK) {
    LOG(ERROR) << "Failed to listen: " << result;
    return EXIT_FAILURE;
  } {
    LOG(INFO) << "SOCKS proxy listening at " << params.listen_addr << ":"
              << params.listen_port;
  }

  auto server_socket1 =
      std::make_unique<net::TCPServerSocket>(&net_log, net::NetLogSource());

  int result1 = server_socket1->ListenWithAddressAndPort(
      params.listen_addr, params.listen_port + 1, kListenBackLog);
  if (result1 != net::OK) {
    LOG(ERROR) << "Failed to listen: " << result1;
    return EXIT_FAILURE;
  } else
  {
    LOG(INFO) << "HTTP proxy listening at " << params.listen_addr << ":"
              << params.listen_port + 1;
  }

  auto socksProxy = std::make_unique<net::NaiveProxy>(
      std::move(server_socket),params.protocol,params.use_proxy,
      context->http_transaction_factory()->GetSession());

  auto httpProxy = std::make_unique<net::NaiveProxy>(
      std::move(server_socket1),net::NaiveProxy::kHttp,params.use_proxy,
      context->http_transaction_factory()->GetSession());

  base::RunLoop().Run();
@triggered96
Copy link
Author

triggered96 commented Mar 18, 2023

目前使用并没有什么副作用。上述仅仅进行测试,并没有把代码做重构,如果需同时进行,需提供一个标志 --listen="socks://0.0.0.0:1088;http://0.0.0.0:1089"。默认 socks在1088端口上监听,而http在1089上监听。

@triggered96
Copy link
Author

作者可以考虑吗?

@ArcCal
Copy link

ArcCal commented Mar 18, 2023

这个功能很有用啊,期待

@ArcCal
Copy link

ArcCal commented Mar 18, 2023

这个功能很有用没用啊,期待

啥意思?

打错了
改过来了

@triggered96
Copy link
Author

triggered96 commented Mar 18, 2023

哈哈哈哈 。其实我也是功能需求才自己修改的。我看issue中有人需要HTTP+SOCSK同时监听,所以发上来了。当然我只做了测试。如果整合,需要进行代码小幅度重构。

@ArcCal
Copy link

ArcCal commented Mar 18, 2023

我现在总是跑两个naive进程,一个监听http,一个监听socks

虽然能用,但确实挺麻烦的

@triggered96 triggered96 changed the title 同时添加对HTTP+SOCSK的监听 同时添加对HTTP+SOCSK的监听(实测有效) Mar 18, 2023
@triggered96
Copy link
Author

作者考虑添加socks+http?

@klzgrad
Copy link
Owner

klzgrad commented Mar 18, 2023

但确实挺麻烦的

不认为。

Do one thing and do it well.

@triggered96
Copy link
Author

triggered96 commented Mar 18, 2023

但确实挺麻烦的

不认为。

Do one thing and do it well.

@klzgrad 您觉得该功能有必要?如果觉得没必要,那我关贴了。--listen="socks://0.0.0.0:1088;http://0.0.0.0:1089"

@zedifen
Copy link

zedifen commented Mar 19, 2023

刚刚我尝试魔改了一下 https://github.com/zedifen/naiveproxy/commit/3bc74be4c8a3834222c315240dd2907a368c25a1, 思路是用 for 循环运行多个配置; 但没进行很多测试, 可能会有 Bug 或者性能退化.

@triggered96
Copy link
Author

刚刚我尝试魔改了一下 zedifen@3bc74be, 思路是用 for 循环运行多个配置; 但没进行很多测试, 可能会有 Bug 或者性能退化.

我觉得--listen="socks://0.0.0.0:1088;http://0.0.0.0:1089"比较好些

@triggered96
Copy link
Author

triggered96 commented Mar 19, 2023

刚刚我尝试魔改了一下 zedifen@3bc74be, 思路是用 for 循环运行多个配置; 但没进行很多测试, 可能会有 Bug 或者性能退化.

  {
    "listen": "socks://0.0.0.0:1088;http://0.0.0.0:1089",
    "proxy": "https://user:[email protected]"
  }

你觉得怎么样?😊

如果这样子,"proxy": "https://user:[email protected]" 会被重复定义

[
  {
    "listen": "socks://127.0.0.1:1080",
    "proxy": "https://user:[email protected]"
  },
  {
    "listen": "http://127.0.0.1:8889",
    "proxy": "https://user:[email protected]"
  }
]

@zedifen
Copy link

zedifen commented Mar 19, 2023

那要避免重复的话, 这样写或许还是要美观一点

{
  "listen": [
    "socks://0.0.0.0:1088",
    "http://0.0.0.0:8889"
  ],
  "proxy": "https://user:[email protected]"
}

@triggered96
Copy link
Author

triggered96 commented Mar 19, 2023

那要避免重复的话, 这样写或许还是要美观一点

{
  "listen": [
    "socks://0.0.0.0:1088",
    "http://0.0.0.0:8889"
  ],
  "proxy": "https://user:[email protected]"
}

可以可以。

@klzgrad
Copy link
Owner

klzgrad commented Mar 19, 2023

./naive --listen='socks://0.0.0.0:1088;http://0.0.0.0:1089'

./naive --listen=socks://0.0.0.0:1088 & ./naive --listen=http://0.0.0.0:1089 &

在我看来没有区别,如果说有区别,是把shell代码移动到C++代码里面,没有必要。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants