Fix meshms conversations parsing when looking for a single SID

This commit is contained in:
Jeremy Lakeman 2014-02-12 15:08:24 +10:30
parent a7b43581ce
commit 348fc5f23b
3 changed files with 25 additions and 10 deletions

View File

@ -46,7 +46,7 @@ public abstract class AbstractId {
private final byte[] binary;
public AbstractId(String hex) throws InvalidHexException {
if (hex.length() != getBinarySize())
if (hex.length() != getBinarySize()*2)
throw new InvalidHexException(this, "invalid length " + hex.length() + " (should be " + (getBinarySize() * 2) + ") of '" + hex + "'");
binary = new byte[getBinarySize()];
int j = 0;

View File

@ -556,30 +556,43 @@ static enum meshms_status read_known_conversations(rhizome_manifest *m, const si
break;
if (config.debug.meshms)
DEBUGF("Reading existing conversation for %s", alloca_tohex_sid_t(sid));
if (their_sid && cmp_sid_t(&sid, their_sid) != 0)
continue;
struct meshms_conversations *ptr = add_conv(conv, &sid);
if (!ptr)
goto end;
unsigned char details[8*3];
// unpack the stored details first so we know where the next record is
unsigned char details[12*3];
r = rhizome_read_buffered(&read, &buff, details, sizeof details);
if (r == -1)
break;
int bytes = r;
uint64_t last_message=0;
uint64_t read_offset=0;
uint64_t their_size=0;
int ofs = 0;
int unpacked = unpack_uint(details, bytes, &ptr->their_last_message);
int unpacked = unpack_uint(details, bytes, &last_message);
if (unpacked == -1)
break;
ofs += unpacked;
unpacked = unpack_uint(details+ofs, bytes-ofs, &ptr->read_offset);
unpacked = unpack_uint(details+ofs, bytes-ofs, &read_offset);
if (unpacked == -1)
break;
ofs += unpacked;
unpacked = unpack_uint(details+ofs, bytes-ofs, &ptr->their_size);
unpacked = unpack_uint(details+ofs, bytes-ofs, &their_size);
if (unpacked == -1)
break;
ofs += unpacked;
read.offset += ofs - bytes;
// skip uninteresting records
if (their_sid && cmp_sid_t(&sid, their_sid) != 0)
continue;
struct meshms_conversations *ptr = add_conv(conv, &sid);
if (!ptr)
goto end;
ptr->their_last_message = last_message;
ptr->read_offset = read_offset;
ptr->their_size = their_size;
}
fault:
status = MESHMS_STATUS_PROTOCOL_FAULT;

View File

@ -199,6 +199,8 @@ test_listConversations() {
assertStdoutGrep --stderr --matches=1 ":$SIDA3::11:11\$"
assertStdoutGrep --stderr --matches=1 ":$SIDA4::14:14\$"
assertStdoutLineCount '==' 5
executeOk_servald meshms list messages $SIDA1 $SIDA2
executeOk_servald meshms list messages $SIDA1 $SIDA4
}
doc_sendNoIdentity="Send message from unknown identity"