p2p instant question sending fixes

This commit is contained in:
mrfry 2023-04-26 15:02:50 +02:00
parent 977c118da8
commit f047701106
9 changed files with 75 additions and 56 deletions

View file

@ -325,13 +325,11 @@ async function authAndGetNewData({
peer,
selfInfo,
lastSyncWithPeer,
lastSync,
}: {
peers: PeerInfo[]
peer: PeerInfo
selfInfo: PeerInfo
lastSyncWithPeer: number
lastSync: number
}): Promise<GetResult<SyncDataRes & { peer: PeerInfo }>> {
let sessionCookie = peer.sessionCookie
@ -354,13 +352,13 @@ async function authAndGetNewData({
return get<SyncDataRes>(
{
headers: {
cookies: `sessionID=${sessionCookie}`,
cookie: `sessionID=${sessionCookie}`,
},
host: peer.host,
port: peer.port,
path: `/api/getnewdatasince?host=${encodeURIComponent(
peerToString(selfInfo)
)}${lastSync ? `&since=${lastSyncWithPeer}` : ''}`,
)}${lastSyncWithPeer ? `&since=${lastSyncWithPeer}` : ''}`,
},
peer.http
)
@ -637,7 +635,6 @@ function setup(data: SubmoduleData): Submodule {
peer: peer,
selfInfo: selfInfo,
lastSyncWithPeer: lastSyncWithPeer,
lastSync: lastSync,
})
})
@ -671,23 +668,28 @@ function setup(data: SubmoduleData): Submodule {
}
const recievedDataCounts: (number | string)[][] = []
const resultDataWithoutEmptyDbs = resultDataWithoutErrors.filter(
(res) => {
const qdbCount = res.questionDbs.length
const { subjCount, questionCount } = countOfQdbs(
res.questionDbs
)
const resultDataWithoutEmptyDbs: (SyncDataRes & { peer: PeerInfo })[] =
[]
resultDataWithoutErrors.forEach((res) => {
const qdbCount = res.questionDbs.length
const { subjCount, questionCount } = countOfQdbs(res.questionDbs)
recievedDataCounts.push([
peerToString(res.peer),
qdbCount,
subjCount,
questionCount,
])
recievedDataCounts.push([
peerToString(res.peer),
qdbCount,
subjCount,
questionCount,
])
return questionCount > 0
if (questionCount > 0) {
resultDataWithoutEmptyDbs.push(res)
} else {
updatePeersFile(peers, {
...res.peer,
lastSync: syncStart,
})
}
)
})
logger.Log(`\tRecieved data from peers:`)
logger.logTable(