Skip to content

Commit 4a2033a

Browse files
LingaoMcarlescufi
authored andcommitted
Bluetooth: Mesh: net cache uses reverse order traversal
Since the net cache is accumulated in positive order, the net cache uses reverse order traversal, which can filter duplicate messages more effectively. Signed-off-by: Lingao Meng <[email protected]>
1 parent 5867492 commit 4a2033a

File tree

1 file changed

+17
-4
lines changed
  • subsys/bluetooth/mesh

1 file changed

+17
-4
lines changed

subsys/bluetooth/mesh/net.c

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,14 @@ static bool check_dup(struct net_buf_simple *data)
119119

120120
val = sys_get_be32(tail - 4) ^ sys_get_be32(tail - 8);
121121

122-
for (i = 0; i < ARRAY_SIZE(dup_cache); i++) {
123-
if (dup_cache[i] == val) {
122+
for (i = dup_cache_next; i > 0;) {
123+
if (dup_cache[--i] == val) {
124+
return true;
125+
}
126+
}
127+
128+
for (i = ARRAY_SIZE(dup_cache); i > dup_cache_next;) {
129+
if (dup_cache[--i] == val) {
124130
return true;
125131
}
126132
}
@@ -135,8 +141,15 @@ static bool msg_cache_match(struct net_buf_simple *pdu)
135141
{
136142
uint16_t i;
137143

138-
for (i = 0U; i < ARRAY_SIZE(msg_cache); i++) {
139-
if (msg_cache[i].src == SRC(pdu->data) &&
144+
for (i = msg_cache_next; i > 0U;) {
145+
if (msg_cache[--i].src == SRC(pdu->data) &&
146+
msg_cache[i].seq == (SEQ(pdu->data) & BIT_MASK(17))) {
147+
return true;
148+
}
149+
}
150+
151+
for (i = ARRAY_SIZE(msg_cache); i > msg_cache_next;) {
152+
if (msg_cache[--i].src == SRC(pdu->data) &&
140153
msg_cache[i].seq == (SEQ(pdu->data) & BIT_MASK(17))) {
141154
return true;
142155
}

0 commit comments

Comments
 (0)