Tweak message ply internals

This commit is contained in:
Jeremy Lakeman 2016-08-15 17:19:34 +09:30
parent b6256ea89a
commit 9697b0991b
4 changed files with 33 additions and 18 deletions

View File

@ -179,7 +179,7 @@ static enum meshms_status get_database_conversations(const keyring_identity *id,
}else{
p=&ptr->my_ply;
}
p->found = 1;
p->found = p->known_bid = 1;
p->bundle_id = bid;
p->version = version;
p->tail = tail;

View File

@ -103,6 +103,12 @@ static int app_meshms_send_message(const struct cli_parsed *parsed, struct cli_c
|| cli_arg(parsed, "payload", &message, NULL, "") == -1)
return -1;
sid_t my_sid, their_sid;
if (str_to_sid_t(&my_sid, my_sidhex) == -1)
return WHY("Invalid sender SID");
if (str_to_sid_t(&their_sid, their_sidhex) == -1)
return WHY("Invalid recipient SID");
if (create_serval_instance_dir() == -1)
return -1;
if (!(keyring = keyring_open_instance_cli(parsed)))
@ -113,11 +119,6 @@ static int app_meshms_send_message(const struct cli_parsed *parsed, struct cli_c
return -1;
}
sid_t my_sid, their_sid;
if (str_to_sid_t(&my_sid, my_sidhex) == -1)
return WHY("invalid sender SID");
if (str_to_sid_t(&their_sid, their_sidhex) == -1)
return WHY("invalid recipient SID");
// include terminating NUL
enum meshms_status status = meshms_send_message(&my_sid, &their_sid, message, strlen(message) + 1);
keyring_free(keyring);
@ -175,7 +176,7 @@ static int app_meshms_list_messages(const struct cli_parsed *parsed, struct cli_
if (iter.delivered && !marked_delivered){
cli_put_long(context, id++, ":");
cli_put_long(context, iter.latest_ack_offset, ":");
cli_put_long(context, iter.timestamp?(int)(now - iter.timestamp):-1, ":");
cli_put_long(context, iter.timestamp ? (now - iter.timestamp):(long)-1, ":");
cli_put_string(context, "ACK", ":");
cli_put_string(context, "delivered", "\n");
marked_delivered = 1;
@ -183,7 +184,7 @@ static int app_meshms_list_messages(const struct cli_parsed *parsed, struct cli_
// TODO new message format here
cli_put_long(context, id++, ":");
cli_put_long(context, iter.offset, ":");
cli_put_long(context, iter.timestamp?(int)(now - iter.timestamp):-1, ":");
cli_put_long(context, iter.timestamp ? (now - iter.timestamp):(long)-1, ":");
cli_put_string(context, ">", ":");
cli_put_string(context, iter.text, "\n");
break;
@ -193,7 +194,7 @@ static int app_meshms_list_messages(const struct cli_parsed *parsed, struct cli_
if (iter.read && !marked_read) {
cli_put_long(context, id++, ":");
cli_put_long(context, iter.read_offset, ":");
cli_put_long(context, iter.timestamp?(int)(now - iter.timestamp):-1, ":");
cli_put_long(context, iter.timestamp ? (now - iter.timestamp):(long)-1, ":");
cli_put_string(context, "MARK", ":");
cli_put_string(context, "read", "\n");
marked_read = 1;
@ -201,7 +202,7 @@ static int app_meshms_list_messages(const struct cli_parsed *parsed, struct cli_
// TODO new message format here
cli_put_long(context, id++, ":");
cli_put_long(context, iter.offset, ":");
cli_put_long(context, iter.timestamp?(int)(now - iter.timestamp):-1, ":");
cli_put_long(context, iter.timestamp ? (now - iter.timestamp):(long)-1, ":");
cli_put_string(context, "<", ":");
cli_put_string(context, iter.text, "\n");
break;

View File

@ -11,9 +11,9 @@
static int message_ply_load_manifest(const keyring_identity *id, struct message_ply *ply, rhizome_manifest *m)
{
assert(ply->found);
assert(ply->known_bid);
if (rhizome_retrieve_manifest(&ply->bundle_id, m) != RHIZOME_BUNDLE_STATUS_SAME)
return -1;
return 1;
rhizome_authenticate_author(m);
if (!m->haveSecret || m->authorship != AUTHOR_AUTHENTIC)
return -1;
@ -59,7 +59,7 @@ static int message_ply_fill_manifest(const keyring_identity *id, const sid_t *re
assert(m->haveSecret);
assert(!recipient || m->payloadEncryption == PAYLOAD_ENCRYPTED);
ply->bundle_id = m->cryptoSignPublic;
ply->found = 1;
ply->found = ply->known_bid = 1;
}
return ret;
}
@ -72,11 +72,24 @@ int message_ply_append(const keyring_identity *id, const char *service, const si
return -1;
int ret=-1;
if (ply->found){
if (message_ply_load_manifest(id, ply, m)!=0)
goto end;
} else {
if (ply->known_bid){
switch(message_ply_load_manifest(id, ply, m)){
case 0:
ply->found = 1;
break;
case 1:
ply->found = 0;
break;
default:
goto end;
}
}
if (!ply->found){
rhizome_manifest_set_service(m, service);
if (ply->known_bid)
rhizome_manifest_set_id(m, &ply->bundle_id);
if (message_ply_fill_manifest(id, recipient, ply, m)!=0)
goto end;
}

View File

@ -14,7 +14,8 @@ struct message_ply {
uint64_t version;
uint64_t tail;
uint64_t size;
uint8_t found;
uint8_t found:1;
uint8_t known_bid:1;
};
// cursor state for reading one ply