* companion radio: new CMD_EXPORT_CONTACT, CMD_IMPORT_CONTACT

This commit is contained in:
Scott Powell 2025-02-15 15:57:02 +11:00
parent 65580c76d0
commit a2fa4caa3f
4 changed files with 64 additions and 12 deletions

View file

@ -262,6 +262,24 @@ bool BaseChatMesh::shareContactZeroHop(const ContactInfo& contact) {
return true; // success
}
uint8_t BaseChatMesh::exportContact(const ContactInfo& contact, uint8_t dest_buf[]) {
return getBlobByKey(contact.id.pub_key, PUB_KEY_SIZE, dest_buf); // retrieve last raw advert packet
}
bool BaseChatMesh::importContact(const uint8_t src_buf[], uint8_t len) {
auto pkt = obtainNewPacket();
if (pkt) {
if (pkt->readFrom(src_buf, len) && pkt->getPayloadType() == PAYLOAD_TYPE_ADVERT) {
pkt->header |= ROUTE_TYPE_FLOOD; // simulate it being received flood-mode
_pendingLoopback = pkt; // loop-back, as if received over radio
return true; // success
} else {
releasePacket(pkt); // undo the obtainNewPacket()
}
}
return false; // error
}
bool BaseChatMesh::sendLogin(const ContactInfo& recipient, const char* password, uint32_t& est_timeout) {
uint8_t shared_secret[32];
self_id.calcSharedSecret(shared_secret, recipient.id); // TODO: cache this
@ -416,4 +434,10 @@ void BaseChatMesh::loop() {
onSendTimeout();
txt_send_timeout = 0;
}
}
if (_pendingLoopback) {
onRecvPacket(_pendingLoopback); // loop-back, as if received over radio
releasePacket(_pendingLoopback); // undo the obtainNewPacket()
_pendingLoopback = NULL;
}
}

View file

@ -60,6 +60,7 @@ class BaseChatMesh : public mesh::Mesh {
mesh::GroupChannel channels[MAX_GROUP_CHANNELS];
int num_channels;
#endif
mesh::Packet* _pendingLoopback;
uint8_t temp_buf[MAX_TRANS_UNIT];
mesh::Packet* composeMsgPacket(const ContactInfo& recipient, uint32_t timestamp, uint8_t attempt, const char *text, uint32_t& expected_ack);
@ -73,6 +74,7 @@ protected:
num_channels = 0;
#endif
txt_send_timeout = 0;
_pendingLoopback = NULL;
}
// 'UI' concepts, for sub-classes to implement
@ -108,6 +110,8 @@ public:
bool sendGroupMessage(uint32_t timestamp, mesh::GroupChannel& channel, const char* sender_name, const char* text, int text_len);
bool sendLogin(const ContactInfo& recipient, const char* password, uint32_t& est_timeout);
bool shareContactZeroHop(const ContactInfo& contact);
uint8_t exportContact(const ContactInfo& contact, uint8_t dest_buf[]);
bool importContact(const uint8_t src_buf[], uint8_t len);
void resetPathTo(ContactInfo& recipient);
void scanRecentContacts(int last_n, ContactVisitor* visitor);
ContactInfo* searchContactsByPrefix(const char* name_prefix);