---
title: llarp/net/traffic_policy.hpp

---

# llarp/net/traffic_policy.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::net](Namespaces/namespacellarp_1_1net.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::net::ProtocolInfo](Classes/structllarp_1_1net_1_1ProtocolInfo.md)** <br>information about an IP protocol  |
| struct | **[llarp::net::TrafficPolicy](Classes/structllarp_1_1net_1_1TrafficPolicy.md)** <br>information about what traffic an endpoint will carry  |




## Source code

```cpp
#pragma once

#include "ip_range.hpp"
#include "ip_packet.hpp"
#include "llarp/util/status.hpp"

#include <set>

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

    bool
    BEncode(llarp_buffer_t* buf) const;

    bool
    BDecode(llarp_buffer_t* buf);

    util::StatusObject
    ExtractStatus() const;

    bool
    MatchesPacket(const IPPacket& pkt) const;

    bool
    operator<(const ProtocolInfo& other) const
    {
      return std::tie(protocol, port) < std::tie(other.protocol, 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);
    util::StatusObject
    ExtractStatus() const;

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


-------------------------------

Updated on 2022-11-08 at 16:19:49 +0000
