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

WebTorrent support #4123

Merged
merged 12 commits into from
Jul 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@
[submodule "deps/asio-gnutls"]
path = deps/asio-gnutls
url = https://github.com/paullouisageneau/boost-asio-gnutls.git
[submodule "deps/libdatachannel"]
path = deps/libdatachannel
url = https://github.com/paullouisageneau/libdatachannel.git
[submodule "deps/json"]
path = deps/json
url = https://github.com/vinniefalco/json.git
12 changes: 9 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ matrix:
- env: variant=debug crypto=openssl docs=1 tests=1 examples=1 tools=1 toolset=darwin
os: osx
osx_image: xcode11.2
- env: variant=debug crypto=openssl python=1 toolset=darwin ios=1
- env: variant=debug crypto=openssl webtorrent=on python=1 toolset=darwin ios=1
paullouisageneau marked this conversation as resolved.
Show resolved Hide resolved
os: osx
osx_image: xcode11.2
- env: variant=debug toolset=gcc pylint=1 clang_tidy=1
Expand All @@ -21,11 +21,13 @@ matrix:
- env: variant=debug tests=1 toolset=gcc sanitizer=on fuzzers=1
- env: variant=debug tests=1 mmap=off toolset=gcc
- env: variant=debug sim=1 crypto=openssl toolset=gcc sanitizer=on
- env: variant=debug tests=1 crypto=gnutls toolset=gcc sanitizer=on
- env: variant=debug tests=1 crypto=gnutls webtorrent=on toolset=gcc sanitizer=on
addons:
apt:
packages:
- gnutls-dev
- nettle-dev
- python3-websockets
# - env: variant=debug tests=1 crypto=wolfssl toolset=gcc sanitizer=on
- env: variant=release coverage=1 tests=1 toolset=gcc-coverage python=1 python_dist=1
- env: dist=1 toolset=gcc install_boost=1
Expand Down Expand Up @@ -243,7 +245,7 @@ script:

- cd $TRAVIS_BUILD_DIR
- 'if [ "$pylint" == "1" ]; then
python3 -m flake8 --max-line-length=120 --ignore=E741,W504,E126,W503,E121,E124,E123;
python3 -m flake8 --max-line-length=120 --ignore=E741,W504,E126,W503,E121,E124,E123,E402 --exclude=deps/libdatachannel,deps/json;
fi'
- 'if [ "$sonar_scan" == "1" ]; then
build-wrapper-linux-x86-64 --out-dir bw-output ${B2} -a -j2 cxxstd=17 optimization=off crypto=$crypto deprecated-functions=off $toolset variant=$variant -l300 &&
Expand All @@ -266,6 +268,10 @@ script:
export B2_ARGS="${B2_ARGS} openssl-lib=/usr/local/opt/[email protected]/lib openssl-include=/usr/local/opt/[email protected]/include" ;
fi'

- 'if [[ $webtorrent == "on" ]]; then
export B2_ARGS="${B2_ARGS} webtorrent=on";
fi'

- 'if [ "$check_headers" == "1" ]; then
${B2} -j2 check-headers ${B2_ARGS};
fi'
Expand Down
80 changes: 59 additions & 21 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,11 @@ set(libtorrent_aux_include_files
utp_stream
vector
win_crypto_provider
win_util)
win_util
rtc_signaling
rtc_stream
websocket_stream
websocket_tracker_connection)

set(try_signal_include_files
try_signal
Expand Down Expand Up @@ -400,6 +404,10 @@ set(sources
posix_disk_io
posix_storage
ssl
rtc_signaling
rtc_stream
websocket_stream
websocket_tracker_connection

# -- extensions --
ut_pex
Expand Down Expand Up @@ -466,27 +474,27 @@ feature_option(static_runtime "build libtorrent with static runtime" OFF)
find_public_dependency(Threads REQUIRED)

if(CMAKE_CXX_COMPILER_ID MATCHES Clang)
add_compile_options(
-Weverything
-Wno-documentation
-Wno-c++98-compat-pedantic
-Wno-padded
-Wno-global-constructors
-Wno-exit-time-destructors
-Wno-weak-vtables
-Wno-return-std-move-in-c++11
-Wno-unknown-warning-option)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Weverything \
-Wno-documentation \
-Wno-c++98-compat-pedantic \
-Wno-padded \
-Wno-global-constructors \
-Wno-exit-time-destructors \
-Wno-weak-vtables \
-Wno-return-std-move-in-c++11 \
-Wno-unknown-warning-option")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's the rationale for this change? I'm no expert on CMake, but it seems like a step backwards to use global variables rather than associating build properties with targets

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it because add_compile_options adds options also for C code, which breaks the compilation of libdatachannel's dependencies. Since the options were added globally before anyway I changed to CMAKE_CXX_FLAGS to make them exclusive to C++.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, I see. I didn't realize at first that this adds global compiler flags. I'm a bit surprised they aren't just added to the libtorrent target.
@zeule do you have any thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't know an elegant way to achieve what we want, because we want those flags to be defined for the libtorrent target and the tests, but we can't make them public libtorrent flags because we don't want them to escape into the libtorrent interface (via pkg-config or cmake targets).

These two solutions seem to be least ugly to me:

  1. Add a dummy target with these options in its INTERFACE flags. Link it privately to libtorrent and the tests.
  2. Add these flags to the libtorrent target as PUBLIC, but hide them under $<BUILD_INTERFACE: generator expression, so that they will not escape to the exported target.

The second one needs testing for the pkg-config generator, but otherwise is, probably, the best way to go.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

option two seems risky to me. it would mean anyone adding libtorrent as a cmake dependency would get all these flags too, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if they reference the target from a build tree.

elseif(CMAKE_CXX_COMPILER_ID MATCHES GNU)
add_compile_options(
-Wall
-Wextra
-Wpedantic
-Wparentheses
-Wvla
-Wc++11-compat
-Wno-format-zero-length
-Wno-noexcept-type
-ftemplate-depth=512)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} \
-Wall \
-Wextra \
-Wpedantic \
-Wparentheses \
-Wvla \
-Wc++11-compat \
-Wno-format-zero-length \
-Wno-noexcept-type \
-ftemplate-depth=512")
elseif(MSVC)
add_compile_options(
/W4
Expand Down Expand Up @@ -625,6 +633,8 @@ target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME extens
DESCRIPTION "Enables protocol extensions" DISABLED TORRENT_DISABLE_EXTENSIONS)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME i2p DEFAULT ON
DESCRIPTION "build with I2P support" DISABLED TORRENT_USE_I2P=0)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME webtorrent DEFAULT OFF
DESCRIPTION "build with WebTorrent support" DISABLED TORRENT_USE_RTC=0)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME logging DEFAULT ON
DESCRIPTION "build with logging" DISABLED TORRENT_DISABLE_LOGGING)
target_optional_compile_definitions(torrent-rasterbar PUBLIC FEATURE NAME mutable-torrents DEFAULT ON
Expand Down Expand Up @@ -737,6 +747,28 @@ else()
target_compile_definitions(torrent-rasterbar PUBLIC TORRENT_DISABLE_DHT)
endif()

if (webtorrent)
option(USE_JUICE "Use libjuice instead of libnice for libdatachannel" ON)
option(NO_WEBSOCKET "Enable WebSocket support in libdatachannel" ON)
if(GNUTLS_FOUND)
option(USE_GNUTLS "Use GnuTLS instead of OpenSSL for libdatachannel" ON)
else()
option(USE_GNUTLS "Use GnuTLS instead of OpenSSL for libdatachannel" OFF)
endif()
add_subdirectory(deps/libdatachannel EXCLUDE_FROM_ALL)
if(CMAKE_CXX_COMPILER_ID MATCHES Clang|GNU)
target_compile_options(datachannel-static PRIVATE
-Wno-pedantic
-Wno-unused-parameter
-Wno-unused-variable
-Wno-format-nonliteral)
endif()
if(CMAKE_CXX_COMPILER_ID MATCHES GNU)
target_compile_options(usrsctp-static PRIVATE
-Wno-format-truncation)
endif()
endif()

# Boost
find_public_dependency(Boost REQUIRED COMPONENTS system)
target_include_directories(torrent-rasterbar PUBLIC ${Boost_INCLUDE_DIRS})
Expand Down Expand Up @@ -810,6 +842,12 @@ include(CheckCXXCompilerFlag)

add_subdirectory(bindings)

if(webtorrent)
target_link_libraries(torrent-rasterbar PRIVATE LibDataChannel::LibDataChannelStatic)
target_include_directories(torrent-rasterbar PRIVATE deps/json/include)
paullouisageneau marked this conversation as resolved.
Show resolved Hide resolved
target_compile_definitions(torrent-rasterbar PRIVATE BOOST_JSON_HEADER_ONLY)
endif()

install(TARGETS torrent-rasterbar EXPORT LibtorrentRasterbarTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
Expand Down
1 change: 1 addition & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* libtorrent now requires C++17 to build
* added support for WebTorrent

2.0 release

Expand Down
30 changes: 26 additions & 4 deletions Jamfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ else
}

use-project /try_signal : ./deps/try_signal ;
use-project /libdatachannel : ./deps/libdatachannel ;

VERSION = 2.0.0 ;

Expand Down Expand Up @@ -82,7 +83,7 @@ rule linking ( properties * )
else if <crypto>gnutls in $(properties)
{
result += <library>./deps/asio-gnutls//asio-gnutls ;
result += <library>gnutls ;
result += <library>gnutls/<link>shared ;
}
else if <crypto>libcrypto in $(properties)
{
Expand Down Expand Up @@ -210,10 +211,18 @@ rule linking ( properties * )
if <link>shared in $(properties)
{
result += <library>/try_signal//try_signal/<link>static/<fpic>on ;
if <webtorrent>on in $(properties)
{
result += <library>/libdatachannel//libdatachannel/<link>static/<fpic>on ;
}
}
else
{
result += <library>/try_signal//try_signal/<link>static ;
if <webtorrent>on in $(properties)
{
result += <library>/libdatachannel//libdatachannel/<link>static ;
}
}

return $(result) ;
Expand Down Expand Up @@ -519,6 +528,10 @@ feature i2p : on off : composite propagated ;
feature.compose <i2p>on : <define>TORRENT_USE_I2P=1 ;
feature.compose <i2p>off : <define>TORRENT_USE_I2P=0 ;

feature webtorrent : off on : composite propagated ;
feature.compose <webtorrent>on : <define>TORRENT_USE_RTC=1 ;
feature.compose <webtorrent>off : <define>TORRENT_USE_RTC=0 ;

feature iconv : auto on off : composite propagated ;
feature.compose <iconv>on : <define>TORRENT_USE_ICONV=1 ;
feature.compose <iconv>off : <define>TORRENT_USE_ICONV=0 ;
Expand Down Expand Up @@ -576,7 +589,8 @@ feature.compose <crypto>openssl
: <define>TORRENT_USE_LIBCRYPTO
<define>TORRENT_USE_OPENSSL
<define>TORRENT_SSL_PEERS
<define>OPENSSL_NO_SSL2 ;
<define>OPENSSL_NO_SSL2
<gnutls>off ;
arvidn marked this conversation as resolved.
Show resolved Hide resolved
feature.compose <crypto>wolfssl
: <define>TORRENT_USE_WOLFSSL
<define>TORRENT_USE_LIBCRYPTO
Expand All @@ -586,10 +600,12 @@ feature.compose <crypto>wolfssl
<define>OPENSSL_ALL
<define>WOLFSSL_SHA512
<define>WOLFSSL_NGINX
<define>WC_NO_HARDEN ;
<define>WC_NO_HARDEN
<gnutls>off ;
feature.compose <crypto>gnutls
: <define>TORRENT_USE_GNUTLS
<define>TORRENT_SSL_PEERS ;
<define>TORRENT_SSL_PEERS
<gnutls>on ;
feature.compose <crypto>libcrypto : <define>TORRENT_USE_LIBCRYPTO ;
feature.compose <crypto>gcrypt : <define>TORRENT_USE_LIBGCRYPT ;

Expand Down Expand Up @@ -805,6 +821,10 @@ SOURCES =
posix_disk_io
posix_storage
ssl
rtc_signaling
rtc_stream
websocket_stream
websocket_tracker_connection

# -- extensions --
ut_pex
Expand Down Expand Up @@ -890,6 +910,8 @@ lib torrent
<define>TORRENT_BUILDING_LIBRARY
<link>shared:<define>TORRENT_BUILDING_SHARED
<define>BOOST_NO_DEPRECATED
<include>./deps/json/include
<define>BOOST_JSON_HEADER_ONLY
paullouisageneau marked this conversation as resolved.
Show resolved Hide resolved
<link>shared:<define>BOOST_SYSTEM_SOURCE

# https://github.com/chriskohlhoff/asio/issues/290#issuecomment-377727614
Expand Down
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,11 @@ SOURCES = \
web_connection_base.cpp \
web_peer_connection.cpp \
write_resume_data.cpp \
xml_parse.cpp
xml_parse.cpp \
rtc_signaling.cpp \
rtc_stream.cpp \
websocket_stream.cpp \
websocket_tracker_connection.cpp

HEADERS = \
ConvertUTF.h \
Expand Down Expand Up @@ -646,6 +650,10 @@ HEADERS = \
aux_/vector.hpp \
aux_/win_crypto_provider.hpp \
aux_/win_util.hpp \
aux_/rtc_signaling.hpp \
aux_/rtc_stream.hpp \
aux_/websocket_stream.hpp \
aux_/websocket_tracker_connection.hpp \
\
extensions/smart_ban.hpp \
extensions/ut_metadata.hpp \
Expand Down Expand Up @@ -715,6 +723,8 @@ ASIO_GNUTLS = \
test/gnutls/rfc2818_verification.cpp \
test/gnutls/stream.cpp

DATACHANNEL = $(shell cd deps/libdatachannel && git ls-files)
arvidn marked this conversation as resolved.
Show resolved Hide resolved

SIM_SOURCES = \
Jamfile \
create_torrent.cpp \
Expand Down Expand Up @@ -1057,6 +1067,7 @@ TEST_EXTRA = Jamfile \
corrupt.gz \
invalid1.gz \
utf8_test.txt \
utf8_latin1_test.txt \
web_server.py \
socks.py \
http_proxy.py \
Expand All @@ -1080,6 +1091,7 @@ dist: FORCE
$(addprefix simulation/,${SIM_SOURCES}) \
$(addprefix deps/try_signal/,${TRY_SIGNAL}) \
$(addprefix deps/asio-gnutls/,${ASIO_GNUTLS}) \
$(addprefix deps/libdatachannel/,${DATACHANNEL}) \
$(addprefix simulation/libsimulator/,${LIBSIM_EXTRA}) \
$(addprefix simulation/libsimulator/test,${LIBSIM_TEST}) \
$(addprefix simulation/libsimulator/include/simulator/,${LIBSIM_HEADERS}) \
Expand Down
Loading