mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-10-31 09:20:21 +00:00
7caa87862e
All #ifndef guards on headers have been removed, I think, in favor of #pragma once Headers are now included as `#include "filename"` if the included file resides in the same directory as the file including it, or any subdirectory therein. Otherwise they are included as `#include <project/top/dir/relative/path/filename>` The above does not include system/os headers.
43 lines
1.1 KiB
C++
43 lines
1.1 KiB
C++
#pragma once
|
|
#include <llarp/net/net_int.hpp>
|
|
#include <llarp/net/ip_packet.hpp>
|
|
#include <functional>
|
|
#include <unordered_map>
|
|
|
|
namespace llarp::vpn
|
|
{
|
|
using PacketHandlerFunc = std::function<void(llarp::net::IPPacket)>;
|
|
|
|
struct Layer4Handler
|
|
{
|
|
virtual ~Layer4Handler() = default;
|
|
|
|
virtual void
|
|
HandleIPPacket(llarp::net::IPPacket pkt) = 0;
|
|
|
|
virtual void AddSubHandler(nuint16_t, PacketHandlerFunc){};
|
|
};
|
|
|
|
class PacketRouter
|
|
{
|
|
PacketHandlerFunc m_BaseHandler;
|
|
std::unordered_map<uint8_t, std::unique_ptr<Layer4Handler>> m_IPProtoHandler;
|
|
|
|
public:
|
|
/// baseHandler will be called if no other handlers matches a packet
|
|
explicit PacketRouter(PacketHandlerFunc baseHandler);
|
|
|
|
/// feed in an ip packet for handling
|
|
void
|
|
HandleIPPacket(llarp::net::IPPacket pkt);
|
|
|
|
/// add a non udp packet handler using ip protocol proto
|
|
void
|
|
AddIProtoHandler(uint8_t proto, PacketHandlerFunc func);
|
|
|
|
/// helper that adds a udp packet handler for UDP destinted for localport
|
|
void
|
|
AddUDPHandler(huint16_t localport, PacketHandlerFunc func);
|
|
};
|
|
} // namespace llarp::vpn
|