|
0
|
1 |
#ifndef _CSH_
|
|
|
2 |
#define _CSH_ 1
|
|
|
3 |
|
|
|
4 |
#include <stdlib.h>
|
|
|
5 |
#include <string.h>
|
|
|
6 |
#include <stdio.h>
|
|
|
7 |
#include <unistd.h>
|
|
|
8 |
#include <pthread.h>
|
|
|
9 |
#include <signal.h>
|
|
|
10 |
#include <errno.h>
|
|
|
11 |
#include <time.h>
|
|
|
12 |
#include <math.h>
|
|
|
13 |
#include <sys/types.h>
|
|
|
14 |
#include <sys/socket.h>
|
|
|
15 |
#include <netdb.h>
|
|
|
16 |
#include <sys/time.h>
|
|
|
17 |
#include <openssl/ssl.h>
|
|
|
18 |
#include <openssl/bio.h>
|
|
|
19 |
#include <openssl/err.h>
|
|
|
20 |
#include <sys/wait.h>
|
|
|
21 |
#include <sys/select.h>
|
|
|
22 |
#include <sys/mman.h>
|
|
|
23 |
#include <semaphore.h>
|
|
|
24 |
#include <signal.h>
|
|
|
25 |
#include <execinfo.h>
|
|
|
26 |
#include <libgen.h>
|
|
|
27 |
|
|
|
28 |
typedef struct DebugS {
|
|
|
29 |
char id[128];
|
|
|
30 |
char msg[256];
|
|
|
31 |
} DebugT, *DebugP;
|
|
|
32 |
#define DebugA() (DebugP)malloc(sizeof(DebugT))
|
|
|
33 |
|
|
|
34 |
typedef struct ShareS {
|
|
|
35 |
int conns;
|
|
|
36 |
int msgs;
|
|
|
37 |
int act;
|
|
|
38 |
int mashOpenClientCount;
|
|
|
39 |
int mashOpenSSLClientCount;
|
|
|
40 |
sem_t counterSem;
|
|
|
41 |
sem_t debugSem;
|
|
|
42 |
} ShareT, *ShareP;
|
|
|
43 |
#define ShareA(v) if((v = mmap(NULL, sizeof(ShareT), PROT_READ|PROT_WRITE, MAP_SHARED|MAP_ANONYMOUS, -1, 0)) < 0) SYSERR("mmap")
|
|
|
44 |
|
|
|
45 |
typedef struct CSS {
|
|
|
46 |
DebugT debug;
|
|
|
47 |
int debMaxLev;
|
|
|
48 |
int port0;
|
|
|
49 |
int portZ;
|
|
|
50 |
char *text;
|
|
|
51 |
int ttl;
|
|
|
52 |
int mp0;
|
|
|
53 |
int mn;
|
|
|
54 |
int rp0;
|
|
|
55 |
int rn;
|
|
|
56 |
struct timespec pace;
|
|
|
57 |
int pacing;
|
|
|
58 |
int issl;
|
|
|
59 |
int connThreshold; // connection retry threshhold
|
|
|
60 |
int connTO; // connection timeout in usecs
|
|
|
61 |
int selTO; // selection timeout in secs
|
|
|
62 |
char *ceP; // -->SSL certs path
|
|
|
63 |
char *caP; // -->CA certs path
|
|
|
64 |
ShareP shP;
|
|
|
65 |
char home[128];
|
|
|
66 |
} CST, *CSP;
|
|
|
67 |
#define CSA(v) if((v = (CSP)malloc(sizeof(CST))) < 0) SYSERR("malloc")
|
|
|
68 |
|
|
|
69 |
typedef struct HeaderS {
|
|
|
70 |
int ttl;
|
|
|
71 |
int ts;
|
|
|
72 |
int listPort;
|
|
|
73 |
} HeaderT, *HeaderP;
|
|
|
74 |
typedef struct PayloadS {
|
|
|
75 |
time_t ts;
|
|
|
76 |
char text;
|
|
|
77 |
} PayloadT, *PayloadP;
|
|
|
78 |
typedef struct ContainerS {
|
|
|
79 |
HeaderT hdr;
|
|
|
80 |
PayloadT payl;
|
|
|
81 |
} ContainerT, *ContainerP;
|
|
|
82 |
typedef struct DataS {
|
|
|
83 |
DebugT debug;
|
|
|
84 |
ContainerP contP;
|
|
|
85 |
int dataLen;
|
|
|
86 |
} DataT, *DataP;
|
|
|
87 |
#define DataA(v) if((v = (DataP)malloc(sizeof(DataT))) < 0) SYSERR("malloc")
|
|
|
88 |
|
|
|
89 |
typedef struct SocketS {
|
|
|
90 |
int remPort;
|
|
|
91 |
int sc;
|
|
|
92 |
SSL *sslP;
|
|
|
93 |
} SocketT, *SocketP;
|
|
|
94 |
#define SocketA(v) if((v = (SocketP)malloc(sizeof(SocketT))) < 0) SYSERR("malloc")
|
|
|
95 |
|
|
|
96 |
typedef enum{ring, mash} topology;
|
|
|
97 |
typedef struct NodeS {
|
|
|
98 |
DebugT debug;
|
|
|
99 |
topology topo;
|
|
|
100 |
int ssc;
|
|
|
101 |
int locPort;
|
|
|
102 |
int first;
|
|
|
103 |
int last;
|
|
|
104 |
int nodes;
|
|
|
105 |
int nodeIdx;
|
|
|
106 |
int kicker;
|
|
|
107 |
int *forw;
|
|
|
108 |
int closing;
|
|
|
109 |
pthread_t closingThread;
|
|
|
110 |
SocketP cliSides;
|
|
|
111 |
SocketP srvSides;
|
|
|
112 |
DataT data;
|
|
|
113 |
int len;
|
|
|
114 |
int ssl;
|
|
|
115 |
SSL_CTX *ctx;
|
|
|
116 |
struct sigaction *sigactP;
|
|
|
117 |
} NodeT, *NodeP;
|
|
|
118 |
#define NodeA(v) if((v = (NodeP)malloc(sizeof(NodeT))) < 0) SYSERR("malloc")
|
|
|
119 |
typedef enum{client, server} nodeside;
|
|
|
120 |
|
|
|
121 |
extern void debug_init();
|
|
|
122 |
extern char *gpa(struct sockaddr *);
|
|
|
123 |
extern void gai(int, struct addrinfo *ai, DebugP);
|
|
|
124 |
#define GAI(level, ai) gai(level, ai, deP)
|
|
|
125 |
extern void ssl_err(DebugP, char*);
|
|
|
126 |
extern void abend(DebugP);
|
|
|
127 |
extern void Node(topology, int*, int, int, int, int);
|
|
|
128 |
extern void Data(DataP, DebugP);
|
|
|
129 |
extern int dttlData(DataP);
|
|
|
130 |
extern int ttlData(DataP);
|
|
|
131 |
extern int remPortData(DataP);
|
|
|
132 |
extern DataP loadData(DataP, int, char*);
|
|
|
133 |
extern char *unldData(DataP);
|
|
|
134 |
extern char *digest24Data(DataP, char *);
|
|
|
135 |
extern int chkData(DataP);
|
|
|
136 |
extern void sabotageData(DataP);
|
|
|
137 |
extern int tsData(DataP);
|
|
|
138 |
extern void back_trace();
|
|
|
139 |
extern void pre(char *);
|
|
|
140 |
extern void deb(int, DebugP);
|
|
|
141 |
extern void err(int, char *, DebugP);
|
|
|
142 |
|
|
|
143 |
#define DEBID(...) sprintf(deP->id, __VA_ARGS__)
|
|
|
144 |
#define LOG(level, ...) sprintf(deP->msg, __VA_ARGS__), deb(level, deP)
|
|
|
145 |
#define SYSERR(e) LOG(0, "%s: %s (%d)", e, strerror(errno), errno), abend(deP)
|
|
|
146 |
#define SSLERR(e) ssl_err(deP, e)
|
|
|
147 |
#define SOFTERR(e) LOG(0, e), fflush(stderr)
|
|
|
148 |
#define HARDERR(e) SOFTERR(e), abend(deP);
|
|
|
149 |
#define ERR(e) perror(e), exit(EXIT_FAILURE)
|
|
|
150 |
|
|
|
151 |
#define PACING SIGUSR1
|
|
|
152 |
|
|
|
153 |
extern CSP csP;
|
|
|
154 |
|
|
|
155 |
#endif
|