---
title: llarp/layers/flow/flow_info.hpp

---

# llarp/layers/flow/flow_info.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)**  |
| **[std](Namespaces/namespacestd.md)** <br>STL namespace.  |

## Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[llarp::layers::flow::FlowInfo](Classes/structllarp_1_1layers_1_1flow_1_1FlowInfo.md)** <br>information about our flow identity.  |
| struct | **[std::hash< llarp::layers::flow::FlowInfo >](Classes/structstd_1_1hash_3_01llarp_1_1layers_1_1flow_1_1FlowInfo_01_4.md)**  |




## Source code

```cpp
#pragma once

#include <oxenc/hex.h>
#include "flow_addr.hpp"
#include "flow_tag.hpp"
#include "flow_constants.hpp"

#include <llarp/constants/bits.hpp>

#include <cstddef>
#include <limits>
#include <llarp/service/convotag.hpp>
#include <utility>
#include <valarray>

namespace llarp::layers::flow
{

  struct FlowInfo
  {
    FlowAddr src, dst;

    std::set<FlowTag> flow_tags;

    uint16_t mtu{default_flow_mtu};

    std::string
    ToString() const;

    bool
    operator==(const FlowInfo& other) const;
  };
}  // namespace llarp::layers::flow

namespace llarp
{
  template <>
  inline constexpr bool IsToStringFormattable<llarp::layers::flow::FlowInfo> = true;

}

namespace std
{
  template <>
  struct hash<llarp::layers::flow::FlowInfo>
  {
    static inline constexpr size_t num_hash_bits = llarp::util::num_bits<size_t>();

    // incremenets idx by one and hashes the member
    template <typename T>
    size_t
    hash_member(const T& member, size_t n, size_t prev_hash) const
    {
      size_t h = std::hash<T>{}(member);
      // for the first element just return the hash xor previous hash.
      if (n == 0)
        return h ^ prev_hash;

      auto bytes = std::valarray<bool>(num_hash_bits);
      for (size_t idx = 0; idx < bytes.size(); ++idx)
        bytes[idx] = (h & idx) != 0;

      bytes.cshift(static_cast<int>(n % num_hash_bits));
    }

    size_t
    operator()(const llarp::layers::flow::FlowInfo& info) const
    {
      size_t h{};
      size_t n{};

      h = hash_member(info.src, n++, h);
      h = hash_member(info.dst, n++, h);

      for (const auto& tag : info.flow_tags)
        h = hash_member(tag, n++, h);
      return h;
    }
  };
}  // namespace std
```


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

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