Skip to content

Commit

Permalink
clang-formatted and actions
Browse files Browse the repository at this point in the history
  • Loading branch information
loglund committed May 18, 2021
1 parent 59e7a88 commit a4f6f64
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 85 deletions.
18 changes: 18 additions & 0 deletions .github/gcc-problem-matcher.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"problemMatcher": [
{
"owner": "gcc-problem-matcher",
"severity": "error",
"pattern": [
{
"regexp": "^../../(.*):(\\d+):(\\d+):\\s+(?:fatal\\s+)?(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
]
}
]
}
130 changes: 130 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
name: Build
on: [push, pull_request]
jobs:
# Builds performed in docker
docker_builds:
strategy:
fail-fast: false
matrix:
config:
- container: conanio/gcc5
cxx_mkspec: --cxx_mkspec=cxx_gxx54_x64
name: GCC 5.4
- container: conanio/gcc9
cxx_mkspec: --cxx_mkspec=cxx_gxx92_x64
name: GCC 9.2
- container: conanio/clang39
name: Clang 3.9
cxx_mkspec: --cxx_mkspec=cxx_clang39_x64
- container: conanio/clang10
name: Clang 10
- container: conanio/clang10
cxx_mkspec: --cxx_mkspec=cxx_clang10_address_sanitizer_x64
name: Clang 10 Address Sanitizer
# TODO: Re-able this when we have fixed memory issue in google-test
# - container: conanio/clang10
# cxx_mkspec: --cxx_mkspec=cxx_clang10_memory_sanitizer_x64
# name: Clang 10 Memory Sanitizer
- container: conanio/clang10
cxx_mkspec: --cxx_mkspec=cxx_clang10_thread_sanitizer_x64
name: Clang 10 Thread Sanitizer
runs-on: [self-hosted, docker]
name: ${{ matrix.config.name }}
container:
image: ${{ matrix.config.container }}
options: --user 0:0
volumes:
- /home/buildbot/.ssh:/root/.ssh
steps:
- name: Install SSH client
run: apt update && apt -y install openssh-client
- name: Checkout source code
uses: actions/checkout@v2
- name: Waf Configure
run: python3 waf configure --git_protocol=git@ ${{ matrix.config.cxx_mkspec }}
- name: Waf Build
run: |
echo "::add-matcher::.github/gcc-problem-matcher.json"
python3 waf
- name: Waf Test
run: python3 waf --run_tests
# Build performed on runner using make specs
cxx_mkspec:
strategy:
fail-fast: false
matrix:
config:
- cxx_mkspec: cxx_clang70_x64
name: Clang 7.0 64-Bit
- cxx_mkspec: cxx_gxx83_x64
name: GCC 8.3 64-Bit
runs-on: [self-hosted, "${{ matrix.config.cxx_mkspec }}"]
name: ${{ matrix.config.name }}
env:
python: python3
steps:
- name: Rename python3 to python on Windows
if: runner.os == 'Windows'
run: echo "python=python" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf8 -Append
- name: Checkout
uses: actions/checkout@v2
- name: Configure
env:
GIT_SSH_COMMAND: "${{ runner.os != 'Linux' && 'ssh' || 'ssh -i /home/buildbot/.ssh/id_ed25519 -o IdentitiesOnly=yes' }}"
run: ${{ env.python }} waf configure --git_protocol=git@ --cxx_mkspec=${{ matrix.config.cxx_mkspec }}
- name: Build
run: |
echo "::add-matcher::.github/gcc-problem-matcher.json"
${{ env.python }} waf
- name: Test
run: ${{ env.python }} waf --run_tests
# Code Format Check
clang-format:
name: ClangFormat
runs-on: [self-hosted, docker]
container:
image: fifty2technology/clang-format
options: --user 0:0
steps:
- name: Checkout source code
uses: actions/checkout@v2
- name: Run Clang-format
run: clang-format --help
- name: Run Clang-format
run: clang-format -version
- name: Run Clang-format
run: find ./ -iname *.hpp -o -iname *.cpp -o -iname *.c -o -iname *.h | xargs clang-format --dry-run --Werror
# Valgrind Check
valgrind:
name: Valgrind
runs-on: [self-hosted, valgrind]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure
env:
GIT_SSH_COMMAND: "${{ runner.os != 'Linux' && 'ssh' || 'ssh -i /home/buildbot/.ssh/id_ed25519 -o IdentitiesOnly=yes' }}"
run: python3 waf configure --git_protocol=git@
- name: Build
run: |
echo "::add-matcher::.github/gcc-problem-matcher.json"
python3 waf
- name: Valgrind Test
run: python3 waf --run_tests --run_cmd="valgrind %s"
# NDEBUG compilation
ndebug:
name: No Assertions
runs-on: [self-hosted, linux]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Configure
env:
GIT_SSH_COMMAND: "${{ runner.os != 'Linux' && 'ssh' || 'ssh -i /home/buildbot/.ssh/id_ed25519 -o IdentitiesOnly=yes' }}"
run: python3 waf configure --cxx_nodebug --git_protocol=git@
- name: Build
run: |
echo "::add-matcher::.github/gcc-problem-matcher.json"
python3 waf
- name: Valgrind Test
run: python3 waf --run_tests
100 changes: 38 additions & 62 deletions examples/sample_tunnel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,23 @@
#include <tunnel/tun_interface.hpp>

#include <cassert>
#include <deque>
#include <iostream>
#include <unistd.h>
#include <vector>
#include <deque>

#include <boost/asio.hpp>
#include <boost/program_options.hpp>


/**
* Create Tunnel:
* Local machine (192.168.1.2):
* sudo build/linux/examples/udp_tunnel2 --tunnel_ip 10.0.0.1 --remote_ip 192.168.1.3 --local_ip 192.168.1.2
* sudo build/linux/examples/udp_tunnel2 --tunnel_ip 10.0.0.1 --remote_ip
* 192.168.1.3 --local_ip 192.168.1.2
*
* Remote machine (192.168.1.3):
* sudo build/linux/examples/udp_tunnel2 --tunnel_ip 10.0.0.2 --remote_ip 192.168.1.2 --local_ip 192.168.1.3
* sudo build/linux/examples/udp_tunnel2 --tunnel_ip 10.0.0.2 --remote_ip
* 192.168.1.2 --local_ip 192.168.1.3
*
* Communication:
* Local machine (192.168.1.2 / 10.0.0.1):
Expand All @@ -35,17 +36,11 @@
class sample_tunnel
{
public:

sample_tunnel(
boost::asio::io_service& io,
int tun_fd,
uint32_t mtu,
boost::asio::ip::udp::endpoint local_endpoint,
boost::asio::ip::udp::endpoint remote_endpoint) :
sample_tunnel(boost::asio::io_service& io, int tun_fd, uint32_t mtu,
boost::asio::ip::udp::endpoint local_endpoint,
boost::asio::ip::udp::endpoint remote_endpoint) :
m_socket(io),
m_mtu(mtu),
m_stream_descriptor(io),
m_local_endpoint(local_endpoint),
m_mtu(mtu), m_stream_descriptor(io), m_local_endpoint(local_endpoint),
m_remote_endpoint(remote_endpoint)
{
m_stream_descriptor.assign(tun_fd);
Expand Down Expand Up @@ -73,22 +68,17 @@ class sample_tunnel
}

private:

void async_network_receive()
{
m_rx_buffer.resize(m_mtu);
m_socket.async_receive(
boost::asio::buffer(m_rx_buffer),
std::bind(
&sample_tunnel::handle_async_network_receive,
this,
std::placeholders::_1,
std::placeholders::_2));
std::bind(&sample_tunnel::handle_async_network_receive, this,
std::placeholders::_1, std::placeholders::_2));
}

void handle_async_network_receive(
const boost::system::error_code& ec,
std::size_t bytes)
void handle_async_network_receive(const boost::system::error_code& ec,
std::size_t bytes)
{
if (ec == boost::system::errc::operation_canceled)
{
Expand All @@ -102,28 +92,22 @@ class sample_tunnel
}
std::cout << "udp receive " << bytes << std::endl;
m_rx_buffer.resize(bytes);
boost::asio::write(
m_stream_descriptor,
boost::asio::buffer(m_rx_buffer));
boost::asio::write(m_stream_descriptor,
boost::asio::buffer(m_rx_buffer));
async_network_receive();
}


void async_tun_read()
{
m_tx_buffer.resize(m_mtu);
m_stream_descriptor.async_read_some(
boost::asio::buffer(m_tx_buffer),
std::bind(
&sample_tunnel::handle_async_tun_read,
this,
std::placeholders::_1,
std::placeholders::_2));
std::bind(&sample_tunnel::handle_async_tun_read, this,
std::placeholders::_1, std::placeholders::_2));
}

void handle_async_tun_read(
const boost::system::error_code& ec,
std::size_t bytes)
void handle_async_tun_read(const boost::system::error_code& ec,
std::size_t bytes)
{
if (ec == boost::system::errc::operation_canceled)
{
Expand All @@ -141,7 +125,6 @@ class sample_tunnel
}

private:

boost::asio::ip::udp::socket m_socket;

const uint32_t m_mtu;
Expand All @@ -168,19 +151,19 @@ int main(int argc, char* argv[])
// Parse the prorgram options
bpo::options_description options("Commandline Options");

options.add_options()
("tunnel_ip,t", bpo::value<std::string>(&tunnel_ip)->required(),
"Specify the IPv4 address to set on the created tunnel "
"interface [required]")
("local_ip,l", bpo::value<std::string>(&local_ip)->required(),
"Specify the IPv4 address of the local interface that the tunnel "
"should send to and receive from [required]")
("remote_ip,r", bpo::value<std::string>(&remote_ip)->required(),
"Specify the remote IPv4 address the tunnel should send to and receive "
"from [required]")
("port,p", bpo::value<uint16_t>(&port)->default_value(9999),
"Set the port to use for the udp tunnel")
("help,h", "Print this help message");
options.add_options()(
"tunnel_ip,t", bpo::value<std::string>(&tunnel_ip)->required(),
"Specify the IPv4 address to set on the created tunnel "
"interface [required]")(
"local_ip,l", bpo::value<std::string>(&local_ip)->required(),
"Specify the IPv4 address of the local interface that the tunnel "
"should send to and receive from [required]")(
"remote_ip,r", bpo::value<std::string>(&remote_ip)->required(),
"Specify the remote IPv4 address the tunnel should send to and receive "
"from [required]")("port,p",
bpo::value<uint16_t>(&port)->default_value(9999),
"Set the port to use for the udp tunnel")(
"help,h", "Print this help message");

bpo::variables_map opts;

Expand Down Expand Up @@ -212,7 +195,7 @@ int main(int argc, char* argv[])
<< " (remote)." << std::endl;
std::cout << "Setting up virtual interface with ip " << tunnel_ip
<< ". All communication on this interface will go through the "
"udp tunnel."
"udp tunnel."
<< std::endl;

tunnel::tun_interface iface;
Expand All @@ -227,20 +210,13 @@ int main(int argc, char* argv[])
boost::asio::io_service io;

auto local_endpoint = boost::asio::ip::udp::endpoint(
boost::asio::ip::address_v4::from_string(local_ip),
port);
boost::asio::ip::address_v4::from_string(local_ip), port);

auto remote_endpoint = boost::asio::ip::udp::endpoint(
boost::asio::ip::address_v4::from_string(remote_ip),
port);

sample_tunnel tunnel(
io,
iface.native_handle(),
iface.mtu(),
local_endpoint,
remote_endpoint
);
boost::asio::ip::address_v4::from_string(remote_ip), port);

sample_tunnel tunnel(io, iface.native_handle(), iface.mtu(), local_endpoint,
remote_endpoint);

tunnel.start();

Expand Down
2 changes: 1 addition & 1 deletion src/tunnel/linux/layer_log.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class layer_log
}

std::string result;
int unpack[] {0, (result += detail::to_string(args), 0)...};
int unpack[]{0, (result += detail::to_string(args), 0)...};
(void)unpack;
std::cout << result << std::endl;
}
Expand Down
Loading

0 comments on commit a4f6f64

Please sign in to comment.