mirror of
https://github.com/oxen-io/lokinet
synced 2023-12-14 06:53:00 +01:00
* add protocol type to snode traffic
* make path::PathSet::SendPacketToRemote know about protocol type
This commit is contained in:
parent
e4ca7ce4de
commit
9d483a12db
|
@ -203,7 +203,8 @@ namespace llarp
|
|||
}
|
||||
|
||||
bool
|
||||
BaseSession::QueueUpstreamTraffic(llarp::net::IPPacket pkt, const size_t N)
|
||||
BaseSession::QueueUpstreamTraffic(
|
||||
llarp::net::IPPacket pkt, const size_t N, service::ProtocolType t)
|
||||
{
|
||||
const auto pktbuf = pkt.ConstBuffer();
|
||||
const llarp_buffer_t& buf = pktbuf;
|
||||
|
@ -214,6 +215,7 @@ namespace llarp
|
|||
if (queue.size() == 0)
|
||||
{
|
||||
queue.emplace_back();
|
||||
queue.back().protocol = t;
|
||||
return queue.back().PutBuffer(buf, m_Counter++);
|
||||
}
|
||||
auto& back = queue.back();
|
||||
|
@ -221,9 +223,10 @@ namespace llarp
|
|||
if (back.Size() + buf.sz > N)
|
||||
{
|
||||
queue.emplace_back();
|
||||
queue.back().protocol = t;
|
||||
return queue.back().PutBuffer(buf, m_Counter++);
|
||||
}
|
||||
|
||||
back.protocol = t;
|
||||
return back.PutBuffer(buf, m_Counter++);
|
||||
}
|
||||
|
||||
|
@ -340,23 +343,23 @@ namespace llarp
|
|||
}
|
||||
|
||||
void
|
||||
SNodeSession::SendPacketToRemote(const llarp_buffer_t& buf)
|
||||
SNodeSession::SendPacketToRemote(const llarp_buffer_t& buf, service::ProtocolType t)
|
||||
{
|
||||
net::IPPacket pkt;
|
||||
if (not pkt.Load(buf))
|
||||
return;
|
||||
pkt.ZeroAddresses();
|
||||
QueueUpstreamTraffic(std::move(pkt), llarp::routing::ExitPadSize);
|
||||
QueueUpstreamTraffic(std::move(pkt), llarp::routing::ExitPadSize, t);
|
||||
}
|
||||
|
||||
void
|
||||
ExitSession::SendPacketToRemote(const llarp_buffer_t& buf)
|
||||
ExitSession::SendPacketToRemote(const llarp_buffer_t& buf, service::ProtocolType t)
|
||||
{
|
||||
net::IPPacket pkt;
|
||||
if (not pkt.Load(buf))
|
||||
return;
|
||||
pkt.ZeroSourceAddress();
|
||||
QueueUpstreamTraffic(std::move(pkt), llarp::routing::ExitPadSize);
|
||||
QueueUpstreamTraffic(std::move(pkt), llarp::routing::ExitPadSize, t);
|
||||
}
|
||||
} // namespace exit
|
||||
} // namespace llarp
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "exit_messages.hpp"
|
||||
#include "service/protocol_type.hpp"
|
||||
#include <llarp/net/ip_packet.hpp>
|
||||
#include <llarp/path/pathbuilder.hpp>
|
||||
#include <llarp/routing/transfer_traffic_message.hpp>
|
||||
|
@ -76,7 +77,8 @@ namespace llarp
|
|||
HandlePathBuilt(llarp::path::Path_ptr p) override;
|
||||
|
||||
bool
|
||||
QueueUpstreamTraffic(llarp::net::IPPacket pkt, const size_t packSize);
|
||||
QueueUpstreamTraffic(
|
||||
llarp::net::IPPacket pkt, const size_t packSize, service::ProtocolType t);
|
||||
|
||||
/// flush upstream to exit via paths
|
||||
bool
|
||||
|
@ -181,7 +183,7 @@ namespace llarp
|
|||
Name() const override;
|
||||
|
||||
virtual void
|
||||
SendPacketToRemote(const llarp_buffer_t& pkt) override;
|
||||
SendPacketToRemote(const llarp_buffer_t& pkt, service::ProtocolType t) override;
|
||||
|
||||
protected:
|
||||
void
|
||||
|
@ -210,7 +212,7 @@ namespace llarp
|
|||
Name() const override;
|
||||
|
||||
virtual void
|
||||
SendPacketToRemote(const llarp_buffer_t& pkt) override;
|
||||
SendPacketToRemote(const llarp_buffer_t& pkt, service::ProtocolType t) override;
|
||||
|
||||
protected:
|
||||
void
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <llarp/util/bits.hpp>
|
||||
|
||||
#include <cassert>
|
||||
#include "service/protocol_type.hpp"
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -235,8 +236,9 @@ namespace llarp
|
|||
auto itr = m_SNodeSessions.find(pk);
|
||||
if (itr != m_SNodeSessions.end())
|
||||
{
|
||||
if (itr->second->QueueUpstreamTraffic(pkt, routing::ExitPadSize))
|
||||
return;
|
||||
// TODO: quic (?)
|
||||
itr->second->SendPacketToRemote(pkt.ConstBuffer(), service::ProtocolType::TrafficV4);
|
||||
return;
|
||||
}
|
||||
}
|
||||
auto tryFlushingTraffic = [&](exit::Endpoint* const ep) -> bool {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <llarp/service/endpoint.hpp>
|
||||
#include "service/protocol_type.hpp"
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -39,7 +40,7 @@ namespace llarp
|
|||
}
|
||||
|
||||
void
|
||||
SendPacketToRemote(const llarp_buffer_t&) override{};
|
||||
SendPacketToRemote(const llarp_buffer_t&, service::ProtocolType) override{};
|
||||
|
||||
huint128_t ObtainIPForAddr(std::variant<service::Address, RouterID>) override
|
||||
{
|
||||
|
|
|
@ -973,8 +973,9 @@ namespace llarp
|
|||
sendFunc = std::bind(
|
||||
&TunEndpoint::SendToSNodeOrQueue,
|
||||
this,
|
||||
itr->second.as_array(),
|
||||
std::placeholders::_1);
|
||||
RouterID{itr->second.as_array()},
|
||||
std::placeholders::_1,
|
||||
service::ProtocolType::TrafficV4);
|
||||
}
|
||||
else if (m_state->m_ExitEnabled and src != m_OurIP)
|
||||
{
|
||||
|
@ -982,7 +983,7 @@ namespace llarp
|
|||
sendFunc = std::bind(
|
||||
&TunEndpoint::SendToServiceOrQueue,
|
||||
this,
|
||||
service::Address(itr->second.as_array()),
|
||||
service::Address{itr->second.as_array()},
|
||||
std::placeholders::_1,
|
||||
service::ProtocolType::Exit);
|
||||
}
|
||||
|
@ -991,7 +992,7 @@ namespace llarp
|
|||
sendFunc = std::bind(
|
||||
&TunEndpoint::SendToServiceOrQueue,
|
||||
this,
|
||||
service::Address(itr->second.as_array()),
|
||||
service::Address{itr->second.as_array()},
|
||||
std::placeholders::_1,
|
||||
pkt.ServiceProtocol());
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
#include <queue>
|
||||
#include <type_traits>
|
||||
#include <variant>
|
||||
#include "service/protocol_type.hpp"
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
@ -40,7 +41,7 @@ namespace llarp
|
|||
Configure(const NetworkConfig& conf, const DnsConfig& dnsConf) override;
|
||||
|
||||
void
|
||||
SendPacketToRemote(const llarp_buffer_t&) override{};
|
||||
SendPacketToRemote(const llarp_buffer_t&, service::ProtocolType) override{};
|
||||
|
||||
std::string
|
||||
GetIfName() const override;
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "path_types.hpp"
|
||||
#include "service/protocol_type.hpp"
|
||||
#include <llarp/router_id.hpp>
|
||||
#include <llarp/routing/message.hpp>
|
||||
#include <llarp/service/intro_set.hpp>
|
||||
|
@ -276,7 +277,7 @@ namespace llarp
|
|||
BuildOneAlignedTo(const RouterID endpoint) = 0;
|
||||
|
||||
virtual void
|
||||
SendPacketToRemote(const llarp_buffer_t& pkt) = 0;
|
||||
SendPacketToRemote(const llarp_buffer_t& pkt, service::ProtocolType t) = 0;
|
||||
|
||||
virtual std::optional<std::vector<RouterContact>>
|
||||
GetHopsForBuild() = 0;
|
||||
|
|
|
@ -30,6 +30,8 @@ namespace llarp
|
|||
return false;
|
||||
if (!BEncodeWriteDictMsgType(buf, "A", "I"))
|
||||
return false;
|
||||
if (!BEncodeWriteDictInt("P", protocol, buf))
|
||||
return false;
|
||||
if (!BEncodeWriteDictInt("S", S, buf))
|
||||
return false;
|
||||
if (!BEncodeWriteDictInt("V", version, buf))
|
||||
|
@ -45,6 +47,8 @@ namespace llarp
|
|||
bool read = false;
|
||||
if (!BEncodeMaybeReadDictInt("S", S, read, key, buf))
|
||||
return false;
|
||||
if (!BEncodeMaybeReadDictInt("P", protocol, read, key, buf))
|
||||
return false;
|
||||
if (!BEncodeMaybeReadDictInt("V", version, read, key, buf))
|
||||
return false;
|
||||
if (!BEncodeMaybeReadDictList("X", X, read, key, buf))
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include <llarp/crypto/encrypted.hpp>
|
||||
#include "message.hpp"
|
||||
#include <llarp/service/protocol_type.hpp>
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -15,6 +16,7 @@ namespace llarp
|
|||
struct TransferTrafficMessage final : public IMessage
|
||||
{
|
||||
std::vector<llarp::Encrypted<MaxExitMTU + ExitOverhead>> X;
|
||||
service::ProtocolType protocol;
|
||||
size_t _size = 0;
|
||||
|
||||
void
|
||||
|
@ -23,6 +25,7 @@ namespace llarp
|
|||
X.clear();
|
||||
_size = 0;
|
||||
version = 0;
|
||||
protocol = service::ProtocolType::TrafficV4;
|
||||
}
|
||||
|
||||
size_t
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include "outbound_context.hpp"
|
||||
#include "protocol.hpp"
|
||||
#include "service/info.hpp"
|
||||
#include "service/protocol_type.hpp"
|
||||
#include <llarp/util/str.hpp>
|
||||
#include <llarp/util/buffer.hpp>
|
||||
#include <llarp/util/meta/memfn.hpp>
|
||||
|
@ -1380,22 +1381,30 @@ namespace llarp
|
|||
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);
|
||||
if (auto maybe = GetEndpointWithConvoTag(tag))
|
||||
{
|
||||
auto addr = *maybe;
|
||||
if (auto ptr = std::get_if<Address>(&addr))
|
||||
{
|
||||
return SendToServiceOrQueue(*ptr, pkt, t);
|
||||
}
|
||||
if (auto ptr = std::get_if<RouterID>(&addr))
|
||||
{
|
||||
return SendToSNodeOrQueue(*ptr, pkt, t);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
Endpoint::SendToSNodeOrQueue(const RouterID& addr, const llarp_buffer_t& buf)
|
||||
Endpoint::SendToSNodeOrQueue(const RouterID& addr, const llarp_buffer_t& buf, ProtocolType t)
|
||||
{
|
||||
auto pkt = std::make_shared<net::IPPacket>();
|
||||
if (!pkt->Load(buf))
|
||||
return false;
|
||||
EnsurePathToSNode(addr, [pkt](RouterID, exit::BaseSession_ptr s) {
|
||||
EnsurePathToSNode(addr, [pkt, t](RouterID, exit::BaseSession_ptr s) {
|
||||
if (s)
|
||||
s->QueueUpstreamTraffic(*pkt, routing::ExitPadSize);
|
||||
s->SendPacketToRemote(pkt->ConstBuffer(), t);
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "protocol.hpp"
|
||||
#include "quic/server.hpp"
|
||||
#include "sendcontext.hpp"
|
||||
#include "service/protocol_type.hpp"
|
||||
#include "session.hpp"
|
||||
#include "lookup.hpp"
|
||||
#include <llarp/hook/ihook.hpp>
|
||||
|
@ -361,7 +362,7 @@ namespace llarp
|
|||
SendToServiceOrQueue(
|
||||
const service::Address& addr, const llarp_buffer_t& payload, ProtocolType t);
|
||||
bool
|
||||
SendToSNodeOrQueue(const RouterID& addr, const llarp_buffer_t& payload);
|
||||
SendToSNodeOrQueue(const RouterID& addr, const llarp_buffer_t& payload, ProtocolType t);
|
||||
|
||||
std::optional<AuthInfo>
|
||||
MaybeGetAuthInfoForEndpoint(service::Address addr);
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <llarp/util/meta/memfn.hpp>
|
||||
|
||||
#include "endpoint_util.hpp"
|
||||
#include "service/protocol_type.hpp"
|
||||
|
||||
#include <random>
|
||||
#include <algorithm>
|
||||
|
@ -601,9 +602,9 @@ namespace llarp
|
|||
}
|
||||
|
||||
void
|
||||
OutboundContext::SendPacketToRemote(const llarp_buffer_t& buf)
|
||||
OutboundContext::SendPacketToRemote(const llarp_buffer_t& buf, service::ProtocolType t)
|
||||
{
|
||||
AsyncEncryptAndSendTo(buf, ProtocolType::Exit);
|
||||
AsyncEncryptAndSendTo(buf, t);
|
||||
}
|
||||
|
||||
} // namespace service
|
||||
|
|
|
@ -72,7 +72,7 @@ namespace llarp
|
|||
|
||||
/// for exits
|
||||
void
|
||||
SendPacketToRemote(const llarp_buffer_t&) override;
|
||||
SendPacketToRemote(const llarp_buffer_t&, ProtocolType t) override;
|
||||
|
||||
bool
|
||||
ShouldBuildMore(llarp_time_t now) const override;
|
||||
|
|
|
@ -91,7 +91,7 @@ namespace llarp
|
|||
}
|
||||
|
||||
void
|
||||
SendPacketToRemote(const llarp_buffer_t&) override{};
|
||||
SendPacketToRemote(const llarp_buffer_t&, service::ProtocolType) override{};
|
||||
|
||||
std::string
|
||||
GetOurAddress() const
|
||||
|
|
Loading…
Reference in a new issue