Blame


1 3efd8e31 2022-10-23 thomas /*
2 3efd8e31 2022-10-23 thomas * Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
3 3efd8e31 2022-10-23 thomas *
4 3efd8e31 2022-10-23 thomas * Permission to use, copy, modify, and distribute this software for any
5 3efd8e31 2022-10-23 thomas * purpose with or without fee is hereby granted, provided that the above
6 3efd8e31 2022-10-23 thomas * copyright notice and this permission notice appear in all copies.
7 3efd8e31 2022-10-23 thomas *
8 3efd8e31 2022-10-23 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 3efd8e31 2022-10-23 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 3efd8e31 2022-10-23 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 3efd8e31 2022-10-23 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 3efd8e31 2022-10-23 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 3efd8e31 2022-10-23 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 3efd8e31 2022-10-23 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 3efd8e31 2022-10-23 thomas */
16 3efd8e31 2022-10-23 thomas
17 3efd8e31 2022-10-23 thomas
18 3efd8e31 2022-10-23 thomas #define GOTD_UNIX_SOCKET "/var/run/gotd.sock"
19 3efd8e31 2022-10-23 thomas #define GOTD_UNIX_SOCKET_BACKLOG 10
20 3efd8e31 2022-10-23 thomas #define GOTD_UNIX_GROUP "_gotsh"
21 3efd8e31 2022-10-23 thomas #define GOTD_USER "_gotd"
22 3efd8e31 2022-10-23 thomas #define GOTD_CONF_PATH "/etc/gotd.conf"
23 3efd8e31 2022-10-23 thomas
24 3efd8e31 2022-10-23 thomas #define GOTD_MAXCLIENTS 1024
25 3efd8e31 2022-10-23 thomas #define GOTD_FD_RESERVE 5
26 3efd8e31 2022-10-23 thomas #define GOTD_FD_NEEDED 6
27 3efd8e31 2022-10-23 thomas #define GOTD_SOCK_FILENO 3
28 3efd8e31 2022-10-23 thomas
29 3efd8e31 2022-10-23 thomas /* Client hash tables need some extra room. */
30 3efd8e31 2022-10-23 thomas #define GOTD_CLIENT_TABLE_SIZE (GOTD_MAXCLIENTS * 4)
31 3efd8e31 2022-10-23 thomas
32 3efd8e31 2022-10-23 thomas enum gotd_procid {
33 3efd8e31 2022-10-23 thomas PROC_GOTD = 0,
34 3efd8e31 2022-10-23 thomas PROC_REPO_READ,
35 3efd8e31 2022-10-23 thomas PROC_REPO_WRITE,
36 3efd8e31 2022-10-23 thomas PROC_MAX,
37 3efd8e31 2022-10-23 thomas };
38 3efd8e31 2022-10-23 thomas
39 3efd8e31 2022-10-23 thomas struct gotd_imsgev {
40 3efd8e31 2022-10-23 thomas struct imsgbuf ibuf;
41 3efd8e31 2022-10-23 thomas void (*handler)(int, short, void *);
42 3efd8e31 2022-10-23 thomas void *handler_arg;
43 3efd8e31 2022-10-23 thomas struct event ev;
44 3efd8e31 2022-10-23 thomas short events;
45 3efd8e31 2022-10-23 thomas };
46 3efd8e31 2022-10-23 thomas
47 3efd8e31 2022-10-23 thomas struct gotd_child_proc {
48 3efd8e31 2022-10-23 thomas pid_t pid;
49 3efd8e31 2022-10-23 thomas enum gotd_procid type;
50 3efd8e31 2022-10-23 thomas char repo_name[NAME_MAX];
51 3efd8e31 2022-10-23 thomas char chroot_path[PATH_MAX];
52 3efd8e31 2022-10-23 thomas int pipe[2];
53 3efd8e31 2022-10-23 thomas struct gotd_imsgev iev;
54 3efd8e31 2022-10-23 thomas size_t nhelpers;
55 3efd8e31 2022-10-23 thomas };
56 3efd8e31 2022-10-23 thomas
57 3efd8e31 2022-10-23 thomas struct gotd_repo {
58 3efd8e31 2022-10-23 thomas TAILQ_ENTRY(gotd_repo) entry;
59 3efd8e31 2022-10-23 thomas
60 3efd8e31 2022-10-23 thomas char name[NAME_MAX];
61 3efd8e31 2022-10-23 thomas char path[PATH_MAX];
62 3efd8e31 2022-10-23 thomas };
63 3efd8e31 2022-10-23 thomas TAILQ_HEAD(gotd_repolist, gotd_repo);
64 3efd8e31 2022-10-23 thomas
65 3efd8e31 2022-10-23 thomas enum gotd_client_state {
66 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_LIST_REFS,
67 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_CAPABILITIES,
68 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_WANT,
69 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_REF_UPDATE,
70 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_MORE_REF_UPDATES,
71 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_HAVE,
72 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_PACKFILE,
73 3efd8e31 2022-10-23 thomas GOTD_STATE_EXPECT_DONE,
74 3efd8e31 2022-10-23 thomas GOTD_STATE_DONE,
75 3efd8e31 2022-10-23 thomas };
76 3efd8e31 2022-10-23 thomas
77 3efd8e31 2022-10-23 thomas struct gotd_client_capability {
78 3efd8e31 2022-10-23 thomas char *key;
79 3efd8e31 2022-10-23 thomas char *value;
80 3efd8e31 2022-10-23 thomas };
81 3efd8e31 2022-10-23 thomas
82 3efd8e31 2022-10-23 thomas struct gotd_object_id_array {
83 3efd8e31 2022-10-23 thomas struct got_object_id **ids;
84 3efd8e31 2022-10-23 thomas size_t nalloc;
85 3efd8e31 2022-10-23 thomas size_t nids;
86 3efd8e31 2022-10-23 thomas };
87 3efd8e31 2022-10-23 thomas
88 3efd8e31 2022-10-23 thomas struct gotd {
89 3efd8e31 2022-10-23 thomas pid_t pid;
90 3efd8e31 2022-10-23 thomas char unix_socket_path[PATH_MAX];
91 3efd8e31 2022-10-23 thomas char unix_group_name[32];
92 3efd8e31 2022-10-23 thomas char user_name[32];
93 3efd8e31 2022-10-23 thomas struct gotd_repolist repos;
94 3efd8e31 2022-10-23 thomas int nrepos;
95 3efd8e31 2022-10-23 thomas int verbosity;
96 3efd8e31 2022-10-23 thomas struct event ev;
97 3efd8e31 2022-10-23 thomas struct event pause;
98 3efd8e31 2022-10-23 thomas struct gotd_child_proc *procs;
99 3efd8e31 2022-10-23 thomas int nprocs;
100 3efd8e31 2022-10-23 thomas };
101 3efd8e31 2022-10-23 thomas
102 3efd8e31 2022-10-23 thomas enum gotd_imsg_type {
103 3efd8e31 2022-10-23 thomas /* An error occured while processing a request. */
104 3efd8e31 2022-10-23 thomas GOTD_IMSG_ERROR,
105 3efd8e31 2022-10-23 thomas
106 3efd8e31 2022-10-23 thomas /* Request a list of references. */
107 3efd8e31 2022-10-23 thomas GOTD_IMSG_LIST_REFS,
108 3efd8e31 2022-10-23 thomas GOTD_IMSG_LIST_REFS_INTERNAL,
109 3efd8e31 2022-10-23 thomas
110 3efd8e31 2022-10-23 thomas /* References. */
111 3efd8e31 2022-10-23 thomas GOTD_IMSG_REFLIST,
112 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF,
113 3efd8e31 2022-10-23 thomas GOTD_IMSG_SYMREF,
114 3efd8e31 2022-10-23 thomas
115 3efd8e31 2022-10-23 thomas /* Git protocol capabilities. */
116 3efd8e31 2022-10-23 thomas GOTD_IMSG_CAPABILITIES,
117 3efd8e31 2022-10-23 thomas GOTD_IMSG_CAPABILITY,
118 3efd8e31 2022-10-23 thomas
119 3efd8e31 2022-10-23 thomas /* Git protocol chatter. */
120 3efd8e31 2022-10-23 thomas GOTD_IMSG_WANT, /* The client wants an object. */
121 3efd8e31 2022-10-23 thomas GOTD_IMSG_HAVE, /* The client has an object. */
122 3efd8e31 2022-10-23 thomas GOTD_IMSG_ACK, /* The server has an object or a reference. */
123 3efd8e31 2022-10-23 thomas GOTD_IMSG_NAK, /* The server does not have an object/ref. */
124 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATE, /* The client wants to update a reference. */
125 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_DELETE, /* The client wants to delete a reference. */
126 3efd8e31 2022-10-23 thomas GOTD_IMSG_FLUSH, /* The client sent a flush packet. */
127 3efd8e31 2022-10-23 thomas GOTD_IMSG_DONE, /* The client is done chatting. */
128 3efd8e31 2022-10-23 thomas
129 3efd8e31 2022-10-23 thomas /* Sending or receiving a pack file. */
130 3efd8e31 2022-10-23 thomas GOTD_IMSG_SEND_PACKFILE, /* The server is sending a pack file. */
131 3efd8e31 2022-10-23 thomas GOTD_IMSG_RECV_PACKFILE, /* The server is receiving a pack file. */
132 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKIDX_FILE, /* Temporary file handle for new pack index. */
133 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_PIPE, /* Pipe to send/receive a pack file stream. */
134 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_PROGRESS, /* Progress reporting. */
135 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_READY, /* Pack file is ready to be sent. */
136 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_STATUS, /* Received pack success/failure status. */
137 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_INSTALL, /* Received pack file can be installed. */
138 3efd8e31 2022-10-23 thomas GOTD_IMSG_PACKFILE_DONE, /* Pack file has been sent/received. */
139 3efd8e31 2022-10-23 thomas
140 3efd8e31 2022-10-23 thomas /* Reference updates. */
141 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATES_START, /* Ref updates starting. */
142 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATE_OK, /* Update went OK. */
143 3efd8e31 2022-10-23 thomas GOTD_IMSG_REF_UPDATE_NG, /* Update was not good. */
144 3efd8e31 2022-10-23 thomas GOTD_IMSG_REFS_UPDATED, /* The server proccessed all ref updates. */
145 3efd8e31 2022-10-23 thomas
146 3efd8e31 2022-10-23 thomas /* Client is disconnecting. */
147 3efd8e31 2022-10-23 thomas GOTD_IMSG_DISCONNECT,
148 3efd8e31 2022-10-23 thomas };
149 3efd8e31 2022-10-23 thomas
150 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_ERROR. */
151 3efd8e31 2022-10-23 thomas struct gotd_imsg_error {
152 3efd8e31 2022-10-23 thomas int code; /* an error code from got_error.h */
153 3efd8e31 2022-10-23 thomas int errno_code; /* in case code equals GOT_ERR_ERRNO */
154 3efd8e31 2022-10-23 thomas uint32_t client_id;
155 3efd8e31 2022-10-23 thomas char msg[GOT_ERR_MAX_MSG_SIZE];
156 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
157 3efd8e31 2022-10-23 thomas
158 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_LIST_REFS. */
159 3efd8e31 2022-10-23 thomas struct gotd_imsg_list_refs {
160 3efd8e31 2022-10-23 thomas char repo_name[NAME_MAX];
161 3efd8e31 2022-10-23 thomas int client_is_reading; /* 1 if reading, 0 if writing */
162 3efd8e31 2022-10-23 thomas };
163 3efd8e31 2022-10-23 thomas
164 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_LIST_REFS_INTERNAL. */
165 3efd8e31 2022-10-23 thomas struct gotd_imsg_list_refs_internal {
166 3efd8e31 2022-10-23 thomas uint32_t client_id;
167 3efd8e31 2022-10-23 thomas };
168 3efd8e31 2022-10-23 thomas
169 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REFLIST. */
170 3efd8e31 2022-10-23 thomas struct gotd_imsg_reflist {
171 3efd8e31 2022-10-23 thomas size_t nrefs;
172 3efd8e31 2022-10-23 thomas
173 3efd8e31 2022-10-23 thomas /* Followed by nrefs times of gotd_imsg_ref/gotd_imsg_symref data. */
174 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
175 3efd8e31 2022-10-23 thomas
176 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF data. */
177 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref {
178 3efd8e31 2022-10-23 thomas uint8_t id[SHA1_DIGEST_LENGTH];
179 3efd8e31 2022-10-23 thomas size_t name_len;
180 3efd8e31 2022-10-23 thomas /* Followed by name_len data bytes. */
181 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
182 3efd8e31 2022-10-23 thomas
183 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_SYMREF data. */
184 3efd8e31 2022-10-23 thomas struct gotd_imsg_symref {
185 3efd8e31 2022-10-23 thomas size_t name_len;
186 3efd8e31 2022-10-23 thomas size_t target_len;
187 3efd8e31 2022-10-23 thomas uint8_t target_id[SHA1_DIGEST_LENGTH];
188 3efd8e31 2022-10-23 thomas
189 3efd8e31 2022-10-23 thomas /*
190 3efd8e31 2022-10-23 thomas * Followed by name_len + target_len data bytes.
191 3efd8e31 2022-10-23 thomas */
192 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
193 3efd8e31 2022-10-23 thomas
194 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_CAPABILITIES data. */
195 3efd8e31 2022-10-23 thomas struct gotd_imsg_capabilities {
196 3efd8e31 2022-10-23 thomas size_t ncapabilities;
197 3efd8e31 2022-10-23 thomas
198 3efd8e31 2022-10-23 thomas /*
199 3efd8e31 2022-10-23 thomas * Followed by ncapabilities * GOTD_IMSG_CAPABILITY.
200 3efd8e31 2022-10-23 thomas */
201 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
202 3efd8e31 2022-10-23 thomas
203 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_CAPABILITY data. */
204 3efd8e31 2022-10-23 thomas struct gotd_imsg_capability {
205 3efd8e31 2022-10-23 thomas size_t key_len;
206 3efd8e31 2022-10-23 thomas size_t value_len;
207 3efd8e31 2022-10-23 thomas
208 3efd8e31 2022-10-23 thomas /*
209 3efd8e31 2022-10-23 thomas * Followed by key_len + value_len data bytes.
210 3efd8e31 2022-10-23 thomas */
211 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
212 3efd8e31 2022-10-23 thomas
213 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_WANT data. */
214 3efd8e31 2022-10-23 thomas struct gotd_imsg_want {
215 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
216 3efd8e31 2022-10-23 thomas uint32_t client_id;
217 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
218 3efd8e31 2022-10-23 thomas
219 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_HAVE data. */
220 3efd8e31 2022-10-23 thomas struct gotd_imsg_have {
221 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
222 3efd8e31 2022-10-23 thomas uint32_t client_id;
223 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
224 3efd8e31 2022-10-23 thomas
225 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_ACK data. */
226 3efd8e31 2022-10-23 thomas struct gotd_imsg_ack {
227 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
228 3efd8e31 2022-10-23 thomas uint32_t client_id;
229 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
230 3efd8e31 2022-10-23 thomas
231 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_NAK data. */
232 3efd8e31 2022-10-23 thomas struct gotd_imsg_nak {
233 3efd8e31 2022-10-23 thomas uint8_t object_id[SHA1_DIGEST_LENGTH];
234 3efd8e31 2022-10-23 thomas uint32_t client_id;
235 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
236 3efd8e31 2022-10-23 thomas
237 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_STATUS data. */
238 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_status {
239 3efd8e31 2022-10-23 thomas size_t reason_len;
240 3efd8e31 2022-10-23 thomas
241 3efd8e31 2022-10-23 thomas /* Followed by reason_len data bytes. */
242 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
243 3efd8e31 2022-10-23 thomas
244 3efd8e31 2022-10-23 thomas
245 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATE data. */
246 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update {
247 3efd8e31 2022-10-23 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
248 3efd8e31 2022-10-23 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
249 3efd8e31 2022-10-23 thomas int ref_is_new;
250 3efd8e31 2022-10-23 thomas uint32_t client_id;
251 3efd8e31 2022-10-23 thomas size_t name_len;
252 3efd8e31 2022-10-23 thomas
253 3efd8e31 2022-10-23 thomas /* Followed by name_len data bytes. */
254 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
255 3efd8e31 2022-10-23 thomas
256 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATES_START data. */
257 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_updates_start {
258 3efd8e31 2022-10-23 thomas int nref_updates;
259 3efd8e31 2022-10-23 thomas uint32_t client_id;
260 3efd8e31 2022-10-23 thomas
261 3efd8e31 2022-10-23 thomas /* Followed by nref_updates GOT_IMSG_REF_UPDATE_OK/NG messages. */
262 3efd8e31 2022-10-23 thomas };
263 3efd8e31 2022-10-23 thomas
264 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATE_OK data. */
265 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update_ok {
266 3efd8e31 2022-10-23 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
267 3efd8e31 2022-10-23 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
268 3efd8e31 2022-10-23 thomas int ref_is_new;
269 3efd8e31 2022-10-23 thomas uint32_t client_id;
270 3efd8e31 2022-10-23 thomas size_t name_len;
271 3efd8e31 2022-10-23 thomas
272 3efd8e31 2022-10-23 thomas /* Followed by name_len data bytes. */
273 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
274 3efd8e31 2022-10-23 thomas
275 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_REF_UPDATE_NG data. */
276 3efd8e31 2022-10-23 thomas struct gotd_imsg_ref_update_ng {
277 3efd8e31 2022-10-23 thomas uint8_t old_id[SHA1_DIGEST_LENGTH];
278 3efd8e31 2022-10-23 thomas uint8_t new_id[SHA1_DIGEST_LENGTH];
279 3efd8e31 2022-10-23 thomas uint32_t client_id;
280 3efd8e31 2022-10-23 thomas size_t name_len;
281 3efd8e31 2022-10-23 thomas size_t reason_len;
282 3efd8e31 2022-10-23 thomas
283 3efd8e31 2022-10-23 thomas /* Followed by name_len + reason_len data bytes. */
284 3efd8e31 2022-10-23 thomas } __attribute__((__packed__));
285 3efd8e31 2022-10-23 thomas
286 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_SEND_PACKFILE data. */
287 3efd8e31 2022-10-23 thomas struct gotd_imsg_send_packfile {
288 3efd8e31 2022-10-23 thomas uint32_t client_id;
289 3efd8e31 2022-10-23 thomas int report_progress;
290 3efd8e31 2022-10-23 thomas
291 3efd8e31 2022-10-23 thomas /* delta cache file is sent as a file descriptor */
292 3efd8e31 2022-10-23 thomas
293 3efd8e31 2022-10-23 thomas /* followed by two GOTD_IMSG_PACKFILE_PIPE messages */
294 3efd8e31 2022-10-23 thomas };
295 3efd8e31 2022-10-23 thomas
296 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_RECV_PACKFILE data. */
297 3efd8e31 2022-10-23 thomas struct gotd_imsg_recv_packfile {
298 3efd8e31 2022-10-23 thomas uint32_t client_id;
299 3efd8e31 2022-10-23 thomas int report_status;
300 3efd8e31 2022-10-23 thomas
301 3efd8e31 2022-10-23 thomas /* pack destination temp file is sent as a file descriptor */
302 3efd8e31 2022-10-23 thomas };
303 3efd8e31 2022-10-23 thomas
304 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_PIPE data. */
305 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_pipe {
306 3efd8e31 2022-10-23 thomas uint32_t client_id;
307 3efd8e31 2022-10-23 thomas };
308 3efd8e31 2022-10-23 thomas
309 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKIDX_FILE data. */
310 3efd8e31 2022-10-23 thomas struct gotd_imsg_packidx_file {
311 3efd8e31 2022-10-23 thomas uint32_t client_id;
312 3efd8e31 2022-10-23 thomas };
313 3efd8e31 2022-10-23 thomas
314 3efd8e31 2022-10-23 thomas
315 3efd8e31 2022-10-23 thomas /*
316 3efd8e31 2022-10-23 thomas * Structure for GOTD_IMSG_PACKFILE_PROGRESS and
317 3efd8e31 2022-10-23 thomas * GOTD_IMSG_PACKFILE_READY data.
318 3efd8e31 2022-10-23 thomas */
319 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_progress {
320 3efd8e31 2022-10-23 thomas uint32_t client_id;
321 3efd8e31 2022-10-23 thomas int ncolored;
322 3efd8e31 2022-10-23 thomas int nfound;
323 3efd8e31 2022-10-23 thomas int ntrees;
324 3efd8e31 2022-10-23 thomas off_t packfile_size;
325 3efd8e31 2022-10-23 thomas int ncommits;
326 3efd8e31 2022-10-23 thomas int nobj_total;
327 3efd8e31 2022-10-23 thomas int nobj_deltify;
328 3efd8e31 2022-10-23 thomas int nobj_written;
329 3efd8e31 2022-10-23 thomas };
330 3efd8e31 2022-10-23 thomas
331 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_INSTALL. */
332 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_install {
333 3efd8e31 2022-10-23 thomas uint32_t client_id;
334 3efd8e31 2022-10-23 thomas uint8_t pack_sha1[SHA1_DIGEST_LENGTH];
335 3efd8e31 2022-10-23 thomas };
336 3efd8e31 2022-10-23 thomas
337 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_PACKFILE_DONE data. */
338 3efd8e31 2022-10-23 thomas struct gotd_imsg_packfile_done {
339 3efd8e31 2022-10-23 thomas uint32_t client_id;
340 3efd8e31 2022-10-23 thomas };
341 3efd8e31 2022-10-23 thomas
342 3efd8e31 2022-10-23 thomas /* Structure for GOTD_IMSG_DISCONNECT data. */
343 3efd8e31 2022-10-23 thomas struct gotd_imsg_disconnect {
344 3efd8e31 2022-10-23 thomas uint32_t client_id;
345 3efd8e31 2022-10-23 thomas };
346 3efd8e31 2022-10-23 thomas
347 3efd8e31 2022-10-23 thomas int parse_config(const char *, enum gotd_procid, struct gotd *);
348 3efd8e31 2022-10-23 thomas
349 3efd8e31 2022-10-23 thomas /* imsg.c */
350 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_flush(struct imsgbuf *);
351 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_recv(struct imsg *, struct imsgbuf *, size_t);
352 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_poll_recv(struct imsg *, struct imsgbuf *,
353 3efd8e31 2022-10-23 thomas size_t);
354 3efd8e31 2022-10-23 thomas const struct got_error *gotd_imsg_recv_error(uint32_t *client_id,
355 3efd8e31 2022-10-23 thomas struct imsg *imsg);
356 3efd8e31 2022-10-23 thomas int gotd_imsg_send_error(struct imsgbuf *ibuf, uint32_t, uint32_t,
357 3efd8e31 2022-10-23 thomas const struct got_error *);
358 3efd8e31 2022-10-23 thomas int gotd_imsg_send_error_event(struct gotd_imsgev *, uint32_t, uint32_t,
359 3efd8e31 2022-10-23 thomas const struct got_error *);
360 3efd8e31 2022-10-23 thomas void gotd_imsg_event_add(struct gotd_imsgev *);
361 3efd8e31 2022-10-23 thomas int gotd_imsg_compose_event(struct gotd_imsgev *, uint16_t, uint32_t, int,
362 3efd8e31 2022-10-23 thomas void *, uint16_t);
363 3efd8e31 2022-10-23 thomas int gotd_imsg_forward(struct gotd_imsgev *, struct imsg *, int);
364 3efd8e31 2022-10-23 thomas
365 3efd8e31 2022-10-23 thomas void gotd_imsg_send_ack(struct got_object_id *, struct imsgbuf *,
366 3efd8e31 2022-10-23 thomas uint32_t, pid_t);
367 3efd8e31 2022-10-23 thomas void gotd_imsg_send_nak(struct got_object_id *, struct imsgbuf *,
368 3efd8e31 2022-10-23 thomas uint32_t, pid_t);