Helium
flow.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 FLOW_H
27 #define FLOW_H
28 
29 #include "he.h"
30 #include "he_internal.h"
31 
47 he_return_code_t he_conn_inside_packet_received(he_conn_t *conn, uint8_t *packet, size_t length);
48 
70 he_return_code_t he_conn_outside_data_received(he_conn_t *conn, uint8_t *buffer, size_t length);
71 
72 he_return_code_t he_internal_flow_process_message(he_conn_t *conn, he_packet_buffer_t *read_packet);
73 he_return_code_t he_internal_flow_fetch_message(he_conn_t *conn, he_packet_buffer_t *read_packet);
75 
76 he_return_code_t he_internal_flow_outside_packet_received(he_conn_t *conn, uint8_t *packet,
77  size_t length);
78 he_return_code_t he_internal_flow_outside_stream_received(he_conn_t *conn, uint8_t *buffer,
79  size_t length);
80 he_return_code_t he_internal_flow_outside_data_verify_connection(he_conn_t *conn);
81 he_return_code_t he_internal_flow_outside_data_handle_messages(he_conn_t *conn);
82 
83 bool he_internal_flow_should_fragment(he_conn_t *conn, uint16_t effective_pmtu, uint16_t length);
84 
85 #ifdef HE_ENABLE_MULTITHREADED
86 extern HE_THREAD_LOCAL uint8_t *cur_packet;
87 extern HE_THREAD_LOCAL size_t cur_packet_length;
88 extern HE_THREAD_LOCAL bool packet_seen;
89 
90 static inline void he_internal_set_packet(he_conn_t *conn, uint8_t *packet, size_t len) {
91  cur_packet_length = len;
92  cur_packet = packet;
93 }
94 
95 static inline void he_internal_set_packet_seen(he_conn_t *conn, bool value) {
96  packet_seen = value;
97 }
98 
99 static inline bool he_internal_is_packet_seen(he_conn_t *conn) {
100  return packet_seen;
101 }
102 
103 static inline bool he_internal_is_pkt_available(he_conn_t *conn) {
104  return !packet_seen && cur_packet;
105 }
106 
107 static inline size_t he_internal_copy_packet(he_conn_t *conn, char *buf) {
108  memcpy(buf, cur_packet, cur_packet_length);
109  return cur_packet_length;
110 }
111 
112 static inline size_t he_internal_get_packet_length(he_conn_t *conn) {
113  return cur_packet_length;
114 }
115 
116 #else // HE_ENABLE_MULTITHREADED
117 
118 static inline void he_internal_set_packet(he_conn_t *conn, uint8_t *packet, size_t len) {
119  conn->incoming_data_length = len;
120  conn->incoming_data = packet;
121 }
122 
123 static inline void he_internal_set_packet_seen(he_conn_t *conn, bool value) {
124  conn->packet_seen = value;
125 }
126 
127 static inline bool he_internal_is_packet_seen(he_conn_t *conn) {
128  return conn->packet_seen;
129 }
130 
131 static inline bool he_internal_is_pkt_available(he_conn_t *conn) {
132  return !!conn->incoming_data;
133 }
134 
135 static inline size_t he_internal_copy_packet(he_conn_t *conn, char *buf) {
136  memcpy(buf, conn->incoming_data, conn->incoming_data_length);
137  return conn->incoming_data_length;
138 }
139 
140 static inline size_t he_internal_get_packet_length(he_conn_t *conn) {
141  return conn->incoming_data_length;
142 }
143 #endif // HE_ENABLE_MULTITHREADED
144 
145 #endif // FLOW_H
he_packet_buffer
Definition: he_internal.h:75
he_internal.h
Core internal header file for libhelium.
he_internal_flow_should_fragment
bool he_internal_flow_should_fragment(he_conn_t *conn, uint16_t effective_pmtu, uint16_t length)
Definition: flow.c:37
he_return_code_t
enum he_return_code he_return_code_t
All possible return codes for helium.
he_conn::incoming_data
uint8_t * incoming_data
Pointer to incoming data buffer.
Definition: he_internal.h:254
he_internal_update_session_incoming
he_return_code_t he_internal_update_session_incoming(he_conn_t *conn, he_wire_hdr_t *hdr)
Definition: flow.c:267
he_conn_inside_packet_received
he_return_code_t he_conn_inside_packet_received(he_conn_t *conn, uint8_t *packet, size_t length)
Called when the host application needs to deliver an inside packet to Helium.
Definition: flow.c:41
he_conn_outside_data_received
he_return_code_t he_conn_outside_data_received(he_conn_t *conn, uint8_t *buffer, size_t length)
Called when the host application needs to deliver outside data to be processed by Helium.
Definition: flow.c:299
he_conn::incoming_data_length
size_t incoming_data_length
Length of the data in the.
Definition: he_internal.h:256
he.h
Core public header file for libhelium.
he_wire_hdr
The wire header format It is strongly discouraged to interact with this header structure,...
Definition: he.h:564
he_conn::packet_seen
bool packet_seen
Packet seen.
Definition: he_internal.h:258
he_conn
Definition: he_internal.h:170