/// <summary> /// /// </summary> /// <param name="uri"></param> /// <param name="address"></param> public void AddEndPoint(Uri uri, InetAddress address) { // Adds the given endpoint to the socket address and starts the // listening/writing cycle IPEndPoint remoteAddress = new IPEndPoint(uri.GetIPAddress(), uri.Port); /* * TODO FIXME probably the new TransactionManager isn't needed, however * i'll still create it but copy the values needed for automatic testing * SubIssue #1 */ /*bool testingOld = false; * * string presetTidOld = ""; * // -- start of the code that enables a transaction test. * if (transactionManager != null) * { * testingOld = transactionManager.testing; * presetTidOld = transactionManager.presetTID; * } * transactionManager = new TransactionManager(this); * transactionManager.testing = testingOld; * transactionManager.presetTID = presetTidOld; * // -- end of the code that enables a transaction test.*/ _socket.Connect(remoteAddress); Connections connectionsInstance = MSRPStack.GetConnectionsInstance(address); _ioOperationGroup = new ThreadGroup(connectionsInstance.ConnectionsGroup, string.Format("IO OP connection {0} group", uri.ToString())); connectionsInstance.StartConnectionThread(this, _ioOperationGroup); }
/// <summary> /// Release all of the resources associated with this session. /// It could eventually, but not necessarily, close connections conforming to /// RFC 4975. /// After teardown, this session can no longer be used. /// </summary> public void TearDown() { // clear local resources _toPath = null; if (_sendQueue != null) { _sendQueue.ForEach(m => m.Discard()); _sendQueue = null; } if (TransactionManager != null) { TransactionManager.RemoveSession(this); TransactionManager = null; } // FIXME: (msrp-31) allow connection reuse by sessions. if (Connection != null) { Connection.Close(); Connection = null; } if (_stack != null) { _stack.RemoveActiveSession(this); _stack = null; } }
public static MSRPStack GetInstance() { if (_instance == null) { _instance = new MSRPStack(); } return(_instance); }
/// <summary> /// method used to eventually trigger an success report /// </summary> /// <param name="message">the message that triggered this call</param> /// <param name="transaction">the transaction that triggered this call</param> /// <param name="lastCallCount"></param> /// <param name="callCount"></param> public void TriggerSuccessReport(Message message, Transaction transaction, long lastCallCount, long callCount) { if (message.WantSuccessReport) { //use this mechanism also as a way of asserting also if a message //with a negative success report is complete or not if (ShouldGenerateReport(message, lastCallCount, callCount)) { //if there was a change in the number of bytes accounted for MSRPStack.GenerateAndSendSuccessReport(message, transaction, null); } } }
/// <summary> /// Notify sessions related to this connection that this connection is lost. /// </summary> /// <param name="exception">the reason it was lost.</param> private void NotifyConnectionLoss(Exception exception) { List <Session> attachedSessions = new List <Session>(); foreach (Session s in MSRPStack.GetInstance().ActiveSessions) { if (this == s.Connection) { attachedSessions.Add(s); } } // No concurrent modifications: have active sessions remove // themselves from the stack foreach (Session s in attachedSessions) { s.TriggerConnectionLost(exception); } }
/// <summary> /// /// </summary> /// <param name="isSecure"></param> /// <param name="isRelay"></param> /// <param name="toURI"></param> /// <param name="address"></param> Session(bool isSecure, bool isRelay, Uri toURI, InetAddress address) { LocalAddress = address; IsSecure = isSecure; IsRelay = isRelay; try { Connection = MSRPStack.GetConnectionsInstance(address); Uri = ((Connections)Connection).GenerateNewUri(); _stack.AddConnection(Uri, Connection); } catch (Exception e) // wrap exceptions to InternalError { _logger.Error("Error creating Connections: ", e); throw new InternalError(e); } ((Connections)Connection).AddUriToIdentify(Uri, this); _toPath.Add(toURI); _logger.Debug(string.Format("MSRP Session created: secure?[{0}], relay?[{1}], toURI=[{2}], InetAddress:", isSecure, isRelay, address)); }
/// <summary> /// Convenience method that gets the session associated with the given /// transaction /// </summary> /// <param name="transaction">transaction from which to get an associated session</param> /// <returns>the session associated with this transaction</returns> public Session GetAssociatedSession(Transaction transaction) { return(MSRPStack.GetInstance().GetSession(transaction.ToPath[0])); }