Debian Codegraph @

c/src/core/engine-internal.h

raw
1 #ifndef _PROTON_ENGINE_INTERNAL_H
2 #define _PROTON_ENGINE_INTERNAL_H 1
3
4 /*
5 *
6 * Licensed to the Apache Software Foundation (ASF) under one
7 * or more contributor license agreements. See the NOTICE file
8 * distributed with this work for additional information
9 * regarding copyright ownership. The ASF licenses this file
10 * to you under the Apache License, Version 2.0 (the
11 * "License"); you may not use this file except in compliance
12 * with the License. You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing,
17 * software distributed under the License is distributed on an
18 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
19 * KIND, either express or implied. See the License for the
20 * specific language governing permissions and limitations
21 * under the License.
22 *
23 */
24
25 #include <proton/object.h>
26 #include <proton/engine.h>
27 #include <proton/types.h>
28
29 #include "buffer.h"
30 #include "dispatcher.h"
31 #include "logger_private.h"
32 #include "util.h"
33
34 #if __cplusplus
35 extern "C" {
36 #endif
37
38 typedef enum pn_endpoint_type_t {CONNECTION, SESSION, SENDER, RECEIVER} pn_endpoint_type_t;
39
40 typedef struct pn_endpoint_t pn_endpoint_t;
41
42 struct pn_condition_t {
43 pn_string_t *name;
44 pn_string_t *description;
45 pn_data_t *info;
46 };
47
48 struct pn_endpoint_t {
49 pn_condition_t condition;
50 pn_condition_t remote_condition;
51 pn_endpoint_t *endpoint_next;
52 pn_endpoint_t *endpoint_prev;
53 pn_endpoint_t *transport_next;
54 pn_endpoint_t *transport_prev;
55 int refcount; // when this hits zero we generate a final event
56 uint8_t state;
57 uint8_t type;
58 bool modified;
59 bool freed;
60 bool referenced;
61 };
62
63 typedef struct {
64 pn_sequence_t id;
65 bool sending;
66 bool sent;
67 bool init;
68 } pn_delivery_state_t;
69
70 typedef struct {
71 pn_sequence_t next;
72 pn_hash_t *deliveries;
73 } pn_delivery_map_t;
74
75 typedef struct {
76 // XXX: stop using negative numbers
77 uint32_t local_handle;
78 uint32_t remote_handle;
79 pn_sequence_t delivery_count;
80 pn_sequence_t link_credit;
81 } pn_link_state_t;
82
83 typedef struct {
84 pn_delivery_map_t incoming;
85 pn_delivery_map_t outgoing;
86 pn_hash_t *local_handles;
87 pn_hash_t *remote_handles;
88 uint64_t disp_code;
89 pn_sequence_t incoming_transfer_count;
90 pn_sequence_t incoming_window;
91 pn_sequence_t remote_incoming_window;
92 pn_sequence_t outgoing_transfer_count;
93 pn_sequence_t outgoing_window;
94 pn_sequence_t disp_first;
95 pn_sequence_t disp_last;
96 // XXX: stop using negative numbers
97 uint16_t local_channel;
98 uint16_t remote_channel;
99 bool incoming_init;
100 bool disp;
101 bool disp_settled;
102 bool disp_type;
103 } pn_session_state_t;
104
105 typedef struct pn_io_layer_t {
106 ssize_t (*process_input)(struct pn_transport_t *transport, unsigned int layer, const char *, size_t);
107 ssize_t (*process_output)(struct pn_transport_t *transport, unsigned int layer, char *, size_t);
108 void (*handle_error)(struct pn_transport_t* transport, unsigned int layer);
109 int64_t (*process_tick)(struct pn_transport_t *transport, unsigned int layer, int64_t);
110 size_t (*buffered_output)(struct pn_transport_t *transport); // how much output is held
111 } pn_io_layer_t;
112
113 extern const pn_io_layer_t pni_passthru_layer;
114 extern const pn_io_layer_t ssl_layer;
115 extern const pn_io_layer_t sasl_header_layer;
116 extern const pn_io_layer_t sasl_write_header_layer;
117
118 // Bit flag defines for the protocol layers
119 typedef uint8_t pn_io_layer_flags_t;
120 #define LAYER_NONE 0
121 #define LAYER_AMQP1 1
122 #define LAYER_AMQPSASL 2
123 #define LAYER_AMQPSSL 4
124 #define LAYER_SSL 8
125
126 typedef struct pni_sasl_t pni_sasl_t;
127 typedef struct pni_ssl_t pni_ssl_t;
128
129 struct pn_transport_t {
130 pn_logger_t logger;
131 pn_tracer_t tracer;
132 pni_sasl_t *sasl;
133 pni_ssl_t *ssl;
134 pn_connection_t *connection; // reference counted
135 char *remote_container;
136 char *remote_hostname;
137 pn_data_t *remote_offered_capabilities;
138 pn_data_t *remote_desired_capabilities;
139 pn_data_t *remote_properties;
140 pn_data_t *disp_data;
141 //#define PN_DEFAULT_MAX_FRAME_SIZE (16*1024)
142 /* This is wrong and bad we should really use a sensible starting size not unlimited */
143 #define PN_DEFAULT_MAX_FRAME_SIZE (0) /* for now, allow unlimited size */
144 uint32_t local_max_frame;
145 uint32_t remote_max_frame;
146 pn_condition_t remote_condition;
147 pn_condition_t condition;
148 pn_error_t *error;
149
150 #define PN_IO_LAYER_CT 3
151 const pn_io_layer_t *io_layers[PN_IO_LAYER_CT];
152
153 /* dead remote detection */
154 pn_millis_t local_idle_timeout;
155 pn_millis_t remote_idle_timeout;
156 pn_timestamp_t dead_remote_deadline;
157 uint64_t last_bytes_input;
158
159 /* keepalive */
160 pn_timestamp_t keepalive_deadline;
161 uint64_t last_bytes_output;
162
163 pn_hash_t *local_channels;
164 pn_hash_t *remote_channels;
165
166
167 /* scratch area */
168 pn_buffer_t *frame; // frame under construction
169
170 // Temporary - ??
171 pn_buffer_t *output_buffer;
172
173 /* statistics */
174 uint64_t bytes_input;
175 uint64_t bytes_output;
176 uint64_t output_frames_ct;
177 uint64_t input_frames_ct;
178
179 /* output buffered for send */
180 #define PN_TRANSPORT_INITIAL_BUFFER_SIZE (8*1024)
181 size_t output_size;
182 size_t output_pending;
183 char *output_buf;
184
185 /* input from peer */
186 size_t input_size;
187 size_t input_pending;
188 char *input_buf;
189
190 pn_record_t *context;
191
192 /*
193 * The maximum channel number can be constrained in several ways:
194 * 1. an unchangeable limit imposed by this library code
195 * 2. a limit imposed by the remote peer when the connection is opened,
196 * which this app must honor
197 * 3. a limit imposed by this app, which may be raised and lowered
198 * until the OPEN frame is sent.
199 * These constraints are all summed up in channel_max, below.
200 */
201 #define PN_IMPL_CHANNEL_MAX 32767
202 uint16_t local_channel_max;
203 uint16_t remote_channel_max;
204 uint16_t channel_max;
205
206 pn_io_layer_flags_t allowed_layers;
207 pn_io_layer_flags_t present_layers;
208
209 bool freed;
210 bool open_sent;
211 bool open_rcvd;
212 bool close_sent;
213 bool close_rcvd;
214 bool tail_closed; // input stream closed by driver
215 bool head_closed;
216 bool done_processing; // if true, don't call pn_process again
217 bool posted_idle_timeout;
218 bool server;
219 bool halt;
220 bool auth_required;
221 bool authenticated;
222 bool encryption_required;
223
224 bool referenced;
225 };
226
227 struct pn_connection_t {
228 pn_endpoint_t endpoint;
229 pn_endpoint_t *endpoint_head;
230 pn_endpoint_t *endpoint_tail;
231 pn_endpoint_t *transport_head; // reference counted
232 pn_endpoint_t *transport_tail;
233 pn_list_t *sessions;
234 pn_list_t *freed;
235 pn_transport_t *transport;
236 pn_delivery_t *work_head;
237 pn_delivery_t *work_tail;
238 pn_delivery_t *tpwork_head; // reference counted
239 pn_delivery_t *tpwork_tail;
240 pn_string_t *container;
241 pn_string_t *hostname;
242 pn_string_t *auth_user;
243 pn_string_t *authzid;
244 pn_string_t *auth_password;
245 pn_data_t *offered_capabilities;
246 pn_data_t *desired_capabilities;
247 pn_data_t *properties;
248 pn_collector_t *collector;
249 pn_record_t *context;
250 pn_list_t *delivery_pool;
251 struct pn_connection_driver_t *driver;
252 };
253
254 struct pn_session_t {
255 pn_endpoint_t endpoint;
256 pn_session_state_t state;
257 pn_connection_t *connection; // reference counted
258 pn_list_t *links;
259 pn_list_t *freed;
260 pn_record_t *context;
261 size_t incoming_capacity;
262 pn_sequence_t incoming_bytes;
263 pn_sequence_t outgoing_bytes;
264 pn_sequence_t incoming_deliveries;
265 pn_sequence_t outgoing_deliveries;
266 pn_sequence_t outgoing_window;
267 };
268
269 struct pn_terminus_t {
270 pn_string_t *address;
271 pn_data_t *properties;
272 pn_data_t *capabilities;
273 pn_data_t *outcomes;
274 pn_data_t *filter;
275 pn_seconds_t timeout;
276 uint8_t durability;
277 uint8_t expiry_policy;
278 uint8_t type;
279 uint8_t distribution_mode;
280 bool has_expiry_policy;
281 bool dynamic;
282 };
283
284 struct pn_link_t {
285 pn_endpoint_t endpoint;
286 pn_terminus_t source;
287 pn_terminus_t target;
288 pn_terminus_t remote_source;
289 pn_terminus_t remote_target;
290 pn_link_state_t state;
291 pn_string_t *name;
292 pn_session_t *session; // reference counted
293 pn_delivery_t *unsettled_head;
294 pn_delivery_t *unsettled_tail;
295 pn_delivery_t *current;
296 pn_record_t *context;
297 pn_data_t *properties;
298 pn_data_t *remote_properties;
299 size_t unsettled_count;
300 uint64_t max_message_size;
301 uint64_t remote_max_message_size;
302 pn_sequence_t available;
303 pn_sequence_t credit;
304 pn_sequence_t queued;
305 pn_sequence_t more_id;
306 int drained; // number of drained credits
307 uint8_t snd_settle_mode;
308 uint8_t rcv_settle_mode;
309 uint8_t remote_snd_settle_mode;
310 uint8_t remote_rcv_settle_mode;
311 bool drain_flag_mode; // receiver only
312 bool drain;
313 bool detached;
314 bool more_pending;
315 };
316
317 struct pn_disposition_t {
318 pn_condition_t condition;
319 uint64_t type;
320 pn_data_t *data;
321 pn_data_t *annotations;
322 uint64_t section_offset;
323 uint32_t section_number;
324 bool failed;
325 bool undeliverable;
326 bool settled;
327 };
328
329 struct pn_delivery_t {
330 pn_disposition_t local;
331 pn_disposition_t remote;
332 pn_link_t *link; // reference counted
333 pn_buffer_t *tag;
334 pn_delivery_t *unsettled_next;
335 pn_delivery_t *unsettled_prev;
336 pn_delivery_t *work_next;
337 pn_delivery_t *work_prev;
338 pn_delivery_t *tpwork_next;
339 pn_delivery_t *tpwork_prev;
340 pn_delivery_state_t state;
341 pn_buffer_t *bytes;
342 pn_record_t *context;
343 bool updated;
344 bool settled; // tracks whether we're in the unsettled list or not
345 bool work;
346 bool tpwork;
347 bool done;
348 bool referenced;
349 bool aborted;
350 };
351
352 #define PN_SET_LOCAL(OLD, NEW) \
353 (OLD) = ((OLD) & PN_REMOTE_MASK) | (NEW)
354
355 #define PN_SET_REMOTE(OLD, NEW) \
356 (OLD) = ((OLD) & PN_LOCAL_MASK) | (NEW)
357
358 void pn_link_dump(pn_link_t *link);
359
360 void pn_dump(pn_connection_t *conn);
361 void pn_transport_sasl_init(pn_transport_t *transport);
362
363 void pn_condition_init(pn_condition_t *condition);
364 void pn_condition_tini(pn_condition_t *condition);
365 void pn_modified(pn_connection_t *connection, pn_endpoint_t *endpoint, bool emit);
366 void pn_real_settle(pn_delivery_t *delivery); // will free delivery if link is freed
367 void pn_clear_tpwork(pn_delivery_t *delivery);
368 void pn_work_update(pn_connection_t *connection, pn_delivery_t *delivery);
369 void pn_clear_modified(pn_connection_t *connection, pn_endpoint_t *endpoint);
370 void pn_connection_bound(pn_connection_t *conn);
371 void pn_connection_unbound(pn_connection_t *conn);
372 int pn_do_error(pn_transport_t *transport, const char *condition, const char *fmt, ...);
373 void pn_set_error_layer(pn_transport_t *transport);
374 void pn_session_unbound(pn_session_t* ssn);
375 void pn_link_unbound(pn_link_t* link);
376 void pn_ep_incref(pn_endpoint_t *endpoint);
377 void pn_ep_decref(pn_endpoint_t *endpoint);
378
379 ssize_t pni_transport_grow_capacity(pn_transport_t *transport, size_t n);
380
381 #if __cplusplus
382 }
383 #endif
384
385 #endif /* engine-internal.h */