aboutsummaryrefslogtreecommitdiff
path: root/ffi/pyouroboros_build_irm.py
blob: 1fc515ea9bc25a61a85ebcf812da703abc20e91d (plain)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
#
# Ouroboros - Copyright (C) 2016 - 2026
#
# Python API for Ouroboros
#
#    Dimitri Staessens <dimitri@ouroboros.rocks>
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public License
# version 2.1 as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., http://www.fsf.org/about/contact/.
#

from cffi import FFI

ffibuilder: FFI = FFI()

ffibuilder.cdef("""
/* System types */
typedef int... pid_t;
typedef long... time_t;

struct timespec {
    time_t tv_sec;
    long   tv_nsec;
    ...;
};

/* OUROBOROS VERSION.H */
#define OUROBOROS_VERSION_MAJOR ...
#define OUROBOROS_VERSION_MINOR ...
#define OUROBOROS_VERSION_PATCH ...

/* Network types */
struct in_addr { ...; };
struct in6_addr { ...; };

/* OUROBOROS QOS.H */
typedef struct qos_spec {
        uint32_t delay;
        uint64_t bandwidth;
        uint8_t  availability;
        uint32_t loss;
        uint32_t ber;
        uint8_t  in_order;
        uint32_t max_gap;
        uint32_t timeout;       /* Timeout in ms */
} qosspec_t;

/* OUROBOROS IPCP.H */
enum ipcp_type {
        IPCP_LOCAL     = ...,
        IPCP_UNICAST   = ...,
        IPCP_BROADCAST = ...,
        IPCP_ETH_LLC   = ...,
        IPCP_ETH_DIX   = ...,
        IPCP_UDP4      = ...,
        IPCP_UDP6      = ...,
        IPCP_INVALID   = ...
};

/* Unicast IPCP policies */
enum pol_addr_auth {
        ADDR_AUTH_FLAT_RANDOM = ...,
        ADDR_AUTH_INVALID     = ...
};

enum pol_link_state {
        LS_SIMPLE  = ...,
        LS_LFA     = ...,
        LS_ECMP    = ...,
        LS_INVALID = ...
};

struct ls_config {
        enum pol_link_state pol;
        time_t              t_recalc;
        time_t              t_update;
        time_t              t_timeo;
};

enum pol_routing {
        ROUTING_LINK_STATE = ...,
        ROUTING_INVALID    = ...
};

struct routing_config {
        enum pol_routing pol;
        union {
                struct ls_config ls;
        };
};

enum pol_cong_avoid {
        CA_NONE    = ...,
        CA_MB_ECN  = ...,
        CA_INVALID = ...
};

struct dt_config {
        struct {
                uint8_t addr_size;
                uint8_t eid_size;
                uint8_t max_ttl;
        };
        struct routing_config routing;
};

enum pol_dir {
        DIR_DHT     = ...,
        DIR_INVALID = ...
};

enum pol_dir_hash {
        DIR_HASH_SHA3_224 = ...,
        DIR_HASH_SHA3_256 = ...,
        DIR_HASH_SHA3_384 = ...,
        DIR_HASH_SHA3_512 = ...,
        DIR_HASH_INVALID  = ...
};

struct dir_dht_config {
        struct {
                uint32_t alpha;
                uint32_t k;
                uint32_t t_expire;
                uint32_t t_refresh;
                uint32_t t_replicate;
        } params;
        uint64_t peer;
};

struct dir_config {
        enum pol_dir pol;
        union {
                struct dir_dht_config dht;
        };
};

struct uni_config {
        struct dt_config    dt;
        struct dir_config   dir;
        enum pol_addr_auth  addr_auth_type;
        enum pol_cong_avoid cong_avoid;
};

struct eth_config {
        char     dev[256]; /* DEV_NAME_SIZE + 1 */
        uint16_t ethertype;
};

struct udp4_config {
        struct in_addr ip_addr;
        struct in_addr dns_addr;
        uint16_t       port;
};

struct udp6_config {
        struct in6_addr ip_addr;
        struct in6_addr dns_addr;
        uint16_t        port;
};

struct layer_info {
        char              name[256]; /* LAYER_NAME_SIZE + 1 */
        enum pol_dir_hash dir_hash_algo;
};

struct ipcp_config {
        struct layer_info layer_info;
        enum ipcp_type    type;

        union {
                struct uni_config  unicast;
                struct udp4_config udp4;
                struct udp6_config udp6;
                struct eth_config  eth;
        };
};

/* OUROBOROS NAME.H */
#define BIND_AUTO ...

enum pol_balance {
        LB_RR      = ...,
        LB_SPILL   = ...,
        LB_INVALID = ...
};

struct name_sec_paths {
        char enc[512]; /* NAME_PATH_SIZE + 1 */
        char key[512]; /* NAME_PATH_SIZE + 1 */
        char crt[512]; /* NAME_PATH_SIZE + 1 */
};

struct name_info {
        char             name[256]; /* NAME_SIZE + 1 */
        enum pol_balance pol_lb;

        struct name_sec_paths s;
        struct name_sec_paths c;
};

/* OUROBOROS IRM.H */

struct ipcp_list_info {
        pid_t          pid;
        enum ipcp_type type;
        char           name[255]; /* NAME_SIZE */
        char           layer[255]; /* LAYER_NAME_SIZE */
};

pid_t   irm_create_ipcp(const char *   name,
                        enum ipcp_type type);

int     irm_destroy_ipcp(pid_t pid);

ssize_t irm_list_ipcps(struct ipcp_list_info ** ipcps);

int     irm_enroll_ipcp(pid_t        pid,
                        const char * dst);

int     irm_bootstrap_ipcp(pid_t                      pid,
                           const struct ipcp_config * conf);

int     irm_connect_ipcp(pid_t        pid,
                         const char * component,
                         const char * dst,
                         qosspec_t    qs);

int     irm_disconnect_ipcp(pid_t        pid,
                            const char * component,
                            const char * dst);

int     irm_bind_program(const char * prog,
                         const char * name,
                         uint16_t     opts,
                         int          argc,
                         char **      argv);

int     irm_unbind_program(const char * progr,
                           const char * name);

int     irm_bind_process(pid_t        pid,
                         const char * name);

int     irm_unbind_process(pid_t        pid,
                           const char * name);

int     irm_create_name(struct name_info * info);

int     irm_destroy_name(const char * name);

ssize_t irm_list_names(struct name_info ** names);

int     irm_reg_name(const char * name,
                     pid_t        pid);

int     irm_unreg_name(const char * name,
                       pid_t        pid);

/* IRM WRAPPER HELPERS */
int ipcp_config_udp4_set_ip(struct ipcp_config * conf,
                            const char *         ip_str);

int ipcp_config_udp4_set_dns(struct ipcp_config * conf,
                             const char *         dns_str);

int ipcp_config_udp6_set_ip(struct ipcp_config * conf,
                            const char *         ip_str);

int ipcp_config_udp6_set_dns(struct ipcp_config * conf,
                             const char *         dns_str);

/* libc */
void free(void *ptr);
""")

ffibuilder.set_source("_ouroboros_irm_cffi",
                      """
#include "ouroboros/version.h"
#include "ouroboros/qos.h"
#include "irm_wrap.h"
                      """,
                      libraries=['ouroboros-irm'],
                      extra_compile_args=["-I./ffi/"])

if __name__ == "__main__":
    ffibuilder.compile(verbose=True)