From 95d0aa505aeb03cf6f7df0d86574ba561080028f Mon Sep 17 00:00:00 2001 From: annpeter Date: Tue, 5 Jan 2021 23:32:44 +0800 Subject: [PATCH 1/2] fix bugs 1. reply ACK to server, when get BYE signal 2. when receive 2xx, reply ACK to server. In case some server think this call not succeed, and terminate this call 3. delay to hang up the call when send CANCEL, the server will answer 487, then hang up. in case the server constantly answer 487 with no response --- .gitignore | 2 ++ .../peers/sip/core/useragent/handlers/ByeHandler.java | 7 ++++++- .../InviteClientTransactionStateTerminated.java | 6 ++++++ .../peers/sip/transaction/NonInviteServerTransaction.java | 2 +- .../sourceforge/peers/sip/transport/MessageReceiver.java | 7 +++++++ 5 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index bf2de308..dcab7eb2 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,5 @@ peers-demo/src/main/java/net/sourceforge/peers/demo/MyConfig.java \#*# bin/ logs/ +.idea +*.iml \ No newline at end of file diff --git a/peers-lib/src/main/java/net/sourceforge/peers/sip/core/useragent/handlers/ByeHandler.java b/peers-lib/src/main/java/net/sourceforge/peers/sip/core/useragent/handlers/ByeHandler.java index 4ff4fad8..11f6b2a5 100644 --- a/peers-lib/src/main/java/net/sourceforge/peers/sip/core/useragent/handlers/ByeHandler.java +++ b/peers-lib/src/main/java/net/sourceforge/peers/sip/core/useragent/handlers/ByeHandler.java @@ -27,6 +27,7 @@ import net.sourceforge.peers.sip.transaction.ClientTransaction; import net.sourceforge.peers.sip.transaction.ClientTransactionUser; import net.sourceforge.peers.sip.transaction.NonInviteClientTransaction; +import net.sourceforge.peers.sip.transaction.NonInviteServerTransaction; import net.sourceforge.peers.sip.transaction.ServerTransaction; import net.sourceforge.peers.sip.transaction.ServerTransactionUser; import net.sourceforge.peers.sip.transaction.Transaction; @@ -103,7 +104,11 @@ public void handleBye(SipRequest sipRequest, Dialog dialog) { serverTransaction.sendReponse(sipResponse); - dialogManager.removeDialog(dialog.getId()); + // repeat with line 78. + // reply ACK to server, when get BYE signal + if (serverTransaction instanceof NonInviteServerTransaction) { + ((NonInviteServerTransaction)serverTransaction).sendLastResponse(); + } SipListener sipListener = userAgent.getSipListener(); if (sipListener != null) { diff --git a/peers-lib/src/main/java/net/sourceforge/peers/sip/transaction/InviteClientTransactionStateTerminated.java b/peers-lib/src/main/java/net/sourceforge/peers/sip/transaction/InviteClientTransactionStateTerminated.java index 5e7a0f56..c01855e7 100644 --- a/peers-lib/src/main/java/net/sourceforge/peers/sip/transaction/InviteClientTransactionStateTerminated.java +++ b/peers-lib/src/main/java/net/sourceforge/peers/sip/transaction/InviteClientTransactionStateTerminated.java @@ -29,4 +29,10 @@ public InviteClientTransactionStateTerminated(String id, super(id, inviteClientTransaction, logger); } + @Override + public void received2xx() { + // when receive 2xx, reply ACK to server, In case some server think this call not succeed, and terminate this call + logger.info("received 2xx on terminated."); + inviteClientTransaction.createAndSendAck(); + } } diff --git a/peers-lib/src/main/java/net/sourceforge/peers/sip/transaction/NonInviteServerTransaction.java b/peers-lib/src/main/java/net/sourceforge/peers/sip/transaction/NonInviteServerTransaction.java index 489eb93b..27a91025 100644 --- a/peers-lib/src/main/java/net/sourceforge/peers/sip/transaction/NonInviteServerTransaction.java +++ b/peers-lib/src/main/java/net/sourceforge/peers/sip/transaction/NonInviteServerTransaction.java @@ -96,7 +96,7 @@ public void sendReponse(SipResponse sipResponse) { } } - void sendLastResponse() { + public void sendLastResponse() { //sipServerTransport.sendResponse(responses.get(responses.size() - 1)); int nbOfResponses = responses.size(); if (nbOfResponses > 0) { diff --git a/peers-lib/src/main/java/net/sourceforge/peers/sip/transport/MessageReceiver.java b/peers-lib/src/main/java/net/sourceforge/peers/sip/transport/MessageReceiver.java index a412ab69..140a1899 100644 --- a/peers-lib/src/main/java/net/sourceforge/peers/sip/transport/MessageReceiver.java +++ b/peers-lib/src/main/java/net/sourceforge/peers/sip/transport/MessageReceiver.java @@ -52,6 +52,8 @@ public abstract class MessageReceiver implements Runnable { private Config config; protected Logger logger; + protected long stopTime = -1L; + public MessageReceiver(int port, TransactionManager transactionManager, TransportManager transportManager, Config config, Logger logger) { super(); @@ -187,7 +189,12 @@ protected void processMessage(byte[] message, InetAddress sourceIp, } public synchronized void setListening(boolean isListening) { + logger.info("execute stop listen ..."); this.isListening = isListening; + + if(!isListening){ + this.stopTime = System.currentTimeMillis(); + } } public synchronized boolean isListening() { From a7db41ff09e8d50d72a1f7488926f727463324fe Mon Sep 17 00:00:00 2001 From: annpeter Date: Thu, 7 Jan 2021 00:30:25 +0800 Subject: [PATCH 2/2] add code delay stop --- .../net/sourceforge/peers/sip/transport/MessageReceiver.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/peers-lib/src/main/java/net/sourceforge/peers/sip/transport/MessageReceiver.java b/peers-lib/src/main/java/net/sourceforge/peers/sip/transport/MessageReceiver.java index 140a1899..452ba0ca 100644 --- a/peers-lib/src/main/java/net/sourceforge/peers/sip/transport/MessageReceiver.java +++ b/peers-lib/src/main/java/net/sourceforge/peers/sip/transport/MessageReceiver.java @@ -66,7 +66,8 @@ public MessageReceiver(int port, TransactionManager transactionManager, } public void run() { - while (isListening) { + // delay to hang up the call when send CANCEL, the server will answer 487, then hang up, in case the server constantly answer 487 with no response + while (isListening || (stopTime > 0 && System.currentTimeMillis() - stopTime < 100)) { try { listen(); } catch (IOException e) {