├── libtorrent.go ├── interfaces ├── peer_info.i ├── create_torrent.i ├── socket.i ├── bitfield.i ├── extensions.i ├── alert.i ├── torrent_info.i ├── alert_types.i ├── add_torrent_params.i ├── boost_array.i ├── entry.i ├── file_storage.i ├── torrent_handle.i ├── std_map.i ├── session.i └── dht.i ├── libtorrent_android.go ├── .gitignore ├── docker ├── scripts │ ├── build-swig.sh │ ├── build-openssl.sh │ ├── build-boost.sh │ ├── build-golang.sh │ └── build-libtorrent.sh ├── linux-x86.Dockerfile ├── linux-x64.Dockerfile ├── linux-arm64.Dockerfile ├── linux-arm.Dockerfile ├── linux-armv7.Dockerfile ├── android-x86.Dockerfile ├── android-arm64.Dockerfile ├── windows-x86.Dockerfile ├── windows-x64.Dockerfile ├── android-arm.Dockerfile ├── android-x64.Dockerfile └── darwin-x64.Dockerfile ├── libtorrent_cgo.go ├── platform_host.mk ├── .travis.yml ├── platform_target.mk ├── LICENSE ├── README.md ├── .gitlab-ci.yml ├── libtorrent.swigcxx └── Makefile /libtorrent.go: -------------------------------------------------------------------------------- 1 | package libtorrent 2 | -------------------------------------------------------------------------------- /interfaces/peer_info.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | %} 4 | 5 | %include 6 | -------------------------------------------------------------------------------- /interfaces/create_torrent.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | %} 4 | 5 | %include 6 | -------------------------------------------------------------------------------- /interfaces/socket.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | %} 4 | 5 | %include 6 | 7 | namespace libtorrent { 8 | class tcp; 9 | class udp; 10 | } 11 | -------------------------------------------------------------------------------- /libtorrent_android.go: -------------------------------------------------------------------------------- 1 | // +build android 2 | 3 | package libtorrent 4 | 5 | // #cgo pkg-config: --static libtorrent-rasterbar openssl 6 | // #cgo android LDFLAGS: -lm -lgnustl_shared -ldl 7 | import "C" 8 | -------------------------------------------------------------------------------- /interfaces/bitfield.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | %} 4 | 5 | %extend libtorrent::bitfield { 6 | void const* bytes() const { 7 | return (void*)self->data(); 8 | } 9 | } 10 | %ignore libtorrent::bitfield::bytes; 11 | 12 | %include 13 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | .idea 8 | _obj 9 | _test 10 | 11 | # Architecture specific extensions/prefixes 12 | *.[568vq] 13 | [568vq].out 14 | 15 | *.cgo1.go 16 | *.cgo2.c 17 | _cgo_defun.c 18 | _cgo_gotypes.go 19 | _cgo_export.* 20 | 21 | _testmain.go 22 | 23 | *.exe 24 | -------------------------------------------------------------------------------- /interfaces/extensions.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | #include 5 | %} 6 | 7 | %extend libtorrent::session { 8 | void add_extensions() { 9 | self->add_extension(&libtorrent::create_smart_ban_plugin); 10 | self->add_extension(&libtorrent::create_ut_metadata_plugin); 11 | self->add_extension(&libtorrent::create_ut_pex_plugin); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /interfaces/alert.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | %} 5 | 6 | %ignore libtorrent::log_alert; 7 | %ignore libtorrent::peer_log_alert; 8 | %ignore libtorrent::portmap_log_alert; 9 | %ignore libtorrent::torrent_log_alert; 10 | %ignore libtorrent::stats_alert; 11 | %ignore libtorrent::picker_log_alert; 12 | 13 | %include 14 | %include 15 | 16 | %{ 17 | using libtorrent::time_point; 18 | %} 19 | -------------------------------------------------------------------------------- /interfaces/torrent_info.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | #include 5 | %} 6 | 7 | %ignore libtorrent::sha1_hash::begin; 8 | %ignore libtorrent::sha1_hash::end; 9 | %ignore libtorrent::sanitize_append_path_element; 10 | %ignore libtorrent::verify_encoding; 11 | 12 | %include 13 | %include "entry.i" 14 | %include 15 | %include "file_storage.i" 16 | %include 17 | -------------------------------------------------------------------------------- /docker/scripts/build-swig.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | if [ ! -f "swig-${SWIG_VERSION}.tar.gz" ]; then 5 | wget -q https://github.com/swig/swig/archive/${SWIG_VERSION}.tar.gz -O swig-${SWIG_VERSION}.tar.gz 6 | fi 7 | echo "$SWIG_SHA256 swig-${SWIG_VERSION}.tar.gz" | sha256sum -c - 8 | tar -xzf swig-${SWIG_VERSION}.tar.gz 9 | rm swig-${SWIG_VERSION}.tar.gz 10 | cd swig-${SWIG_VERSION}/ 11 | ./autogen.sh 1>log 2>err 12 | ./configure 1>log 2>err 13 | make -j $(cat /proc/cpuinfo | grep processor | wc -l) 1>log 2>err 14 | make install 1>log 2>err 15 | rm -rf `pwd` 16 | -------------------------------------------------------------------------------- /libtorrent_cgo.go: -------------------------------------------------------------------------------- 1 | // +build !android 2 | 3 | package libtorrent 4 | 5 | // #cgo pkg-config: --static libtorrent-rasterbar openssl 6 | // #cgo darwin CXXFLAGS: -fvisibility=hidden 7 | // #cgo darwin LDFLAGS: -lm -lstdc++ 8 | // #cgo linux CXXFLAGS: -std=c++11 -I/usr/include/libtorrent -I/usr/include -I/usr/include/i386-linux-gnu -Wno-deprecated-declarations 9 | // #cgo linux LDFLAGS: -lm -lstdc++ -ldl -lrt 10 | // #cgo windows CXXFLAGS: -std=c++11 -DIPV6_TCLASS=39 -DSWIGWIN -D_WIN32_WINNT=0x0600 -D__MINGW32__ 11 | // #cgo windows LDFLAGS: -static-libgcc -static-libstdc++ 12 | import "C" 13 | -------------------------------------------------------------------------------- /interfaces/alert_types.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | #include 5 | %} 6 | 7 | %extend libtorrent::save_resume_data_alert { 8 | entry resume_data() const { 9 | boost::shared_ptr ptr; 10 | ptr = boost::make_shared(*self->resume_data); 11 | return *ptr; 12 | } 13 | } 14 | %ignore libtorrent::save_resume_data_alert::resume_data; 15 | 16 | %include 17 | %include 18 | %include 19 | -------------------------------------------------------------------------------- /interfaces/add_torrent_params.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | #include 5 | %} 6 | 7 | %extend libtorrent::add_torrent_params { 8 | const libtorrent::torrent_info* get_torrent_info() { 9 | return self->ti.get(); 10 | } 11 | void set_torrent_info(libtorrent::torrent_info torrent_info) { 12 | boost::shared_ptr ptr; 13 | ptr = boost::make_shared(torrent_info); 14 | self->ti = ptr; 15 | } 16 | } 17 | %ignore libtorrent::add_torrent_params::ti; 18 | 19 | %include 20 | -------------------------------------------------------------------------------- /docker/scripts/build-openssl.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | if [ ! -f "openssl-${OPENSSL_VERSION}.tar.gz" ]; then 5 | wget -q https://www.openssl.org/source/openssl-${OPENSSL_VERSION}.tar.gz 6 | fi 7 | echo "$OPENSSL_SHA256 openssl-${OPENSSL_VERSION}.tar.gz" | sha256sum -c - 8 | tar -xzf openssl-${OPENSSL_VERSION}.tar.gz 9 | rm openssl-${OPENSSL_VERSION}.tar.gz 10 | cd openssl-${OPENSSL_VERSION}/ 11 | CROSS_COMPILE=${CROSS_TRIPLE}- ./Configure threads no-shared ${OPENSSL_OPTS} --prefix=${CROSS_ROOT} 1>log 2>err 12 | make -j $(cat /proc/cpuinfo | grep processor | wc -l) 1>log 2>err 13 | make install 1>log 2>err 14 | rm -rf `pwd` 15 | -------------------------------------------------------------------------------- /platform_host.mk: -------------------------------------------------------------------------------- 1 | ifeq ($(OS), Windows_NT) 2 | HOST_OS = windows 3 | ifeq ($(PROCESSOR_ARCHITECTURE), AMD64) 4 | ARCH = x64 5 | else ifeq ($(PROCESSOR_ARCHITECTURE), x86) 6 | ARCH = x86 7 | endif 8 | else 9 | UNAME_S := $(shell uname -s) 10 | UNAME_M := $(shell uname -m) 11 | ifeq ($(UNAME_S), Linux) 12 | HOST_OS = linux 13 | else ifeq ($(UNAME_S), Darwin) 14 | HOST_OS = darwin 15 | endif 16 | ifeq ($(UNAME_M), x86_64) 17 | HOST_ARCH = x64 18 | else ifneq ($(filter %86, $(UNAME_M)),) 19 | HOST_ARCH = x86 20 | else ifneq ($(findstring arm, $(UNAME_M)),) 21 | HOST_ARCH = arm 22 | endif 23 | endif 24 | -------------------------------------------------------------------------------- /interfaces/boost_array.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | %} 5 | 6 | %typemap(gotype) boost::array, boost::array, boost::array*, boost::array* "[]byte" 7 | 8 | %typemap(in) boost::array 9 | %{ 10 | memcpy($1.data(), $input.array, $1.size() < $input.len ? $1.size() : $input.len); 11 | %} 12 | 13 | %typemap(out) boost::array 14 | %{ 15 | $result.array = (void*)$1.data(); 16 | $result.len = (intgo)$1.size(); 17 | $result.cap = $result.len; 18 | %} 19 | 20 | %typemap(out) boost::array* 21 | %{ 22 | $result.array = (void*)$1->data(); 23 | $result.len = (intgo)$1->size(); 24 | $result.cap = $result.len; 25 | %} 26 | 27 | %include 28 | -------------------------------------------------------------------------------- /interfaces/entry.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | %} 5 | 6 | %include 7 | %include 8 | 9 | namespace libtorrent { 10 | std::string bencode(const entry& e); 11 | error_code bdecode(std::string data, bdecode_node& ret); 12 | } 13 | 14 | %{ 15 | namespace libtorrent { 16 | std::string bencode(const entry& e) { 17 | std::ostringstream oss; 18 | bencode(std::ostream_iterator(oss), e); 19 | return oss.str(); 20 | } 21 | 22 | error_code bdecode(std::string data, bdecode_node& ret) { 23 | error_code ec; 24 | bdecode((const char*)data.c_str(), (const char*)(data.c_str() + data.size()), ret, ec); 25 | return ec; 26 | } 27 | } 28 | %} 29 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | language: go 3 | go: 4 | - "1.11" 5 | 6 | env: 7 | - PLATFORM=android-arm 8 | - PLATFORM=android-arm64 9 | - PLATFORM=android-x64 10 | - PLATFORM=android-x86 11 | - PLATFORM=darwin-x64 12 | - PLATFORM=linux-arm 13 | - PLATFORM=linux-armv7 14 | - PLATFORM=linux-arm64 15 | - PLATFORM=linux-x64 16 | - PLATFORM=linux-x86 17 | - PLATFORM=windows-x64 18 | - PLATFORM=windows-x86 19 | 20 | services: 21 | - docker 22 | 23 | before_install: 24 | - make pull 25 | 26 | install: 27 | - make env 28 | 29 | script: 30 | - make $PLATFORM 31 | - | 32 | if [ "${TRAVIS_PULL_REQUEST}" = "false" ] && [ "${TRAVIS_BRANCH}" = "master" ]; then 33 | docker login -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD" 34 | make push 35 | fi 36 | -------------------------------------------------------------------------------- /docker/scripts/build-boost.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | if [ ! -f "boost_${BOOST_VERSION_FILE}.tar.bz2" ]; then 5 | wget -q https://dl.bintray.com/boostorg/release/${BOOST_VERSION}/source/boost_${BOOST_VERSION_FILE}.tar.bz2 6 | fi 7 | echo "$BOOST_SHA256 boost_${BOOST_VERSION_FILE}.tar.bz2" | sha256sum -c - 8 | tar -xjf boost_${BOOST_VERSION_FILE}.tar.bz2 9 | rm boost_${BOOST_VERSION_FILE}.tar.bz2 10 | cd boost_${BOOST_VERSION_FILE}/ 11 | ./bootstrap.sh --prefix=${CROSS_ROOT} ${BOOST_BOOTSTRAP_OPTS} 12 | echo "using ${BOOST_CC} : ${BOOST_OS} : ${CROSS_TRIPLE}-${BOOST_CXX} ${BOOST_FLAGS} ;" > ${HOME}/user-config.jam 13 | ./b2 --with-date_time --with-system --with-chrono --with-random --prefix=${CROSS_ROOT} toolset=${BOOST_CC}-${BOOST_OS} ${BOOST_OPTS} link=static variant=release threading=multi target-os=${BOOST_TARGET_OS} install 1>/dev/null 2>/dev/null 14 | rm -rf ${HOME}/user-config.jam 15 | rm -rf `pwd` 16 | -------------------------------------------------------------------------------- /platform_target.mk: -------------------------------------------------------------------------------- 1 | GCC_TARGET = $(CC) 2 | 3 | ifneq ($(findstring darwin, $(GCC_TARGET)),) 4 | TARGET_OS = darwin 5 | else ifneq ($(findstring mingw, $(GCC_TARGET)),) 6 | TARGET_OS = windows 7 | else ifneq ($(findstring android, $(GCC_TARGET)),) 8 | TARGET_OS = android 9 | else ifneq ($(findstring linux, $(GCC_TARGET)),) 10 | TARGET_OS = linux 11 | endif 12 | 13 | ifneq ($(findstring x86_64, $(GCC_TARGET)),) 14 | TARGET_ARCH = x64 15 | else ifneq ($(findstring i386, $(GCC_TARGET)),) 16 | TARGET_ARCH = x86 17 | else ifneq ($(findstring i486, $(GCC_TARGET)),) 18 | TARGET_ARCH = x86 19 | else ifneq ($(findstring i586, $(GCC_TARGET)),) 20 | TARGET_ARCH = x86 21 | else ifneq ($(findstring i686, $(GCC_TARGET)),) 22 | TARGET_ARCH = x86 23 | else ifneq ($(findstring aarch64, $(GCC_TARGET)),) 24 | TARGET_ARCH = arm64 25 | else ifneq ($(findstring armv7, $(GCC_TARGET)),) 26 | TARGET_ARCH = armv7 27 | else ifneq ($(findstring arm, $(GCC_TARGET)),) 28 | TARGET_ARCH = arm 29 | endif 30 | -------------------------------------------------------------------------------- /docker/scripts/build-golang.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | set -ex 4 | mkdir -p /usr/local/bootstrap 5 | if [ ! -f "golang-bootstrap.tar.gz" ]; then 6 | wget -q "$GOLANG_BOOTSTRAP_URL" -O golang-bootstrap.tar.gz 7 | fi 8 | echo "$GOLANG_BOOTSTRAP_SHA256 golang-bootstrap.tar.gz" | sha256sum -c - 9 | tar -C /usr/local/bootstrap -xzf golang-bootstrap.tar.gz 10 | rm golang-bootstrap.tar.gz 11 | cd /usr/local/bootstrap/go/src 12 | ./make.bash 1>/dev/null 2>/dev/null 13 | export GOROOT_BOOTSTRAP=/usr/local/bootstrap/go 14 | 15 | cd /build 16 | if [ ! -f "golang.tar.gz" ]; then 17 | wget -q "$GOLANG_SRC_URL" -O golang.tar.gz 18 | fi 19 | echo "$GOLANG_SRC_SHA256 golang.tar.gz" | sha256sum -c - 20 | tar -C /usr/local -xzf golang.tar.gz 21 | rm golang.tar.gz 22 | cd /usr/local/go/src 23 | ./make.bash 1>/dev/null 2>/dev/null 24 | 25 | CC_FOR_TARGET=${GOLANG_CC} CXX_FOR_TARGET=${GOLANG_CXX} GOOS=${GOLANG_OS} GOARCH=${GOLANG_ARCH} GOARM=${GOLANG_ARM} CGO_ENABLED=1 ./make.bash --no-clean 26 | rm -rf /usr/local/bootstrap /usr/local/go/pkg/bootstrap 27 | -------------------------------------------------------------------------------- /docker/scripts/build-libtorrent.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -ex 3 | if [ -v LT_PTHREADS ]; then 4 | echo "#define BOOST_SP_USE_PTHREADS" >> ${CROSS_ROOT}/include/boost/config/user.hpp 5 | fi 6 | if [ ! -f "${LIBTORRENT_VERSION}.tar.gz" ]; then 7 | wget -q https://github.com/arvidn/libtorrent/archive/`echo ${LIBTORRENT_VERSION} | sed 's/\\./_/g'`.tar.gz 8 | fi 9 | tar -xzf ${LIBTORRENT_VERSION}.tar.gz 10 | rm ${LIBTORRENT_VERSION}.tar.gz 11 | cd libtorrent-`echo ${LIBTORRENT_VERSION} | sed 's/\\./_/g'`/ 12 | ./autotool.sh 13 | sed -i 's/$PKG_CONFIG openssl --libs-only-/$PKG_CONFIG openssl --static --libs-only-/' ./configure 14 | if [ -v LT_OSXCROSS ]; then 15 | export OSXCROSS_PKG_CONFIG_PATH=${CROSS_ROOT}/lib/pkgconfig/ 16 | fi 17 | CC=${LT_CC} CXX=${LT_CXX} \ 18 | CFLAGS="${CFLAGS} -O2 ${LT_FLAGS}" \ 19 | CXXFLAGS="${CXXFLAGS} ${LT_CXXFLAGS} ${CFLAGS}" \ 20 | LIBS=${LT_LIBS} \ 21 | ./configure \ 22 | --enable-static \ 23 | --disable-shared \ 24 | --disable-deprecated-functions \ 25 | --host=${CROSS_TRIPLE} \ 26 | --prefix=${CROSS_ROOT} \ 27 | --with-boost=${CROSS_ROOT} --with-boost-libdir=${CROSS_ROOT}/lib ${LT_OPTS} 28 | make -j $(cat /proc/cpuinfo | grep processor | wc -l) && make install 29 | rm -rf `pwd` 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, Steeve Morin 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | Neither the name of the {organization} nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /docker/linux-x86.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:linux-x86 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Install Boost.System 30 | COPY scripts/build-boost.sh /build/ 31 | ENV BOOST_CC gcc 32 | ENV BOOST_CXX c++ 33 | ENV BOOST_OS linux 34 | ENV BOOST_TARGET_OS linux 35 | RUN ./build-boost.sh 36 | 37 | # Install OpenSSL 38 | COPY scripts/build-openssl.sh /build/ 39 | ENV OPENSSL_OPTS linux-elf 40 | RUN ./build-openssl.sh 41 | 42 | # Install SWIG 43 | COPY scripts/build-swig.sh /build/ 44 | RUN ./build-swig.sh 45 | 46 | # Install Golang 47 | COPY scripts/build-golang.sh /build/ 48 | ENV GOLANG_CC ${CROSS_TRIPLE}-cc 49 | ENV GOLANG_CXX ${CROSS_TRIPLE}-c++ 50 | ENV GOLANG_OS linux 51 | ENV GOLANG_ARCH 386 52 | RUN ./build-golang.sh 53 | ENV PATH ${PATH}:/usr/local/go/bin 54 | 55 | # Install libtorrent 56 | COPY scripts/build-libtorrent.sh /build/ 57 | ENV LT_CC ${CROSS_TRIPLE}-gcc 58 | ENV LT_CXX ${CROSS_TRIPLE}-g++ 59 | RUN ./build-libtorrent.sh 60 | -------------------------------------------------------------------------------- /docker/linux-x64.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:linux-x64 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Install Boost.System 30 | COPY scripts/build-boost.sh /build/ 31 | ENV BOOST_CC gcc 32 | ENV BOOST_CXX c++ 33 | ENV BOOST_OS linux 34 | ENV BOOST_TARGET_OS linux 35 | RUN ./build-boost.sh 36 | 37 | # Install OpenSSL 38 | COPY scripts/build-openssl.sh /build/ 39 | ENV OPENSSL_OPTS linux-x86_64 40 | RUN ./build-openssl.sh 41 | 42 | # Install SWIG 43 | COPY scripts/build-swig.sh /build/ 44 | RUN ./build-swig.sh 45 | 46 | # Install Golang 47 | COPY scripts/build-golang.sh /build/ 48 | ENV GOLANG_CC ${CROSS_TRIPLE}-cc 49 | ENV GOLANG_CXX ${CROSS_TRIPLE}-c++ 50 | ENV GOLANG_OS linux 51 | ENV GOLANG_ARCH amd64 52 | RUN ./build-golang.sh 53 | ENV PATH ${PATH}:/usr/local/go/bin 54 | 55 | # Install libtorrent 56 | COPY scripts/build-libtorrent.sh /build/ 57 | ENV LT_CC ${CROSS_TRIPLE}-gcc 58 | ENV LT_CXX ${CROSS_TRIPLE}-g++ 59 | RUN ./build-libtorrent.sh 60 | -------------------------------------------------------------------------------- /docker/linux-arm64.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:linux-arm64 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Install Boost.System 30 | COPY scripts/build-boost.sh /build/ 31 | ENV BOOST_CC gcc 32 | ENV BOOST_CXX c++ 33 | ENV BOOST_OS linux 34 | ENV BOOST_TARGET_OS linux 35 | ENV BOOST_OPTS cxxflags=-fPIC cflags=-fPIC 36 | RUN ./build-boost.sh 37 | 38 | # Install OpenSSL 39 | COPY scripts/build-openssl.sh /build/ 40 | ENV OPENSSL_OPTS linux-aarch64 41 | RUN ./build-openssl.sh 42 | 43 | # Install SWIG 44 | COPY scripts/build-swig.sh /build/ 45 | RUN ./build-swig.sh 46 | 47 | # Install Golang 48 | COPY scripts/build-golang.sh /build/ 49 | ENV GOLANG_CC ${CROSS_TRIPLE}-cc 50 | ENV GOLANG_CXX ${CROSS_TRIPLE}-c++ 51 | ENV GOLANG_OS linux 52 | ENV GOLANG_ARCH arm64 53 | RUN ./build-golang.sh 54 | ENV PATH ${PATH}:/usr/local/go/bin 55 | 56 | # Install libtorrent 57 | COPY scripts/build-libtorrent.sh /build/ 58 | ENV LT_CC ${CROSS_TRIPLE}-gcc 59 | ENV LT_CXX ${CROSS_TRIPLE}-g++ 60 | ENV LT_PTHREADS TRUE 61 | ENV LT_CXXFLAGS -std=c++11 62 | RUN ./build-libtorrent.sh 63 | -------------------------------------------------------------------------------- /docker/linux-arm.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:linux-arm 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Install Boost.System 30 | COPY scripts/build-boost.sh /build/ 31 | ENV BOOST_CC gcc 32 | ENV BOOST_CXX c++ 33 | ENV BOOST_OS linux 34 | ENV BOOST_TARGET_OS linux 35 | ENV BOOST_OPTS cxxflags=-fPIC cflags=-fPIC 36 | RUN ./build-boost.sh 37 | 38 | # Install OpenSSL 39 | COPY scripts/build-openssl.sh /build/ 40 | ENV OPENSSL_OPTS linux-armv4 41 | RUN ./build-openssl.sh 42 | 43 | # Install SWIG 44 | COPY scripts/build-swig.sh /build/ 45 | RUN ./build-swig.sh 46 | 47 | # Install Golang 48 | COPY scripts/build-golang.sh /build/ 49 | ENV GOLANG_CC ${CROSS_TRIPLE}-cc 50 | ENV GOLANG_CXX ${CROSS_TRIPLE}-c++ 51 | ENV GOLANG_OS linux 52 | ENV GOLANG_ARCH arm 53 | ENV GOLANG_ARM 6 54 | RUN ./build-golang.sh 55 | ENV PATH ${PATH}:/usr/local/go/bin 56 | 57 | # Install libtorrent 58 | COPY scripts/build-libtorrent.sh /build/ 59 | ENV LT_CC ${CROSS_TRIPLE}-gcc 60 | ENV LT_CXX ${CROSS_TRIPLE}-g++ 61 | ENV LT_PTHREADS TRUE 62 | ENV LT_CXXFLAGS -std=c++11 63 | RUN ./build-libtorrent.sh 64 | -------------------------------------------------------------------------------- /docker/linux-armv7.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:linux-armv7 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Install Boost.System 30 | COPY scripts/build-boost.sh /build/ 31 | ENV BOOST_CC gcc 32 | ENV BOOST_CXX c++ 33 | ENV BOOST_OS linux 34 | ENV BOOST_TARGET_OS linux 35 | ENV BOOST_OPTS cxxflags=-fPIC cflags=-fPIC 36 | RUN ./build-boost.sh 37 | 38 | # Install OpenSSL 39 | COPY scripts/build-openssl.sh /build/ 40 | ENV OPENSSL_OPTS linux-armv4 41 | RUN ./build-openssl.sh 42 | 43 | # Install SWIG 44 | COPY scripts/build-swig.sh /build/ 45 | RUN ./build-swig.sh 46 | 47 | # Install Golang 48 | COPY scripts/build-golang.sh /build/ 49 | ENV GOLANG_CC ${CROSS_TRIPLE}-cc 50 | ENV GOLANG_CXX ${CROSS_TRIPLE}-c++ 51 | ENV GOLANG_OS linux 52 | ENV GOLANG_ARCH arm 53 | ENV GOLANG_ARM 7 54 | RUN ./build-golang.sh 55 | ENV PATH ${PATH}:/usr/local/go/bin 56 | 57 | # Install libtorrent 58 | COPY scripts/build-libtorrent.sh /build/ 59 | ENV LT_CC ${CROSS_TRIPLE}-gcc 60 | ENV LT_CXX ${CROSS_TRIPLE}-g++ 61 | ENV LT_PTHREADS TRUE 62 | ENV LT_CXXFLAGS -std=c++11 63 | RUN ./build-libtorrent.sh 64 | -------------------------------------------------------------------------------- /docker/android-x86.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:android-x86 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Install Boost.System 30 | COPY scripts/build-boost.sh /build/ 31 | ENV BOOST_CC clang 32 | ENV BOOST_CXX clang++ 33 | ENV BOOST_OS android 34 | ENV BOOST_TARGET_OS linux 35 | ENV BOOST_OPTS cxxflags=-fPIC cflags=-fPIC 36 | RUN ./build-boost.sh 37 | 38 | # Install OpenSSL 39 | COPY scripts/build-openssl.sh /build/ 40 | ENV OPENSSL_OPTS linux-generic32 -fPIC 41 | RUN ./build-openssl.sh 42 | 43 | # Install SWIG 44 | COPY scripts/build-swig.sh /build/ 45 | RUN ./build-swig.sh 46 | 47 | # Install Golang 48 | COPY scripts/build-golang.sh /build/ 49 | ENV GOLANG_CC ${CROSS_TRIPLE}-clang 50 | ENV GOLANG_CXX ${CROSS_TRIPLE}-clang++ 51 | ENV GOLANG_OS android 52 | ENV GOLANG_ARCH 386 53 | RUN ./build-golang.sh 54 | ENV PATH ${PATH}:/usr/local/go/bin 55 | 56 | # Install libtorrent 57 | COPY scripts/build-libtorrent.sh /build/ 58 | ENV LT_CC ${CROSS_TRIPLE}-clang 59 | ENV LT_CXX ${CROSS_TRIPLE}-clang++ 60 | ENV LT_PTHREADS TRUE 61 | ENV LT_FLAGS -fPIC -fPIE 62 | ENV LT_CXXFLAGS -Wno-macro-redefined -Wno-c++11-extensions 63 | RUN ./build-libtorrent.sh 64 | -------------------------------------------------------------------------------- /interfaces/file_storage.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include 21 | %} 22 | 23 | %ignore libtorrent::disk_io_thread::do_read_and_hash; 24 | %ignore libtorrent::disk_io_thread::do_resolve_links; 25 | 26 | // SWiG voodoo for Windows and the dreaded "'iovec' has not been declared"... 27 | namespace libtorrent { 28 | namespace file {} 29 | } 30 | 31 | %include 32 | %include 33 | %include 34 | %include 35 | %include 36 | %include 37 | %include 38 | %include 39 | %include 40 | %include 41 | %include 42 | %include 43 | %include 44 | %include 45 | %include 46 | %include 47 | %include 48 | %include 49 | %include 50 | -------------------------------------------------------------------------------- /docker/android-arm64.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:android-arm64 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Install Boost.System 30 | COPY scripts/build-boost.sh /build/ 31 | ENV BOOST_CC clang 32 | ENV BOOST_CXX clang++ 33 | ENV BOOST_OS android 34 | ENV BOOST_TARGET_OS linux 35 | ENV BOOST_OPTS cxxflags=-fPIC cflags=-fPIC 36 | RUN ./build-boost.sh 37 | 38 | # Install OpenSSL 39 | COPY scripts/build-openssl.sh /build/ 40 | ENV OPENSSL_OPTS linux-aarch64 -fPIC 41 | RUN ./build-openssl.sh 42 | 43 | # Install SWIG 44 | COPY scripts/build-swig.sh /build/ 45 | RUN ./build-swig.sh 46 | 47 | # Install Golang 48 | COPY scripts/build-golang.sh /build/ 49 | ENV GOLANG_CC ${CROSS_TRIPLE}-clang 50 | ENV GOLANG_CXX ${CROSS_TRIPLE}-clang++ 51 | ENV GOLANG_OS android 52 | ENV GOLANG_ARCH arm64 53 | ENV GOLANG_ARM 7 54 | RUN ./build-golang.sh 55 | ENV PATH ${PATH}:/usr/local/go/bin 56 | 57 | # Install libtorrent 58 | COPY scripts/build-libtorrent.sh /build/ 59 | ENV LT_CC ${CROSS_TRIPLE}-clang 60 | ENV LT_CXX ${CROSS_TRIPLE}-clang++ 61 | ENV LT_PTHREADS TRUE 62 | ENV LT_FLAGS -fPIC -fPIE 63 | ENV LT_CXXFLAGS -Wno-macro-redefined -Wno-c++11-extensions 64 | RUN ./build-libtorrent.sh 65 | -------------------------------------------------------------------------------- /docker/windows-x86.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:windows-x86 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Install Boost.System 30 | COPY scripts/build-boost.sh /build/ 31 | ENV BOOST_CC gcc 32 | ENV BOOST_CXX c++ 33 | ENV BOOST_OS mingw32 34 | ENV BOOST_TARGET_OS windows 35 | ENV BOOST_OPTS address-model=32 architecture=x86 threadapi=win32 36 | RUN ./build-boost.sh 37 | 38 | # Install OpenSSL 39 | COPY scripts/build-openssl.sh /build/ 40 | ENV OPENSSL_OPTS mingw 41 | RUN ./build-openssl.sh 42 | 43 | # Install SWIG 44 | COPY scripts/build-swig.sh /build/ 45 | RUN ./build-swig.sh 46 | 47 | # Install Golang 48 | COPY scripts/build-golang.sh /build/ 49 | ENV GOLANG_CC ${CROSS_TRIPLE}-cc 50 | ENV GOLANG_CXX ${CROSS_TRIPLE}-c++ 51 | ENV GOLANG_OS windows 52 | ENV GOLANG_ARCH 386 53 | RUN ./build-golang.sh 54 | ENV PATH ${PATH}:/usr/local/go/bin 55 | 56 | # Install libtorrent 57 | COPY scripts/build-libtorrent.sh /build/ 58 | ENV LT_CC ${CROSS_TRIPLE}-cc 59 | ENV LT_CXX ${CROSS_TRIPLE}-c++ 60 | ENV LT_FLAGS -lmswsock -DUNICODE -D_UNICODE -DWIN32 -DWIN32_LEAN_AND_MEAN -DIPV6_TCLASS=39 -D_WIN32_WINNT=0x0501 61 | ENV LT_CXXFLAGS -std=c++11 62 | ENV LT_LIBS -lmswsock 63 | RUN ./build-libtorrent.sh 64 | -------------------------------------------------------------------------------- /docker/windows-x64.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:windows-x64 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Install Boost.System 30 | COPY scripts/build-boost.sh /build/ 31 | ENV BOOST_CC gcc 32 | ENV BOOST_CXX c++ 33 | ENV BOOST_OS mingw64 34 | ENV BOOST_TARGET_OS windows 35 | ENV BOOST_OPTS address-model=64 architecture=x86 threadapi=win32 36 | RUN ./build-boost.sh 37 | 38 | # Install OpenSSL 39 | COPY scripts/build-openssl.sh /build/ 40 | ENV OPENSSL_OPTS mingw64 41 | RUN ./build-openssl.sh 42 | 43 | # Install SWIG 44 | COPY scripts/build-swig.sh /build/ 45 | RUN ./build-swig.sh 46 | 47 | # Install Golang 48 | COPY scripts/build-golang.sh /build/ 49 | ENV GOLANG_CC ${CROSS_TRIPLE}-cc 50 | ENV GOLANG_CXX ${CROSS_TRIPLE}-c++ 51 | ENV GOLANG_OS windows 52 | ENV GOLANG_ARCH amd64 53 | RUN ./build-golang.sh 54 | ENV PATH ${PATH}:/usr/local/go/bin 55 | 56 | # Install libtorrent 57 | COPY scripts/build-libtorrent.sh /build/ 58 | ENV LT_CC ${CROSS_TRIPLE}-cc 59 | ENV LT_CXX ${CROSS_TRIPLE}-c++ 60 | ENV LT_FLAGS -lmswsock -DUNICODE -D_UNICODE -DWIN32 -DWIN32_LEAN_AND_MEAN -DIPV6_TCLASS=39 -D_WIN32_WINNT=0x0600 61 | ENV LT_CXXFLAGS -std=c++11 62 | ENV LT_LIBS -lmswsock 63 | RUN ./build-libtorrent.sh 64 | -------------------------------------------------------------------------------- /interfaces/torrent_handle.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | %} 9 | 10 | %include 11 | %include 12 | %include 13 | 14 | // %template(stdVectorPeerInfo) std::vector; 15 | %template(stdVectorPartialPieceInfo) std::vector; 16 | %template(stdVectorAnnounceEntry) std::vector; 17 | %template(stdVectorTorrentHandle) std::vector; 18 | 19 | // Equaler interface 20 | %rename(Equal) libtorrent::torrent_handle::operator==; 21 | %rename(NotEqual) libtorrent::torrent_handle::operator!=; 22 | %rename(Less) libtorrent::torrent_handle::operator<; 23 | 24 | %array_class(libtorrent::block_info, block_info_list); 25 | 26 | %extend libtorrent::torrent_handle { 27 | const libtorrent::torrent_info* torrent_file() { 28 | return self->torrent_file().get(); 29 | } 30 | } 31 | %ignore libtorrent::torrent_handle::torrent_file; 32 | %ignore libtorrent::torrent_handle::use_interface; 33 | 34 | %extend libtorrent::partial_piece_info { 35 | block_info_list* blocks() { 36 | return block_info_list_frompointer(self->blocks); 37 | } 38 | } 39 | %ignore libtorrent::partial_piece_info::blocks; 40 | %ignore libtorrent::hash_value; 41 | %ignore libtorrent::block_info::peer; // linux_arm 42 | %ignore libtorrent::block_info::set_peer; // linux_arm 43 | 44 | %feature("director") torrent_handle; 45 | %feature("director") torrent_info; 46 | %feature("director") torrent_status; 47 | 48 | %include 49 | %include 50 | %include 51 | %include 52 | #include 53 | %include 54 | -------------------------------------------------------------------------------- /docker/android-arm.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:android-arm 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Install Boost.System 30 | COPY scripts/build-boost.sh /build/ 31 | ENV BOOST_CC clang 32 | ENV BOOST_CXX clang++ 33 | ENV BOOST_OS android 34 | ENV BOOST_TARGET_OS linux 35 | ENV BOOST_OPTS cxxflags=-fPIC cflags=-fPIC 36 | RUN ./build-boost.sh 37 | 38 | # Install OpenSSL 39 | COPY scripts/build-openssl.sh /build/ 40 | ENV OPENSSL_OPTS linux-armv4 41 | RUN ./build-openssl.sh 42 | 43 | # Install SWIG 44 | COPY scripts/build-swig.sh /build/ 45 | RUN ./build-swig.sh 46 | 47 | # Install Golang 48 | COPY scripts/build-golang.sh /build/ 49 | ENV GOLANG_CC ${CROSS_TRIPLE}-clang 50 | ENV GOLANG_CXX ${CROSS_TRIPLE}-clang++ 51 | ENV GOLANG_OS android 52 | ENV GOLANG_ARCH arm 53 | ENV GOLANG_ARM 7 54 | RUN ./build-golang.sh 55 | ENV PATH ${PATH}:/usr/local/go/bin 56 | 57 | # Install libtorrent 58 | COPY scripts/build-libtorrent.sh /build/ 59 | ENV LT_CC ${CROSS_TRIPLE}-clang 60 | ENV LT_CXX ${CROSS_TRIPLE}-clang++ 61 | ENV LT_PTHREADS TRUE 62 | ENV LT_FLAGS -fPIC -DINT64_MAX=0x7fffffffffffffffLL -DINT16_MAX=32767 -DINT16_MIN=-32768 -DTORRENT_PRODUCTION_ASSERTS 63 | ENV LT_CXXFLAGS -Wno-macro-redefined -Wno-c++11-extensions 64 | RUN ./build-libtorrent.sh 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | libtorrent-go [![Build Status](https://travis-ci.org/scakemyer/libtorrent-go.svg?branch=master)](https://travis-ci.org/scakemyer/libtorrent-go) 2 | ============= 3 | 4 | SWIG Go bindings for libtorrent-rasterbar 5 | 6 | Forked from 7 | 8 | 9 | Changes 10 | ------- 11 | 12 | + CamelCased identifier names 13 | + peer_info support 14 | + save and load resume_data support 15 | + crashes on Android ARM fixed 16 | 17 | Download and Build 18 | ------------------ 19 | 20 | + First, you need [Docker](https://docs.docker.com/engine/installation/) and [golang](https://golang.org/doc/install) 21 | 22 | + Create Go home folder and set $GOPATH environment variable: 23 | 24 | mkdir ~/go 25 | export GOPATH=~/go 26 | 27 | + Download libtorrent-go: 28 | 29 | go get github.com/scakemyer/libtorrent-go 30 | cd ~/go/src/github.com/scakemyer/libtorrent-go 31 | 32 | * Pull the cross-compiler image for your platform: 33 | 34 | make pull PLATFORM=android-arm 35 | 36 | + Next, you need to prepare Docker environments. You can do it with two ways: 37 | 38 | make envs 39 | 40 | This will download and build all needed development packages and could take hours. But it can be necessary if you want to make your own customizations. 41 | 42 | You can also prepare specific environments like so: 43 | 44 | make env PLATFORM=android-arm 45 | 46 | + Build libtorrent-go: 47 | 48 | make [ android-arm | android-arm64 | android-x86 | android-x64 | 49 | linux-x86 | linux-x64 | linux-arm | linux-armv7 | linux-arm64 | 50 | windows-x86 | windows-x64 | darwin-x64 ] 51 | 52 | To build libtorrent bindings for all platforms use `make` or specify needed platform, e.g. `make android-arm`. 53 | Built packages will be placed under `~/go/pkg/` 54 | 55 | 56 | Thanks 57 | ------ 58 | - [steeve](https://github.com/steeve) for his awesome work. 59 | - [dimitriss](https://github.com/dimitriss) for his great updates. 60 | -------------------------------------------------------------------------------- /docker/android-x64.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:android-x64 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Install Boost.System 30 | COPY scripts/build-boost.sh /build/ 31 | ENV BOOST_CC clang 32 | ENV BOOST_CXX clang++ 33 | ENV BOOST_OS android 34 | ENV BOOST_TARGET_OS linux 35 | ENV BOOST_OPTS cxxflags=-fPIC cflags=-fPIC 36 | RUN ./build-boost.sh 37 | 38 | # Install OpenSSL 39 | COPY scripts/build-openssl.sh /build/ 40 | ENV OPENSSL_OPTS linux-generic64 -fPIC 41 | RUN ./build-openssl.sh 42 | 43 | # Install SWIG 44 | COPY scripts/build-swig.sh /build/ 45 | RUN ./build-swig.sh 46 | 47 | # Install Golang 48 | COPY scripts/build-golang.sh /build/ 49 | ENV GOLANG_CC ${CROSS_TRIPLE}-clang 50 | ENV GOLANG_CXX ${CROSS_TRIPLE}-clang++ 51 | ENV GOLANG_OS android 52 | ENV GOLANG_ARCH amd64 53 | RUN ./build-golang.sh 54 | ENV PATH ${PATH}:/usr/local/go/bin 55 | 56 | # Install libtorrent 57 | COPY scripts/build-libtorrent.sh /build/ 58 | ENV LT_CC ${CROSS_TRIPLE}-clang 59 | ENV LT_CXX ${CROSS_TRIPLE}-clang++ 60 | ENV LT_PTHREADS TRUE 61 | ENV LT_FLAGS -fPIC -fPIE 62 | ENV LT_CXXFLAGS -Wno-macro-redefined -Wno-c++11-extensions 63 | RUN ./build-libtorrent.sh 64 | RUN ln -s ${CROSS_ROOT}/${CROSS_TRIPLE}/lib64/libgnustl_shared.so ${CROSS_ROOT}/${CROSS_TRIPLE}/lib/libgnustl_shared.so 65 | -------------------------------------------------------------------------------- /interfaces/std_map.i: -------------------------------------------------------------------------------- 1 | /* ----------------------------------------------------------------------------- 2 | * std_map.i 3 | * 4 | * SWIG typemaps for std::map 5 | * ----------------------------------------------------------------------------- */ 6 | 7 | %include 8 | 9 | // ------------------------------------------------------------------------ 10 | // std::map 11 | // ------------------------------------------------------------------------ 12 | 13 | %{ 14 | #include 15 | #include 16 | #include 17 | %} 18 | 19 | // exported class 20 | 21 | namespace std { 22 | 23 | template class map { 24 | // add typemaps here 25 | public: 26 | typedef size_t size_type; 27 | typedef ptrdiff_t difference_type; 28 | typedef K key_type; 29 | typedef T mapped_type; 30 | map(); 31 | map(const map &); 32 | 33 | unsigned int size() const; 34 | bool empty() const; 35 | void clear(); 36 | %extend { 37 | const T& get(const K& key) throw (std::out_of_range) { 38 | std::map::iterator i = self->find(key); 39 | if (i != self->end()) 40 | return i->second; 41 | else 42 | throw std::out_of_range("key not found"); 43 | } 44 | void set(const K& key, const T& x) { 45 | (*self)[key] = x; 46 | } 47 | void del(const K& key) throw (std::out_of_range) { 48 | std::map::iterator i = self->find(key); 49 | if (i != self->end()) 50 | self->erase(i); 51 | else 52 | throw std::out_of_range("key not found"); 53 | } 54 | bool has_key(const K& key) { 55 | std::map::iterator i = self->find(key); 56 | return i != self->end(); 57 | } 58 | const std::vector& keys() { 59 | std::vector keys_v; 60 | for(std::map::iterator iter = self->begin(); iter != self->end(); ++iter) { 61 | keys_v.push_back(iter->first); 62 | } 63 | return keys_v; 64 | } 65 | } 66 | }; 67 | } 68 | -------------------------------------------------------------------------------- /interfaces/session.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | %} 14 | 15 | %feature("director") session_handle; 16 | 17 | // These are problematic, so we ignore them. 18 | %ignore libtorrent::session_handle::add_extension; 19 | %ignore libtorrent::session_handle::dht_put_item; 20 | 21 | %template(stdVectorAlerts) std::vector; 22 | 23 | %extend libtorrent::session { 24 | libtorrent::session_handle* get_handle() { 25 | return self; 26 | } 27 | } 28 | %extend libtorrent::session_handle { 29 | std::vector pop_alerts() { 30 | std::vector alerts; 31 | self->pop_alerts(&alerts); 32 | return alerts; 33 | } 34 | } 35 | %ignore libtorrent::session_handle::pop_alerts; 36 | 37 | %include "extensions.i" 38 | %include 39 | %include 40 | %include 41 | %include 42 | %include 43 | %include 44 | %include 45 | %include 46 | %include 47 | %include 48 | %include 49 | 50 | %extend libtorrent::settings_pack { 51 | void set_bool(std::string const& name, bool val) { 52 | $self->set_bool(libtorrent::setting_by_name(name), val); 53 | }; 54 | void set_int(std::string const& name, int val) { 55 | $self->set_int(libtorrent::setting_by_name(name), val); 56 | }; 57 | void set_str(std::string const& name, std::string const& val) { 58 | $self->set_str(libtorrent::setting_by_name(name), val); 59 | }; 60 | bool get_bool(std::string const& name) const { 61 | return $self->get_bool(libtorrent::setting_by_name(name)); 62 | } 63 | int get_int(std::string const& name) const { 64 | return $self->get_int(libtorrent::setting_by_name(name)); 65 | } 66 | std::string get_str(std::string const& name) const { 67 | return $self->get_str(libtorrent::setting_by_name(name)); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /docker/darwin-x64.Dockerfile: -------------------------------------------------------------------------------- 1 | FROM cross-compiler:darwin-x64 2 | 3 | RUN mkdir -p /build 4 | WORKDIR /build 5 | 6 | ARG BOOST_VERSION 7 | ARG BOOST_VERSION_FILE 8 | ARG BOOST_SHA256 9 | ARG OPENSSL_VERSION 10 | ARG OPENSSL_SHA256 11 | ARG SWIG_VERSION 12 | ARG SWIG_SHA256 13 | ARG GOLANG_VERSION 14 | ARG GOLANG_SRC_URL 15 | ARG GOLANG_SRC_SHA256 16 | ARG GOLANG_BOOTSTRAP_VERSION 17 | ARG GOLANG_BOOTSTRAP_URL 18 | ARG GOLANG_BOOTSTRAP_SHA256 19 | ARG LIBTORRENT_VERSION 20 | 21 | # Local testing 22 | # COPY files/boost_${BOOST_VERSION_FILE}.tar.bz2 /build/ 23 | # COPY files/openssl-${OPENSSL_VERSION}.tar.gz /build/ 24 | # COPY files/swig-${SWIG_VERSION}.tar.gz /build/ 25 | # COPY files/go${GOLANG_VERSION}.src.tar.gz /build/golang.tar.gz 26 | # COPY files/go${GOLANG_BOOTSTRAP_VERSION}.tar.gz /build/golang-bootstrap.tar.gz 27 | # COPY files/${LIBTORRENT_VERSION}.tar.gz /build/ 28 | 29 | # Fix Boost using wrong archiver / ignoring flags 30 | # https://svn.boost.org/trac/boost/ticket/12573 31 | # https://github.com/boostorg/build/blob/boost-1.63.0/src/tools/clang-darwin.jam#L133 32 | RUN mv /usr/bin/ar /usr/bin/ar.orig && \ 33 | mv /usr/bin/strip /usr/bin/strip.orig && \ 34 | mv /usr/bin/ranlib /usr/bin/ranlib.orig && \ 35 | ln -sf ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-ar /usr/bin/ar && \ 36 | ln -sf ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-strip /usr/bin/strip && \ 37 | ln -sf ${CROSS_ROOT}/bin/${CROSS_TRIPLE}-ranlib /usr/bin/ranlib 38 | 39 | # Install Boost.System 40 | COPY scripts/build-boost.sh /build/ 41 | ENV BOOST_CC clang 42 | ENV BOOST_CXX c++ 43 | ENV BOOST_OS darwin 44 | ENV BOOST_TARGET_OS darwin 45 | ENV BOOST_BOOTSTRAP --with-toolset=clang 46 | RUN ./build-boost.sh 47 | 48 | # Move back ar, strip and ranlib... 49 | RUN mv /usr/bin/ar.orig /usr/bin/ar && \ 50 | mv /usr/bin/strip.orig /usr/bin/strip && \ 51 | mv /usr/bin/ranlib.orig /usr/bin/ranlib 52 | 53 | # Install OpenSSL 54 | COPY scripts/build-openssl.sh /build/ 55 | ENV OPENSSL_OPTS darwin64-x86_64-cc 56 | RUN ./build-openssl.sh 57 | 58 | # Install SWIG 59 | COPY scripts/build-swig.sh /build/ 60 | RUN ./build-swig.sh 61 | 62 | # Install Golang 63 | COPY scripts/build-golang.sh /build/ 64 | ENV GOLANG_CC ${CROSS_TRIPLE}-cc 65 | ENV GOLANG_CXX ${CROSS_TRIPLE}-c++ 66 | ENV GOLANG_OS darwin 67 | ENV GOLANG_ARCH amd64 68 | RUN ./build-golang.sh 69 | ENV PATH ${PATH}:/usr/local/go/bin 70 | 71 | # Install libtorrent 72 | COPY scripts/build-libtorrent.sh /build/ 73 | ENV LT_CC ${CROSS_TRIPLE}-cc 74 | ENV LT_CXX ${CROSS_TRIPLE}-c++ 75 | ENV LT_OSXCROSS TRUE 76 | ENV LT_CXXFLAGS -Wno-c++11-extensions -Wno-c++11-long-long 77 | RUN ./build-libtorrent.sh 78 | -------------------------------------------------------------------------------- /interfaces/dht.i: -------------------------------------------------------------------------------- 1 | %{ 2 | #include 3 | #include 4 | #include 5 | #include 6 | %} 7 | 8 | %{ 9 | namespace libtorrent { 10 | class dht_put_operation { 11 | public: 12 | entry *data; 13 | boost::array public_key; 14 | boost::array private_key; 15 | std::string salt; 16 | 17 | dht_put_operation(unsigned char* public_key, unsigned char* private_key) { 18 | for (int i = 0; i < 32; i++) { 19 | this->public_key[i] = public_key[i]; 20 | } 21 | for (int i = 0; i < 64; i++) { 22 | this->private_key[i] = private_key[i]; 23 | } 24 | } 25 | }; 26 | 27 | class dht_get_operation { 28 | public: 29 | entry *data; 30 | boost::array public_key; 31 | std::string salt; 32 | 33 | dht_get_operation(unsigned char* public_key) { 34 | for (int i = 0; i < 32; i++) { 35 | this->public_key[i] = public_key[i]; 36 | } 37 | } 38 | }; 39 | 40 | void dht_put_item_cb(entry& e, boost::array& sig, boost::uint64_t& seq, 41 | std::string const& salt, char const* public_key, char const* private_key, 42 | entry& data) 43 | { 44 | e = data; 45 | std::vector buf; 46 | bencode(std::back_inserter(buf), e); 47 | seq++; 48 | libtorrent::dht::sign_mutable_item( 49 | std::pair(buf.data(), buf.size()), 50 | std::pair(salt.data(), salt.size()), 51 | seq, 52 | public_key, 53 | private_key, 54 | sig.data()); 55 | } 56 | } 57 | %} 58 | 59 | namespace libtorrent { 60 | class dht_put_operation { 61 | public: 62 | entry *data; 63 | boost::array public_key; 64 | boost::array private_key; 65 | std::string salt; 66 | 67 | dht_put_operation(unsigned char* INOUT, unsigned char* INOUT); 68 | }; 69 | 70 | class dht_get_operation { 71 | public: 72 | entry *data; 73 | boost::array public_key; 74 | std::string salt; 75 | 76 | dht_get_operation(unsigned char* INOUT); 77 | }; 78 | } 79 | 80 | %extend libtorrent::session { 81 | libtorrent::sha1_hash dht_put_item(entry& item) { 82 | return $self->dht_put_item(item); 83 | } 84 | 85 | void dht_get_item(libtorrent::dht_get_operation& op) { 86 | $self->dht_get_item(op.public_key, op.salt); 87 | } 88 | 89 | void dht_put_mutable_item(libtorrent::dht_put_operation& op) { 90 | $self->dht_put_item( 91 | op.public_key, 92 | boost::bind( 93 | &libtorrent::dht_put_item_cb, _1, _2, _3, _4, 94 | op.public_key.data(), op.private_key.data(), *op.data), 95 | op.salt); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /.gitlab-ci.yml: -------------------------------------------------------------------------------- 1 | image: docker:latest 2 | services: 3 | - docker:dind 4 | variables: 5 | DOCKER_DRIVER: overlay 6 | GOPATH: $CI_PROJECT_DIR/../gopath 7 | 8 | stages: 9 | - build 10 | - push 11 | 12 | before_script: 13 | - docker info 14 | - mkdir -p $GOPATH 15 | - apk update 16 | - apk add make 17 | 18 | .build_template: &build_definition 19 | script: 20 | - make pull 21 | - make env 22 | - make $PLATFORM 23 | except: 24 | - tags 25 | 26 | .push_template: &push_definition 27 | script: 28 | - make pull 29 | - make env 30 | - make $PLATFORM 31 | after_script: 32 | - docker login -u="${DOCKER_USERNAME}" -p="${DOCKER_PASSWORD}" 33 | - make push 34 | only: 35 | - tags 36 | 37 | android-arm: 38 | stage: build 39 | variables: 40 | PLATFORM: android-arm 41 | <<: *build_definition 42 | android-arm-hub: 43 | stage: push 44 | variables: 45 | PLATFORM: android-arm 46 | <<: *push_definition 47 | 48 | android-arm64: 49 | stage: build 50 | variables: 51 | PLATFORM: android-arm64 52 | <<: *build_definition 53 | android-arm64-hub: 54 | stage: push 55 | variables: 56 | PLATFORM: android-arm64 57 | <<: *push_definition 58 | 59 | android-x64: 60 | stage: build 61 | variables: 62 | PLATFORM: android-x64 63 | <<: *build_definition 64 | android-x64-hub: 65 | stage: push 66 | variables: 67 | PLATFORM: android-x64 68 | <<: *push_definition 69 | 70 | android-x86: 71 | stage: build 72 | variables: 73 | PLATFORM: android-x86 74 | <<: *build_definition 75 | android-x86-hub: 76 | stage: push 77 | variables: 78 | PLATFORM: android-x86 79 | <<: *push_definition 80 | 81 | darwin-x64: 82 | stage: build 83 | variables: 84 | PLATFORM: darwin-x64 85 | <<: *build_definition 86 | darwin-x64-hub: 87 | stage: push 88 | variables: 89 | PLATFORM: darwin-x64 90 | <<: *push_definition 91 | 92 | linux-arm: 93 | stage: build 94 | variables: 95 | PLATFORM: linux-arm 96 | <<: *build_definition 97 | linux-arm-hub: 98 | stage: push 99 | variables: 100 | PLATFORM: linux-arm 101 | <<: *push_definition 102 | 103 | linux-armv7: 104 | stage: build 105 | variables: 106 | PLATFORM: linux-armv7 107 | <<: *build_definition 108 | android-armv7-hub: 109 | stage: push 110 | variables: 111 | PLATFORM: linux-armv7 112 | <<: *push_definition 113 | 114 | linux-arm64: 115 | stage: build 116 | variables: 117 | PLATFORM: linux-arm64 118 | <<: *build_definition 119 | linux-arm64-hub: 120 | stage: push 121 | variables: 122 | PLATFORM: linux-arm64 123 | <<: *push_definition 124 | 125 | linux-x64: 126 | stage: build 127 | variables: 128 | PLATFORM: linux-x64 129 | <<: *build_definition 130 | linux-x64-hub: 131 | stage: push 132 | variables: 133 | PLATFORM: linux-x64 134 | <<: *push_definition 135 | 136 | linux-x86: 137 | stage: build 138 | variables: 139 | PLATFORM: linux-x86 140 | <<: *build_definition 141 | linux-x86-hub: 142 | stage: push 143 | variables: 144 | PLATFORM: linux-x86 145 | <<: *push_definition 146 | 147 | windows-x64: 148 | stage: build 149 | variables: 150 | PLATFORM: windows-x64 151 | <<: *build_definition 152 | windows-x64-hub: 153 | stage: push 154 | variables: 155 | PLATFORM: windows-x64 156 | <<: *push_definition 157 | 158 | windows-x86: 159 | stage: build 160 | variables: 161 | PLATFORM: windows-x86 162 | <<: *build_definition 163 | windows-x86-hub: 164 | stage: push 165 | variables: 166 | PLATFORM: windows-x86 167 | <<: *push_definition 168 | -------------------------------------------------------------------------------- /libtorrent.swigcxx: -------------------------------------------------------------------------------- 1 | %module (directors="1") libtorrent 2 | 3 | #pragma SWIG nowarn=204 // CPP #warning, ""unknown OS, assuming BSD"", ""unknown platform, assuming the longest path is 255"". 4 | #pragma SWIG nowarn=302 // Identifier 'GetCArray' redefined (ignored) (Renamed from 'get_c_array'), previous definition of 'GetCArray' (Renamed from 'get_c_array'). 5 | #pragma SWIG nowarn=312 // Nested union not currently supported (ignored). 6 | #pragma SWIG nowarn=314 // 'range' is a Go keyword, renaming to 'Xrange' 7 | #pragma SWIG nowarn=315 // Nothing known about 'boost::asio::ip::tcp'. 8 | #pragma SWIG nowarn=317 // Specialization of non-template ''. 9 | #pragma SWIG nowarn=319 // No access specifier given for base class 'boost::noncopyable' (ignored). 10 | #pragma SWIG nowarn=325 // Nested struct not currently supported (const_iterator ignored) 11 | #pragma SWIG nowarn=341 // The 'using' keyword in type aliasing is not fully supported yet. 12 | #pragma SWIG nowarn=401 // Nothing known about base class ''. Ignored. 13 | #pragma SWIG nowarn=402 // Base class '' is incomplete. 14 | #pragma SWIG nowarn=451 // Setting a const char * variable may leak memory. 15 | #pragma SWIG nowarn=503 // Can't wrap 'Operator ...' unless renamed to a valid identifier. 16 | #pragma SWIG nowarn=516 // Overloaded method ... ignored, using ... instead. 17 | #pragma SWIG nowarn=890 // Ignoring '...' due to Go name ('...') conflict with '...' 18 | 19 | %{ 20 | // #include 21 | // #include 22 | %} 23 | 24 | %include 25 | %include 26 | %include 27 | 28 | #define BOOST_POSIX_API 29 | #define BOOST_NO_TYPEID 30 | #define BOOST_SYSTEM_CONSTEXPR 31 | #define TORRENT_NO_DEPRECATE 32 | 33 | namespace std { 34 | typedef int time_t; 35 | 36 | %template(stdVectorInt) vector; 37 | %template(stdVectorChar) vector; 38 | %template(stdVectorSizeType) vector; 39 | %template(stdPairIntInt) pair; 40 | %template(stdPairStringInt) pair; 41 | } 42 | 43 | namespace boost { 44 | typedef ::int64_t int64_t; 45 | } 46 | 47 | namespace libtorrent 48 | { 49 | class time_duration; 50 | 51 | time_duration milliseconds(int64_t n) { 52 | return boost::chrono::milliseconds(n); 53 | } 54 | time_duration seconds(int64_t n) { 55 | return boost::chrono::seconds(n); 56 | } 57 | } 58 | 59 | %rename("%(camelcase)s", %$isclass) ""; 60 | %rename("%(camelcase)s", %$isvariable) ""; 61 | %rename("%(camelcase)s", %$isenumitem) ""; 62 | %rename("%(camelcase)s", %$isenum) ""; 63 | %rename("%(camelcase)s", %$istemplate) ""; 64 | %rename("%(camelcase)s", %$isfunction) ""; 65 | %rename("%(camelcase)s", %$isnamespace) ""; 66 | 67 | // These are problematic, ignore them for now 68 | %ignore libtorrent::throw_invalid_handle; 69 | %ignore libtorrent::web_seed_entry; 70 | %ignore libtorrent::boosttime_deprecated_; 71 | 72 | %ignore libtorrent::time_now_string; 73 | %ignore libtorrent::merkle_num_leafs; 74 | %ignore libtorrent::merkle_num_nodes; 75 | %ignore libtorrent::merkle_get_parent; 76 | %ignore libtorrent::trim_path_element; 77 | %ignore libtorrent::merkle_get_sibling; 78 | %ignore libtorrent::detail::get_symlink_path; 79 | %ignore libtorrent::detail::get_file_attributes; 80 | %ignore libtorrent::log_time; 81 | %ignore libtorrent::parse_int; 82 | %ignore libtorrent::blockinfo::setpeer; 83 | 84 | // Windows... 85 | %ignore libtorrent::file_status::block_special; 86 | %ignore libtorrent::file_status::link; 87 | %ignore libtorrent::file_status::socket; 88 | 89 | %include 90 | %include 91 | %include 92 | %include 93 | %include 94 | %include 95 | 96 | %include 97 | %include 98 | 99 | %include "interfaces/boost_array.i" 100 | 101 | %include 102 | %include 103 | %include 104 | %include 105 | %include 106 | %include 107 | 108 | %include "interfaces/bitfield.i" 109 | %include "interfaces/socket.i" 110 | %include 111 | %include "interfaces/torrent_info.i" 112 | %include 113 | %include 114 | %include "interfaces/peer_info.i" 115 | %include "interfaces/torrent_handle.i" 116 | %include "interfaces/add_torrent_params.i" 117 | %include "interfaces/alert.i" 118 | %include "interfaces/alert_types.i" 119 | %include "interfaces/create_torrent.i" 120 | %include "interfaces/session.i" 121 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | PROJECT = quasarhq 2 | NAME = libtorrent-go 3 | GO_PACKAGE = github.com/scakemyer/$(NAME) 4 | CC = cc 5 | CXX = c++ 6 | PKG_CONFIG = pkg-config 7 | DOCKER = docker 8 | DOCKER_IMAGE = $(NAME) 9 | PLATFORMS = \ 10 | android-arm \ 11 | android-arm64 \ 12 | android-x64 \ 13 | android-x86 \ 14 | darwin-x64 \ 15 | linux-arm \ 16 | linux-armv7 \ 17 | linux-arm64 \ 18 | linux-x64 \ 19 | linux-x86 \ 20 | windows-x64 \ 21 | windows-x86 22 | 23 | BOOST_VERSION = 1.69.0 24 | BOOST_VERSION_FILE = $(shell echo $(BOOST_VERSION) | sed s/\\./_/g) 25 | BOOST_SHA256 = 8f32d4617390d1c2d16f26a27ab60d97807b35440d45891fa340fc2648b04406 26 | 27 | OPENSSL_VERSION = 1.1.1b 28 | OPENSSL_SHA256 = 5c557b023230413dfb0756f3137a13e6d726838ccd1430888ad15bfb2b43ea4b 29 | 30 | # SWIG_VERSION = fbeb566014a1d320df972aef965daf042db7db36 # 3.0.12 31 | # SWIG_SHA256 = 64971de92b8a1da0b9ffb4b51e9214bb936c4dbbc304367899cdb07280b94af6 32 | SWIG_VERSION = be491506a4036f627778b71641dff1fdf66b9a67 # master on 2019/03/01 33 | SWIG_SHA256 = c8d87a9bd8c01dfb7883b9341e13742b3f209cf817fd0d72232f434e061538ff 34 | 35 | GOLANG_VERSION = 1.12 36 | GOLANG_SRC_URL = https://golang.org/dl/go$(GOLANG_VERSION).src.tar.gz 37 | GOLANG_SRC_SHA256 = 09c43d3336743866f2985f566db0520b36f4992aea2b4b2fd9f52f17049e88f2 38 | 39 | GOLANG_BOOTSTRAP_VERSION = 1.4-bootstrap-20170531 40 | GOLANG_BOOTSTRAP_URL = https://dl.google.com/go/go$(GOLANG_BOOTSTRAP_VERSION).tar.gz 41 | GOLANG_BOOTSTRAP_SHA256 = 49f806f66762077861b7de7081f586995940772d29d4c45068c134441a743fa2 42 | 43 | LIBTORRENT_VERSION = RC_1_1 44 | 45 | include platform_host.mk 46 | 47 | ifneq ($(CROSS_TRIPLE),) 48 | CC := $(CROSS_TRIPLE)-$(CC) 49 | CXX := $(CROSS_TRIPLE)-$(CXX) 50 | endif 51 | 52 | include platform_target.mk 53 | 54 | ifeq ($(TARGET_ARCH), x86) 55 | GOARCH = 386 56 | else ifeq ($(TARGET_ARCH), x64) 57 | GOARCH = amd64 58 | else ifeq ($(TARGET_ARCH), arm) 59 | GOARCH = arm 60 | GOARM = 6 61 | else ifeq ($(TARGET_ARCH), armv7) 62 | GOARCH = arm 63 | GOARM = 7 64 | PATH_SUFFIX = v7 65 | PKGDIR = -pkgdir /go/pkg/linux_armv7 66 | else ifeq ($(TARGET_ARCH), arm64) 67 | GOARCH = arm64 68 | GOARM = 69 | endif 70 | 71 | ifeq ($(TARGET_OS), windows) 72 | GOOS = windows 73 | else ifeq ($(TARGET_OS), darwin) 74 | GOOS = darwin 75 | else ifeq ($(TARGET_OS), linux) 76 | GOOS = linux 77 | else ifeq ($(TARGET_OS), android) 78 | GOOS = android 79 | ifeq ($(TARGET_ARCH), arm) 80 | GOARM = 7 81 | else 82 | GOARM = 83 | endif 84 | GO_LDFLAGS = -extldflags=-pie 85 | endif 86 | 87 | ifneq ($(CROSS_ROOT),) 88 | CROSS_CFLAGS = -I$(CROSS_ROOT)/include -I$(CROSS_ROOT)/$(CROSS_TRIPLE)/include 89 | CROSS_LDFLAGS = -L$(CROSS_ROOT)/lib 90 | PKG_CONFIG_PATH = $(CROSS_ROOT)/lib/pkgconfig 91 | endif 92 | 93 | LIBTORRENT_CFLAGS = $(CFLAGS) $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --cflags libtorrent-rasterbar) -std=c++11 94 | LIBTORRENT_LDFLAGS = $(LDFLAGS) $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) $(PKG_CONFIG) --static --libs libtorrent-rasterbar) 95 | DEFINE_IGNORES = __STDC__|_cdecl|__cdecl|_fastcall|__fastcall|_stdcall|__stdcall|__declspec 96 | CC_DEFINES = $(shell echo | $(CC) -dM -E - | grep -v -E "$(DEFINE_IGNORES)" | sed -E "s/\#define[[:space:]]+([a-zA-Z0-9_()]+)[[:space:]]+(.*)/-D\1="\2"/g" | tr '\n' ' ') 97 | 98 | ifeq ($(TARGET_OS), windows) 99 | CC_DEFINES += -DSWIGWIN 100 | CC_DEFINES += -D_WIN32_WINNT=0x0600 101 | ifeq ($(TARGET_ARCH), x64) 102 | CC_DEFINES += -DSWIGWORDSIZE32 103 | endif 104 | else ifeq ($(TARGET_OS), darwin) 105 | CC = $(CROSS_ROOT)/bin/$(CROSS_TRIPLE)-clang 106 | CXX = $(CROSS_ROOT)/bin/$(CROSS_TRIPLE)-clang++ 107 | CC_DEFINES += -DSWIGMAC 108 | CC_DEFINES += -DBOOST_HAS_PTHREADS 109 | else ifeq ($(TARGET_OS), android) 110 | CC = $(CROSS_ROOT)/bin/$(CROSS_TRIPLE)-clang 111 | CXX = $(CROSS_ROOT)/bin/$(CROSS_TRIPLE)-clang++ 112 | GO_LDFLAGS += -flto 113 | endif 114 | 115 | 116 | OUT_PATH = $(shell go env GOPATH)/pkg/$(GOOS)_$(GOARCH)$(PATH_SUFFIX) 117 | OUT_LIBRARY = $(OUT_PATH)/$(GO_PACKAGE).a 118 | 119 | .PHONY: $(PLATFORMS) 120 | 121 | all: 122 | for i in $(PLATFORMS); do \ 123 | $(MAKE) $$i; \ 124 | done 125 | 126 | $(PLATFORMS): 127 | ifeq ($@, all) 128 | $(MAKE) all 129 | else 130 | $(DOCKER) run --rm -v $(GOPATH):/go -v $(shell pwd):/go/src/$(GO_PACKAGE) -w /go/src/$(GO_PACKAGE) -e GOPATH=/go $(DOCKER_IMAGE):$@ make re; 131 | endif 132 | 133 | build: 134 | SWIG_FLAGS='$(CC_DEFINES) $(LIBTORRENT_CFLAGS)' \ 135 | CC=$(CC) CXX=$(CXX) \ 136 | PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) \ 137 | CGO_ENABLED=1 \ 138 | GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) \ 139 | PATH=.:$$PATH \ 140 | go install -v -ldflags '$(GO_LDFLAGS)' -x $(PKGDIR) 141 | 142 | clean: 143 | rm -rf $(OUT_LIBRARY) 144 | 145 | re: clean build 146 | 147 | env: 148 | $(DOCKER) build \ 149 | --build-arg BOOST_VERSION=$(BOOST_VERSION) \ 150 | --build-arg BOOST_VERSION_FILE=$(BOOST_VERSION_FILE) \ 151 | --build-arg BOOST_SHA256=$(BOOST_SHA256) \ 152 | --build-arg OPENSSL_VERSION=$(OPENSSL_VERSION) \ 153 | --build-arg OPENSSL_SHA256=$(OPENSSL_SHA256) \ 154 | --build-arg SWIG_VERSION=$(SWIG_VERSION) \ 155 | --build-arg SWIG_SHA256=$(SWIG_SHA256) \ 156 | --build-arg GOLANG_VERSION=$(GOLANG_VERSION) \ 157 | --build-arg GOLANG_SRC_URL=$(GOLANG_SRC_URL) \ 158 | --build-arg GOLANG_SRC_SHA256=$(GOLANG_SRC_SHA256) \ 159 | --build-arg GOLANG_BOOTSTRAP_VERSION=$(GOLANG_BOOTSTRAP_VERSION) \ 160 | --build-arg GOLANG_BOOTSTRAP_URL=$(GOLANG_BOOTSTRAP_URL) \ 161 | --build-arg GOLANG_BOOTSTRAP_SHA256=$(GOLANG_BOOTSTRAP_SHA256) \ 162 | --build-arg LIBTORRENT_VERSION=$(LIBTORRENT_VERSION) \ 163 | -t $(DOCKER_IMAGE):$(PLATFORM) \ 164 | -f docker/$(PLATFORM).Dockerfile docker 165 | 166 | envs: 167 | for i in $(PLATFORMS); do \ 168 | $(MAKE) env PLATFORM=$$i; \ 169 | done 170 | 171 | pull: 172 | docker pull $(PROJECT)/cross-compiler:$(PLATFORM) 173 | docker tag $(PROJECT)/cross-compiler:$(PLATFORM) cross-compiler:$(PLATFORM) 174 | 175 | push: 176 | docker tag libtorrent-go:$(PLATFORM) $(PROJECT)/libtorrent-go:$(PLATFORM) 177 | docker push $(PROJECT)/libtorrent-go:$(PLATFORM) 178 | 179 | runtest: 180 | CC=${CC} CXX=$(CXX) \ 181 | PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) \ 182 | CGO_ENABLED=1 \ 183 | GOOS=$(GOOS) GOARCH=$(GOARCH) GOARM=$(GOARM) \ 184 | PATH=.:$$PATH \ 185 | cd test; go run -x test.go; cd .. 186 | 187 | retest: 188 | $(DOCKER) run --rm -v $(GOPATH):/go -v $(shell pwd):/go/src/$(GO_PACKAGE) -w /go/src/$(GO_PACKAGE) -e GOPATH=/go $(DOCKER_IMAGE):linux-x64 make runtest; 189 | --------------------------------------------------------------------------------