2016-06-28 03:39:02 +00:00
|
|
|
|
|
|
|
#ifndef __SERVAL_DNA__MESSAGE_PLY_H
|
|
|
|
#define __SERVAL_DNA__MESSAGE_PLY_H
|
|
|
|
|
|
|
|
#define MESSAGE_PLY_MAX_LEN 4095
|
|
|
|
|
|
|
|
#define MESSAGE_BLOCK_TYPE_ACK 0x01
|
|
|
|
#define MESSAGE_BLOCK_TYPE_MESSAGE 0x02 // NUL-terminated UTF8 string
|
|
|
|
#define MESSAGE_BLOCK_TYPE_TIME 0x03 // local timestamp record
|
|
|
|
|
|
|
|
// the manifest details for one ply
|
|
|
|
struct message_ply {
|
|
|
|
rhizome_bid_t bundle_id;
|
2017-02-06 02:23:12 +00:00
|
|
|
sid_t author;
|
2016-06-28 03:39:02 +00:00
|
|
|
uint64_t version;
|
|
|
|
uint64_t tail;
|
|
|
|
uint64_t size;
|
2016-08-15 07:49:34 +00:00
|
|
|
uint8_t found:1;
|
|
|
|
uint8_t known_bid:1;
|
2016-06-28 03:39:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// cursor state for reading one ply
|
|
|
|
struct message_ply_read {
|
|
|
|
// rhizome payload
|
|
|
|
struct rhizome_read read;
|
|
|
|
// block buffer
|
|
|
|
struct rhizome_read_buffer buff;
|
2017-02-27 01:28:28 +00:00
|
|
|
rhizome_bid_t bundle_id;
|
2016-10-12 01:40:21 +00:00
|
|
|
// copy of the manifest name field
|
|
|
|
const char *name;
|
2017-02-06 02:23:12 +00:00
|
|
|
// copy of the manifest author
|
|
|
|
sid_t author;
|
2016-06-28 03:39:02 +00:00
|
|
|
// details of the current record
|
|
|
|
uint64_t record_end_offset;
|
|
|
|
uint16_t record_length;
|
|
|
|
size_t record_size;
|
2016-08-17 01:58:36 +00:00
|
|
|
uint8_t type;
|
2016-06-28 03:39:02 +00:00
|
|
|
// raw record data
|
2016-08-17 01:58:36 +00:00
|
|
|
uint8_t *record;
|
2016-06-28 03:39:02 +00:00
|
|
|
};
|
|
|
|
|
2017-02-13 00:25:21 +00:00
|
|
|
struct message_ply_write{
|
|
|
|
rhizome_manifest *m;
|
|
|
|
struct rhizome_write write;
|
|
|
|
};
|
|
|
|
|
2017-02-21 03:06:38 +00:00
|
|
|
int message_ply_read_open(struct message_ply_read *ply, const rhizome_bid_t *bid, const sign_keypair_t *keypair);
|
2016-06-28 03:39:02 +00:00
|
|
|
void message_ply_read_close(struct message_ply_read *ply);
|
|
|
|
int message_ply_read_prev(struct message_ply_read *ply);
|
|
|
|
int message_ply_find_prev(struct message_ply_read *ply, char type);
|
2016-08-17 01:58:36 +00:00
|
|
|
int message_ply_is_open(struct message_ply_read *ply);
|
|
|
|
void message_ply_read_rewind(struct message_ply_read *ply);
|
2016-06-28 03:39:02 +00:00
|
|
|
|
2017-02-27 01:28:28 +00:00
|
|
|
struct message_ply_ack{
|
|
|
|
uint64_t start_offset;
|
|
|
|
uint64_t end_offset;
|
|
|
|
const uint8_t *binary;
|
|
|
|
size_t binary_length;
|
|
|
|
};
|
|
|
|
|
2017-02-15 05:05:20 +00:00
|
|
|
int message_ply_parse_timestamp(struct message_ply_read *ply, time_s_t *timestamp);
|
2017-02-27 01:28:28 +00:00
|
|
|
int message_ply_parse_ack(struct message_ply_read *ply, struct message_ply_ack *ack);
|
2017-02-15 05:05:20 +00:00
|
|
|
|
2017-02-13 00:25:21 +00:00
|
|
|
int message_ply_write_open(
|
|
|
|
struct message_ply_write *ply_write,
|
|
|
|
const struct keyring_identity *id,
|
|
|
|
const char *service,
|
|
|
|
const sid_t *recipient,
|
|
|
|
struct message_ply *ply,
|
|
|
|
const char *name,
|
|
|
|
unsigned nassignments,
|
|
|
|
const struct rhizome_manifest_field_assignment *assignments,
|
|
|
|
uint64_t advance_by);
|
|
|
|
|
2017-05-10 01:31:02 +00:00
|
|
|
int message_ply_write_finish(struct message_ply_write *write, struct message_ply *ply);
|
2017-02-13 00:25:21 +00:00
|
|
|
void message_ply_write_close(struct message_ply_write *write);
|
|
|
|
|
2017-02-27 01:28:28 +00:00
|
|
|
void message_ply_append_ack(struct overlay_buffer *b, const struct message_ply_ack *ack);
|
2016-06-28 03:39:02 +00:00
|
|
|
void message_ply_append_timestamp(struct overlay_buffer *b);
|
|
|
|
void message_ply_append_message(struct overlay_buffer *b, const char *message, size_t message_len);
|
2016-08-24 07:03:39 +00:00
|
|
|
int message_ply_append(const struct keyring_identity *id, const char *service, const sid_t *recipient, struct message_ply *ply, struct overlay_buffer *b,
|
2016-10-16 00:11:01 +00:00
|
|
|
const char *name, unsigned nassignments, const struct rhizome_manifest_field_assignment *assignments);
|
2016-06-28 03:39:02 +00:00
|
|
|
|
2017-02-06 02:23:12 +00:00
|
|
|
#endif
|