Skip to content

Commit 635de1f

Browse files
committed
deduplicate env timestamp on messages
1 parent 23f9909 commit 635de1f

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

lib/recv.js

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ body:
9595
<Buffer 08 06 12 00 28 a8 cf ee db bb 2e 38 00 42 fb 03 11 0a 21 05 c1 2f 19 01 ef 8e 62 8f 8e f3 58 25 42 47 de cc 5d 43 e3 a1 70 dd 22 1e f7 c7 68 63 c9 d5 ... >,
9696
id: Long { low: -347036081, high: 1342692244, unsigned: true } } }
9797
*/
98-
//console.log('message', message)
98+
//console.log('wsMessage', wsMessage)
9999
if (wsMessage.type !== 1 || !wsMessage.request) {
100100
console.warn('unhandled websocket message', wsMessage)
101101
return
@@ -111,10 +111,12 @@ content:
111111
<Buffer 11 0a 21 05 1c 97 2a 1b d8 d7 35 38 01 4f 90 eb 66 18 9d 96 36 b6 da d5 ac a6 21 ab 8f 02 ce 46 8c 7f d0 29 12 2b 2e 71 4c a5 14 50 2a 10 1a fe 2b f3 ... > }
112112
*/
113113
//console.log('env', env)
114+
//console.log('env timestamp', env.timestamp.toString())
114115
if (decodeMessageMap[env.type]) {
115116
const res = await decodeMessageMap[env.type](env, ourKeypair)
116117
if (res) {
117-
return {...res, snodeExp: msg.expiration, hash: msg.hash}
118+
//console.log('res', res)
119+
return {...res, snodeExp: msg.expiration, hash: msg.hash, timestamp: env.timestamp.toString() }
118120
} else {
119121
return {}
120122
}
@@ -123,6 +125,37 @@ content:
123125
}
124126
}
125127

128+
/*
129+
pubKeyAsk start https://54.39.15.185:22120/storage_rpc/v1 05aba1ad0ac5f3f5dbd14c54e81ce2a26c58e6fa2b2a901d40eb85246c3ce31b22 xJwZ9reNcRjeJZhLriFxvo3aURsokOsm0c0YN6S7a1c
130+
recv::checkBox - foundHash xJwZ9reNcRjeJZhLriFxvo3aURsokOsm0c0YN6S7a1c in results? false
131+
1669959312621 SessionClient::poll - recvLib got {
132+
lastHash: 'xJwZ9reNcRjeJZhLriFxvo3aURsokOsm0c0YN6S7a1c',
133+
messages: []
134+
}
135+
pubKeyAsk start https://149.56.113.46:22106/storage_rpc/v1 05aba1ad0ac5f3f5dbd14c54e81ce2a26c58e6fa2b2a901d40eb85246c3ce31b22 xJwZ9reNcRjeJZhLriFxvo3aURsokOsm0c0YN6S7a1c
136+
recv::checkBox - foundHash xJwZ9reNcRjeJZhLriFxvo3aURsokOsm0c0YN6S7a1c in results? false
137+
1669959343209 SessionClient::poll - recvLib got {
138+
lastHash: 'alN/b0GFAC6FH7jWQtTwXtZ7bkNYT1xK40fvenM4uAY',
139+
messages: [
140+
{
141+
dataMessage: [DataMessage],
142+
source: '05b69cc33267ada004c60677f39bcc3db91f1cfd841c0a3226a2b2bcc062d28959',
143+
snodeExp: 1671168929902,
144+
hash: 'U/wmKjLCEr9ph09APgyTNefmV1b4G+pMdXf6bgVSUgw'
145+
},
146+
{
147+
dataMessage: [DataMessage],
148+
source: '05b69cc33267ada004c60677f39bcc3db91f1cfd841c0a3226a2b2bcc062d28959',
149+
snodeExp: 1671168929901,
150+
hash: 'alN/b0GFAC6FH7jWQtTwXtZ7bkNYT1xK40fvenM4uAY'
151+
}
152+
]
153+
}
154+
setLast alN/b0GFAC6FH7jWQtTwXtZ7bkNYT1xK40fvenM4uAY
155+
1669959343565 DM from 05b69cc33267ada004c60677f39bcc3db91f1cfd841c0a3226a2b2bcc062d28959 Vector12ProMax: 1234567890xffa
156+
1669959343565 DM from 05b69cc33267ada004c60677f39bcc3db91f1cfd841c0a3226a2b2bcc062d28959 Vector12ProMax: 1234567890xffa
157+
*/
158+
126159
async function checkBox(pubKey, ourKeypair, inLasthash, lib, debug) {
127160
if (!ourKeypair) {
128161
console.trace('lib::recv - no ourKeypair')
@@ -194,6 +227,7 @@ async function checkBox(pubKey, ourKeypair, inLasthash, lib, debug) {
194227
return handleMessage(msg, ourKeypair)
195228
}))
196229
const ts = Date.now()
230+
const msgMap = {} // deduplicate duplicate envelope timestamp
197231
for(const m of newMsgs) {
198232
//console.log('m', m)
199233
//console.log('ts', ts, '-', m.snodeExp)
@@ -205,7 +239,9 @@ async function checkBox(pubKey, ourKeypair, inLasthash, lib, debug) {
205239
//console.log('UPDATING lastHash to', m.hash)
206240
useLastHash = m.hash
207241
}
242+
msgMap[m.timestamp] = m
208243
}
244+
newMsgs = Object.values(msgMap)
209245
}
210246
//console.log('returning', useLastHash)
211247
return {

0 commit comments

Comments
 (0)