---
title: llarp::quic::Endpoint
summary: QUIC Tunnel Endpoint; this is the class that implements either end of a quic tunnel for both servers and clients. 

---

# llarp::quic::Endpoint



QUIC Tunnel [Endpoint](); this is the class that implements either end of a quic tunnel for both servers and clients. 


`#include <endpoint.hpp>`

Inherited by [llarp::quic::Client](Classes/classllarp_1_1quic_1_1Client.md), [llarp::quic::Server](Classes/classllarp_1_1quic_1_1Server.md)

## Protected Classes

|                | Name           |
| -------------- | -------------- |
| struct | **[version_info](Classes/structllarp_1_1quic_1_1Endpoint_1_1version__info.md)**  |

## Protected Types

|                | Name           |
| -------------- | -------------- |
| using std::shared_ptr< [Connection](Classes/classllarp_1_1quic_1_1Connection.md) > | **[primary_conn_ptr](Classes/classllarp_1_1quic_1_1Endpoint.md#using-primary-conn-ptr)**  |
| using std::weak_ptr< [Connection](Classes/classllarp_1_1quic_1_1Connection.md) > | **[alias_conn_ptr](Classes/classllarp_1_1quic_1_1Endpoint.md#using-alias-conn-ptr)**  |
| using decltype(conns)::iterator | **[conns_iterator](Classes/classllarp_1_1quic_1_1Endpoint.md#using-conns-iterator)**  |

## Public Functions

|                | Name           |
| -------------- | -------------- |
| void | **[receive_packet](Classes/classllarp_1_1quic_1_1Endpoint.md#function-receive-packet)**(const [SockAddr](Classes/structllarp_1_1SockAddr.md) & src, uint8_t ecn, bstring_view data)<br>Called from tun code via [TunnelManager]() to deliver an incoming packet to us.  |
| std::shared_ptr< uvw::Loop > | **[get_loop](Classes/classllarp_1_1quic_1_1Endpoint.md#function-get-loop)**()<br>Returns a shared pointer to the uvw loop.  |
| void | **[make_stateless_reset_token](Classes/classllarp_1_1quic_1_1Endpoint.md#function-make-stateless-reset-token)**(const [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md) & cid, unsigned char * dest) |
| | **[Endpoint](Classes/classllarp_1_1quic_1_1Endpoint.md#function-endpoint)**(const [Endpoint](Classes/classllarp_1_1quic_1_1Endpoint.md) & ) =delete |
| | **[Endpoint](Classes/classllarp_1_1quic_1_1Endpoint.md#function-endpoint)**([Endpoint](Classes/classllarp_1_1quic_1_1Endpoint.md) && ) =delete |

## Protected Functions

|                | Name           |
| -------------- | -------------- |
| | **[Endpoint](Classes/classllarp_1_1quic_1_1Endpoint.md#function-endpoint)**([EndpointBase](Classes/classllarp_1_1EndpointBase.md) & service_endpoint_) |
| virtual | **[~Endpoint](Classes/classllarp_1_1quic_1_1Endpoint.md#function-~endpoint)**() |
| void | **[handle_packet](Classes/classllarp_1_1quic_1_1Endpoint.md#function-handle-packet)**(const [Packet](Classes/structllarp_1_1quic_1_1Packet.md) & p) |
| std::optional< [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md) > | **[handle_packet_init](Classes/classllarp_1_1quic_1_1Endpoint.md#function-handle-packet-init)**(const [Packet](Classes/structllarp_1_1quic_1_1Packet.md) & p) |
| void | **[handle_conn_packet](Classes/classllarp_1_1quic_1_1Endpoint.md#function-handle-conn-packet)**([Connection](Classes/classllarp_1_1quic_1_1Connection.md) & c, const [Packet](Classes/structllarp_1_1quic_1_1Packet.md) & p) |
| virtual std::shared_ptr< [Connection](Classes/classllarp_1_1quic_1_1Connection.md) > | **[accept_initial_connection](Classes/classllarp_1_1quic_1_1Endpoint.md#function-accept-initial-connection)**(const [Packet](Classes/structllarp_1_1quic_1_1Packet.md) & ) |
| [io_result](Classes/structllarp_1_1quic_1_1io__result.md) | **[read_packet](Classes/classllarp_1_1quic_1_1Endpoint.md#function-read-packet)**(const [Packet](Classes/structllarp_1_1quic_1_1Packet.md) & p, [Connection](Classes/classllarp_1_1quic_1_1Connection.md) & conn) |
| virtual size_t | **[write_packet_header](Classes/classllarp_1_1quic_1_1Endpoint.md#function-write-packet-header)**(nuint16_t pseudo_port, uint8_t ecn) =0 |
| [io_result](Classes/structllarp_1_1quic_1_1io__result.md) | **[send_packet](Classes/classllarp_1_1quic_1_1Endpoint.md#function-send-packet)**(const [Address](Classes/classllarp_1_1quic_1_1Address.md) & to, bstring_view data, uint8_t ecn) |
| [io_result](Classes/structllarp_1_1quic_1_1io__result.md) | **[send_packet](Classes/classllarp_1_1quic_1_1Endpoint.md#function-send-packet)**(const [Address](Classes/classllarp_1_1quic_1_1Address.md) & to, std::string_view data, uint8_t ecn) |
| [io_result](Classes/structllarp_1_1quic_1_1io__result.md) | **[send_packet](Classes/classllarp_1_1quic_1_1Endpoint.md#function-send-packet)**(const [Address](Classes/classllarp_1_1quic_1_1Address.md) & to, const std::vector< std::byte > & data, uint8_t ecn) |
| void | **[send_version_negotiation](Classes/classllarp_1_1quic_1_1Endpoint.md#function-send-version-negotiation)**(const [version_info](Classes/structllarp_1_1quic_1_1Endpoint_1_1version__info.md) & vi, const [Address](Classes/classllarp_1_1quic_1_1Address.md) & source) |
| std::pair< std::shared_ptr< [Connection](Classes/classllarp_1_1quic_1_1Connection.md) >, bool > | **[get_conn](Classes/classllarp_1_1quic_1_1Endpoint.md#function-get-conn)**(const [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md) & cid) |
| void | **[close_connection](Classes/classllarp_1_1quic_1_1Endpoint.md#function-close-connection)**([Connection](Classes/classllarp_1_1quic_1_1Connection.md) & conn, uint64_t code =NGTCP2_NO_ERROR, bool application =false, std::string_view close_reason =""sv) |
| void | **[start_draining](Classes/classllarp_1_1quic_1_1Endpoint.md#function-start-draining)**([Connection](Classes/classllarp_1_1quic_1_1Connection.md) & conn)<br>Puts a connection into draining mode (i.e.  |
| void | **[check_timeouts](Classes/classllarp_1_1quic_1_1Endpoint.md#function-check-timeouts)**() |
| bool | **[delete_conn](Classes/classllarp_1_1quic_1_1Endpoint.md#function-delete-conn)**(const [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md) & cid)<br>Deletes a connection from `conns`; if the connecion is a primary connection shared pointer then it is removed and [clean_alias_conns()]() is immediately called to remove any aliases to the connection.  |
| void | **[clean_alias_conns](Classes/classllarp_1_1quic_1_1Endpoint.md#function-clean-alias-conns)**()<br>Removes any connection id aliases that no longer have associated Connections.  |
| [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md) | **[add_connection_id](Classes/classllarp_1_1quic_1_1Endpoint.md#function-add-connection-id)**([Connection](Classes/classllarp_1_1quic_1_1Connection.md) & conn, size_t cid_length =ConnectionID::max_size())<br>Creates a new, unused connection ID alias for the given connection; adds the alias to `conns` and returns the [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md).  |

## Public Attributes

|                | Name           |
| -------------- | -------------- |
| size_t | **[default_stream_buffer_size](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-default-stream-buffer-size)**  |
| std::array< std::byte, net::IPPacket::MaxSize > | **[buf_](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-buf-)**  |

## Protected Attributes

|                | Name           |
| -------------- | -------------- |
| [EndpointBase](Classes/classllarp_1_1EndpointBase.md) & | **[service_endpoint](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-service-endpoint)** <br>the service endpoint we are owned by  |
| [Address](Classes/classllarp_1_1quic_1_1Address.md) | **[local_addr](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-local-addr)** <br>local "address" is the IPv6 unspecified address since we don't have (or care about) the actual local address for building quic packets.  |
| std::shared_ptr< uvw::TimerHandle > | **[expiry_timer](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-expiry-timer)**  |
| std::vector< std::byte > | **[buf](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-buf)**  |
| std::unordered_map< [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md), std::variant< primary_conn_ptr, alias_conn_ptr > > | **[conns](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-conns)**  |
| std::queue< std::pair< [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md), std::chrono::steady_clock::time_point > > | **[draining](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-draining)**  |
| [NullCrypto](Classes/structllarp_1_1quic_1_1NullCrypto.md) | **[null_crypto](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-null-crypto)**  |
| std::array< std::byte, 32 > | **[static_secret](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-static-secret)**  |
| constexpr size_t | **[max_buf_size](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-max-buf-size)**  |
| constexpr size_t | **[max_pkt_size_v4](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-max-pkt-size-v4)**  |
| constexpr size_t | **[max_pkt_size_v6](Classes/classllarp_1_1quic_1_1Endpoint.md#variable-max-pkt-size-v6)**  |

## Friends

|                | Name           |
| -------------- | -------------- |
| class | **[Connection](Classes/classllarp_1_1quic_1_1Endpoint.md#friend-connection)**  |

## Protected Types Documentation

### using primary_conn_ptr

```cpp
using llarp::quic::Endpoint::primary_conn_ptr =  std::shared_ptr<Connection>;
```


### using alias_conn_ptr

```cpp
using llarp::quic::Endpoint::alias_conn_ptr =  std::weak_ptr<Connection>;
```


### using conns_iterator

```cpp
using llarp::quic::Endpoint::conns_iterator =  decltype(conns)::iterator;
```


## Public Functions Documentation

### function receive_packet

```cpp
void receive_packet(
    const SockAddr & src,
    uint8_t ecn,
    bstring_view data
)
```

Called from tun code via [TunnelManager]() to deliver an incoming packet to us. 

**Parameters**: 

  * **src** - the source address; this may be a tun interface address, or may be a fake IPv6 address based on the convo tag. The port is not used. 
  * **ecn** - the packet ecn parameter 


### function get_loop

```cpp
std::shared_ptr< uvw::Loop > get_loop()
```

Returns a shared pointer to the uvw loop. 

### function make_stateless_reset_token

```cpp
void make_stateless_reset_token(
    const ConnectionID & cid,
    unsigned char * dest
)
```


### function Endpoint

```cpp
Endpoint(
    const Endpoint & 
) =delete
```


### function Endpoint

```cpp
Endpoint(
    Endpoint && 
) =delete
```


## Protected Functions Documentation

### function Endpoint

```cpp
explicit Endpoint(
    EndpointBase & service_endpoint_
)
```


### function ~Endpoint

```cpp
virtual ~Endpoint()
```


### function handle_packet

```cpp
void handle_packet(
    const Packet & p
)
```


### function handle_packet_init

```cpp
std::optional< ConnectionID > handle_packet_init(
    const Packet & p
)
```


### function handle_conn_packet

```cpp
void handle_conn_packet(
    Connection & c,
    const Packet & p
)
```


### function accept_initial_connection

```cpp
inline virtual std::shared_ptr< Connection > accept_initial_connection(
    const Packet & 
)
```


**Reimplemented by**: [llarp::quic::Server::accept_initial_connection](Classes/classllarp_1_1quic_1_1Server.md#function-accept-initial-connection)


### function read_packet

```cpp
io_result read_packet(
    const Packet & p,
    Connection & conn
)
```


### function write_packet_header

```cpp
virtual size_t write_packet_header(
    nuint16_t pseudo_port,
    uint8_t ecn
) =0
```


**Reimplemented by**: [llarp::quic::Server::write_packet_header](Classes/classllarp_1_1quic_1_1Server.md#function-write-packet-header), [llarp::quic::Client::write_packet_header](Classes/classllarp_1_1quic_1_1Client.md#function-write-packet-header)


### function send_packet

```cpp
io_result send_packet(
    const Address & to,
    bstring_view data,
    uint8_t ecn
)
```


### function send_packet

```cpp
inline io_result send_packet(
    const Address & to,
    std::string_view data,
    uint8_t ecn
)
```


### function send_packet

```cpp
inline io_result send_packet(
    const Address & to,
    const std::vector< std::byte > & data,
    uint8_t ecn
)
```


### function send_version_negotiation

```cpp
void send_version_negotiation(
    const version_info & vi,
    const Address & source
)
```


### function get_conn

```cpp
std::pair< std::shared_ptr< Connection >, bool > get_conn(
    const ConnectionID & cid
)
```


### function close_connection

```cpp
void close_connection(
    Connection & conn,
    uint64_t code =NGTCP2_NO_ERROR,
    bool application =false,
    std::string_view close_reason =""sv
)
```


### function start_draining

```cpp
void start_draining(
    Connection & conn
)
```

Puts a connection into draining mode (i.e. 

after getting a connection close). This will keep the connection registered for the recommended 3*Probe Timeout, during which we drop packets that use the connection id and after which we will forget about it. 


### function check_timeouts

```cpp
void check_timeouts()
```


### function delete_conn

```cpp
bool delete_conn(
    const ConnectionID & cid
)
```

Deletes a connection from `conns`; if the connecion is a primary connection shared pointer then it is removed and [clean_alias_conns()]() is immediately called to remove any aliases to the connection. 

If the given connection is an alias connection then it is removed but no cleanup is performed. Returns true if something was removed, false if the connection was not found. 


### function clean_alias_conns

```cpp
void clean_alias_conns()
```

Removes any connection id aliases that no longer have associated Connections. 

### function add_connection_id

```cpp
ConnectionID add_connection_id(
    Connection & conn,
    size_t cid_length =ConnectionID::max_size()
)
```

Creates a new, unused connection ID alias for the given connection; adds the alias to `conns` and returns the [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md). 

## Public Attributes Documentation

### variable default_stream_buffer_size

```cpp
size_t default_stream_buffer_size = 64 * 1024;
```


### variable buf_

```cpp
std::array< std::byte, net::IPPacket::MaxSize > buf_;
```


## Protected Attributes Documentation

### variable service_endpoint

```cpp
EndpointBase & service_endpoint;
```

the service endpoint we are owned by 

### variable local_addr

```cpp
Address local_addr {in6addr_any};
```

local "address" is the IPv6 unspecified address since we don't have (or care about) the actual local address for building quic packets. 

The port of this address must be set to our local pseudo-port, for clients, and 0 for a server. 


### variable expiry_timer

```cpp
std::shared_ptr< uvw::TimerHandle > expiry_timer;
```


### variable buf

```cpp
std::vector< std::byte > buf;
```


### variable conns

```cpp
std::unordered_map< ConnectionID, std::variant< primary_conn_ptr, alias_conn_ptr > > conns;
```


### variable draining

```cpp
std::queue< std::pair< ConnectionID, std::chrono::steady_clock::time_point > > draining;
```


### variable null_crypto

```cpp
NullCrypto null_crypto;
```


### variable static_secret

```cpp
std::array< std::byte, 32 > static_secret;
```


### variable max_buf_size

```cpp
static constexpr size_t max_buf_size = 64 * 1024;
```


### variable max_pkt_size_v4

```cpp
static constexpr size_t max_pkt_size_v4 = NGTCP2_MAX_UDP_PAYLOAD_SIZE;
```


### variable max_pkt_size_v6

```cpp
static constexpr size_t max_pkt_size_v6 = NGTCP2_MAX_UDP_PAYLOAD_SIZE;
```


## Friends

### friend Connection

```cpp
friend class Connection(
    Connection 
);
```


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

Updated on 2023-01-23 at 22:05:55 +0000