pull/1576/head
Jeff Becker 3 years ago
parent 4446f2fc16
commit 1885b1cae9
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

2
external/ngtcp2 vendored

@ -1 +1 @@
Subproject commit 51e95c8d8972abd69515d9790e8fbb774262d9ea Subproject commit 241882dcda534ed6657f10626b7886583c052dd3

@ -34,7 +34,7 @@ target_link_libraries(lokinet-util PUBLIC
nlohmann_json::nlohmann_json nlohmann_json::nlohmann_json
filesystem filesystem
date::date date::date
oxenmq oxenmq::oxenmq
) )
if(ANDROID) if(ANDROID)
@ -98,6 +98,7 @@ add_library(lokinet-quic
quic/tunnel_client.cpp quic/tunnel_client.cpp
quic/tunnel_server.cpp quic/tunnel_server.cpp
) )
target_link_libraries(lokinet-quic PRIVATE lokinet-platform ngtcp2) target_link_libraries(lokinet-quic PRIVATE lokinet-platform ngtcp2)
add_library(liblokinet add_library(liblokinet
@ -197,6 +198,7 @@ add_library(liblokinet
service/address.cpp service/address.cpp
service/async_key_exchange.cpp service/async_key_exchange.cpp
service/auth.cpp service/auth.cpp
service/convotag.cpp
service/context.cpp service/context.cpp
service/endpoint_state.cpp service/endpoint_state.cpp
service/endpoint_util.cpp service/endpoint_util.cpp
@ -237,7 +239,7 @@ if(WITH_HIVE)
) )
endif() endif()
target_link_libraries(liblokinet PUBLIC cxxopts lokinet-platform lokinet-util lokinet-cryptography lokinet-quic sqlite_orm) target_link_libraries(liblokinet PUBLIC cxxopts lokinet-platform lokinet-util lokinet-cryptography lokinet-quic sqlite_orm ngtcp2)
target_link_libraries(liblokinet PRIVATE libunbound) target_link_libraries(liblokinet PRIVATE libunbound)

@ -1,6 +1,8 @@
#include <bits/stdint-uintn.h>
#include <chrono> #include <chrono>
#include "config.hpp" #include "config.hpp"
#include "config/definition.hpp"
#include "ini.hpp" #include "ini.hpp"
#include <llarp/constants/defaults.hpp> #include <llarp/constants/defaults.hpp>
#include <llarp/constants/files.hpp> #include <llarp/constants/files.hpp>
@ -621,6 +623,16 @@ namespace llarp
m_SRVRecords.push_back(std::move(newSRV)); m_SRVRecords.push_back(std::move(newSRV));
}); });
conf.defineOption<uint16_t>(
"network",
"expose",
ClientOnly,
MultiValue,
Comment{
"expose a local port via quic for liblokinet",
},
[this](uint16_t port) { m_quicServerPorts.insert(port); });
// Deprecated options: // Deprecated options:
conf.defineOption<std::string>("network", "enabled", Deprecated); conf.defineOption<std::string>("network", "enabled", Deprecated);
} }

@ -121,6 +121,8 @@ namespace llarp
std::optional<huint128_t> m_baseV6Address; std::optional<huint128_t> m_baseV6Address;
std::unordered_set<uint16_t> m_quicServerPorts;
// TODO: // TODO:
// on-up // on-up
// on-down // on-down

@ -1,5 +1,4 @@
#include "address.hpp" #include "address.hpp"
#include <netinet/in.h>
#include <cstring> #include <cstring>
#include <iostream> #include <iostream>

@ -14,17 +14,17 @@ namespace llarp::service
sockaddr_in6 sockaddr_in6
ConvoTag::ToV6() const ConvoTag::ToV6() const
{ {
const auto* ptr = reinterpret_cast<const uint64_t*>(m_data.data()); const auto* ptr = reinterpret_cast<const uint64_t*>(data());
sockaddr_in6 saddr{}; sockaddr_in6 saddr{};
saddr.sin6_family = AF_INET6; saddr.sin6_family = AF_INET6;
saddr.sin6_addr = net::HUIntToIn6(huint128_t{ptr[0], ptr[1]}); saddr.sin6_addr = net::HUIntToIn6(huint128_t{uint128_t{ptr[0], ptr[1]}});
return saddr; return saddr;
} }
void void
ConvoTag::FromV6(sockaddr_in6 saddr) ConvoTag::FromV6(sockaddr_in6 saddr)
{ {
std::copy_n(saddr.sin6_addr.s6_addr, m_data.size(), m_data.data()); std::copy_n(saddr.sin6_addr.s6_addr, size(), data());
} }
} // namespace llarp::service } // namespace llarp::service

@ -19,17 +19,25 @@
#include "endpoint_state.hpp" #include "endpoint_state.hpp"
#include "endpoint_util.hpp" #include "endpoint_util.hpp"
#include "hidden_service_address_lookup.hpp" #include "hidden_service_address_lookup.hpp"
#include "net/ip.hpp"
#include "outbound_context.hpp" #include "outbound_context.hpp"
#include "protocol.hpp" #include "protocol.hpp"
#include "service/info.hpp"
#include <llarp/util/str.hpp> #include <llarp/util/str.hpp>
#include <llarp/util/buffer.hpp> #include <llarp/util/buffer.hpp>
#include <llarp/util/meta/memfn.hpp> #include <llarp/util/meta/memfn.hpp>
#include <llarp/hook/shell.hpp> #include <llarp/hook/shell.hpp>
#include <llarp/link/link_manager.hpp> #include <llarp/link/link_manager.hpp>
#include <llarp/tooling/dht_event.hpp> #include <llarp/tooling/dht_event.hpp>
#include <llarp/quic/server.hpp>
#include <utility> #include <utility>
#include <llarp/quic/server.hpp>
#include <llarp/quic/tunnel.hpp>
#include <llarp/ev/ev_libuv.hpp>
#include <uvw.hpp>
namespace llarp namespace llarp
{ {
namespace service namespace service
@ -72,6 +80,63 @@ namespace llarp
m_StartupLNSMappings[name] = std::make_pair(range, auth); m_StartupLNSMappings[name] = std::make_pair(range, auth);
}); });
auto loop = uv::Loop::MaybeGetLoop(Router()->loop());
auto callback = [this, loop, ports = conf.m_quicServerPorts](
quic::Server& serv, quic::Stream& stream, uint16_t port) {
if (ports.count(port) == 0)
{
return false;
}
stream.close_callback = [](quic::Stream& st,
[[maybe_unused]] std::optional<uint64_t> errcode) {
auto tcp = st.data<uvw::TCPHandle>();
if (tcp)
tcp->close();
};
auto localIP = net::TruncateV6(GetIfAddr());
std::string localhost = localIP.ToString();
auto tcp = loop->resource<uvw::TCPHandle>();
auto error_handler = tcp->once<uvw::ErrorEvent>(
[&stream, localhost, port](const uvw::ErrorEvent&, uvw::TCPHandle&) {
LogWarn("Failed to connect to ", localhost, ":", port, ", shutting down quic stream");
stream.close(quic::tunnel::ERROR_CONNECT);
});
tcp->once<uvw::ConnectEvent>(
[streamw = stream.weak_from_this(), error_handler = std::move(error_handler)](
const uvw::ConnectEvent&, uvw::TCPHandle& tcp) {
auto peer = tcp.peer();
auto stream = streamw.lock();
if (!stream)
{
LogWarn(
"Connected to ",
peer.ip,
":",
peer.port,
" but quic stream has gone away; resetting local connection");
tcp.closeReset();
return;
}
LogDebug("Connected to ", peer.ip, ":", peer.port, " for quic ", stream->id());
tcp.erase(error_handler);
quic::tunnel::install_stream_forwarding(tcp, *stream);
assert(stream->used() == 0);
stream->append_buffer(new std::byte[1]{quic::tunnel::CONNECT_INIT}, 1);
tcp.read();
});
tcp->connect(localhost, port);
return true;
};
m_QuicServer = std::make_shared<quic::Server>(this, loop, callback);
return m_state->Configure(conf); return m_state->Configure(conf);
} }
@ -1317,6 +1382,16 @@ namespace llarp
return true; return true;
} }
bool
Endpoint::SendTo(ConvoTag tag, const llarp_buffer_t& pkt, ProtocolType t)
{
// TODO: support snode
ServiceInfo ident{};
if (not GetSenderFor(tag, ident))
return false;
return SendToServiceOrQueue(ident.Addr(), pkt, t);
}
bool bool
Endpoint::SendToSNodeOrQueue(const RouterID& addr, const llarp_buffer_t& buf) Endpoint::SendToSNodeOrQueue(const RouterID& addr, const llarp_buffer_t& buf)
{ {

@ -11,11 +11,13 @@
#include "identity.hpp" #include "identity.hpp"
#include "pendingbuffer.hpp" #include "pendingbuffer.hpp"
#include "protocol.hpp" #include "protocol.hpp"
#include "quic/server.hpp"
#include "sendcontext.hpp" #include "sendcontext.hpp"
#include "session.hpp" #include "session.hpp"
#include "lookup.hpp" #include "lookup.hpp"
#include <llarp/hook/ihook.hpp> #include <llarp/hook/ihook.hpp>
#include <llarp/util/compare_ptr.hpp> #include <llarp/util/compare_ptr.hpp>
#include <unordered_map>
#include "endpoint_types.hpp" #include "endpoint_types.hpp"
#include "auth.hpp" #include "auth.hpp"
@ -463,6 +465,8 @@ namespace llarp
ConvoMap& Sessions(); ConvoMap& Sessions();
// clang-format on // clang-format on
thread::Queue<RecvDataEvent> m_RecvQueue; thread::Queue<RecvDataEvent> m_RecvQueue;
std::shared_ptr<quic::Server> m_QuicServer;
}; };
using Endpoint_ptr = std::shared_ptr<Endpoint>; using Endpoint_ptr = std::shared_ptr<Endpoint>;

Loading…
Cancel
Save