llarp/net/traffic_policy.hpp

Namespaces

Name
llarp
[crypto.hpp]
llarp::net

Classes

Name
struct llarp::net::ProtocolInfo
information about an IP protocol
struct llarp::net::TrafficPolicy
information about what traffic an endpoint will carry

Source code

#pragma once

#include "ip_range.hpp"
#include "ip_packet.hpp"

#include <set>

namespace llarp::net
{
  struct ProtocolInfo
  {
    IPProtocol protocol;
    std::optional<port_t> port;

    bool
    BEncode(llarp_buffer_t* buf) const;

    bool
    BDecode(llarp_buffer_t* buf);

    bool
    MatchesPacket(const IPPacket& pkt) const;

    bool
    operator<(const ProtocolInfo& other) const
    {
      const auto h_port = ToHost(port.value_or(port_t{}));
      const auto h_other_port = ToHost(other.port.value_or(port_t{}));
      return std::tie(protocol, h_port) < std::tie(other.protocol, h_other_port);
    }

    ProtocolInfo() = default;

    explicit ProtocolInfo(std::string_view spec);
  };

  struct TrafficPolicy
  {
    std::set<IPRange> ranges;

    std::set<ProtocolInfo> protocols;

    bool
    BEncode(llarp_buffer_t* buf) const;

    bool
    BDecode(llarp_buffer_t* buf);

    bool
    AllowsTraffic(const IPPacket& pkt) const;
  };
}  // namespace llarp::net

Updated on 2026-01-10 at 22:49:45 +0000