ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
establish.h File Reference

Go to the source code of this file.

Data Structures

struct  network_establish_config_t
struct  network_establish_result_t
 This is the handoff point for network establish config. Callers fill name, address, default_port, connect before passing it on; consumers read the values during the operation and return ownership only where the member contract explicitly says they do. More...

Typedefs

typedef asciichat_error_t(* network_connection_prepare_fn) (network_connection_t *, const connection_endpoint_t *, const char *, void *)

Functions

asciichat_error_t network_connection_establish (const network_establish_config_t *config, network_connection_t **owner, network_establish_result_t *attempt)

Typedef Documentation

◆ network_connection_prepare_fn

typedef asciichat_error_t(* network_connection_prepare_fn) (network_connection_t *, const connection_endpoint_t *, const char *, void *)

Definition at line 5 of file establish.h.

Function Documentation

◆ network_connection_establish()

asciichat_error_t network_connection_establish ( const network_establish_config_t * config,
network_connection_t ** owner,
network_establish_result_t * attempt )

Definition at line 3 of file lib/network/establish.c.

4 {
5 if (!config || !owner || *owner || !attempt || !config->prepare || config->protocol > NETWORK_PROTOCOL_DISCOVERY)
6 return SET_ERRNO(ERROR_INVALID_PARAM, "Invalid connection establishment parameters");
7 *attempt = (network_establish_result_t){0};
8 asciichat_error_t result = network_connection_open(config->name, config->address, config->default_port,
9 config->connect, owner, &attempt->endpoint);
10 if (result != ASCIICHAT_OK)
11 return result;
12 result = config->prepare(*owner, &attempt->endpoint, config->password, config->context);
13 if (result != ASCIICHAT_OK)
14 return result;
16 handshake->defer_password_prompt = true;
18 if (config->authenticate)
19 mode |= ACIP_CRYPTO_AUTH;
20 result = network_client_negotiate(network_connection_transport(*owner), handshake, mode, config->protocol);
21 attempt->password_failure = handshake->password_failure;
22 if (result == ASCIICHAT_OK)
24 return result;
25}
#define SET_ERRNO(code,...)
unsigned char uint8_t
Definition common.h:60
asciichat_error_t
Error and exit codes - unified status values (0-255).
Definition error_codes.h:44
@ ASCIICHAT_OK
Definition error_codes.h:46
@ ERROR_INVALID_PARAM
#define ACIP_CRYPTO_AUTH
Authentication only (no payload encryption).
Definition packet.h:1140
asciichat_error_t network_connection_open(const char *name, const char *address, uint16_t port, const network_connect_config_t *settings, network_connection_t **out, connection_endpoint_t *resolved)
void network_connection_ready(network_connection_t *c)
crypto_handshake_context_t * network_connection_handshake(network_connection_t *c)
acip_transport_t * network_connection_transport(network_connection_t *c)
uint8_t network_connection_crypto_mode(network_connection_t *c)
asciichat_error_t network_client_negotiate(acip_transport_t *transport, crypto_handshake_context_t *ctx, uint8_t mode, network_protocol_t protocol)
@ NETWORK_PROTOCOL_DISCOVERY
Definition negotiation.h:5
Cryptographic handshake context structure.
network_protocol_t protocol
Definition establish.h:13
network_connection_prepare_fn prepare
Definition establish.h:15
const network_connect_config_t * connect
Definition establish.h:11
This is the handoff point for network establish config. Callers fill name, address,...
Definition establish.h:24
connection_endpoint_t endpoint
Definition establish.h:25

References ACIP_CRYPTO_AUTH, network_establish_config_t::address, ASCIICHAT_OK, network_establish_config_t::authenticate, network_establish_config_t::connect, network_establish_config_t::context, network_establish_config_t::default_port, crypto_handshake_context_t::defer_password_prompt, network_establish_result_t::endpoint, ERROR_INVALID_PARAM, network_establish_config_t::name, network_client_negotiate(), network_connection_crypto_mode(), network_connection_handshake(), network_connection_open(), network_connection_ready(), network_connection_transport(), NETWORK_PROTOCOL_DISCOVERY, network_establish_config_t::password, crypto_handshake_context_t::password_failure, network_establish_result_t::password_failure, network_establish_config_t::prepare, network_establish_config_t::protocol, and SET_ERRNO.

Referenced by session_connection_establish().