mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
* added RTCClock::getCurrentTimeUnique(), for when timestamps need to be unique (if temp rapid-fire)
This commit is contained in:
parent
a115626afd
commit
ba181da94a
4 changed files with 19 additions and 7 deletions
|
|
@ -165,7 +165,7 @@ class MyMesh : public mesh::Mesh {
|
||||||
}
|
}
|
||||||
|
|
||||||
int handleRequest(ClientInfo* sender, uint8_t* payload, size_t payload_len) {
|
int handleRequest(ClientInfo* sender, uint8_t* payload, size_t payload_len) {
|
||||||
uint32_t now = getRTCClock()->getCurrentTime();
|
uint32_t now = getRTCClock()->getCurrentTimeUnique();
|
||||||
memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp
|
memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp
|
||||||
|
|
||||||
switch (payload[0]) {
|
switch (payload[0]) {
|
||||||
|
|
@ -333,7 +333,7 @@ protected:
|
||||||
client->last_timestamp = timestamp;
|
client->last_timestamp = timestamp;
|
||||||
client->is_admin = is_admin;
|
client->is_admin = is_admin;
|
||||||
|
|
||||||
uint32_t now = getRTCClock()->getCurrentTime();
|
uint32_t now = getRTCClock()->getCurrentTimeUnique();
|
||||||
memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp
|
memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp
|
||||||
memcpy(&reply_data[4], "OK", 2);
|
memcpy(&reply_data[4], "OK", 2);
|
||||||
|
|
||||||
|
|
@ -441,7 +441,7 @@ protected:
|
||||||
handleCommand(sender_timestamp, (const char *) &data[5], (char *) &temp[5]);
|
handleCommand(sender_timestamp, (const char *) &data[5], (char *) &temp[5]);
|
||||||
int text_len = strlen((char *) &temp[5]);
|
int text_len = strlen((char *) &temp[5]);
|
||||||
if (text_len > 0) {
|
if (text_len > 0) {
|
||||||
uint32_t timestamp = getRTCClock()->getCurrentTime();
|
uint32_t timestamp = getRTCClock()->getCurrentTimeUnique();
|
||||||
if (timestamp == sender_timestamp) {
|
if (timestamp == sender_timestamp) {
|
||||||
// WORKAROUND: the two timestamps need to be different, in the CLI view
|
// WORKAROUND: the two timestamps need to be different, in the CLI view
|
||||||
timestamp++;
|
timestamp++;
|
||||||
|
|
|
||||||
|
|
@ -200,8 +200,7 @@ class MyMesh : public mesh::Mesh {
|
||||||
strncpy(posts[next_post_idx].text, postData, MAX_POST_TEXT_LEN);
|
strncpy(posts[next_post_idx].text, postData, MAX_POST_TEXT_LEN);
|
||||||
posts[next_post_idx].text[MAX_POST_TEXT_LEN] = 0;
|
posts[next_post_idx].text[MAX_POST_TEXT_LEN] = 0;
|
||||||
|
|
||||||
posts[next_post_idx].post_timestamp = getRTCClock()->getCurrentTime();
|
posts[next_post_idx].post_timestamp = getRTCClock()->getCurrentTimeUnique();
|
||||||
// TODO: only post at maximum of ONE PER SECOND, so that post_timestamps are UNIQUE!!
|
|
||||||
next_post_idx = (next_post_idx + 1) % MAX_UNSYNCED_POSTS;
|
next_post_idx = (next_post_idx + 1) % MAX_UNSYNCED_POSTS;
|
||||||
|
|
||||||
next_push = futureMillis(PUSH_NOTIFY_DELAY_MILLIS);
|
next_push = futureMillis(PUSH_NOTIFY_DELAY_MILLIS);
|
||||||
|
|
@ -328,6 +327,7 @@ protected:
|
||||||
uint32_t now = getRTCClock()->getCurrentTime();
|
uint32_t now = getRTCClock()->getCurrentTime();
|
||||||
client->last_activity = now;
|
client->last_activity = now;
|
||||||
|
|
||||||
|
now = getRTCClock()->getCurrentTimeUnique();
|
||||||
memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp
|
memcpy(reply_data, &now, 4); // response packets always prefixed with timestamp
|
||||||
// TODO: maybe reply with count of messages waiting to be synced for THIS client?
|
// TODO: maybe reply with count of messages waiting to be synced for THIS client?
|
||||||
reply_data[4] = RESP_SERVER_LOGIN_OK;
|
reply_data[4] = RESP_SERVER_LOGIN_OK;
|
||||||
|
|
@ -393,7 +393,7 @@ protected:
|
||||||
} else if (sender_timestamp > client->last_timestamp) { // prevent replay attacks
|
} else if (sender_timestamp > client->last_timestamp) { // prevent replay attacks
|
||||||
client->last_timestamp = sender_timestamp;
|
client->last_timestamp = sender_timestamp;
|
||||||
|
|
||||||
uint32_t now = getRTCClock()->getCurrentTime();
|
uint32_t now = getRTCClock()->getCurrentTimeUnique();
|
||||||
client->last_activity = now;
|
client->last_activity = now;
|
||||||
client->push_failures = 0; // reset so push can resume (if prev failed)
|
client->push_failures = 0; // reset so push can resume (if prev failed)
|
||||||
|
|
||||||
|
|
|
||||||
12
src/Mesh.h
12
src/Mesh.h
|
|
@ -8,6 +8,10 @@ namespace mesh {
|
||||||
* An abstraction of the device's Realtime Clock.
|
* An abstraction of the device's Realtime Clock.
|
||||||
*/
|
*/
|
||||||
class RTCClock {
|
class RTCClock {
|
||||||
|
uint32_t last_unique;
|
||||||
|
protected:
|
||||||
|
RTCClock() { last_unique = 0; }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/**
|
/**
|
||||||
* \returns the current time. in UNIX epoch seconds.
|
* \returns the current time. in UNIX epoch seconds.
|
||||||
|
|
@ -18,6 +22,14 @@ public:
|
||||||
* \param time current time in UNIX epoch seconds.
|
* \param time current time in UNIX epoch seconds.
|
||||||
*/
|
*/
|
||||||
virtual void setCurrentTime(uint32_t time) = 0;
|
virtual void setCurrentTime(uint32_t time) = 0;
|
||||||
|
|
||||||
|
uint32_t getCurrentTimeUnique() {
|
||||||
|
uint32_t t = getCurrentTime();
|
||||||
|
if (t <= last_unique) {
|
||||||
|
return ++last_unique;
|
||||||
|
}
|
||||||
|
return last_unique = t;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class GroupChannel {
|
class GroupChannel {
|
||||||
|
|
|
||||||
|
|
@ -286,7 +286,7 @@ bool BaseChatMesh::sendLogin(const ContactInfo& recipient, const char* password,
|
||||||
|
|
||||||
int tlen;
|
int tlen;
|
||||||
uint8_t temp[24];
|
uint8_t temp[24];
|
||||||
uint32_t now = getRTCClock()->getCurrentTime();
|
uint32_t now = getRTCClock()->getCurrentTimeUnique();
|
||||||
memcpy(temp, &now, 4); // mostly an extra blob to help make packet_hash unique
|
memcpy(temp, &now, 4); // mostly an extra blob to help make packet_hash unique
|
||||||
if (recipient.type == ADV_TYPE_ROOM) {
|
if (recipient.type == ADV_TYPE_ROOM) {
|
||||||
memcpy(&temp[4], &recipient.sync_since, 4);
|
memcpy(&temp[4], &recipient.sync_since, 4);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue