Skip to content

Commit f5dd1a6

Browse files
committed
deal with older lastHashes and modern network
1 parent 23861d7 commit f5dd1a6

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

lib/lib.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,39 @@ async function jsonAsk(url, fetchOptions = {}) {
138138
if (json.match(/Service node is not ready:/)) {
139139
return
140140
}
141+
// handle 2021 change
142+
// https://github.com/oxen-io/oxen-storage-server/commit/7f148b4d6ee7f6052fbab4e6234ab3a4411fd95c
143+
if (json.match(/Invalid last_hash: expected base64 \(43 chars\)/)) {
144+
// just clear out last hash
145+
return {
146+
lastHash: ' ',
147+
messages: [],
148+
}
149+
/*
150+
const bodyData = JSON.parse(fetchOptions.body)
151+
if (bodyData?.params?.lastHash?.length !== 43) {
152+
// retry without
153+
console.warn('lib::jsonAsk - last_hash', bodyData.params.lastHash, 'is invalid, retrying without, so we can retrieve anything', fetchOptions)
154+
//const props = ['method', 'body', 'headers', 'timeout']
155+
delete bodyData.params.lastHash
156+
fetchOptions.body = JSON.stringify(bodyData)
157+
const json2 = await textAsk(url, fetchOptions)
158+
// huh this doesn't have a lastHash
159+
console.log('got', json2)
160+
try {
161+
const obj = JSON.parse(json2)
162+
163+
return obj
164+
} catch (e) {
165+
console.error('lib::jsonAsk - err', e, 'json', json2, 'options', fetchOptions)
166+
return
167+
}
168+
return jsonAsk(url, fetchOptions)
169+
}
170+
console.warn('got invalid last_hash', bodyData.params.lastHash, 'is 43...', bodyData)
171+
return
172+
*/
173+
}
141174
try {
142175
const obj = JSON.parse(json)
143176
return obj

0 commit comments

Comments
 (0)