Skip to content

Commit

Permalink
big reorg, more commits to come
Browse files Browse the repository at this point in the history
  • Loading branch information
dr7ana committed Jan 13, 2025
1 parent 74a64bb commit 208eed6
Show file tree
Hide file tree
Showing 93 changed files with 966 additions and 1,526 deletions.
2 changes: 1 addition & 1 deletion .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ NamespaceIndentation: All
# shorties
AllowShortBlocksOnASingleLine: 'false'
AllowShortCaseLabelsOnASingleLine: 'false'
AllowShortFunctionsOnASingleLine: Inline
AllowShortFunctionsOnASingleLine: All
AllowShortIfStatementsOnASingleLine: 'false'
AllowShortLoopsOnASingleLine: 'false'

Expand Down
39 changes: 9 additions & 30 deletions llarp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,27 +73,27 @@ add_dependencies(lokinet-utils genversion)
lokinet_add_library(lokinet-contact
contact/client_contact.cpp
contact/client_intro.cpp

contact/contactdb.cpp

contact/keys.cpp

contact/relay_contact.cpp
contact/relay_contact_local.cpp
contact/relay_contact_remote.cpp

contact/router_id.cpp

contact/sns.cpp

contact/tag.cpp
)

# Network interface files used for mediating ip traffic
lokinet_add_library(lokinet-ip
net/ip_packet.cpp
net/policy.cpp
net/utils.cpp
)

# Addressing and event loop files used by lokinet-core and other libraries
# needed by rpc/ link/ config/ path/ dht/
lokinet_add_library(lokinet-addressing
address/address.cpp
address/ip_packet.cpp
address/ip_range.cpp
address/utils.cpp

Expand All @@ -102,15 +102,11 @@ lokinet_add_library(lokinet-addressing
ev/types.cpp
ev/udp.cpp

# net/ip.cpp
# net/net_int.cpp

router_version.cpp # to be deleted shortly
)

# lokinet-platform holds all platform specific code
lokinet_add_library(lokinet-platform
# net/interface_info.cpp
vpn/packet_router.cpp
vpn/platform.cpp
)
Expand Down Expand Up @@ -173,7 +169,6 @@ endif()
# nodedb data published to the network and versions of it stored locally
lokinet_add_library(lokinet-nodedb
bootstrap.cpp # config, router.hpp
net/traffic_policy.cpp # config, intro_set
nodedb.cpp
profiling.cpp # path, router, service::endpoint
)
Expand Down Expand Up @@ -212,17 +207,12 @@ lokinet_add_library(lokinet-path
path/transit_hop.cpp
)

#target_link_libraries(lokinet-core PUBLIC lokinet-core-utils)
#target_link_libraries(lokinet-core-utils PUBLIC lokinet-dns)
#target_link_libraries(lokinet-dns PUBLIC lokinet-dns-platform)
#target_link_libraries(lokinet-dns PUBLIC lokinet-utils lokinet-cryptography lokinet-config lokinet-dns-platform)

# Link libraries to their internals
target_link_libraries(lokinet-wire PUBLIC lokinet-addressing)
target_link_libraries(lokinet-nodedb PUBLIC lokinet-addressing lokinet-cryptography)
target_link_libraries(lokinet-platform PUBLIC lokinet-cryptography)
target_link_libraries(lokinet-platform PUBLIC lokinet-cryptography lokinet-ip)
target_link_libraries(lokinet-rpc PUBLIC lokinet-wire lokinet-contact)
target_link_libraries(lokinet-addressing PUBLIC lokinet-utils lokinet-cryptography lokinet-contact)
target_link_libraries(lokinet-addressing PUBLIC lokinet-utils lokinet-cryptography lokinet-contact lokinet-ip)
target_link_libraries(lokinet-wire PUBLIC lokinet-cryptography)
target_link_libraries(lokinet-config PUBLIC lokinet-cryptography)

Expand Down Expand Up @@ -289,17 +279,6 @@ target_link_libraries(lokinet-base
)


# target_link_libraries(lokinet-rpc PUBLIC oxenmq::oxenmq)
# target_link_libraries(lokinet-core PUBLIC oxenmq::oxenmq)
# target_link_libraries(lokinet-config PUBLIC oxenmq::oxenmq)
# target_link_libraries(lokinet-nodedb PUBLIC oxenmq::oxenmq)
# target_link_libraries(lokinet-path PUBLIC oxenmq::oxenmq)
# target_link_libraries(lokinet-platform PUBLIC oxenmq::oxenmq Threads::Threads)
# target_link_libraries(lokinet-cryptography PUBLIC sodium)
# target_link_libraries(lokinet-dns PUBLIC libunbound)
# target_link_libraries(lokinet-utils PUBLIC nlohmann_json::nlohmann_json)
# target_link_libraries(lokinet-wire PUBLIC oxenmq::oxenmq quic)

if(WITH_EMBEDDED_LOKINET)
include(GNUInstallDirs)
add_library(lokinet-shared SHARED lokinet_shared.cpp)
Expand Down
20 changes: 4 additions & 16 deletions llarp/address/address.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,7 @@ namespace llarp
return std::tie(_pubkey, _is_client) == std::tie(other._pubkey, other._is_client);
}

bool NetworkAddress::operator!=(const NetworkAddress& other) const
{
return !(*this == other);
}
bool NetworkAddress::operator!=(const NetworkAddress& other) const { return !(*this == other); }

std::optional<RelayAddress> RelayAddress::from_relay_addr(std::string arg)
{
Expand All @@ -73,18 +70,9 @@ namespace llarp
throw std::invalid_argument{"Invalid pubkey passed to RelayAddress constructor: {}"_format(arg)};
}

bool RelayAddress::operator<(const RelayAddress& other) const
{
return _pubkey < other._pubkey;
}
bool RelayAddress::operator<(const RelayAddress& other) const { return _pubkey < other._pubkey; }

bool RelayAddress::operator==(const RelayAddress& other) const
{
return _pubkey == other._pubkey;
}
bool RelayAddress::operator==(const RelayAddress& other) const { return _pubkey == other._pubkey; }

bool RelayAddress::operator!=(const RelayAddress& other) const
{
return !(*this == other);
}
bool RelayAddress::operator!=(const RelayAddress& other) const { return !(*this == other); }
} // namespace llarp
1 change: 0 additions & 1 deletion llarp/address/address.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
#include <llarp/contact/router_id.hpp>
#include <llarp/contact/sns.hpp>
#include <llarp/util/aligned.hpp>
#include <llarp/util/concept.hpp>

#include <oxen/quic.hpp>

Expand Down
67 changes: 0 additions & 67 deletions llarp/address/ip_headers.hpp

This file was deleted.

10 changes: 2 additions & 8 deletions llarp/address/ip_range.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,9 @@ namespace llarp
return _contains(std::get<ipv6>(other.base_ip()));
}

bool IPRange::_contains(const ipv4& other) const
{
return _ipv4_range().contains(other);
}
bool IPRange::_contains(const ipv4& other) const { return _ipv4_range().contains(other); }

bool IPRange::_contains(const ipv6& other) const
{
return _ipv6_range().contains(other);
}
bool IPRange::_contains(const ipv6& other) const { return _ipv6_range().contains(other); }

bool IPRange::contains(const ip_v& other) const
{
Expand Down
2 changes: 0 additions & 2 deletions llarp/address/ip_range.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

#include "utils.hpp"

#include <llarp/util/concept.hpp>

#include <oxenc/bt_serialize.h>

namespace llarp
Expand Down
58 changes: 0 additions & 58 deletions llarp/address/types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,64 +25,6 @@ namespace llarp
} // namespace concepts

using KeyedAddress = oxen::quic::RemoteAddress;

inline constexpr uint32_t ipv6_flowlabel_mask = 0b0000'0000'0000'1111'1111'1111'1111'1111;

inline constexpr size_t ICMP_HEADER_SIZE{8};

// Compares the given ip variant against a quic address
// Returns:
// - true : ip == address
// - false : ip != address
// Error:
// - throws : ip and address are mismatched ipv4 vs ipv6
inline bool ip_equals_address(const ip_v& ip, const oxen::quic::Address& addr, bool compare_v4)
{
if (compare_v4 and std::holds_alternative<ipv4>(ip))
return std::get<ipv4>(ip) == addr.to_ipv4();

if (not compare_v4 and std::holds_alternative<ipv6>(ip))
return std::get<ipv6>(ip) == addr.to_ipv6();

throw std::invalid_argument{
"Failed to compare ip variant in desired {} scheme!"_format(compare_v4 ? "ipv4" : "ipv6")};
}

struct ipv6_header
{
union
{
#if __BYTE_ORDER == __LITTLE_ENDIAN
unsigned char pad_small : 4;
unsigned char version : 4;
#else
unsigned char version : 4;
unsigned char pad_small : 4;
#endif
uint8_t pad[3];
uint32_t flowlabel;
} preamble;

uint16_t payload_len;
uint8_t protocol;
uint8_t hoplimit;
in6_addr src;
in6_addr dest;

/// Returns the flowlabel (stored in network order) in HOST ORDER
uint32_t get_flowlabel() const { return ntohl(preamble.flowlabel & htonl(ipv6_flowlabel_mask)); }

/// Sets a flowlabel in network order. Takes in a label in HOST ORDER
void set_flowlabel(uint32_t label)
{
// the ipv6 flow label is the last 20 bits in the first 32 bits of the header
preamble.flowlabel =
(htonl(ipv6_flowlabel_mask) & htonl(label)) | (preamble.flowlabel & htonl(~ipv6_flowlabel_mask));
}
};

static_assert(sizeof(ipv6_header) == 40);

} // namespace llarp

namespace std
Expand Down
Loading

0 comments on commit 208eed6

Please sign in to comment.