Helium
conn.h
Go to the documentation of this file.
1 /* *
2  * Lightway Core
3  * Copyright (C) 2021 Express VPN International Ltd.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * as published by the Free Software Foundation; either version 2
8  * of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19 
26 #ifndef CONN_H
27 #define CONN_H
28 
29 #include <he.h>
30 
31 // Scale 1 second to wolf to 100ms
32 #define HE_WOLF_TIMEOUT_MULTIPLIER 100
33 #define HE_WOLF_RENEGOTIATION_TIMEOUT_MULTIPLIER 1000
34 
44 
53 void he_conn_destroy(he_conn_t *conn);
54 
70 
85 
94 int he_conn_set_username(he_conn_t *conn, const char *username);
95 
102 const char *he_conn_get_username(const he_conn_t *conn);
103 
112 bool he_conn_is_username_set(const he_conn_t *conn);
113 
123 he_return_code_t he_conn_set_password(he_conn_t *conn, const char *password);
124 
133 bool he_conn_is_password_set(const he_conn_t *conn);
134 
145 he_return_code_t he_conn_set_auth_buffer(he_conn_t *conn, uint8_t auth_type, uint8_t *buffer,
146  uint16_t length);
155 bool he_conn_is_auth_buffer_set(const he_conn_t *conn);
156 
169 int he_conn_set_outside_mtu(he_conn_t *conn, int mtu);
170 
177 
187 
198 
204 void *he_conn_get_context(he_conn_t *conn);
205 he_return_code_t he_internal_conn_configure(he_conn_t *conn, he_ssl_ctx_t *ctx);
206 
233  he_plugin_chain_t *inside_plugins,
234  he_plugin_chain_t *outside_plugins);
235 
258  he_plugin_chain_t *inside_plugins,
259  he_plugin_chain_t *outside_plugins);
260 
274 
275 void he_internal_disconnect_and_shutdown(he_conn_t *conn);
276 
277 void he_internal_change_conn_state(he_conn_t *conn, he_conn_state_t state);
278 
286 he_return_code_t he_internal_send_message(he_conn_t *conn, uint8_t *message, uint16_t length);
287 he_return_code_t he_internal_send_goodbye(he_conn_t *conn);
288 he_return_code_t he_internal_send_auth(he_conn_t *conn);
289 
301 
312 he_return_code_t he_internal_renegotiate_ssl(he_conn_t *conn);
313 
319 
329 
337 
346 
350 uint64_t he_conn_get_session_id(he_conn_t *conn);
351 
355 he_return_code_t he_conn_set_session_id(he_conn_t *conn, uint64_t session_id);
356 
365 
373 bool he_conn_is_error_fatal(he_conn_t *conn, he_return_code_t error_msg);
374 
393 he_return_code_t he_conn_rotate_session_id(he_conn_t *conn, uint64_t *new_session_id);
394 
401 
402 void he_internal_generate_event(he_conn_t *conn, he_conn_event_t event);
403 
413 he_return_code_t he_conn_set_protocol_version(he_conn_t *conn, uint8_t major_version,
414  uint8_t minor_version);
415 
416 size_t he_internal_calculate_data_packet_length(he_conn_t *conn, size_t length);
417 
425 he_return_code_t he_internal_generate_session_id(he_conn_t *conn, uint64_t *session_id_out);
426 
427 #endif // CONN_H
const char * he_conn_get_username(const he_conn_t *conn)
Get the username that Helium will authenticate with, previously set by he_conn_set_username.
Definition: conn.c:664
he_return_code_t he_conn_set_password(he_conn_t *conn, const char *password)
Sets the password Helium should use to authenticate with.
Definition: conn.c:672
enum he_return_code he_return_code_t
All possible return codes for helium.
Definition: he.h:433
Definition: he.h:575
bool he_conn_is_error_fatal(he_conn_t *conn, he_return_code_t error_msg)
Returns true if a given error (a return from libhelium where he_return_code_t != HE_SUCCESS) is obvio...
Definition: conn.c:34
he_return_code_t he_conn_nudge(he_conn_t *conn)
Nudges Helium.
Definition: conn.c:556
he_return_code_t he_conn_rotate_session_id(he_conn_t *conn, uint64_t *new_session_id)
Rotate the session ID for this connection.
Definition: conn.c:612
int he_conn_get_outside_mtu(he_conn_t *conn)
Get the MTU value for the outside transport mechanism. *.
Definition: conn.c:717
bool he_conn_supports_renegotiation(he_conn_t *conn)
Whether this particular connection supports renegoation.
Definition: conn.c:638
he_return_code_t he_internal_send_message(he_conn_t *conn, uint8_t *message, uint16_t length)
Sends a message over the secured tunnel.
Definition: conn.c:375
he_return_code_t he_conn_set_auth_buffer(he_conn_t *conn, uint8_t auth_type, uint8_t *buffer, uint16_t length)
Sets the opaque buffer Helium should use to authenticate with.
Definition: conn.c:681
void he_conn_destroy(he_conn_t *conn)
Releases all memory allocate by Helium for this connection.
Definition: conn.c:130
void he_internal_update_timeout(he_conn_t *conn)
Updates the timeout for a connectionand triggers the timeout callback if set.
Definition: conn.c:522
he_return_code_t he_conn_set_protocol_version(he_conn_t *conn, uint8_t major_version, uint8_t minor_version)
On the server, sets the major/minor version number for this connection.
Definition: conn.c:646
int he_conn_get_nudge_time(he_conn_t *conn)
Returns the number of miliseconds that host application should wait before nudging Helium...
Definition: conn.c:549
enum he_conn_state he_conn_state_t
Status codes for a Helium connection.
bool he_conn_is_password_set(const he_conn_t *conn)
Check if the password has been set.
Definition: conn.c:677
int he_conn_set_outside_mtu(he_conn_t *conn, int mtu)
Set the MTU for the outside transport mechanism. Usually this will be the MTU of the devices Internet...
Definition: conn.c:710
he_return_code_t he_conn_schedule_renegotiation(he_conn_t *conn)
Tell Helium to schedule a renegotiation.
Definition: conn.c:475
bool he_conn_is_auth_buffer_set(const he_conn_t *conn)
Check if the auth buffer has been set.
Definition: conn.c:706
he_return_code_t he_conn_is_valid_client(he_ssl_ctx_t *ssl_ctx, he_conn_t *conn)
Checks whether the client conn has the basic values to allow Helium to connect.
Definition: conn.c:78
int he_conn_set_username(he_conn_t *conn, const char *username)
Set the username to authenticate with.
Definition: conn.c:659
Core internal header file for libhelium.
uint64_t he_conn_get_session_id(he_conn_t *conn)
Returns the session ID for this connection.
Definition: conn.c:764
void * he_conn_get_context(he_conn_t *conn)
Retrieve the pointer to the user supplied context.
Definition: conn.c:760
bool he_conn_is_outside_mtu_set(he_conn_t *conn)
Check if the outside MTU has been set.
Definition: conn.c:721
he_return_code_t he_conn_disconnect(he_conn_t *conn)
Try to cleanly disconnect from the remote Helium instance (client or server).
Definition: conn.c:302
he_return_code_t he_conn_send_keepalive(he_conn_t *conn)
Tell Helium to send a keepalive message. This can be used to avoid NAT timing out.
Definition: conn.c:403
uint64_t he_conn_get_pending_session_id(he_conn_t *conn)
Returns the pending session ID for this connection, if there is one.
Definition: conn.c:768
he_return_code_t he_internal_generate_session_id(he_conn_t *conn, uint64_t *session_id_out)
Generate a random session ID.
Definition: conn.c:602
he_return_code_t he_conn_set_session_id(he_conn_t *conn, uint64_t session_id)
Sets the session ID for this connection.
Definition: conn.c:772
he_conn_state_t he_conn_get_state(he_conn_t *conn)
Returns the state that the conn is currently in.
Definition: conn.c:591
he_return_code_t he_conn_client_connect(he_conn_t *conn, he_ssl_ctx_t *ssl_ctx, he_plugin_chain_t *inside_plugins, he_plugin_chain_t *outside_plugins)
Tries to establish a connection with a Helium server.
Definition: conn.c:254
he_return_code_t he_conn_is_valid_server(he_ssl_ctx_t *ssl_ctx, he_conn_t *conn)
Checks whether the client conn has the basic values to allow Helium to connect.
Definition: conn.c:108
he_return_code_t he_conn_set_context(he_conn_t *conn, void *data)
Store a pointer in the context that will be made available in all Helium callbacks.
Definition: conn.c:754
bool he_conn_is_username_set(const he_conn_t *conn)
Check if the password has been set.
Definition: conn.c:668
Definition: he.h:483
he_return_code_t he_conn_server_connect(he_conn_t *conn, he_ssl_ctx_t *ssl_ctx, he_plugin_chain_t *inside_plugins, he_plugin_chain_t *outside_plugins)
Tries to establish a connection with a Helium client.
Definition: conn.c:272
he_conn_t * he_conn_create(void)
Creates a Helium connection struct.
Definition: conn.c:126