mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-27 22:11:39 -04:00
Better encapsulation
This commit is contained in:
parent
048c5c445d
commit
d8a7016d8d
@ -12,6 +12,7 @@
|
|||||||
#include <atomic.hpp>
|
#include <atomic.hpp>
|
||||||
|
|
||||||
#include "net/ethernet_layer.hpp"
|
#include "net/ethernet_layer.hpp"
|
||||||
|
#include "net/connection_handler.hpp"
|
||||||
#include "net/ip_layer.hpp"
|
#include "net/ip_layer.hpp"
|
||||||
#include "net/network.hpp"
|
#include "net/network.hpp"
|
||||||
#include "net/socket.hpp"
|
#include "net/socket.hpp"
|
||||||
@ -96,6 +97,10 @@ private:
|
|||||||
std::expected<void> finalize_packet_direct(network::interface_descriptor& interface, network::ethernet::packet& p);
|
std::expected<void> finalize_packet_direct(network::interface_descriptor& interface, network::ethernet::packet& p);
|
||||||
|
|
||||||
network::ip::layer* parent;
|
network::ip::layer* parent;
|
||||||
|
|
||||||
|
std::atomic<size_t> local_port;
|
||||||
|
|
||||||
|
network::connection_handler<network::tcp::tcp_connection> connections;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of tcp namespace
|
} // end of tcp namespace
|
||||||
|
@ -9,10 +9,12 @@
|
|||||||
#define NET_UDP_LAYER_H
|
#define NET_UDP_LAYER_H
|
||||||
|
|
||||||
#include <types.hpp>
|
#include <types.hpp>
|
||||||
|
#include <atomic.hpp>
|
||||||
|
|
||||||
#include "net/ethernet_layer.hpp"
|
#include "net/ethernet_layer.hpp"
|
||||||
#include "net/ip_layer.hpp"
|
#include "net/ip_layer.hpp"
|
||||||
#include "net/network.hpp"
|
#include "net/network.hpp"
|
||||||
|
#include "net/connection_handler.hpp"
|
||||||
|
|
||||||
namespace network {
|
namespace network {
|
||||||
|
|
||||||
@ -41,6 +43,17 @@ struct kernel_packet_descriptor {
|
|||||||
network::ip::address target_ip;
|
network::ip::address target_ip;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct udp_connection {
|
||||||
|
size_t local_port; ///< The local source port
|
||||||
|
size_t server_port; ///< The server port
|
||||||
|
network::ip::address server_address; ///< The server address
|
||||||
|
|
||||||
|
bool connected = false;
|
||||||
|
bool server = false;
|
||||||
|
|
||||||
|
network::socket* socket = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
struct layer {
|
struct layer {
|
||||||
layer(network::ip::layer* parent);
|
layer(network::ip::layer* parent);
|
||||||
|
|
||||||
@ -109,6 +122,10 @@ private:
|
|||||||
|
|
||||||
network::dns::layer* dns_layer;
|
network::dns::layer* dns_layer;
|
||||||
network::dhcp::layer* dhcp_layer;
|
network::dhcp::layer* dhcp_layer;
|
||||||
|
|
||||||
|
std::atomic<size_t> local_port;
|
||||||
|
|
||||||
|
network::connection_handler<udp_connection> connections;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of upd namespace
|
} // end of upd namespace
|
||||||
|
@ -6,11 +6,9 @@
|
|||||||
//=======================================================================
|
//=======================================================================
|
||||||
|
|
||||||
#include <bit_field.hpp>
|
#include <bit_field.hpp>
|
||||||
#include <atomic.hpp>
|
|
||||||
|
|
||||||
#include "conc/condition_variable.hpp"
|
#include "conc/condition_variable.hpp"
|
||||||
|
|
||||||
#include "net/connection_handler.hpp"
|
|
||||||
#include "net/tcp_layer.hpp"
|
#include "net/tcp_layer.hpp"
|
||||||
#include "net/dns_layer.hpp"
|
#include "net/dns_layer.hpp"
|
||||||
#include "net/checksum.hpp"
|
#include "net/checksum.hpp"
|
||||||
@ -23,10 +21,9 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::atomic<size_t> local_port;
|
|
||||||
|
|
||||||
static constexpr size_t timeout_ms = 1000;
|
static constexpr size_t timeout_ms = 1000;
|
||||||
static constexpr size_t max_tries = 5;
|
static constexpr size_t max_tries = 5;
|
||||||
|
constexpr size_t default_tcp_header_length = 20;
|
||||||
|
|
||||||
using flag_data_offset = std::bit_field<uint16_t, uint8_t, 12, 4>;
|
using flag_data_offset = std::bit_field<uint16_t, uint8_t, 12, 4>;
|
||||||
using flag_reserved = std::bit_field<uint16_t, uint8_t, 9, 3>;
|
using flag_reserved = std::bit_field<uint16_t, uint8_t, 9, 3>;
|
||||||
@ -40,8 +37,6 @@ using flag_rst = std::bit_field<uint16_t, uint8_t, 2, 1>;
|
|||||||
using flag_syn = std::bit_field<uint16_t, uint8_t, 1, 1>;
|
using flag_syn = std::bit_field<uint16_t, uint8_t, 1, 1>;
|
||||||
using flag_fin = std::bit_field<uint16_t, uint8_t, 0, 1>;
|
using flag_fin = std::bit_field<uint16_t, uint8_t, 0, 1>;
|
||||||
|
|
||||||
network::connection_handler<network::tcp::tcp_connection> connections;
|
|
||||||
|
|
||||||
void compute_checksum(network::ethernet::packet& packet) {
|
void compute_checksum(network::ethernet::packet& packet) {
|
||||||
auto* ip_header = reinterpret_cast<network::ip::header*>(packet.payload + packet.tag(1));
|
auto* ip_header = reinterpret_cast<network::ip::header*>(packet.payload + packet.tag(1));
|
||||||
auto* tcp_header = reinterpret_cast<network::tcp::header*>(packet.payload + packet.tag(2));
|
auto* tcp_header = reinterpret_cast<network::tcp::header*>(packet.payload + packet.tag(2));
|
||||||
@ -66,8 +61,6 @@ void compute_checksum(network::ethernet::packet& packet) {
|
|||||||
tcp_header->checksum = switch_endian_16(network::checksum_finalize_nz(sum));
|
tcp_header->checksum = switch_endian_16(network::checksum_finalize_nz(sum));
|
||||||
}
|
}
|
||||||
|
|
||||||
constexpr size_t default_tcp_header_length = 20;
|
|
||||||
|
|
||||||
uint16_t get_default_flags() {
|
uint16_t get_default_flags() {
|
||||||
uint16_t flags = 0; // By default
|
uint16_t flags = 0; // By default
|
||||||
|
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
|
|
||||||
#include <atomic.hpp>
|
#include <atomic.hpp>
|
||||||
|
|
||||||
#include "net/connection_handler.hpp"
|
|
||||||
#include "net/udp_layer.hpp"
|
#include "net/udp_layer.hpp"
|
||||||
#include "net/dns_layer.hpp"
|
#include "net/dns_layer.hpp"
|
||||||
#include "net/dhcp_layer.hpp"
|
#include "net/dhcp_layer.hpp"
|
||||||
@ -19,21 +18,6 @@
|
|||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::atomic<size_t> local_port;
|
|
||||||
|
|
||||||
struct udp_connection {
|
|
||||||
size_t local_port; ///< The local source port
|
|
||||||
size_t server_port; ///< The server port
|
|
||||||
network::ip::address server_address; ///< The server address
|
|
||||||
|
|
||||||
bool connected = false;
|
|
||||||
bool server = false;
|
|
||||||
|
|
||||||
network::socket* socket = nullptr;
|
|
||||||
};
|
|
||||||
|
|
||||||
network::connection_handler<udp_connection> connections;
|
|
||||||
|
|
||||||
void compute_checksum(network::ethernet::packet& packet){
|
void compute_checksum(network::ethernet::packet& packet){
|
||||||
auto* ip_header = reinterpret_cast<network::ip::header*>(packet.payload + packet.tag(1));
|
auto* ip_header = reinterpret_cast<network::ip::header*>(packet.payload + packet.tag(1));
|
||||||
auto* udp_header = reinterpret_cast<network::udp::header*>(packet.payload + packet.tag(2));
|
auto* udp_header = reinterpret_cast<network::udp::header*>(packet.payload + packet.tag(2));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user