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

[Bug]: Trojan-Plus 与最新的 boost1.87.0 库版本编译时报错,因无法fork,在这里贴出补丁! #355

Open
zxlhhyccc opened this issue Jan 16, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@zxlhhyccc
Copy link
Contributor

描述您遇到的bug

部分报错如下:

/home/user/openwrt/build_dir/target-arm_xscale_musl_eabi/trojan-plus-10.0.3/src/core/service.cpp: In lambda function:
/home/user/openwrt/build_dir/target-arm_xscale_musl_eabi/trojan-plus-10.0.3/src/core/service.cpp:550:28: error: 'buffer_cast' is not a member of 'boost::asio'; did you mean 'buffer_copy'?
  550 |               boost::asio::buffer_cast<char*>(udp_read_buf.prepare(config.get_udp_recv_buf())), read_length, ttl);
      |                            ^~~~~~~~~~~
      |                            buffer_copy
/home/user/openwrt/build_dir/target-arm_xscale_musl_eabi/trojan-plus-10.0.3/src/core/service.cpp:550:40: error: expected primary-expression before 'char'
  550 |               boost::asio::buffer_cast<char*>(udp_read_buf.prepare(config.get_udp_recv_buf())), read_length, ttl);
      |                                        ^~~~

复现此Bug的步骤

无,编译失败问题。

您想要实现的目的

image

Trojan-Plus在boost1.87.0版本并兼容1.86.0以下版本的补丁已可编译可使用(补丁名:001-Fix-boost1.87-build.patch),boost1.87.0版本已移除了buffer_cast和error_code。

--- a/src/core/service.cpp
+++ b/src/core/service.cpp
@@ -546,8 +546,15 @@ void Service::udp_async_read() {
             int read_length = (int)length;
             int ttl         = -1;
 
+#if BOOST_VERSION >= 108700
+            auto buffer = udp_read_buf.prepare(config.get_udp_recv_buf());
+            char* data = static_cast<char*>(buffer.data());
+
+            targetdst = recv_tproxy_udp_msg((int)udp_socket.native_handle(), udp_recv_endpoint, data, read_length, ttl);
+#else
             targetdst = recv_tproxy_udp_msg((int)udp_socket.native_handle(), udp_recv_endpoint,
               boost::asio::buffer_cast<char*>(udp_read_buf.prepare(config.get_udp_recv_buf())), read_length, ttl);
+#endif
 
             length = read_length < 0 ? 0 : read_length;
             udp_read_buf.commit(length);
--- a/src/session/session.cpp
+++ b/src/session/session.cpp
@@ -68,7 +68,11 @@ void Session::udp_timer_async_wait(int t
     }
 
     boost::system::error_code ec;
+#if BOOST_VERSION >= 108700
+    udp_gc_timer.cancel();
+#else
     udp_gc_timer.cancel(ec);
+#endif
     if (ec) {
         output_debug_info_ec(ec);
         destroy();
@@ -104,7 +108,11 @@ void Session::udp_timer_cancel() {
     }
 
     boost::system::error_code ec;
+#if BOOST_VERSION >= 108700
+    udp_gc_timer.cancel();
+#else
     udp_gc_timer.cancel(ec);
+#endif
     if (ec) {
         output_debug_info_ec(ec);
     }
--- a/src/core/utils.cpp
+++ b/src/core/utils.cpp
@@ -59,8 +59,13 @@ size_t streambuf_append(
         return 0;
     }
 
+#if BOOST_VERSION >= 108700
+    auto* dest      = static_cast<uint8_t*>(target.prepare(n).data());
+    const auto* src = static_cast<const uint8_t*>(append_buf.data().data()) + start;
+#else
     auto* dest      = boost::asio::buffer_cast<uint8_t*>(target.prepare(n));
     const auto* src = boost::asio::buffer_cast<const uint8_t*>(append_buf.data()) + start;
+#endif
     memcpy(dest, src, n);
     target.commit(n);
     return n;
@@ -102,7 +107,11 @@ size_t streambuf_append(boost::asio::str
 size_t streambuf_append(boost::asio::streambuf& target, char append_char) {
     _guard;
     const size_t char_length = sizeof(char);
+#if BOOST_VERSION >= 108700
+    auto cp = gsl::span<char>(static_cast<char*>(target.prepare(char_length).data()), char_length);
+#else
     auto cp = gsl::span<char>(boost::asio::buffer_cast<char*>(target.prepare(char_length)), char_length);
+#endif
     cp[0]   = append_char;
     target.commit(char_length);
     return char_length;
@@ -137,7 +146,11 @@ size_t streambuf_append(boost::asio::str
 
 std::string_view streambuf_to_string_view(const boost::asio::streambuf& target) {
     _guard;
+#if BOOST_VERSION >= 108700
+    return std::string_view(static_cast<const char*>(target.data().data()), target.size());
+#else
     return std::string_view(boost::asio::buffer_cast<const char*>(target.data()), target.size());
+#endif
     _unguard;
 }
 

日志信息

编译报错,见上面。

截图

No response

系统相关信息

无。

其他信息

No response

@zxlhhyccc zxlhhyccc added the bug Something isn't working label Jan 16, 2025
@lwb1978
Copy link
Collaborator

lwb1978 commented Jan 17, 2025

Image

我添加上去了,不过仓库的ac自动编译测试没成功,我现在测试一下编译到系统中是否能成功。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants