---
title: llarp::layers::platform::AddrMapper
summary: in charge of mapping flow addresses and platform addresses to each other 

---

# llarp::layers::platform::AddrMapper



in charge of mapping flow addresses and platform addresses to each other 


`#include <addr_mapper.hpp>`

## Public Functions

|                | Name           |
| -------------- | -------------- |
| | **[AddrMapper](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-addrmapper)**(const [IPRange](Classes/structllarp_1_1IPRange.md) & range) |
| void | **[put](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-put)**([AddressMapping](Classes/structllarp_1_1layers_1_1platform_1_1AddressMapping.md) && )<br>unconditionally put an entry in.  |
| void | **[prune](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-prune)**([flow::FlowLayer](Classes/classllarp_1_1layers_1_1flow_1_1FlowLayer.md) & )<br>prune all mappings we have no flows for  |
| std::optional< [AddressMapping](Classes/structllarp_1_1layers_1_1platform_1_1AddressMapping.md) > | **[get_addr_for_flow](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-get-addr-for-flow)**(const [flow::FlowInfo](Classes/structllarp_1_1layers_1_1flow_1_1FlowInfo.md) & flow)<br>get a platform for a flow if it exists. updates last used time.  |
| bool | **[has_addr_for_flow](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-has-addr-for-flow)**(const [flow::FlowInfo](Classes/structllarp_1_1layers_1_1flow_1_1FlowInfo.md) & flow) const<br>return true if we have an address for this flow info, will not update last used time.  |
| std::optional< [AddressMapping](Classes/structllarp_1_1layers_1_1platform_1_1AddressMapping.md) > | **[mapping_for](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-mapping-for)**(const [PlatformAddr](Classes/structllarp_1_1layers_1_1platform_1_1PlatformAddr.md) & src, const [PlatformAddr](Classes/structllarp_1_1layers_1_1platform_1_1PlatformAddr.md) & dst)<br>find a mapping that best matches src/dst address.  |
| bool | **[is_full](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-is-full)**() const<br>return true if we have mapped as many ip addresses as we are able to.  |
| [AddressMapping](Classes/structllarp_1_1layers_1_1platform_1_1AddressMapping.md) & | **[allocate_mapping](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-allocate-mapping)**(std::optional< [PlatformAddr](Classes/structllarp_1_1layers_1_1platform_1_1PlatformAddr.md) > src =std::nullopt)<br>get a new address mapping with a filled out destination address and an optionally provided source address.  |
| template <typename Viewer_t \> <br>void | **[view_all_entries](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-view-all-entries)**(Viewer_t && visit) const<br>read only iterate over all entries.  |
| template <typename Predicate_t \> <br>auto | **[find_if](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-find-if)**(Predicate_t && pred)<br>return an iterator for first entry matching predicate.  |
| template <typename Predicate_t \> <br>auto | **[find_if](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-find-if)**(Predicate_t && pred) const<br>return an iterator for first entry matching predicate.  |
| template <typename Predicate_t \> <br>void | **[remove_if_entry](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-remove-if-entry)**(Predicate_t && pred)<br>remove via predicate on entry.  |
| template <typename Predicate_t \> <br>void | **[remove_if_mapping](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-remove-if-mapping)**(Predicate_t && pred)<br>remove via predicate on mapping.  |
| std::vector< [AddressMapping](Classes/structllarp_1_1layers_1_1platform_1_1AddressMapping.md) > | **[all_exits](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-all-exits)**() const<br>return all exits we have.  |
| [net::IPRangeMap](Classes/structllarp_1_1net_1_1IPRangeMap.md)< [flow::FlowAddr](Classes/classllarp_1_1layers_1_1flow_1_1FlowAddr.md) > | **[exit_map](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-exit-map)**() const<br>make an ip range map for all our exits.  |

## Public Attributes

|                | Name           |
| -------------- | -------------- |
| const [IPRange](Classes/structllarp_1_1IPRange.md) | **[range](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#variable-range)**  |

## Friends

|                | Name           |
| -------------- | -------------- |
| class | **[ReservedAddressMapping](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#friend-reservedaddressmapping)**  |

## Public Functions Documentation

### function AddrMapper

```cpp
explicit AddrMapper(
    const IPRange & range
)
```


### function put

```cpp
void put(
    AddressMapping && 
)
```

unconditionally put an entry in. 

stomps existing entry. if full, removes the least frequenty used mapping. 


### function prune

```cpp
void prune(
    flow::FlowLayer & 
)
```

prune all mappings we have no flows for 

### function get_addr_for_flow

```cpp
std::optional< AddressMapping > get_addr_for_flow(
    const flow::FlowInfo & flow
)
```

get a platform for a flow if it exists. updates last used time. 

### function has_addr_for_flow

```cpp
bool has_addr_for_flow(
    const flow::FlowInfo & flow
) const
```

return true if we have an address for this flow info, will not update last used time. 

### function mapping_for

```cpp
std::optional< AddressMapping > mapping_for(
    const PlatformAddr & src,
    const PlatformAddr & dst
)
```

find a mapping that best matches src/dst address. 

updates last use time. 


### function is_full

```cpp
bool is_full() const
```

return true if we have mapped as many ip addresses as we are able to. 

### function allocate_mapping

```cpp
AddressMapping & allocate_mapping(
    std::optional< PlatformAddr > src =std::nullopt
)
```

get a new address mapping with a filled out destination address and an optionally provided source address. 

if the source address is nullopt we will use the base address of the range as the source. throws if full. 


### function view_all_entries

```cpp
template <typename Viewer_t >
inline void view_all_entries(
    Viewer_t && visit
) const
```

read only iterate over all entries. 

visit returns false to break iteration. 


### function find_if

```cpp
template <typename Predicate_t >
inline auto find_if(
    Predicate_t && pred
)
```

return an iterator for first entry matching predicate. 

this is a helper so we will not update last used. 


### function find_if

```cpp
template <typename Predicate_t >
inline auto find_if(
    Predicate_t && pred
) const
```

return an iterator for first entry matching predicate. 

this is a helper so we will not update last used. 


### function remove_if_entry

```cpp
template <typename Predicate_t >
inline void remove_if_entry(
    Predicate_t && pred
)
```

remove via predicate on entry. 

### function remove_if_mapping

```cpp
template <typename Predicate_t >
inline void remove_if_mapping(
    Predicate_t && pred
)
```

remove via predicate on mapping. 

### function all_exits

```cpp
std::vector< AddressMapping > all_exits() const
```

return all exits we have. 

last use time not updated. 


### function exit_map

```cpp
net::IPRangeMap< flow::FlowAddr > exit_map() const
```

make an ip range map for all our exits. 

## Public Attributes Documentation

### variable range

```cpp
const IPRange range;
```


## Friends

### friend ReservedAddressMapping

```cpp
friend class ReservedAddressMapping(
    ReservedAddressMapping 
);
```


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

Updated on 2023-03-06 at 20:36:34 +0000