summaryrefslogtreecommitdiff
path: root/src/ipcpd/ipcp.h
blob: aab490c76c8aa1a23b66f4e1e93500eab7fdab77 (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
/*
 * Ouroboros - Copyright (C) 2016 - 2024
 *
 * IPC process structure
 *
 *    Dimitri Staessens <dimitri@ouroboros.rocks>
 *    Sander Vrijders   <sander@ouroboros.rocks>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., http://www.fsf.org/about/contact/.
 */

#ifndef OUROBOROS_IPCPD_IPCP_H
#define OUROBOROS_IPCPD_IPCP_H

#include <ouroboros/hash.h>
#include <ouroboros/ipcp.h>
#include <ouroboros/list.h>
#include <ouroboros/protobuf.h>
#include <ouroboros/qos.h>
#include <ouroboros/sockets.h>
#include <ouroboros/tpm.h>

#include <pthread.h>
#include <time.h>

struct ipcp_ops {
        int   (* ipcp_bootstrap)(const struct ipcp_config * conf);

        int   (* ipcp_enroll)(const char *        dst,
                              struct layer_info * info);

        int   (* ipcp_connect)(const char * dst,
                               const char * component,
                               qosspec_t    qs);

        int   (* ipcp_disconnect)(const char * dst,
                                  const char * component);

        int   (* ipcp_reg)(const uint8_t * hash);

        int   (* ipcp_unreg)(const uint8_t * hash);

        int   (* ipcp_query)(const uint8_t * hash);

        int   (* ipcp_flow_alloc)(int              fd,
                                  const uint8_t *  dst,
                                  qosspec_t        qs,
                                  const buffer_t * data);

        int   (* ipcp_flow_join)(int             fd,
                                 const uint8_t * dst,
                                 qosspec_t       qs);

        int   (* ipcp_flow_alloc_resp)(int              fd,
                                       int              response,
                                       const buffer_t * data);

        int   (* ipcp_flow_dealloc)(int fd);
};

#define ipcp_dir_hash_strlen() (hash_len(ipcpi.dir_hash_algo) * 2)
#define ipcp_dir_hash_len() (hash_len(ipcpi.dir_hash_algo))

extern struct ipcp {
        pid_t              irmd_pid;
        char *             name;

        enum ipcp_type     type;
        char               layer_name[LAYER_NAME_SIZE + 1];

        uint64_t           dt_addr;

        enum hash_algo     dir_hash_algo;

        struct ipcp_ops *  ops;
        int                irmd_fd;

        enum ipcp_state    state;
        pthread_cond_t     state_cond;
        pthread_mutex_t    state_mtx;

        int                sockfd;
        char *             sock_path;

        struct list_head   cmds;
        pthread_cond_t     cmd_cond;
        pthread_mutex_t    cmd_lock;

        int                alloc_id;
        pthread_cond_t     alloc_cond;
        pthread_mutex_t    alloc_lock;

        struct tpm *       tpm;

        pthread_t          acceptor;
} ipcpi;

int             ipcp_init(int               argc,
                          char **           argv,
                          struct ipcp_ops * ops,
                          enum ipcp_type    type);

int             ipcp_start(void);

void            ipcp_sigwait(void);

void            ipcp_stop(void);

void            ipcp_fini(void);

void            ipcp_set_state(enum ipcp_state state);

enum ipcp_state ipcp_get_state(void);

int             ipcp_parse_arg(int    argc,
                               char * argv[]);

/* Helper functions to handle races during flow allocation */
int             ipcp_wait_flow_req_arr(const uint8_t *  dst,
                                       qosspec_t        qs,
                                       time_t           mpl,
                                       const buffer_t * data);

int             ipcp_wait_flow_resp(const int fd);

/* Helper functions for directory entries, could be moved */
uint8_t *       ipcp_hash_dup(const uint8_t * hash);

void            ipcp_hash_str(char            buf[],
                              const uint8_t * hash);

/* Helper function to lock a thread to a core. */
void            ipcp_lock_to_core(void);

#endif /* OUROBOROS_IPCPD_IPCP_H */