Commit a2426162 authored by Ivan Vilata-i-Balaguer's avatar Ivan Vilata-i-Balaguer
Browse files

Merge branch 'master' into multi-peer-reader

parents e2b66860 44794e30
......@@ -121,6 +121,7 @@ file(GLOB client_sources
"./src/util/reachability.cpp"
"./src/util.cpp"
"./src/util/handler_tracker.cpp"
"./src/doh.cpp"
"./src/http_util.cpp"
${VERSION_CPP}
)
......@@ -140,6 +141,7 @@ target_link_libraries(client
Boost::iostreams
lib::asio_utp
cpp_upnp
lib::zdnsparser
lib::gcrypt
lib::json
lib::uri
......
......@@ -31,7 +31,7 @@ FROM base as builder
# This version is a recommendation and this file has been tested to work for it,
# but you may attempt to build other versions by overriding this argument.
# Also see `OUINET_DOCKER_VERSION` below.
ARG OUINET_VERSION=v0.7.3
ARG OUINET_VERSION=v0.8.1
RUN git clone --recursive -b "$OUINET_VERSION" https://github.com/equalitie/ouinet.git
WORKDIR /opt/ouinet
# The C.UTF-8 locale (which is always available in Debian)
......@@ -43,7 +43,7 @@ RUN cp -r /usr/local/src/ouinet/repos/ repo-templates/
ARG OUINET_DEBUG=no
RUN \
if [ $OUINET_DEBUG != yes ]; then \
strip injector client src/ouiservice/obfs4proxy/obfs4proxy \
strip injector client src/ouiservice/obfs4proxy/obfs4proxy test/bt-* test/oui-* \
&& find . -name '*.so' -exec strip '{}' + \
&& find . -wholename '*/libexec/*' -executable -type f -exec strip '{}' + ; \
fi
......@@ -80,6 +80,7 @@ RUN apt-get update && apt-get install -y \
$(echo $OUINET_DEBUG | sed -n 's/^yes$/gdb/p') \
\
lsb-release \
netcat-openbsd \
wget \
&& rm -rf /var/lib/apt/lists/*
# Fetch and install i2pd.
......@@ -104,6 +105,11 @@ RUN ldconfig
COPY --from=builder /opt/ouinet/injector /opt/ouinet/client ./
COPY --from=builder /opt/ouinet/src/ouiservice/obfs4proxy/obfs4proxy ./
COPY --from=builder /opt/ouinet/repo-templates/ repo-templates/
RUN mkdir utils
COPY --from=builder \
/opt/ouinet/test/bt-* /opt/ouinet/test/oui-* \
/usr/local/src/ouinet/scripts/ping-swarm \
utils/
# This ensures that we use the desired Docker-specific files.
RUN echo "$OUINET_DOCKER_VERSION"
COPY --from=builder /usr/local/src/ouinet/scripts/ouinet-wrapper.sh ouinet
......
......@@ -477,6 +477,11 @@ Otherwise you may manually [modify your browser's settings][Firefox proxy] to:
[Firefox proxy]: http://www.wikihow.com/Enter-Proxy-Settings-in-Firefox
"How to Enter Proxy Settings in Firefox"
Additionally, you may want to disable Firefox's automatic captive portal
detection so that you get less noise in client logs. Enter `about:config` in
the location bar and change `network.captive-portal-service.enabled` to
`false`.
Once done, you can visit `localhost` in your browser and it should show you
the *client front-end* with assorted information from the client and
configuration tools:
......
......@@ -2,6 +2,7 @@
include(${CMAKE_CURRENT_LIST_DIR}/dependencies/openssl.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/dependencies/boost.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/dependencies/zdnsparser.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/dependencies/gcrypt.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/dependencies/golang.cmake)
include(${CMAKE_CURRENT_LIST_DIR}/dependencies/json.cmake)
......
include(ExternalProject)
set(ZDNSPARSER_FILENAME
"${CMAKE_CURRENT_BINARY_DIR}/zdnsparser/src/zdnsparser-build/lib/${CMAKE_STATIC_LIBRARY_PREFIX}zdnsparser${CMAKE_STATIC_LIBRARY_SUFFIX}"
)
set(PATCHES
${CMAKE_CURRENT_LIST_DIR}/zdnsparser/disable-tests.patch
${CMAKE_CURRENT_LIST_DIR}/zdnsparser/virtual-destructors.patch
)
set(PATCH_COMMAND
cd ${CMAKE_CURRENT_BINARY_DIR}/zdnsparser/src/zdnsparser
)
foreach (patch ${PATCHES})
set(PATCH_COMMAND ${PATCH_COMMAND} && patch -p1 -i ${patch})
endforeach()
externalproject_add(zdnsparser
# The specified commit supports answers with QNAME format,
# as indicated in <https://github.com/packetzero/dnsparser/pull/3>.
# Some DoH servers use the mentioned answer format.
GIT_REPOSITORY https://github.com/packetzero/dnsparser
GIT_TAG ad79c9b681f6afede9e9af8837159e1b2fbdb836
PATCH_COMMAND "${PATCH_COMMAND}"
UPDATE_COMMAND ""
INSTALL_COMMAND ""
CMAKE_ARGS
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}
-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}
-DANDROID_ABI=${ANDROID_ABI}
-DANDROID_PLATFORM=${ANDROID_PLATFORM}
BUILD_BYPRODUCTS ${ZDNSPARSER_FILENAME}
PREFIX "zdnsparser"
)
add_library(lib_zdnsparser INTERFACE)
add_dependencies(lib_zdnsparser zdnsparser)
add_library(lib::zdnsparser ALIAS lib_zdnsparser)
target_include_directories(lib_zdnsparser
INTERFACE
"${CMAKE_CURRENT_BINARY_DIR}/zdnsparser/src/zdnsparser/include"
)
target_link_libraries(lib_zdnsparser
INTERFACE ${ZDNSPARSER_FILENAME}
)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1fa1462..6e9e8d8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,5 +24,4 @@ include(cmake/cxx_flag_overrides.cmake)
# subdirs
add_subdirectory(src)
-add_subdirectory(test)
diff --git a/include/dnsparser.h b/include/dnsparser.h
index 4d81ea3..5dfaa6c 100644
--- a/include/dnsparser.h
+++ b/include/dnsparser.h
@@ -18,6 +18,8 @@
class DnsParserListener
{
public:
+ virtual ~DnsParserListener() = default;
+
/**
* @param addr Binary IPV4 or IPV6 address in network order.
* @param name Domain name requested.
@@ -30,6 +32,8 @@ public:
class DnsParser
{
public:
+ virtual ~DnsParser() = default;
+
/**
* parse
* When response records are discovered, DnsParserListener.onDnsRec()
......@@ -26,6 +26,7 @@ json;Niels Lohmann;${BUILD}/json/src/json/LICENSE.MIT
uri;Glyn Matthews;${BUILD}/uri/src/uri/LICENSE_1_0.txt
asio-utp;Peter Jankuliak;${SRC}/modules/asio-utp/LICENSE.txt
lampshade;various;${BUILD}/src/ouiservice/lampshade/lampshade-prefix/src/lampshade/LICENSE
zdnsparser;various;${SRC}/scripts/licenses/Apache-2.0
"
echo "$LICENSE_DATA" | (
......
......@@ -75,38 +75,6 @@ echo "NDK_DIR: "$NDK_DIR
echo "SDK_DIR: "$SDK_DIR
echo "PLATFORM: "$PLATFORM
######################################################################
# This variable shall contain paths to generated libraries which
# must all be included in the final Android package.
OUT_LIBS=()
function add_library {
local libs=("$@") lib
for lib in "${libs[@]}"; do
if [ ! -f "$lib" ]; then
echo "Cannot add library \"$lib\": File doesn't exist"
exit 1
fi
OUT_LIBS+=("$lib")
done
}
######################################################################
# This variable shall contain paths to generated binaries which
# must all be included in the final Android package.
OUT_BINARIES=()
function add_binary {
local binaries=("$@") binaries
for binary in "${binaries[@]}"; do
if [ ! -f "$binary" ]; then
echo "Cannot add binary \"$binary\": File doesn't exist"
exit 1
fi
OUT_BINARIES+=("$binary")
done
}
######################################################################
MODES=
ALLOWED_MODES="bootstrap build emu"
......
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#!/bin/sh
# Ping the given Ouinet swarms using BEP5.
#
# Usage: ping-swarm [injectors|bridges|URI]...
#
# Where URI can be an exact URI like "https://example.com/foo/"
# or a group like "example.com/foo" (not equivalent).
#
# Default is to ping both injectors and bridges.
#
# Environment variables:
#
# - OUI_PROTO: Ouinet protocol version number
# - OUI_INJPK: Base32-encoded injector public key (lowercase, no padding)
#
# This must be executed where Ouinet's test utilities are.
set -e
# Uncomment if libraries sit along binaries.
#export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
# Uncomment and edit for fixed default values (can still override with env).
#OUI_PROTO="${OUI_PROTO:-5}"
#OUI_INJPK="${OUI_INJPK:-abcdefghijklmnopqrstuvwxyz234567abcdefghijklmnopqrst}"
if [ ! "$OUI_PROTO" -o ! "$OUI_INJPK" ]; then
echo "Please set OUI_PROTO and OUI_INJPK." > /dev/stderr
exit 1
fi
if [ $# -lt 1 ]; then
exec $0 injectors bridges
fi
ping_peer() { # (endpoint) => (did_reply)
# Sample DHT message from
# <https://www.bittorrent.org/beps/bep_0005.html#ping>.
local ping='d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe'
local host="${1%:*}" port="${1##*:}"
local pong="$(echo -n "$ping" | timeout 2 nc -uW1 "$host" "$port")"
test $? -eq 0 || return 1
test "$(echo -n "$pong" | wc -c)" -gt 0
}
ping_peers() { # () / endpoint* => () / peers replies
local ep peers=0 replies=0 replying
while read ep; do
peers=$((peers + 1))
if ping_peer $ep; then
replying="$replying $ep"
replies=$((replies + 1))
fi
done
echo "Replying peers:$replying" > /dev/stderr
echo $peers $replies
}
select_peers() { # () / bt-pep5_output => () endpoint*
grep -E '^[][\.\:0-9A-Fa-f]+:[0-9]+' | tr -d [] | sed 's/, */\n/g'
}
bep5_query() { # (infohash) => () bt-pep5_output
./bt-bep5 0.0.0.0 get_peers $1 2>&1
}
for group in "$@"; do
# swarm = "ed25519:<base32up_encode(pubkey)>/v<VERSION>/<GROUP>"
case "$group" in
injectors|bridges)
swarm="ed25519:$OUI_INJPK/v$OUI_PROTO/$group"
;;
*)
swarm="ed25519:$OUI_INJPK/v$OUI_PROTO/uri/$group"
esac
# infohash = sha1(swarm)
infohash="$(echo -n "$swarm" | sha1sum | cut -d' ' -f1)"
echo "Group : $group"
echo "Swarm : $swarm"
echo "Infohash: $infohash"
bep5_query "$infohash" | tee /dev/stderr \
| select_peers | ping_peers \
| ( read peers replies
echo "Swarm group=\"$group\": peers=$peers replies=$replies" )
echo
done
......@@ -14,6 +14,8 @@
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/adaptor/transformed.hpp>
#include <boost/range/adaptor/indexed.hpp>
#include <boost/regex.hpp>
#include <iterator>
#include <iostream>
#include <cstdlib> // for atexit()
......@@ -21,6 +23,7 @@
#include "namespaces.h"
#include "origin_pools.h"
#include "doh.h"
#include "http_util.h"
#include "fetch_http_page.h"
#include "client_front_end.h"
......@@ -84,11 +87,15 @@ namespace bt = ouinet::bittorrent;
using tcp = asio::ip::tcp;
using Request = http::request<http::string_body>;
using Response = http::response<http::dynamic_body>;
using TcpLookup = tcp::resolver::results_type;
static const fs::path OUINET_CA_CERT_FILE = "ssl-ca-cert.pem";
static const fs::path OUINET_CA_KEY_FILE = "ssl-ca-key.pem";
static const fs::path OUINET_CA_DH_FILE = "ssl-ca-dh.pem";
// Flags for normal, case-insensitive regular expression.
static const auto rx_icase = boost::regex::normal | boost::regex::icase;
static bool log_transactions() {
return logger.get_threshold() <= DEBUG
|| logger.get_log_file() != nullptr;
......@@ -119,6 +126,15 @@ struct UserAgentMetaData {
return ret;
}
// Apply the metadata to the given request.
template<class Req>
void apply_to(Req& rq) const {
if (is_private && *is_private)
rq.set(http_::request_private_hdr, http_::request_private_true);
if (dht_group)
rq.set(http_::request_group_hdr, *dht_group);
}
};
//------------------------------------------------------------------------------
......@@ -228,8 +244,14 @@ private:
, Cancel& cancel
, Yield yield);
template<class Rq>
Session fetch_via_self( Rq, const UserAgentMetaData&
, Cancel&, Yield);
Response fetch_fresh_from_front_end(const Request&, Yield);
Session fetch_fresh_from_origin(const Request&, Cancel, Yield);
Session fetch_fresh_from_origin( const Request&
, const UserAgentMetaData&
, Cancel, Yield);
Session fetch_fresh_through_connect_proxy(const Request&, Cancel&, Yield);
......@@ -278,7 +300,17 @@ private:
, Request&
, Yield);
GenericStream connect_to_origin(const Request&, Cancel&, Yield);
// Resolve host and port strings.
TcpLookup resolve_tcp_dns( const std::string&, const std::string&
, Cancel&, Yield);
TcpLookup resolve_tcp_doh( const std::string&, const std::string&
, const UserAgentMetaData&
, const doh::Endpoint&
, Cancel&, Yield);
GenericStream connect_to_origin( const Request&
, const UserAgentMetaData&
, Cancel&, Yield);
unique_ptr<OuiServiceImplementationClient>
maybe_wrap_tls(unique_ptr<OuiServiceImplementationClient>);
......@@ -369,6 +401,7 @@ private:
// For debugging
uint64_t _next_connection_id = 0;
ConnectionPool<Endpoint> _injector_connections;
ConnectionPool<bool> _self_connections; // stored value is unused
OriginPools _origin_pools;
asio::ssl::context ssl_ctx;
......@@ -554,8 +587,195 @@ Client::State::fetch_stored_in_dcache( const Request& request
}
//------------------------------------------------------------------------------
template<class Rq>
Session
Client::State::fetch_via_self( Rq request, const UserAgentMetaData& meta
, Cancel& cancel, Yield yield)
{
sys::error_code ec;
// Connect to the client proxy port.
// TODO: Maybe refactor with `fetch_fresh_through_simple_proxy`.
ConnectionPool<bool>::Connection con;
if (_self_connections.empty()) {
if (log_transactions()) {
yield.log("Connecting to self");
}
// TODO: Keep lookup object or allow connecting to endpoint.
auto epl = TcpLookup::create(_config.local_endpoint(), "dummy", "dummy");
auto c = connect_to_host(epl, _ctx.get_executor(), cancel, yield[ec]);
assert(!cancel || ec == asio::error::operation_aborted);
if (ec) {
if (log_transactions()) {
yield.log("Failed to connect to self ec:", ec.message());
}
return or_throw<Session>(yield, ec);
}
con = _self_connections.wrap(std::move(c));
} else {
if (log_transactions()) {
yield.log("Reusing existing self connection");
}
con = _self_connections.pop_front();
}
auto cancel_slot = cancel.connect([&] {