Esempio n. 1
0
        internal void OnSessionReq(LinkSession session, SessionReq e)
        {
            string clientToken = e.Token;
            bool flag = false;
            if (!String.IsNullOrEmpty(clientToken))
            {
                int incomingRetransmission = 0;
                int outgoingRetransmission = 0;
                LinkSession existing;
                lock (recoverable)
                {
                    flag = recoverable.TryGetValue(clientToken, out existing);
                }
                if (flag)
                {
                    Log.Trace("{0} {1} rxC={2} txC={3} rxS={4} txS={5} txSc={6}",
                        Name, existing.Handle, e.RxCounter, e.TxCounter,
                        existing.RxCounter, existing.TxCounter, existing.TxCompleted);

                    if (e.RxCounter < existing.TxCounter)
                    {
                        outgoingRetransmission = (int)(existing.TxCounter - e.RxCounter);
                        if (outgoingRetransmission > existing.TxBuffered)
                        {
                            flag = false;
                        }
                    }
                    if (e.TxCounter > existing.RxCounter)
                    {
                        incomingRetransmission = (int)(e.TxCounter - existing.RxCounter);
                        if (incomingRetransmission > e.TxBuffered)
                        {
                            flag = false;
                        }
                    }
                    if (!flag)
                    {
                        Log.Warn("{0} {1} gave up session recovery",
                            Name, existing.Handle);

                        OnLinkSessionDisconnectedInternal(existing.Handle, existing);
                    }
                }
                if (flag)
                {
                    int handle;
                    lock (existing.SyncRoot)
                    {
                        handle = existing.Handle;
                    }

                    if (handle != 0)
                    {
                        lock (existing.SyncRoot)
                        {
                            CancelRecoveryTimer(handle);
                            session.InheritFrom(existing);
                        }

                        session.Send(new SessionResp {
                            _Transform = false,
                            Token = session.Token,
                            Retransmission = incomingRetransmission
                        });

                        OnLinkSessionRecoveredInternal(handle, session, outgoingRetransmission);
                        return;
                    }
                }
            }

            // Issue a new session token for the given session.
            session.Token = Guid.NewGuid().ToString("N");

            Log.Debug("{0} {1} issued session token {2}",
                Name, session.InternalHandle, session.Token);

            lock (recoverable)
            {
                recoverable[session.Token] = session;
            }

            session.Send(new SessionResp {
                _Transform = false,
                Token = session.Token
            });
        }
Esempio n. 2
0
        internal void OnSessionResp(LinkSession session, SessionResp e)
        {
            LinkSession currentSession = Session;
            string sessionToken = null;
            if (!Object.ReferenceEquals(currentSession, null))
            {
                sessionToken = currentSession.Token;
            }

            // Save the session token from the server.
            session.Token = e.Token;

            Log.Trace("{0} {1} session token {2}",
                Name, session.InternalHandle, e.Token);

            if (!String.IsNullOrEmpty(sessionToken))
            {
                if (sessionToken.Equals(e.Token))
                {
                    // Recovered from instant disconnection.
                    session.InheritFrom(this.session);

                    session.Send(new SessionAck {
                        _Transform = false,
                        Recovered = true
                    });

                    OnLinkSessionRecoveredInternal(session.Handle, session, e.Retransmission);
                    return;
                }

                OnLinkSessionDisconnectedInternal(currentSession.Handle, currentSession);
            }

            session.Send(new SessionAck { _Transform = false });

            OnSessionSetup(session);
        }
Esempio n. 3
0
        /// <summary>
        /// Called by a derived class to initiate a buffer transform handshake.
        /// </summary>
        protected void InitiateHandshake(LinkSession session)
        {
            if (Object.ReferenceEquals(BufferTransform, null))
            {
                return;
            }

            var bufferTransform = (IBufferTransform)BufferTransform.Clone();
            session.BufferTransform = bufferTransform;

            session.Send(new HandshakeReq {
                _Transform = false,
                Data = bufferTransform.InitializeHandshake()
            });
        }
Esempio n. 4
0
        private void SendSessionReq(LinkSession session)
        {
            var req = new SessionReq { _Transform = false };

            LinkSession currentSession = Session;
            if (!Object.ReferenceEquals(currentSession, null) &&
                !String.IsNullOrEmpty(currentSession.Token))
            {
                req.Token = currentSession.Token;
                req.RxCounter = currentSession.RxCounter;
                req.TxCounter = currentSession.TxCounter;
                req.TxBuffered = currentSession.TxBuffered;
            }

            session.Send(req);
        }