---
title: llarp::dns::Server

---

# llarp::dns::Server





Inherits from std::enable_shared_from_this< Server >

## Public Functions

|                | Name           |
| -------------- | -------------- |
| virtual | **[~Server](Classes/classllarp_1_1dns_1_1Server.md#function-~server)**() =default |
| | **[Server](Classes/classllarp_1_1dns_1_1Server.md#function-server)**(EventLoop_ptr loop, [llarp::DnsConfig](Classes/structllarp_1_1DnsConfig.md) conf, unsigned int netif_index) |
| std::vector< [SockAddr](Classes/structllarp_1_1SockAddr.md) > | **[BoundPacketSourceAddrs](Classes/classllarp_1_1dns_1_1Server.md#function-boundpacketsourceaddrs)**() const<br>returns all sockaddr we have from all of our PacketSources  |
| std::optional< [SockAddr](Classes/structllarp_1_1SockAddr.md) > | **[FirstBoundPacketSourceAddr](Classes/classllarp_1_1dns_1_1Server.md#function-firstboundpacketsourceaddr)**() const<br>returns the first sockaddr we have on our packet sources if we have one  |
| void | **[AddResolver](Classes/classllarp_1_1dns_1_1Server.md#function-addresolver)**(std::weak_ptr< [Resolver_Base](Classes/classllarp_1_1dns_1_1Resolver__Base.md) > resolver)<br>add a resolver to this packet handler, does not share ownership  |
| void | **[AddPacketSource](Classes/classllarp_1_1dns_1_1Server.md#function-addpacketsource)**(std::weak_ptr< [PacketSource_Base](Classes/classllarp_1_1dns_1_1PacketSource__Base.md) > resolver)<br>add a packet source to this server, does not share ownership  |
| virtual std::shared_ptr< [PacketSource_Base](Classes/classllarp_1_1dns_1_1PacketSource__Base.md) > | **[MakePacketSourceOn](Classes/classllarp_1_1dns_1_1Server.md#function-makepacketsourceon)**(const [SockAddr](Classes/structllarp_1_1SockAddr.md) & bindaddr, const [llarp::DnsConfig](Classes/structllarp_1_1DnsConfig.md) & conf)<br>create a packet source bound on bindaddr but does not add it  |
| virtual void | **[Start](Classes/classllarp_1_1dns_1_1Server.md#function-start)**()<br>sets up all internal binds and such and begins operation  |
| virtual void | **[Stop](Classes/classllarp_1_1dns_1_1Server.md#function-stop)**()<br>stops all operation  |
| virtual void | **[Reset](Classes/classllarp_1_1dns_1_1Server.md#function-reset)**()<br>reset the internal state  |
| virtual std::shared_ptr< [Resolver_Base](Classes/classllarp_1_1dns_1_1Resolver__Base.md) > | **[MakeDefaultResolver](Classes/classllarp_1_1dns_1_1Server.md#function-makedefaultresolver)**()<br>create the default resolver for out config  |
| bool | **[MaybeHandlePacket](Classes/classllarp_1_1dns_1_1Server.md#function-maybehandlepacket)**(std::shared_ptr< [PacketSource_Base](Classes/classllarp_1_1dns_1_1PacketSource__Base.md) > pktsource, const [SockAddr](Classes/structllarp_1_1SockAddr.md) & resolver, const [SockAddr](Classes/structllarp_1_1SockAddr.md) & from, [llarp::OwnedBuffer](Classes/structllarp_1_1OwnedBuffer.md) buf)<br>feed a packet buffer from a packet source returns true if we decided to process the packet and consumed it returns false if we dont want to process the packet  |
| void | **[SetDNSMode](Classes/classllarp_1_1dns_1_1Server.md#function-setdnsmode)**(bool all_queries)<br>set which dns mode we are in.  |

## Protected Functions

|                | Name           |
| -------------- | -------------- |
| void | **[AddPacketSource](Classes/classllarp_1_1dns_1_1Server.md#function-addpacketsource)**(std::shared_ptr< [PacketSource_Base](Classes/classllarp_1_1dns_1_1PacketSource__Base.md) > resolver)<br>add a packet source to this server, does share ownership  |
| void | **[AddResolver](Classes/classllarp_1_1dns_1_1Server.md#function-addresolver)**(std::shared_ptr< [Resolver_Base](Classes/classllarp_1_1dns_1_1Resolver__Base.md) > resolver)<br>add a resolver to this packet handler, does share ownership  |
| virtual std::shared_ptr< [I_Platform](Classes/classllarp_1_1dns_1_1I__Platform.md) > | **[CreatePlatform](Classes/classllarp_1_1dns_1_1Server.md#function-createplatform)**() const<br>create the platform dependant dns stuff  |

## Protected Attributes

|                | Name           |
| -------------- | -------------- |
| EventLoop_ptr | **[m_Loop](Classes/classllarp_1_1dns_1_1Server.md#variable-m-loop)**  |
| [llarp::DnsConfig](Classes/structllarp_1_1DnsConfig.md) | **[m_Config](Classes/classllarp_1_1dns_1_1Server.md#variable-m-config)**  |
| std::shared_ptr< [I_Platform](Classes/classllarp_1_1dns_1_1I__Platform.md) > | **[m_Platform](Classes/classllarp_1_1dns_1_1Server.md#variable-m-platform)**  |

## Public Functions Documentation

### function ~Server

```cpp
virtual ~Server() =default
```


### function Server

```cpp
explicit Server(
    EventLoop_ptr loop,
    llarp::DnsConfig conf,
    unsigned int netif_index
)
```


### function BoundPacketSourceAddrs

```cpp
std::vector< SockAddr > BoundPacketSourceAddrs() const
```

returns all sockaddr we have from all of our PacketSources 

### function FirstBoundPacketSourceAddr

```cpp
std::optional< SockAddr > FirstBoundPacketSourceAddr() const
```

returns the first sockaddr we have on our packet sources if we have one 

### function AddResolver

```cpp
void AddResolver(
    std::weak_ptr< Resolver_Base > resolver
)
```

add a resolver to this packet handler, does not share ownership 

### function AddPacketSource

```cpp
void AddPacketSource(
    std::weak_ptr< PacketSource_Base > resolver
)
```

add a packet source to this server, does not share ownership 

### function MakePacketSourceOn

```cpp
virtual std::shared_ptr< PacketSource_Base > MakePacketSourceOn(
    const SockAddr & bindaddr,
    const llarp::DnsConfig & conf
)
```

create a packet source bound on bindaddr but does not add it 

### function Start

```cpp
virtual void Start()
```

sets up all internal binds and such and begins operation 

### function Stop

```cpp
virtual void Stop()
```

stops all operation 

### function Reset

```cpp
virtual void Reset()
```

reset the internal state 

### function MakeDefaultResolver

```cpp
virtual std::shared_ptr< Resolver_Base > MakeDefaultResolver()
```

create the default resolver for out config 

### function MaybeHandlePacket

```cpp
bool MaybeHandlePacket(
    std::shared_ptr< PacketSource_Base > pktsource,
    const SockAddr & resolver,
    const SockAddr & from,
    llarp::OwnedBuffer buf
)
```

feed a packet buffer from a packet source returns true if we decided to process the packet and consumed it returns false if we dont want to process the packet 

### function SetDNSMode

```cpp
void SetDNSMode(
    bool all_queries
)
```

set which dns mode we are in. 

true for intercepting all queries. false for just .loki and .snode 


## Protected Functions Documentation

### function AddPacketSource

```cpp
void AddPacketSource(
    std::shared_ptr< PacketSource_Base > resolver
)
```

add a packet source to this server, does share ownership 

### function AddResolver

```cpp
void AddResolver(
    std::shared_ptr< Resolver_Base > resolver
)
```

add a resolver to this packet handler, does share ownership 

### function CreatePlatform

```cpp
virtual std::shared_ptr< I_Platform > CreatePlatform() const
```

create the platform dependant dns stuff 

## Protected Attributes Documentation

### variable m_Loop

```cpp
EventLoop_ptr m_Loop;
```


### variable m_Config

```cpp
llarp::DnsConfig m_Config;
```


### variable m_Platform

```cpp
std::shared_ptr< I_Platform > m_Platform;
```


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

Updated on 2022-09-01 at 18:16:53 +0000