-
Notifications
You must be signed in to change notification settings - Fork 2
/
bridge.h
93 lines (75 loc) · 2.28 KB
/
bridge.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#ifndef _BRIDGE_H
#define _BRIDGE_H 1
#include <sys/socket.h>
#include <sys/un.h>
#include <proton/condition.h>
#include <proton/listener.h>
#include <proton/proactor.h>
#include <proton/sasl.h>
#include "rb.h"
#define DEFAULT_UNIX_SOCKET_PATH "/tmp/smartgateway"
#define DEFAULT_AMQP_URL "amqp://127.0.0.1:5672/collectd/telemetry"
#define DEFAULT_INET_HOST "127.0.0.1"
#define DEFAULT_INET_PORT "30000"
#define DEFAULT_INET_TARGET DEFAULT_INET_HOST ":" DEFAULT_INET_PORT
#define DEFAULT_CID "bridge-%x"
#define DEFAULT_CONTAINER_ID_PATTERN "sa-%x"
#define DEFAULT_STATS_PERIOD "0"
#define DEFAULT_SOCKET_BLOCK "false"
#define DEFAULT_STOP_COUNT "0"
#define DEFAULT_RING_BUFFER_COUNT "5000"
#define DEFAULT_RING_BUFFER_SIZE "2048"
#define DEFAULT_AMQP_BLOCK "false"
#define AMQP_URL_REGEX \
"^(amqps*)://" \
"(([a-z]+)(:([a-z]+))*@)*([a-zA-Z_0-9.-]+|\\[[:a-fA-F0-9]+\\])(:([0-9]+))" \
"?(/[^[:space:]]*)?$"
typedef struct {
char *user;
char *password;
char *address;
char *host;
char *port;
char *url;
} amqp_connection;
typedef struct {
// Parameters section
int standalone;
int verbose;
int domain; // connection to SG, AF_UNIX || AF_INET
int stat_period;
int ring_buffer_size;
int ring_buffer_count;
amqp_connection amqp_con;
const char *container_id;
int message_count;
const char *unix_socket_name;
int socket_flags;
char *peer_host, *peer_port;
// Runtime
pthread_t amqp_rcv_th;
pthread_t socket_snd_th;
int amqp_rcv_th_running;
int socket_snd_th_running;
pn_proactor_t *proactor;
pn_listener_t *listener;
pn_rwbytes_t msgout; /* Buffers for incoming/outgoing messages */
rb_rwbytes_t *rbin;
/* Rcv stats */
volatile long amqp_received;
volatile long amqp_partial;
volatile long amqp_total_batches;
volatile long amqp_link_credit;
volatile bool amqp_block;
/* Ring buffer stats */
volatile long link_credit;
/* Snd stats */
long sock_sent;
long amqp_decode_errs;
long sock_would_block;
// Use a struct big enough more most things
struct sockaddr_un sa;
socklen_t sa_len;
int send_sock;
} app_data_t;
#endif