Skip to content
Merged

Tidy #28

Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 10 additions & 1 deletion TODO
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,13 @@
- [ ] Metrics
- [ ] Graceful Disconnects (?)
- [ ] Version Negotiation (?)
- [ ] Feature flag Negotiation (?)
- [ ] Feature flag Negotiation (?)
- [ ] Automatic serialization of non-complex types
- [ ] Fully asynchronous P2P hole punching using an event-driven I/O model.
- [ ] Add `UDPTransportLayer` and UDP client/server backends, including UDP hole punching for P2P.
- [ ] Enhance error events for P2P connection failures with granular, actionable reasons.
- [ ] Check if PeerLocator's destructor automatically joins its internal thread.
- [ ] Document thread-safety guarantees and concurrency model for all public APIs.
- [ ] Comprehensive performance benchmarks and conduct memory usage profiling.
- [ ] Security audit for the encryption layer
- [x] Refactor znet.h into smaller, modular headers for specific functionalities.
11 changes: 9 additions & 2 deletions examples/basic/client/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
// http://www.apache.org/licenses/LICENSE-2.0
//

#include <iostream>
#include "znet/packet_handler.h"
#include "znet/peer_session.h"
#include "znet/init.h"
#include "znet/client_events.h"
#include "znet/codec.h"
#include "znet/client.h"

#include "packets.h"
#include "znet/znet.h"

#include <iostream>

using namespace znet;

Expand Down
2 changes: 1 addition & 1 deletion examples/basic/common/packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#pragma once

#include "znet/znet.h"
#include "../../../znet/include/znet/packet.h"

using namespace znet;

Expand Down
11 changes: 10 additions & 1 deletion examples/basic/server/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,17 @@
// http://www.apache.org/licenses/LICENSE-2.0
//

#include "znet/packet_handler.h"
#include "znet/peer_session.h"
#include "znet/init.h"
#include "znet/server_events.h"
#include "znet/codec.h"
#include "znet/server.h"
#include "znet/signal_handler.h"

#include "packets.h"
#include "znet/znet.h"

#include <iostream>

using namespace znet;

Expand Down
16 changes: 8 additions & 8 deletions examples/multiversion/client-v1/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
// http://www.apache.org/licenses/LICENSE-2.0
//

#include <iostream>
#include "packets.h"
#include "znet/znet.h"

using namespace znet;
#include "znet/packet_handler.h"
#include "znet/peer_session.h"
#include "znet/init.h"
#include "znet/client_events.h"
#include "znet/codec.h"
#include "znet/client.h"


#include <iostream>
#include "packets.h"
#include "znet/znet.h"
#include "player.h"

#include <iostream>

using namespace znet;

Codecs codecs_;
Expand Down
16 changes: 8 additions & 8 deletions examples/multiversion/client-v2/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@
// http://www.apache.org/licenses/LICENSE-2.0
//

#include <iostream>
#include "packets.h"
#include "znet/znet.h"

using namespace znet;
#include "znet/packet_handler.h"
#include "znet/peer_session.h"
#include "znet/init.h"
#include "znet/client_events.h"
#include "znet/codec.h"
#include "znet/client.h"


#include <iostream>
#include "packets.h"
#include "znet/znet.h"
#include "player.h"

#include <iostream>

using namespace znet;

Codecs codecs_;
Expand Down
4 changes: 3 additions & 1 deletion examples/multiversion/common/packets.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

#pragma once

#include "znet/znet.h"
#include "znet/codec.h"
#include "znet/packet_handler.h"
#include "znet/types.h"
#include "types.h"

using namespace znet;
Expand Down
15 changes: 12 additions & 3 deletions examples/multiversion/server/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@
// http://www.apache.org/licenses/LICENSE-2.0
//

#include <algorithm>
#include <unordered_map>

#include "znet/client.h"
#include "znet/codec.h"
#include "znet/init.h"
#include "znet/packet_handler.h"
#include "znet/peer_session.h"
#include "znet/server_events.h"
#include "znet/server.h"
#include "znet/signal_handler.h"

#include "packets.h"
#include "znet/znet.h"

#include <algorithm>

using namespace znet;

Expand Down
8 changes: 5 additions & 3 deletions examples/p2p/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
// http://www.apache.org/licenses/LICENSE-2.0
//

#include <utility>
#include "znet/p2p.h"
#include "znet/packet_handler.h"
#include "znet/peer_session.h"
#include "znet/init.h"

#include <utility>
#include <deque>
#include "cxxopts.h"
#include "znet/znet.h"
#include "znet/base/inet_addr.h"

using namespace znet;

Expand Down
13 changes: 9 additions & 4 deletions rendezvous-server/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@
// http://www.apache.org/licenses/LICENSE-2.0
//

#include <utility>
#include "znet/p2p.h"
#include "znet/p2p/rendezvous.h"
#include "znet/packet_handler.h"
#include "znet/peer_session.h"
#include "znet/server_events.h"
#include "znet/init.h"

#include "cxxopts.h"

#include <utility>
#include <deque>
#include <random>
#include "cxxopts.h"
#include "znet/p2p/rendezvous.h"
#include "znet/znet.h"

struct UserData {
std::shared_ptr<znet::PeerSession> session_;
Expand Down
2 changes: 1 addition & 1 deletion tests/buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//

#define ZNET_BUFFER_COUNT_MEMORY_ALLOCATIONS
#include "znet/znet.h"

#include "znet/buffer.h"
#include "gtest/gtest.h"

using namespace znet;
Expand Down
2 changes: 1 addition & 1 deletion znet/include/znet/backends/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace backends {
class TCPTransportLayer : public TransportLayer {
public:
TCPTransportLayer(SocketHandle socket);
~TCPTransportLayer();
~TCPTransportLayer() override;

std::shared_ptr<Buffer> Receive() override;
bool Send(std::shared_ptr<Buffer> buffer, SendOptions options = {}) override;
Expand Down
9 changes: 5 additions & 4 deletions znet/include/znet/buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

#pragma once

#include "znet/precompiled.h"
#include "znet/base/types.h"
#include "znet/inet_addr.h"
#include "znet/types.h"
#include "znet/util.h"
#include "znet/logger.h"
#include "znet/base/util.h"
#include "znet/base/inet_addr.h"
#include "znet/precompiled.h"

#include <bitset>

namespace znet {
Expand Down
5 changes: 2 additions & 3 deletions znet/include/znet/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#pragma once

#include <znet/backends/backend.h>
#include "znet/backends/backend.h"
#include "znet/interface.h"
#include "znet/peer_session.h"
#include "znet/precompiled.h"
Expand All @@ -34,8 +34,7 @@ class Client : public Interface {
public:
Client(const ClientConfig& config);
Client(const Client&) = delete;

~Client();
~Client() override;

/**
* @brief Binds client to configured IP address and port. This function is not thread-safe.
Expand Down
2 changes: 1 addition & 1 deletion znet/include/znet/client_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#include "znet/precompiled.h"
#include "znet/peer_session.h"
#include "znet/base/event.h"
#include "znet/event.h"

namespace znet {

Expand Down
1 change: 0 additions & 1 deletion znet/include/znet/close_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#ifndef ZNET_PARENT_CLOSE_OPTIONS_H
#define ZNET_PARENT_CLOSE_OPTIONS_H


#include "znet/precompiled.h"
#include <cstdint>
#include <type_traits>
Expand Down
6 changes: 3 additions & 3 deletions znet/include/znet/codec.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
#define ZNET_PARENT_CODEC_H

#include "znet/precompiled.h"
#include "znet/base/packet.h"
#include "znet/packet_serializer.h"
#include "znet/packet_handler.h"
#include "znet/packet.h"
#include "znet/buffer.h"
#include "znet/packet_handler.h"
#include "znet/packet_serializer.h"

namespace znet {

Expand Down
5 changes: 2 additions & 3 deletions znet/include/znet/encryption.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,9 @@

#pragma once

#include "znet/precompiled.h"
#include "znet/base/packet.h"
#include "znet/logger.h"
#include "znet/packet.h"
#include "znet/packet_handler.h"
#include "znet/precompiled.h"

#include <openssl/dh.h>
#include <openssl/engine.h>
Expand Down
10 changes: 7 additions & 3 deletions znet/include/znet/error.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2024 Metehan Gezer
// Copyright 2025 Metehan Gezer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -8,8 +8,12 @@
// http://www.apache.org/licenses/LICENSE-2.0
//

#pragma once
#ifndef ZNET_PARENT_ERROR_H
#define ZNET_PARENT_ERROR_H

#include "znet/precompiled.h"

std::string GetLastErrorInfo();
std::string GetLastErrorInfo();

#endif

File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright 2023 Metehan Gezer
// Copyright 2025 Metehan Gezer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -11,7 +11,7 @@
#pragma once

#include "znet/precompiled.h"
#include "znet/base/types.h"
#include "znet/types.h"

namespace znet {

Expand Down
2 changes: 1 addition & 1 deletion znet/include/znet/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define ZNET_PARENT_SOCKET_GUARD_H

#include "znet/precompiled.h"
#include "znet/base/types.h"
#include "znet/types.h"

namespace znet {

Expand Down
8 changes: 4 additions & 4 deletions znet/include/znet/interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

#pragma once

#include <utility>

#include "znet/precompiled.h"
#include "znet/base/event.h"
#include "znet/event.h"
#include "znet/packet_handler.h"
#include "znet/precompiled.h"

#include <utility>

namespace znet {

Expand Down
21 changes: 21 additions & 0 deletions znet/include/znet/p2p.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//
// Copyright 2025 Metehan Gezer
//
// 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
//

//
// Created by Metehan Gezer on 22.12.2025.
//

#ifndef ZNET_PARENT_P2P_H
#define ZNET_PARENT_P2P_H

#include "znet/p2p/dialer.h"
#include "znet/p2p/locator.h"

#endif //ZNET_PARENT_P2P_H
3 changes: 1 addition & 2 deletions znet/include/znet/p2p/dialer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
#ifndef ZNET_PARENT_PUNCH_H
#define ZNET_PARENT_PUNCH_H

#include "znet/base/inet_addr.h"
#include "znet/inet_addr.h"
#include "znet/peer_session.h"
#include "znet/precompiled.h"
#include "znet/error.h"

namespace znet {
namespace p2p {
Expand Down
2 changes: 1 addition & 1 deletion znet/include/znet/p2p/locator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#ifndef ZNET_PARENT_LOCATOR_H
#define ZNET_PARENT_LOCATOR_H

#include "znet/base/event.h"
#include "znet/event.h"
#include "znet/client.h"
#include "znet/client_events.h"
#include "znet/precompiled.h"
Expand Down
Loading