---
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)<br>construct addr mapper with an ip range to provide to be routable locally to the system we run on.  |
| [AddressMapping](Classes/structllarp_1_1layers_1_1platform_1_1AddressMapping.md) & | **[put](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-put)**([AddressMapping](Classes/structllarp_1_1layers_1_1platform_1_1AddressMapping.md) && ent)<br>unconditionally put an entry into the addrmapper, stomping any existing entry that used to match the destination it went to.  |
| bool | **[unmap](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-unmap)**([AddressMapping](Classes/structllarp_1_1layers_1_1platform_1_1AddressMapping.md) ent)<br>unmap an address mapping.  |
| 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>remove all mappings we have no flows to.  |
| 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 address for a flow if it exists and update its 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 but will not update last used time of the entry if it exists.  |
| 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 the mapping that matches src/dst address.  |
| std::vector< [AddressMapping](Classes/structllarp_1_1layers_1_1platform_1_1AddressMapping.md) > | **[mappings_to](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-mappings-to)**(const [flow::FlowAddr](Classes/classllarp_1_1layers_1_1flow_1_1FlowAddr.md) & remote) const<br>return all address mappings to this remote and do not update last used time on any of the entries.  |
| 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>explicitly allocate a new address mapping with an unused destination platform addr.  |
| template <typename Viewer_t \> <br>void | **[view_all_mappings](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-view-all-mappings)**(Viewer_t && visit) const<br>read only iterate over all mappings.  |
| 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 mappings matching a predicate. will not update last used time.  |
| template <typename Predicate_t \> <br>auto | **[const_find_if](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-const-find-if)**(Predicate_t && pred) const<br>return a const iterator for first mapping matching a 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 all entries that matches a predicate.  |
| template <typename Predicate_t \> <br>void | **[remove_if](Classes/classllarp_1_1layers_1_1platform_1_1AddrMapper.md#function-remove-if)**(Predicate_t && pred)<br>remove all mappings that match a predicate.  |
| 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 mappings that we have that carry exit traffic.  |
| [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)** <br>our ip range that we are providing to the local system we are running on.  |

## 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
)
```

construct addr mapper with an ip range to provide to be routable locally to the system we run on. 

### function put

```cpp
AddressMapping & put(
    AddressMapping && ent
)
```

unconditionally put an entry into the addrmapper, stomping any existing entry that used to match the destination it went to. 

if the address mapper is full if we had to insert a new entry, we remove the least frequenty used entry. returns a non const l-value reference to the entry that now exists in the address map. 


### function unmap

```cpp
bool unmap(
    AddressMapping ent
)
```

unmap an address mapping. 

returns true if it was removed. 


### function prune

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

remove all mappings we have no flows to. 

### function get_addr_for_flow

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

get a platform address for a flow if it exists and update its last used time. 

returns std::nullopt if there is now mapping for this flow. 


### 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 but will not update last used time of the entry if it exists. 

### function mapping_for

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

find the mapping that matches src/dst address. 

updates last use time on the chosen entry. 


### function mappings_to

```cpp
std::vector< AddressMapping > mappings_to(
    const flow::FlowAddr & remote
) const
```

return all address mappings to this remote and do not update last used time on any of the entries. 

### 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
)
```

explicitly allocate a new address mapping with an unused destination platform addr. 

if a source address is not provided, our interface address with be used. throws if the addrmapper is full. 


### function view_all_mappings

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

read only iterate over all mappings. 

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 mappings matching a predicate. will not update last used time. 

### function const_find_if

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

return a const iterator for first mapping matching a predicate. 

will not update last used time. 


### function remove_if_entry

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

remove all entries that matches a predicate. 

### function remove_if

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

remove all mappings that match a predicate. 

### function all_exits

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

return all mappings that we have that carry exit traffic. 

last use time on entries will not be 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;
```

our ip range that we are providing to the local system we are running on. 

## Friends

### friend ReservedAddressMapping

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


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

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