Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

snp quic #20

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
1b02d30
snp quic
turuslan Feb 11, 2025
f67cf4e
ci
turuslan Feb 11, 2025
ed8eb71
ci
turuslan Feb 11, 2025
f7cf132
snp quic + rebase
turuslan Feb 12, 2025
8444b77
merge rebase
turuslan Feb 12, 2025
bffc90b
forward
turuslan Feb 17, 2025
e499d39
make_shared
turuslan Feb 17, 2025
95699a2
move
turuslan Feb 17, 2025
89f987b
weak
turuslan Feb 17, 2025
0c9f159
set coro thread
turuslan Feb 17, 2025
f742c39
coro yield
turuslan Feb 17, 2025
e814063
enum type
turuslan Feb 17, 2025
bbddad4
cppcodec macro
turuslan Feb 17, 2025
b12bdcd
numeric limits
turuslan Feb 17, 2025
856d7f4
if return
turuslan Feb 17, 2025
5bb57a4
likely
turuslan Feb 17, 2025
b853b9a
self from void
turuslan Feb 17, 2025
22699ad
example
turuslan Feb 17, 2025
ef17c47
sizeof
turuslan Feb 17, 2025
9814d46
rename
turuslan Feb 17, 2025
387193e
rename self
turuslan Feb 17, 2025
0bfb4fd
error text
turuslan Feb 17, 2025
b9d83cc
comment
turuslan Feb 17, 2025
90b06ab
comment
turuslan Feb 17, 2025
a34d339
comment
turuslan Feb 17, 2025
25c3e6d
variant get
turuslan Feb 17, 2025
6aa4b49
hash constraint
turuslan Feb 18, 2025
ad703ed
forward
turuslan Feb 18, 2025
749ee00
comment
turuslan Feb 18, 2025
34c487a
executor constraint
turuslan Feb 18, 2025
8e9d06e
optional
turuslan Feb 18, 2025
4c9e48b
revert optional
turuslan Feb 25, 2025
f5b2466
update qtils
turuslan Feb 26, 2025
927632c
soralog
turuslan Feb 26, 2025
e97ecc8
if
turuslan Feb 26, 2025
4572529
make shared
turuslan Feb 27, 2025
bb881b5
revert "make shared"
turuslan Feb 27, 2025
812e33f
port type
turuslan Mar 3, 2025
2eaf302
shutdown
turuslan Mar 3, 2025
5632697
remove
turuslan Mar 3, 2025
790ce87
log socket read/write error
turuslan Mar 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .ci/.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LINUX_PACKAGES="make \
curl \
git \
libtool \
nasm \
ninja-build \
pkg-config \
python3.12 \
Expand All @@ -22,7 +23,9 @@ MACOS_PACKAGES="make \
rust \
curl \
git \
go \
libtool \
nasm \
ninja \
pkg-config \
[email protected] \
Expand Down
4 changes: 4 additions & 0 deletions BUILD.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

```bash
brew install nasm # vcpkg liblsquic
```
19 changes: 9 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,20 @@ find_package(PkgConfig REQUIRED)
pkg_check_modules(libb2 REQUIRED IMPORTED_TARGET GLOBAL libb2)

find_package(Boost CONFIG REQUIRED COMPONENTS algorithm outcome program_options)
find_package(Boost.DI CONFIG REQUIRED)
find_package(fmt CONFIG REQUIRED)
find_package(yaml-cpp CONFIG REQUIRED)
find_package(jam_crust CONFIG REQUIRED)
find_package(lsquic CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(prometheus-cpp CONFIG REQUIRED)
find_package(qtils CONFIG REQUIRED)
find_package(scale CONFIG REQUIRED)
find_package(soralog CONFIG REQUIRED)
find_package(schnorrkel_crust CONFIG REQUIRED)
find_package(Boost.DI CONFIG REQUIRED)
find_package(qtils CONFIG REQUIRED)
find_package(prometheus-cpp CONFIG REQUIRED)
find_package(soralog CONFIG REQUIRED)
find_package(yaml-cpp CONFIG REQUIRED)
find_package(ZLIB REQUIRED)

add_library(headers INTERFACE)
target_include_directories(headers INTERFACE
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/src_>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)
include(vcpkg-overlay/cppcodec.cmake)

add_subdirectory(src)

Expand Down
3 changes: 3 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ add_subdirectory(metrics)
# Clocks and time subsystem
add_subdirectory(clock)

# Simple Network Protocol
add_subdirectory(snp)

31 changes: 31 additions & 0 deletions src/TODO_qtils/asio_buffer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <boost/asio/buffer.hpp>
#include <qtils/bytes.hpp>

namespace qtils {
inline boost::asio::const_buffer asioBuffer(BytesIn s) {
return {s.data(), s.size()};
}

boost::asio::mutable_buffer asioBuffer(auto &&t)
requires(requires { BytesOut{t}; })
{
BytesOut s{t};
return {s.data(), s.size()};
}

inline BytesIn asioBuffer(const boost::asio::const_buffer &s) {
return {static_cast<const uint8_t *>(s.data()), s.size()};
}

inline BytesOut asioBuffer(const boost::asio::mutable_buffer &s) {
return {static_cast<uint8_t *>(s.data()), s.size()};
}
} // namespace qtils
32 changes: 32 additions & 0 deletions src/TODO_qtils/from_span.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <cstring>
#include <optional>
#include <stdexcept>

#include <qtils/bytes.hpp>

namespace qtils {
inline bool fromSpan(BytesOut out, BytesIn span) {
if (span.size() != out.size()) {
return false;
}
memcpy(out.data(), span.data(), out.size());
return true;
}

template <typename T>
std::optional<T> fromSpan(BytesIn span) {
T out;
if (not fromSpan(out, span)) {
return std::nullopt;
}
return out;
}
} // namespace qtils
11 changes: 11 additions & 0 deletions src/TODO_qtils/macro/forward.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <utility>

#define FORWARD(x) std::forward<decltype(x)>(x)
16 changes: 16 additions & 0 deletions src/TODO_qtils/macro/make_shared.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <memory>

#define MAKE_SHARED_(x_, ...) \
x_ { \
std::make_shared<decltype(x_)::element_type>(__VA_ARGS__) \
}

#define MAKE_SHARED_T(T, ...) std::make_shared<T::element_type>(__VA_ARGS__)
19 changes: 19 additions & 0 deletions src/TODO_qtils/macro/move.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <utility>

#define MOVE(x) \
x { \
std::move(x) \
}

#define MOVE_(x) \
x##_ { \
std::move(x) \
}
18 changes: 18 additions & 0 deletions src/TODO_qtils/macro/weak.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <memory>

#define WEAK_SELF \
weak_self { \
weak_from_this() \
}

#define WEAK_LOCK(name) \
auto name = weak_##name.lock(); \
if (not name) return
84 changes: 84 additions & 0 deletions src/TODO_qtils/map_entry.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <map>
#include <stdexcept>
#include <unordered_map>
#include <variant>

namespace qtils {
template <typename M>
struct MapEntry {
using I = typename M::iterator;
using K = typename M::key_type;

MapEntry(M &map, const K &key) : map{map} {
if (auto it = map.find(key); it != map.end()) {
it_or_key = it;
} else {
it_or_key = key;
}
}

bool has() const {
return std::holds_alternative<I>(it_or_key);
}
operator bool() const {
return has();
}
auto &operator*() {
if (not has()) {
throw std::logic_error{"MapEntry::operator*"};
}
return std::get<I>(it_or_key)->second;
}
auto *operator->() {
if (not has()) {
throw std::logic_error{"MapEntry::operator->"};
}
return &std::get<I>(it_or_key)->second;
}
void insert(M::mapped_type value) {
if (has()) {
throw std::logic_error{"MapEntry::insert"};
}
it_or_key =
map.emplace(std::move(std::get<K>(it_or_key)), std::move(value))
.first;
}
void insert_or_assign(M::mapped_type value) {
if (not has()) {
insert(std::move(value));
} else {
**this = std::move(value);
}
}
M::mapped_type remove() {
if (not has()) {
throw std::logic_error{"MapEntry::remove"};
}
auto node = map.extract(std::get<I>(it_or_key));
it_or_key = std::move(node.key());
return std::move(node.mapped());
}

// NOLINTNEXTLINE(cppcoreguidelines-avoid-const-or-ref-data-members)
M &map;
std::variant<I, K> it_or_key{};
};

template <typename K, typename V, typename L, typename A>
auto entry(std::map<K, V, L, A> &map, const K &key) {
return MapEntry<std::remove_cvref_t<decltype(map)>>{map, key};
}

template <typename K, typename V, typename H, typename E, typename A>
auto entry(std::unordered_map<K, V, H, E, A> &map, const K &key) {
return MapEntry<std::remove_cvref_t<decltype(map)>>{map, key};
}
} // namespace qtils
16 changes: 16 additions & 0 deletions src/TODO_qtils/std_hash_of.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <utility>

namespace qtils {
template <typename T>
size_t stdHashOf(const T &v) {
return std::hash<T>()(v);
}
} // namespace qtils
49 changes: 49 additions & 0 deletions src/coro/coro.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Copyright Quadrivium LLC
* All Rights Reserved
* SPDX-License-Identifier: Apache-2.0
*/

#pragma once

#include <boost/asio/awaitable.hpp>
#include <qtils/outcome.hpp>

namespace jam {
/**
* Return type for coroutine.
*
* Does not resume when:
* - called directly outside executor, returns coroutine.
* - `coroSpawn` called when not running inside executor,
* resumes on next executor tick.
* int main() {
* boost::asio::io_context io;
* coroSpawn(io, []() -> Coro<void> { co_return; }); // suspended
* io.run_one(); // resumes
* // may complete before next statement
* }
* Resumes when:
* - `coroSpawn` when running inside specified executor.
* post(executor, [] {
* coroSpawn(executor, []() -> Coro<void> { co_return; }) // resumes
* // may complete before next statement
* })
* co_await coroSpawn([]() -> Coro<void> { co_return; }) // resumes
* // may complete before next statement
* - `co_await`
* co_await foo() // resumes
* // may complete before next statement
* After resuming may complete before specified statement ends.
*
* Use `CORO_YIELD` explicitly to suspend coroutine until next executor tick.
*/
template <typename T>
using Coro = boost::asio::awaitable<T>;

/**
* Return type for coroutine returning outcome.
*/
template <typename T>
using CoroOutcome = Coro<outcome::result<T>>;
} // namespace jam
Loading
Loading