mirror of
https://github.com/CPunch/Laika.git
synced 2025-07-14 21:40:07 +00:00
Compare commits
No commits in common. "3034c3bd8b9b2e751d39baf510b704d710269760" and "68f8e80c75b631a64c528b1fca52c360c2912de2" have entirely different histories.
3034c3bd8b
...
68f8e80c75
@ -54,7 +54,6 @@ struct sLaika_peer *laikaC_getPeerByPub(struct sLaika_cnc *cnc, uint8_t *pub);
|
|||||||
void laikaC_sweepPeersTask(struct sLaika_taskService *service, struct sLaika_task *task,
|
void laikaC_sweepPeersTask(struct sLaika_taskService *service, struct sLaika_task *task,
|
||||||
clock_t currTick, void *uData);
|
clock_t currTick, void *uData);
|
||||||
|
|
||||||
bool laikaC_iterPeersNext(struct sLaika_cnc *cnc, size_t *i, struct sLaika_peer **peer);
|
|
||||||
void laikaC_iterPeers(struct sLaika_cnc *cnc, tLaika_peerIter iter, void *uData);
|
void laikaC_iterPeers(struct sLaika_cnc *cnc, tLaika_peerIter iter, void *uData);
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -426,27 +426,27 @@ struct sLaika_peer *laikaC_getPeerByPub(struct sLaika_cnc *cnc, uint8_t *pub)
|
|||||||
return elem ? elem->peer : NULL;
|
return elem ? elem->peer : NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool sweepPeers(struct sLaika_peer *peer, void *uData)
|
||||||
|
{
|
||||||
|
struct sLaika_peerInfo *pInfo = GETPINFOFROMPEER(peer);
|
||||||
|
struct sLaika_cnc *cnc = (struct sLaika_cnc *)uData;
|
||||||
|
long currTime = laikaT_getTime();
|
||||||
|
|
||||||
|
/* peer has been silent for a while, kill 'em */
|
||||||
|
if (currTime - pInfo->lastPing > LAIKA_PEER_TIMEOUT) {
|
||||||
|
LAIKA_DEBUG("timeout reached for %p! [%d]\n", peer, currTime - pInfo->lastPing);
|
||||||
|
laikaC_killPeer(cnc, peer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void laikaC_sweepPeersTask(struct sLaika_taskService *service, struct sLaika_task *task,
|
void laikaC_sweepPeersTask(struct sLaika_taskService *service, struct sLaika_task *task,
|
||||||
clock_t currTick, void *uData)
|
clock_t currTick, void *uData)
|
||||||
{
|
{
|
||||||
struct sLaika_cnc *cnc = (struct sLaika_cnc *)uData;
|
struct sLaika_cnc *cnc = (struct sLaika_cnc *)uData;
|
||||||
struct sLaika_peer *peer;
|
|
||||||
struct sLaika_peerInfo *pInfo;
|
|
||||||
size_t i = 0;
|
|
||||||
long currTime = laikaT_getTime();
|
|
||||||
|
|
||||||
while (laikaC_iterPeersNext(cnc, &i, &peer)) {
|
laikaC_iterPeers(cnc, sweepPeers, (void *)cnc);
|
||||||
pInfo = GETPINFOFROMPEER(peer);
|
|
||||||
|
|
||||||
/* peer has been silent for a while, kill 'em */
|
|
||||||
if (currTime - pInfo->lastPing > LAIKA_PEER_TIMEOUT) {
|
|
||||||
LAIKA_DEBUG("timeout reached for %p! [%ld]\n", peer, currTime);
|
|
||||||
laikaC_killPeer(cnc, peer);
|
|
||||||
|
|
||||||
/* reset peer iterator (since the hashmap mightve been reallocated/changed) */
|
|
||||||
i = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* =======================================[[ Peer Iter ]]======================================= */
|
/* =======================================[[ Peer Iter ]]======================================= */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user