mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-01-18 02:39:44 +00:00
Fix meshms conversations parsing when looking for a single SID
This commit is contained in:
parent
a7b43581ce
commit
348fc5f23b
@ -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;
|
||||
|
31
meshms.c
31
meshms.c
@ -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;
|
||||
|
@ -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"
|
||||
|
Loading…
Reference in New Issue
Block a user