add imsg for fetch progress reporting; for now only contains reference info
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
diff --git a/lib/got_lib_privsep.h b/lib/got_lib_privsep.h
index 59fe6e9..f02d6fb 100644
--- a/lib/got_lib_privsep.h
+++ b/lib/got_lib_privsep.h
@@ -110,6 +110,7 @@ enum got_imsg_type {
/* Messages related to networking. */
GOT_IMSG_FETCH_REQUEST,
+ GOT_IMSG_FETCH_PROGRESS,
GOT_IMSG_FETCH_DONE,
GOT_IMSG_IDXPACK_REQUEST,
GOT_IMSG_IDXPACK_DONE,
@@ -232,6 +233,13 @@ struct got_imsg_tag_object {
*/
} __attribute__((__packed__));
+/* Structure for GOT_IMSG_FETCH_PROGRESS data. */
+struct got_imsg_fetch_progress {
+ /* Descirbes a reference which will be fetched. */
+ uint8_t refid[SHA1_DIGEST_LENGTH];
+ /* Followed by reference name in remaining data of imsg buffer. */
+};
+
/* Structure for GOT_IMSG_PACKIDX. */
struct got_imsg_packidx {
size_t len;
@@ -315,6 +323,10 @@ const struct got_error *got_privsep_send_index_pack_req(struct imsgbuf *, int,
const struct got_error *got_privsep_send_index_pack_done(struct imsgbuf *);
const struct got_error *got_privsep_wait_index_pack_done(struct imsgbuf *);
const struct got_error *got_privsep_send_fetch_req(struct imsgbuf *, int);
+const struct got_error *got_privsep_send_fetch_progress(struct imsgbuf *,
+ struct got_object_id *, const char *);
+const struct got_error *got_privsep_recv_fetch_progress(struct got_object_id **,
+ char **, struct imsgbuf *);
const struct got_error *got_privsep_send_fetch_done(struct imsgbuf *,
struct got_object_id);
const struct got_error *got_privsep_wait_fetch_done(struct imsgbuf *,
diff --git a/lib/privsep.c b/lib/privsep.c
index 5885ba7..31b2266 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -419,6 +419,39 @@ got_privsep_send_fetch_req(struct imsgbuf *ibuf, int fd)
}
const struct got_error *
+got_privsep_send_fetch_progress(struct imsgbuf *ibuf,
+ struct got_object_id *refid, const char *refname)
+{
+ const struct got_error *err = NULL;
+ struct ibuf *wbuf;
+ size_t len, reflen = strlen(refname);
+
+ len = sizeof(struct got_imsg_fetch_progress) + reflen;
+ if (len >= MAX_IMSGSIZE - IMSG_HEADER_SIZE)
+ return got_error(GOT_ERR_NO_SPACE);
+
+ wbuf = imsg_create(ibuf, GOT_IMSG_FETCH_PROGRESS, 0, 0, len);
+ if (wbuf == NULL)
+ return got_error_from_errno("imsg_create FETCH_PROGRESS");
+
+ /* Keep in sync with struct got_imsg_fetch_progress definition! */
+ if (imsg_add(wbuf, refid->sha1, SHA1_DIGEST_LENGTH) == -1) {
+ err = got_error_from_errno("imsg_add FETCH_PROGRESS");
+ ibuf_free(wbuf);
+ return err;
+ }
+ if (imsg_add(wbuf, refname, reflen) == -1) {
+ err = got_error_from_errno("imsg_add FETCH_PROGRESS");
+ ibuf_free(wbuf);
+ return err;
+ }
+
+ wbuf->fd = -1;
+ imsg_close(ibuf, wbuf);
+ return flush_imsg(ibuf);
+}
+
+const struct got_error *
got_privsep_send_fetch_done(struct imsgbuf *ibuf, struct got_object_id hash)
{
if (imsg_compose(ibuf, GOT_IMSG_FETCH_DONE, 0, 0, -1,
@@ -427,6 +460,56 @@ got_privsep_send_fetch_done(struct imsgbuf *ibuf, struct got_object_id hash)
return flush_imsg(ibuf);
}
+
+const struct got_error *
+got_privsep_recv_fetch_progress(struct got_object_id **refid,
+ char **refname, struct imsgbuf *ibuf)
+{
+ const struct got_error *err = NULL;
+ struct imsg imsg;
+ size_t datalen;
+ const size_t min_datalen =
+ MIN(sizeof(struct got_imsg_error),
+ sizeof(struct got_imsg_fetch_progress));
+
+ *refid = NULL;
+ *refname = NULL;
+
+ err = got_privsep_recv_imsg(&imsg, ibuf, min_datalen);
+ if (err)
+ return err;
+
+ datalen = imsg.hdr.len - IMSG_HEADER_SIZE;
+ switch (imsg.hdr.type) {
+ case GOT_IMSG_ERROR:
+ err = recv_imsg_error(&imsg, datalen);
+ break;
+ case GOT_IMSG_FETCH_PROGRESS:
+ *refid = malloc(sizeof(**refid));
+ if (*refid == NULL) {
+ err = got_error_from_errno("malloc");
+ break;
+ }
+ memcpy((*refid)->sha1, imsg.data, SHA1_DIGEST_LENGTH);
+ if (datalen <= SHA1_DIGEST_LENGTH) {
+ err = got_error(GOT_ERR_PRIVSEP_MSG);
+ break;
+ }
+ *refname = strndup(imsg.data + SHA1_DIGEST_LENGTH,
+ datalen - SHA1_DIGEST_LENGTH);
+ if (*refname == NULL) {
+ err = got_error_from_errno("strndup");
+ break;
+ }
+ break;
+ default:
+ return got_error(GOT_ERR_PRIVSEP_MSG);
+ }
+
+ imsg_free(&imsg);
+ return err;
+}
+
const struct got_error *
got_privsep_wait_fetch_done(struct imsgbuf *ibuf, struct got_object_id *hash)
{