libp2p / cpp-libp2p

C++17 implementation of libp2p
Apache License 2.0
364 stars 99 forks source link

inconsistent use of BOOST_ASIO_NO_DEPRECATED is unnecessary and dangerous #166

Closed saurik closed 3 years ago

saurik commented 3 years ago

The usage of BOOST_ASIO_NO_DEPRECATED seems to change not only what symbols are available, but the implementation of some functions and maybe even the layout of some classes. As far as I can tell, ASIO is designed to be built either with this defined everywhere, or nowhere. Trying to use cpp-libp2p in a project that is already using Boost ASIO is thereby fraught with peril, as I'm getting inconsistent behaviors due to some symbols being exported from and merged from libp2p files, leading to segmentation faults.

FWIW, my code would work fine with either BOOST_ASIO_NO_DEPRECATED or not, but the core issue is that there are two files in libp2p that have a #define BOOST_ASIO_NO_DEPRECATED but a number of other files that rely on it not being defined. It is my understanding that you should not be defining this yourself in the header files: it should be done at the level of either Boost's build system or like, at most some custom build system that is taking over for Boost's build system, not defined in individual header files.

The code does seem to compile fine if you simply remove the two #defines without making any other changes (though I'm not using your build system to do it, so I'm not at all sure I'm covering all of your build possibilities).

https://github.com/libp2p/cpp-libp2p/blob/91d58f28bb8cbce06fd717082fa2b4274a33ae07/include/libp2p/transport/tcp/tcp_connection.hpp#L9

https://github.com/libp2p/cpp-libp2p/blob/91d58f28bb8cbce06fd717082fa2b4274a33ae07/include/libp2p/transport/tcp/tcp_transport.hpp#L9

turuslan commented 3 years ago

Thanks for your contribution