simplify and comment handle_response_peerpoke()
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@44874 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
parent
312fd57758
commit
ed683ccc2a
1 changed files with 32 additions and 38 deletions
|
@ -11680,44 +11680,39 @@ static int handle_response_register(struct sip_pvt *p, int resp, char *rest, str
|
||||||
/*! \brief Handle qualification responses (OPTIONS) */
|
/*! \brief Handle qualification responses (OPTIONS) */
|
||||||
static void handle_response_peerpoke(struct sip_pvt *p, int resp, struct sip_request *req)
|
static void handle_response_peerpoke(struct sip_pvt *p, int resp, struct sip_request *req)
|
||||||
{
|
{
|
||||||
struct sip_peer *peer;
|
struct sip_peer *peer = p->relatedpeer;
|
||||||
int pingtime;
|
int statechanged, is_reachable, was_reachable;
|
||||||
struct timeval tv;
|
int pingtime = ast_tvdiff_ms(ast_tvnow(), peer->ps);
|
||||||
int statechanged = 0;
|
|
||||||
int newstate = 0;
|
|
||||||
|
|
||||||
if (resp == 100)
|
/*
|
||||||
return;
|
* Compute the response time to a ping (goes in peer->lastms.)
|
||||||
|
* -1 means did not respond, 0 means unknown,
|
||||||
peer = p->relatedpeer;
|
* 1..maxms is a valid response, >maxms means late response.
|
||||||
gettimeofday(&tv, NULL);
|
*/
|
||||||
pingtime = ast_tvdiff_ms(tv, peer->ps);
|
if (pingtime < 1) /* zero = unknown, so round up to 1 */
|
||||||
if (pingtime < 1)
|
|
||||||
pingtime = 1;
|
pingtime = 1;
|
||||||
if ((peer->lastms < 0) || (peer->lastms > peer->maxms)) {
|
|
||||||
if (pingtime <= peer->maxms) {
|
/* Now determine new state and whether it has changed.
|
||||||
ast_log(LOG_NOTICE, "Peer '%s' is now REACHABLE! (%dms / %dms)\n", peer->name, pingtime, peer->maxms);
|
* Use some helper variables to simplify the writing
|
||||||
statechanged = 1;
|
* of the expressions.
|
||||||
newstate = 1;
|
*/
|
||||||
}
|
was_reachable = peer->lastms > 0 && peer->lastms <= peer->maxms;
|
||||||
} else if ((peer->lastms > 0) && (peer->lastms <= peer->maxms)) {
|
is_reachable = pingtime <= peer->maxms;
|
||||||
if (pingtime > peer->maxms) {
|
statechanged = peer->lastms == 0 /* yes, unknown before */
|
||||||
ast_log(LOG_NOTICE, "Peer '%s' is now TOO LAGGED! (%dms / %dms)\n", peer->name, pingtime, peer->maxms);
|
|| ( !was_reachable && is_reachable)
|
||||||
statechanged = 1;
|
|| ( was_reachable && !is_reachable );
|
||||||
newstate = 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!peer->lastms)
|
|
||||||
statechanged = 1;
|
|
||||||
peer->lastms = pingtime;
|
peer->lastms = pingtime;
|
||||||
peer->call = NULL;
|
peer->call = NULL;
|
||||||
if (statechanged) {
|
if (statechanged) {
|
||||||
|
const char *s = is_reachable ? "Reachable" : "Lagged";
|
||||||
|
|
||||||
|
ast_log(LOG_NOTICE, "Peer '%s' is now %s. (%dms / %dms)\n",
|
||||||
|
peer->name, s, pingtime, peer->maxms);
|
||||||
ast_device_state_changed("SIP/%s", peer->name);
|
ast_device_state_changed("SIP/%s", peer->name);
|
||||||
if (newstate == 2) {
|
manager_event(EVENT_FLAG_SYSTEM, "PeerStatus",
|
||||||
manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Lagged\r\nTime: %d\r\n", peer->name, pingtime);
|
"Peer: SIP/%s\r\nPeerStatus: %s\r\nTime: %d\r\n",
|
||||||
} else {
|
peer->name, s, pingtime);
|
||||||
manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Reachable\r\nTime: %d\r\n", peer->name, pingtime);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (peer->pokeexpire > -1)
|
if (peer->pokeexpire > -1)
|
||||||
|
@ -11725,10 +11720,9 @@ static void handle_response_peerpoke(struct sip_pvt *p, int resp, struct sip_req
|
||||||
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
|
ast_set_flag(&p->flags[0], SIP_NEEDDESTROY);
|
||||||
|
|
||||||
/* Try again eventually */
|
/* Try again eventually */
|
||||||
if ((peer->lastms < 0) || (peer->lastms > peer->maxms))
|
peer->pokeexpire = ast_sched_add(sched,
|
||||||
peer->pokeexpire = ast_sched_add(sched, DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer);
|
is_reachable ? DEFAULT_FREQ_OK : DEFAULT_FREQ_NOTOK,
|
||||||
else
|
sip_poke_peer_s, peer);
|
||||||
peer->pokeexpire = ast_sched_add(sched, DEFAULT_FREQ_OK, sip_poke_peer_s, peer);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! \brief Immediately stop RTP, VRTP and UDPTL as applicable */
|
/*! \brief Immediately stop RTP, VRTP and UDPTL as applicable */
|
||||||
|
@ -11780,8 +11774,8 @@ static void handle_response(struct sip_pvt *p, int resp, char *rest, struct sip_
|
||||||
/* We don't really care what the response is, just that it replied back.
|
/* We don't really care what the response is, just that it replied back.
|
||||||
Well, as long as it's not a 100 response... since we might
|
Well, as long as it's not a 100 response... since we might
|
||||||
need to hang around for something more "definitive" */
|
need to hang around for something more "definitive" */
|
||||||
|
if (resp != 100)
|
||||||
handle_response_peerpoke(p, resp, req);
|
handle_response_peerpoke(p, resp, req);
|
||||||
} else if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
|
} else if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) {
|
||||||
switch(resp) {
|
switch(resp) {
|
||||||
case 100: /* 100 Trying */
|
case 100: /* 100 Trying */
|
||||||
|
|
Loading…
Reference in a new issue