diff options
author | Hung-ying Tyan <tyanh@google.com> | 2010-07-23 17:15:30 -0700 |
---|---|---|
committer | Hung-ying Tyan <tyanh@google.com> | 2010-07-23 19:02:41 -0700 |
commit | 3a9c0172c62a78c16f3fc459f21b2de9dbbfad61 (patch) | |
tree | f5549f13b7bca9c76211145665c8e8f5f58c1bc9 | |
parent | dda33c25a640d9964b563a0e82c9e51bbfcb905f (diff) | |
download | nist-sip-3a9c0172c62a78c16f3fc459f21b2de9dbbfad61.tar.gz |
SipService: fix NAT binding lifetime measurement.
Change-Id: I423287c88d7dc1035b2c45f5bae8392ada619a52
-rw-r--r-- | src/com/android/sip/SipServiceImpl.java | 19 | ||||
-rw-r--r-- | src/com/android/sip/SipSessionGroup.java | 12 |
2 files changed, 26 insertions, 5 deletions
diff --git a/src/com/android/sip/SipServiceImpl.java b/src/com/android/sip/SipServiceImpl.java index 55ae2a7..6e5e4f9 100644 --- a/src/com/android/sip/SipServiceImpl.java +++ b/src/com/android/sip/SipServiceImpl.java @@ -478,9 +478,10 @@ class SipServiceImpl extends ISipService.Stub { } private class KeepAliveProcess implements Runnable { - private SipSessionGroup.SipSessionImpl mSession; + private static final String TAG = "\\KEEPALIVE/"; private static final int INCREMENT = 15; private static final int MAX_RETRY = 4; + private SipSessionGroup.SipSessionImpl mSession; private int interval = INCREMENT; private boolean maxIntervalMeasured = false; @@ -489,10 +490,18 @@ class SipServiceImpl extends ISipService.Stub { } public void start() { + FLog.d(TAG, "start keepalive at " + interval); + mTimer.cancel(this); mTimer.set(interval * 1000, this); } public void run() { + synchronized (SipServiceImpl.this) { + keepalive(); + } + } + + private void keepalive() { int retry = 0; Log.d(TAG, " ~~~ keepalive"); mTimer.cancel(this); @@ -509,20 +518,23 @@ class SipServiceImpl extends ISipService.Stub { } } if (retry == MAX_RETRY) { - Log.w(TAG, "Server didn't respond SIP OPTIONS req:" + mSession); + FLog.w(TAG, "Server didn't respond SIP OPTIONS req:" + mSession); return; } if (mSession.isReRegisterRequired()) { mSession.register(EXPIRY_TIME); interval -= INCREMENT; + if (interval <= 0) interval = INCREMENT; + FLog.d(TAG, "--- interval decrease: " + interval); maxIntervalMeasured = true; } else { if (!maxIntervalMeasured) interval += INCREMENT; + FLog.d(TAG, "+++ interval increase: " + interval); mTimer.set(interval * 1000, this); } } - public synchronized void stop() { + public void stop() { mTimer.cancel(this); } } @@ -662,6 +674,7 @@ class SipServiceImpl extends ISipService.Stub { if (isStopped()) return; if (duration > 0) { + mSession.clearReRegisterRequired(); mExpiryTime = SystemClock.elapsedRealtime() + (duration * 1000); diff --git a/src/com/android/sip/SipSessionGroup.java b/src/com/android/sip/SipSessionGroup.java index 8ace93b..38d86f2 100644 --- a/src/com/android/sip/SipSessionGroup.java +++ b/src/com/android/sip/SipSessionGroup.java @@ -433,6 +433,10 @@ class SipSessionGroup implements SipListener { return mReRegisterFlag; } + public void clearReRegisterRequired() { + mReRegisterFlag = false; + } + public void sendKeepAlive() { try { processCommand(new OptionsCommand()); @@ -596,10 +600,14 @@ class SipSessionGroup implements SipListener { if (mRPort == 0) mRPort = rPort; if (mRPort != rPort) { mReRegisterFlag = true; - Log.w(TAG, "The rport is changed, we need to re-register now!"); + Log.w(TAG, String.format("rport is changed: %d <> %d", + mRPort, rPort)); + mRPort = rPort; + } else { + Log.w(TAG, "rport is the same: " + rPort); } } else { - Log.w(TAG, "Remote side did not respect our rport request"); + Log.w(TAG, "peer did not respect our rport request"); } reset(); return true; |