mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
p2p instant question sending fixes
This commit is contained in:
parent
977c118da8
commit
f047701106
9 changed files with 75 additions and 56 deletions
|
@ -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(
|
||||
|
|
|
@ -600,8 +600,7 @@ function setup(data: SubmoduleData): Submodule {
|
|||
)
|
||||
|
||||
res.json({
|
||||
success: resultArray.length > 0,
|
||||
newQuestions: resultArray, // FIXME: this is useless?
|
||||
success: true,
|
||||
totalNewQuestions: totalNewQuestions,
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue