mirror of https://github.com/CPunch/Laika.git
Compare commits
2 Commits
68f8e80c75
...
3034c3bd8b
Author | SHA1 | Date |
---|---|---|
|
3034c3bd8b | |
|
770e34463e |
|
@ -54,6 +54,7 @@ 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();
|
||||||
|
|
||||||
laikaC_iterPeers(cnc, sweepPeers, (void *)cnc);
|
while (laikaC_iterPeersNext(cnc, &i, &peer)) {
|
||||||
|
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 ]]======================================= */
|
||||||
|
@ -472,4 +472,4 @@ void laikaC_iterPeers(struct sLaika_cnc *cnc, tLaika_peerIter iter, void *uData)
|
||||||
/* call iter for every peer in cnc->peers */
|
/* call iter for every peer in cnc->peers */
|
||||||
while (laikaC_iterPeersNext(cnc, &i, &peer))
|
while (laikaC_iterPeersNext(cnc, &i, &peer))
|
||||||
iter(peer, uData);
|
iter(peer, uData);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue