---
title: llarp/layers/platform/platform_stats.hpp

---

# llarp/layers/platform/platform_stats.hpp



## Namespaces

| Name           |
| -------------- |
| **[llarp](Namespaces/namespacellarp.md)** <br>[crypto.hpp] |
| **[llarp::layers](Namespaces/namespacellarp_1_1layers.md)**  |
| **[llarp::layers::flow](Namespaces/namespacellarp_1_1layers_1_1flow.md)**  |
| **[llarp::layers::platform](Namespaces/namespacellarp_1_1layers_1_1platform.md)**  |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::layers::platform::MappingStats](Classes/structllarp_1_1layers_1_1platform_1_1MappingStats.md)** <br>stats on a specific addrmapper mapping.  |
| struct | **[llarp::layers::platform::PlatformStats](Classes/structllarp_1_1layers_1_1platform_1_1PlatformStats.md)**  |




## Source code

```cpp
#pragma once

#include <bits/types/clock_t.h>
#include <charconv>
#include <cstdint>
#include <unordered_set>

#include <llarp/layers/flow/flow_addr.hpp>
#include <llarp/net/ip_range_map.hpp>

#include "addr_mapper.hpp"
#include "llarp/layers/flow/flow_info.hpp"
#include "platform_addr.hpp"

namespace llarp::layers::flow
{
  class FlowLayer;
}

namespace llarp::layers::platform
{

  struct MappingStats
  {
    using clock_t = std::chrono::steady_clock;
    PlatformAddr src, dst;

    flow::FlowAddr laddr, raddr;

    clock_t::time_point created_at;

    std::optional<clock_t::time_point> established_at;

    std::optional<clock_t::time_point> last_active_at;

    MappingStats() = default;
    MappingStats(const AddressMapping& ent, const flow::FlowLayer& flow_layer);

    constexpr bool
    allows_transit() const
    {
      return test(_mask_routable_traffic);
    }

    constexpr bool
    is_ready() const
    {
      return traffic_permitted() and test(_mask_established);
    }

    constexpr bool
    traffic_permitted() const
    {
      if (requires_authentication())
        return has_authenticated();
      return true;
    }

    constexpr bool
    has_authenticated() const
    {
      return test(_mask_auth_ok);
    }

    constexpr bool
    requires_authentication() const
    {
      return test(_mask_auth_required);
    }

    constexpr bool
    locally_initiated() const
    {
      return test(_mask_initiated);
    }

   private:
    static inline constexpr auto _mask_established{1 << 0};
    static inline constexpr auto _mask_auth_required{1 << 1};
    static inline constexpr auto _mask_auth_pending{1 << 2};
    static inline constexpr auto _mask_auth_ok{1 << 3};
    static inline constexpr auto _mask_initiated{1 << 4};
    static inline constexpr auto _mask_routable_traffic{1 << 5};

    static inline constexpr auto _mask_bw_limited{1 << 6};

    static inline constexpr auto _initial_flags = _mask_initiated | _mask_bw_limited;

    constexpr bool
    test(int mask) const
    {
      return _flags & mask;
    }

    constexpr void
    set(int mask)
    {
      _flags |= mask;
    }

    constexpr void
    reset()
    {
      _flags = _initial_flags;
    }

    int _flags;
  };

  struct PlatformStats
  {
    std::vector<MappingStats> addrs;

    bool
    wants_client_exit() const;

    bool
    client_exit_ready() const;
  };
}  // namespace llarp::layers::platform
```


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

Updated on 2023-04-27 at 04:17:17 +0000
