---
title: llarp::quic::Connection

---

# llarp::quic::Connection





Inherits from std::enable_shared_from_this< Connection >

## Public Functions

|                | Name           |
| -------------- | -------------- |
| | **[Connection](Classes/classllarp_1_1quic_1_1Connection.md#function-connection)**([Server](Classes/classllarp_1_1quic_1_1Server.md) & server, const [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md) & base_cid, ngtcp2_pkt_hd & header, const [Path](Classes/structllarp_1_1quic_1_1Path.md) & path)<br>Constructs and initializes a new incoming connection.  |
| | **[Connection](Classes/classllarp_1_1quic_1_1Connection.md#function-connection)**([Client](Classes/classllarp_1_1quic_1_1Client.md) & client, const [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md) & scid, const [Path](Classes/structllarp_1_1quic_1_1Path.md) & path, uint16_t tunnel_port)<br>Establishes a connection from the local [Client](Classes/classllarp_1_1quic_1_1Client.md) to a remote [Server]().  |
| | **[Connection](Classes/classllarp_1_1quic_1_1Connection.md#function-connection)**([Connection](Classes/classllarp_1_1quic_1_1Connection.md) && ) =delete |
| | **[Connection](Classes/classllarp_1_1quic_1_1Connection.md#function-connection)**(const [Connection](Classes/classllarp_1_1quic_1_1Connection.md) & ) =delete |
| [Connection](Classes/classllarp_1_1quic_1_1Connection.md) & | **[operator=](Classes/classllarp_1_1quic_1_1Connection.md#function-operator=)**([Connection](Classes/classllarp_1_1quic_1_1Connection.md) && ) =delete |
| [Connection](Classes/classllarp_1_1quic_1_1Connection.md) & | **[operator=](Classes/classllarp_1_1quic_1_1Connection.md#function-operator=)**(const [Connection](Classes/classllarp_1_1quic_1_1Connection.md) & ) =delete |
| | **[~Connection](Classes/classllarp_1_1quic_1_1Connection.md#function-~connection)**() |
| | **[operator const ngtcp2_conn *](Classes/classllarp_1_1quic_1_1Connection.md#function-operator-const-ngtcp2-conn-*)**() const |
| | **[operator ngtcp2_conn *](Classes/classllarp_1_1quic_1_1Connection.md#function-operator-ngtcp2-conn-*)**() |
| [Server](Classes/classllarp_1_1quic_1_1Server.md) * | **[server](Classes/classllarp_1_1quic_1_1Connection.md#function-server)**() |
| [Client](Classes/classllarp_1_1quic_1_1Client.md) * | **[client](Classes/classllarp_1_1quic_1_1Connection.md#function-client)**() |
| void | **[io_ready](Classes/classllarp_1_1quic_1_1Connection.md#function-io-ready)**() |
| void | **[on_io_ready](Classes/classllarp_1_1quic_1_1Connection.md#function-on-io-ready)**() |
| int | **[setup_server_crypto_initial](Classes/classllarp_1_1quic_1_1Connection.md#function-setup-server-crypto-initial)**() |
| void | **[flush_streams](Classes/classllarp_1_1quic_1_1Connection.md#function-flush-streams)**() |
| int | **[stream_opened](Classes/classllarp_1_1quic_1_1Connection.md#function-stream-opened)**([StreamID](Classes/structllarp_1_1quic_1_1StreamID.md) id) |
| int | **[stream_receive](Classes/classllarp_1_1quic_1_1Connection.md#function-stream-receive)**([StreamID](Classes/structllarp_1_1quic_1_1StreamID.md) id, bstring_view data, bool fin) |
| void | **[stream_closed](Classes/classllarp_1_1quic_1_1Connection.md#function-stream-closed)**([StreamID](Classes/structllarp_1_1quic_1_1StreamID.md) id, uint64_t app_error_code) |
| int | **[stream_ack](Classes/classllarp_1_1quic_1_1Connection.md#function-stream-ack)**([StreamID](Classes/structllarp_1_1quic_1_1StreamID.md) id, size_t size) |
| [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md) | **[make_alias_id](Classes/classllarp_1_1quic_1_1Connection.md#function-make-alias-id)**(size_t cidlen =ConnectionID::max_size()) |
| bool | **[get_handshake_completed](Classes/classllarp_1_1quic_1_1Connection.md#function-get-handshake-completed)**() |
| int | **[get_streams_available](Classes/classllarp_1_1quic_1_1Connection.md#function-get-streams-available)**() |
| const std::shared_ptr< [Stream](Classes/classllarp_1_1quic_1_1Stream.md) > & | **[open_stream](Classes/classllarp_1_1quic_1_1Connection.md#function-open-stream)**(Stream::data_callback_t data_cb, Stream::close_callback_t close_cb) |
| const std::shared_ptr< [Stream](Classes/classllarp_1_1quic_1_1Stream.md) > & | **[get_stream](Classes/classllarp_1_1quic_1_1Connection.md#function-get-stream)**([StreamID](Classes/structllarp_1_1quic_1_1StreamID.md) s) const |
| int | **[init_client](Classes/classllarp_1_1quic_1_1Connection.md#function-init-client)**() |
| int | **[recv_initial_crypto](Classes/classllarp_1_1quic_1_1Connection.md#function-recv-initial-crypto)**(std::basic_string_view< uint8_t > data) |
| int | **[recv_transport_params](Classes/classllarp_1_1quic_1_1Connection.md#function-recv-transport-params)**(std::basic_string_view< uint8_t > data) |
| int | **[send_magic](Classes/classllarp_1_1quic_1_1Connection.md#function-send-magic)**(ngtcp2_crypto_level level) |
| int | **[send_transport_params](Classes/classllarp_1_1quic_1_1Connection.md#function-send-transport-params)**(ngtcp2_crypto_level level) |
| void | **[complete_handshake](Classes/classllarp_1_1quic_1_1Connection.md#function-complete-handshake)**() |

## Public Attributes

|                | Name           |
| -------------- | -------------- |
| [Endpoint](Classes/classllarp_1_1quic_1_1Endpoint.md) & | **[endpoint](Classes/classllarp_1_1quic_1_1Connection.md#variable-endpoint)**  |
| const [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md) | **[base_cid](Classes/classllarp_1_1quic_1_1Connection.md#variable-base-cid)** <br>The primary connection id of this [Connection](Classes/classllarp_1_1quic_1_1Connection.md).  |
| [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md) | **[dest_cid](Classes/classllarp_1_1quic_1_1Connection.md#variable-dest-cid)** <br>The destination connection id we use to send to the other end; the remote end sets this as the source cid in the header.  |
| std::unique_ptr< ngtcp2_conn, connection_deleter > | **[conn](Classes/classllarp_1_1quic_1_1Connection.md#variable-conn)** <br>The underlying ngtcp2 connection object.  |
| [Path](Classes/structllarp_1_1quic_1_1Path.md) | **[path](Classes/classllarp_1_1quic_1_1Connection.md#variable-path)** <br>The most recent [Path](Classes/structllarp_1_1quic_1_1Path.md) we have to/from the remote.  |
| bool | **[draining](Classes/classllarp_1_1quic_1_1Connection.md#variable-draining)** <br>True if we are draining (that is, we recently received a connection close from the other end and should discard everything that comes in on this connection).  |
| bool | **[closing](Classes/classllarp_1_1quic_1_1Connection.md#variable-closing)** <br>True when we are closing; conn_buffer will contain the closing stanza.  |
| std::basic_string< std::byte > | **[conn_buffer](Classes/classllarp_1_1quic_1_1Connection.md#variable-conn-buffer)** <br>Buffer where we store non-stream connection data, e.g.  |
| std::map< [StreamID](Classes/structllarp_1_1quic_1_1StreamID.md), std::shared_ptr< [Stream](Classes/classllarp_1_1quic_1_1Stream.md) > > | **[streams](Classes/classllarp_1_1quic_1_1Connection.md#variable-streams)**  |
| std::function< void([Connection](Classes/classllarp_1_1quic_1_1Connection.md) &)> | **[on_handshake_complete](Classes/classllarp_1_1quic_1_1Connection.md#variable-on-handshake-complete)**  |
| std::function< void([Connection](Classes/classllarp_1_1quic_1_1Connection.md) &)> | **[on_stream_available](Classes/classllarp_1_1quic_1_1Connection.md#variable-on-stream-available)**  |

## Public Functions Documentation

### function Connection

```cpp
Connection(
    Server & server,
    const ConnectionID & base_cid,
    ngtcp2_pkt_hd & header,
    const Path & path
)
```

Constructs and initializes a new incoming connection. 

**Parameters**: 

  * **server** - the [Server](Classes/classllarp_1_1quic_1_1Server.md) object that owns this connection 
  * **base_cid** - the local "primary" [ConnectionID](Classes/structllarp_1_1quic_1_1ConnectionID.md) we use for this connection, typically random 
  * **header** - packet header that initiated the connection
  * **path** - the network path to reach the remote 


### function Connection

```cpp
Connection(
    Client & client,
    const ConnectionID & scid,
    const Path & path,
    uint16_t tunnel_port
)
```

Establishes a connection from the local [Client](Classes/classllarp_1_1quic_1_1Client.md) to a remote [Server](). 

**Parameters**: 

  * **client** - the [Endpoint](Classes/classllarp_1_1quic_1_1Endpoint.md) object that owns this connection 
  * **base_cid** - the client's source (i.e. local) connection ID, typically random 
  * **path** - the network path to reach the remote 
  * **tunnel_port** - the port that this connection should tunnel to on the remote end 


### function Connection

```cpp
Connection(
    Connection && 
) =delete
```


### function Connection

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


### function operator=

```cpp
Connection & operator=(
    Connection && 
) =delete
```


### function operator=

```cpp
Connection & operator=(
    const Connection & 
) =delete
```


### function ~Connection

```cpp
~Connection()
```


### function operator const ngtcp2_conn *

```cpp
inline operator const ngtcp2_conn *() const
```


### function operator ngtcp2_conn *

```cpp
inline operator ngtcp2_conn *()
```


### function server

```cpp
Server * server()
```


### function client

```cpp
Client * client()
```


### function io_ready

```cpp
void io_ready()
```


### function on_io_ready

```cpp
void on_io_ready()
```


### function setup_server_crypto_initial

```cpp
int setup_server_crypto_initial()
```


### function flush_streams

```cpp
void flush_streams()
```


### function stream_opened

```cpp
int stream_opened(
    StreamID id
)
```


### function stream_receive

```cpp
int stream_receive(
    StreamID id,
    bstring_view data,
    bool fin
)
```


### function stream_closed

```cpp
void stream_closed(
    StreamID id,
    uint64_t app_error_code
)
```


### function stream_ack

```cpp
int stream_ack(
    StreamID id,
    size_t size
)
```


### function make_alias_id

```cpp
ConnectionID make_alias_id(
    size_t cidlen =ConnectionID::max_size()
)
```


### function get_handshake_completed

```cpp
bool get_handshake_completed()
```


### function get_streams_available

```cpp
int get_streams_available()
```


### function open_stream

```cpp
const std::shared_ptr< Stream > & open_stream(
    Stream::data_callback_t data_cb,
    Stream::close_callback_t close_cb
)
```


### function get_stream

```cpp
const std::shared_ptr< Stream > & get_stream(
    StreamID s
) const
```


### function init_client

```cpp
int init_client()
```


### function recv_initial_crypto

```cpp
int recv_initial_crypto(
    std::basic_string_view< uint8_t > data
)
```


### function recv_transport_params

```cpp
int recv_transport_params(
    std::basic_string_view< uint8_t > data
)
```


### function send_magic

```cpp
int send_magic(
    ngtcp2_crypto_level level
)
```


### function send_transport_params

```cpp
int send_transport_params(
    ngtcp2_crypto_level level
)
```


### function complete_handshake

```cpp
void complete_handshake()
```


## Public Attributes Documentation

### variable endpoint

```cpp
Endpoint & endpoint;
```


### variable base_cid

```cpp
const ConnectionID base_cid;
```

The primary connection id of this [Connection](Classes/classllarp_1_1quic_1_1Connection.md). 

This is the key of endpoint.conns that stores the actual shared_ptr (everything else in `conns` is a weak_ptr alias). 


### variable dest_cid

```cpp
ConnectionID dest_cid;
```

The destination connection id we use to send to the other end; the remote end sets this as the source cid in the header. 

### variable conn

```cpp
std::unique_ptr< ngtcp2_conn, connection_deleter > conn;
```

The underlying ngtcp2 connection object. 

### variable path

```cpp
Path path;
```

The most recent [Path](Classes/structllarp_1_1quic_1_1Path.md) we have to/from the remote. 

### variable draining

```cpp
bool draining = false;
```

True if we are draining (that is, we recently received a connection close from the other end and should discard everything that comes in on this connection). 

Do not set this directly: instead call Endpoint::start_draining(conn). 


### variable closing

```cpp
bool closing = false;
```

True when we are closing; conn_buffer will contain the closing stanza. 

### variable conn_buffer

```cpp
std::basic_string< std::byte > conn_buffer;
```

Buffer where we store non-stream connection data, e.g. 

for initial transport params during connection and the closing stanza when disconnecting. 


### variable streams

```cpp
std::map< StreamID, std::shared_ptr< Stream > > streams;
```


### variable on_handshake_complete

```cpp
std::function< void(Connection &)> on_handshake_complete;
```


### variable on_stream_available

```cpp
std::function< void(Connection &)> on_stream_available;
```


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

Updated on 2023-02-01 at 20:39:32 +0000