Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
52 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
7526bb9
Merge remote-tracking branch 'origin/master' into snp/quic
turuslan Mar 21, 2025
b932469
soralog constructor
turuslan Mar 31, 2025
7169543
build md
turuslan Mar 31, 2025
b4173f0
make shared private
turuslan Mar 31, 2025
5b679c7
rename
turuslan Mar 31, 2025
e8b2c10
rename
turuslan Apr 11, 2025
a22e48b
deprecated
turuslan Apr 23, 2025
4443997
singleton connection id counter
turuslan Apr 23, 2025
f40fcb4
CREATE_SHARED_METHOD
turuslan Apr 23, 2025
d6e0106
test
turuslan Apr 23, 2025
943204b
move file
turuslan Apr 24, 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
69 changes: 69 additions & 0 deletions DEPRECATED.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
These features were rejected, don't suggest them again.

```c++
#define FORWARD(x) std::forward<decltype(x)>(x)
auto foo(auto &&x) {
bar(FORWARD(x));
}
```

```c++
#define MAKE_SHARED_(x_, ...) std::make_shared<decltype(x_)::element_type>(...)
struct Foo {
Foo() : MAKE_SHARED_(bar_, ...) {}
std::shared_ptr<Bar> bar_;
};
```

```c++
#define MAKE_SHARED_T(x) std::forward<decltype(x)>(x)
using Foo = std::shared_ptr<...>;
MAKE_SHARED_T(Foo, ...);
```

```c++
#define MOVE(x) x{std::move(x)}
auto lambda = [MOVE(x)]() {};
```

```c++
#define MOVE_(x) x##_{std::move(x)}
struct Foo {
Foo(Bar bar) : MOVE_(bar) {}
Bar bar_;
};
```

```c++
#define WEAK_SELF weak_self{weak_from_this()}
auto lambda = [WEAK_SELF]() {};
```

```c++
#define WEAK_LOCK(x) auto x = weak_##x.lock(); if (not x) return
auto lambda = [weak_self]() {
WEAK_LOCK(self);
...
};
```

```c++
class MakeSharedPrivate {
private:
MakeSharedPrivate() = default;
public:
static auto make() {
return MakeSharedPrivate{};
}
};
class Foo : public std::enable_shared_from_this<> {
public:
Foo(MakeSharedPrivate, ...);
static std::shared_ptr<Foo> factory(...) {
// `Foo` can call `MakeSharedPrivate` constructor
return std::make_shared<Foo>(MakeSharedPrivate::make(), ...);
}
};
// error, MakeSharedPrivate has private constructor
injector.create<std::shared_ptr<Foo>>();
```
6 changes: 1 addition & 5 deletions example/snp_chat/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <qtils/unhex.hpp>

#include "coro/spawn.hpp"
#include "crypto/ed25519_literal.hpp"
#include "log/simple.hpp"
#include "snp/connections/address.hpp"
#include "snp/connections/connection.hpp"
Expand All @@ -36,11 +37,6 @@ using jam::snp::StreamPtr;

auto logsys = jam::log::simpleLoggingSystem();

inline auto operator""_ed25519(const char *c, size_t s) {
auto seed = qtils::unhex<jam::crypto::ed25519::Seed>({c, s}).value();
return jam::crypto::ed25519::from_seed(seed);
}

std::vector<KeyPair> keys{
"f8dfdb0f1103d9fb2905204ac32529d5f148761c4321b2865b0a40e15be75f57"_ed25519,
"96c891b8726cb18c781aefc082dbafcb827e16c8f18f22d461e83eabd618e780"_ed25519,
Expand Down
36 changes: 0 additions & 36 deletions src/TODO_qtils/make_shared_private.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/TODO_qtils/map_entry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace qtils {
return std::move(node.mapped());
}

void eraseIfExists() {
void erase() {
if (has()) {
auto it = std::get<I>(it_or_key);
it_or_key = it->first;
Expand Down
16 changes: 16 additions & 0 deletions src/crypto/ed25519_literal.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 <qtils/unhex.hpp>

#include "crypto/ed25519.hpp"

inline auto operator""_ed25519(const char *c, size_t s) {
auto seed = qtils::unhex<jam::crypto::ed25519::Seed>({c, s}).value();
return jam::crypto::ed25519::from_seed(seed);
}
25 changes: 0 additions & 25 deletions src/snp/connections/connection_id_counter.hpp

This file was deleted.

6 changes: 2 additions & 4 deletions src/snp/connections/connections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@ namespace jam::snp {
BOOST_OUTCOME_CO_TRY(self->client_,
lsquic::Engine::make(self->io_context_ptr_,
self->logsys_,
self->connection_id_counter_,
certificate,
std::nullopt,
self));
if (self->config_.listen_port.has_value()) {
BOOST_OUTCOME_CO_TRY(self->server_,
lsquic::Engine::make(self->io_context_ptr_,
self->logsys_,
self->connection_id_counter_,
certificate,
self->config_.listen_port,
self));
Expand Down Expand Up @@ -91,7 +89,7 @@ namespace jam::snp {
controller->onOpen(address.key);
}
} else {
state.eraseIfExists();
state.erase();
}
CORO_WEAK_AWAIT_V(
self, connecting->set(connecting, std::move(connection_result)));
Expand Down Expand Up @@ -128,7 +126,7 @@ namespace jam::snp {
or std::get<Connected>(*state)->info() != connection_info) {
todoPreferConnection();
}
state.eraseIfExists();
state.erase();
if (auto controller = controller_.lock()) {
controller->onClose(connection_info.key);
}
Expand Down
2 changes: 0 additions & 2 deletions src/snp/connections/connections.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "coro/init.hpp"
#include "coro/io_context_ptr.hpp"
#include "snp/connections/config.hpp"
#include "snp/connections/connection_id_counter.hpp"
#include "snp/connections/connection_ptr.hpp"
#include "snp/connections/key.hpp"
#include "snp/connections/lsquic/controller.hpp"
Expand Down Expand Up @@ -94,6 +93,5 @@ namespace jam::snp {
qtils::BytesStdHash>
connections_;
std::unordered_map<ProtocolId, ServeProtocol> protocols_;
ConnectionIdCounter connection_id_counter_;
};
} // namespace jam::snp
23 changes: 9 additions & 14 deletions src/snp/connections/lsquic/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ namespace jam::snp::lsquic {
outcome::result<std::shared_ptr<Engine>> Engine::make(
IoContextPtr io_context_ptr,
std::shared_ptr<log::LoggingSystem> logsys,
ConnectionIdCounter connection_id_counter,
TlsCertificate certificate,
std::optional<uint16_t> listen_port,
std::weak_ptr<EngineController> controller) {
Expand Down Expand Up @@ -102,14 +101,12 @@ namespace jam::snp::lsquic {
if (ec) {
return ec;
}
auto self =
qtils::MakeSharedPrivate::make<Engine>(io_context_ptr,
std::move(logsys),
std::move(connection_id_counter),
std::move(certificate),
std::move(socket),
socket_local_endpoint,
std::move(controller));
auto self = create_shared(io_context_ptr,
std::move(logsys),
std::move(certificate),
std::move(socket),
socket_local_endpoint,
std::move(controller));

api.ea_stream_if = &stream_if;
api.ea_stream_if_ctx = self.get();
Expand All @@ -131,16 +128,13 @@ namespace jam::snp::lsquic {
return self;
}

Engine::Engine(qtils::MakeSharedPrivate,
IoContextPtr io_context_ptr,
Engine::Engine(IoContextPtr io_context_ptr,
std::shared_ptr<log::LoggingSystem> logsys,
ConnectionIdCounter connection_id_counter,
TlsCertificate &&certificate,
Socket &&socket,
Socket::endpoint_type socket_local_endpoint,
std::weak_ptr<EngineController> controller)
: io_context_ptr_{std::move(io_context_ptr)},
connection_id_counter_{std::move(connection_id_counter)},
certificate_{std::move(certificate)},
log_{logsys->getLogger("Engine", "snp")},
socket_{std::move(socket)},
Expand Down Expand Up @@ -476,8 +470,9 @@ namespace jam::snp::lsquic {
if (connecting.has_value() and key != connecting->address.key) {
return ConnectionsError::ENGINE_CONNECT_KEY_MISMATCH;
}
static std::atomic<ConnectionId> connection_id_counter = 0;
conn_ctx->info = ConnectionInfo{
.id = self->connection_id_counter_.make(),
.id = connection_id_counter.fetch_add(1),
.key = key,
};
auto connection = std::make_shared<Connection>(
Expand Down
13 changes: 5 additions & 8 deletions src/snp/connections/lsquic/engine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,14 @@
#include <deque>
#include <lsquic.h>

#include <TODO_qtils/make_shared_private.hpp>
#include <boost/asio/ip/udp.hpp>
#include <boost/asio/steady_timer.hpp>
#include <qtils/create_smart_pointer_macros.hpp>

#include "coro/coro.hpp"
#include "coro/handler.hpp"
#include "coro/io_context_ptr.hpp"
#include "snp/connections/address.hpp"
#include "snp/connections/connection_id_counter.hpp"
#include "snp/connections/connection_info.hpp"
#include "snp/connections/connection_ptr.hpp"
#include "snp/connections/protocol_id.hpp"
Expand Down Expand Up @@ -91,24 +90,23 @@ namespace jam::snp::lsquic {
}
};

class Engine : public std::enable_shared_from_this<Engine> {
class Engine {
friend Connection;
friend Stream;

CREATE_SHARED_METHOD(Engine);

public:
using SelfSPtr = std::shared_ptr<Engine>;

static outcome::result<std::shared_ptr<Engine>> make(
IoContextPtr io_context_ptr,
std::shared_ptr<log::LoggingSystem> logsys,
ConnectionIdCounter connection_id_counter,
TlsCertificate certificate,
std::optional<uint16_t> listen_port,
std::weak_ptr<EngineController> controller);
Engine(qtils::MakeSharedPrivate,
IoContextPtr io_context_ptr,
Engine(IoContextPtr io_context_ptr,
std::shared_ptr<log::LoggingSystem> logsys,
ConnectionIdCounter connection_id_counter,
TlsCertificate &&certificate,
Socket &&socket,
Socket::endpoint_type socket_local_endpoint,
Expand Down Expand Up @@ -192,7 +190,6 @@ namespace jam::snp::lsquic {

IoContextPtr io_context_ptr_;
std::shared_ptr<soralog::Logger> log_;
ConnectionIdCounter connection_id_counter_;
TlsCertificate certificate_;
Socket socket_;
Socket::endpoint_type socket_local_endpoint_;
Expand Down
13 changes: 12 additions & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,15 @@
# SPDX-License-Identifier: Apache-2.0
#

message(STATUS "There are no tests yet")

function(jam_add_test name)
add_executable(${name}
${ARGN}
)
target_link_libraries(${name}
${GTEST_DEPS}
)
add_test(${name} ${name})
endfunction()

add_subdirectory(snp)
11 changes: 11 additions & 0 deletions tests/snp/CMakeLists.txt
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
#

jam_add_test(snp_test snp_test.cpp)
target_link_libraries(snp_test
logger
snp
)
Loading
Loading