Esempio n. 1
0
        public ThreadedAssociation(DatagramTransport transport, AssociationListener al, bool isClient, int srcPort,
                                   int destPort)
            : base(transport, al, isClient, srcPort, destPort)
        {
            try
            {
                _transpMTU = Math.Min(transport.GetReceiveLimit(), transport.GetSendLimit());
                logger.LogDebug("Transport MTU is now " + _transpMTU);
            }
            catch (IOException x)
            {
                logger.LogWarning("Failed to get suitable transport mtu ");
                logger.LogWarning(x.ToString());
            }

            _freeBlocks = new Queue <DataChunk>(/*MAXBLOCKS*/);
            _inFlight   = new Dictionary <long, DataChunk>(MAXBLOCKS);

            for (int i = 0; i < MAXBLOCKS; i++)
            {
                DataChunk dc = new DataChunk();
                lock (_freeBlocks)
                {
                    _freeBlocks.Enqueue(dc);
                }
            }

            resetCwnd();
        }
Esempio n. 2
0
        void startRcv()
        {
            Association me = this;

            _rcv = new Thread(() =>
            {
                try
                {
                    byte[] buf = new byte[_transp.GetReceiveLimit()];
                    while (_rcv != null)
                    {
                        try
                        {
                            int length = _transp.Receive(buf, 0, buf.Length, TICK);
                            if (length == DtlsSrtpTransport.DTLS_RECEIVE_ERROR_CODE)
                            {
                                // The DTLS transport has been closed or i no longer available.
                                break;
                            }
                            //logger.LogDebug("SCTP message received: " + Packet.getHex(buf, 0, length));
                            ByteBuffer pbb = new ByteBuffer(buf);
                            pbb.Limit      = length;
                            Packet rec     = new Packet(pbb);
                            deal(rec);
                        }
                        catch (SocketException e)
                        {
                            // ignore. it should be a timeout.
                            switch (e.SocketErrorCode)
                            {
                            case SocketError.TimedOut:
                                logger.LogDebug("tick time out");
                                break;

                            default:
                                throw e;
                            }
                        }
                    }
                    logger.LogDebug("SCTP message receive was empty, closing association listener.");

                    _transp.Close();
                }
                catch (EndOfStreamException eof)
                {
                    unexpectedClose(eof);
                    logger.LogDebug(eof.ToString());
                }
                catch (Exception ex)
                {
                    logger.LogDebug("Association receive failed " + ex.GetType().Name + " " + ex.ToString());
                }
            });
            _rcv.Priority = ThreadPriority.AboveNormal;
            _rcv.Name     = "AssocRcv" + __assocNo;
            _rcv.Start();
        }
Esempio n. 3
0
        void startRcv()
        {
            Association me = this;

            _rcv = new Thread(() => {
                try {
                    byte[] buf = new byte[_transp.GetReceiveLimit()];
                    while (_rcv != null)
                    {
                        try {
                            int length = _transp.Receive(buf, 0, buf.Length, TICK);
                            if (length == -1)
                            {
                                Logger.Trace("Probably tick time out");
                                continue;
                            }
                            Logger.Trace("DTLS message received\n" + Packet.getHex(buf, 0, length));
                            ByteBuffer pbb = new ByteBuffer(buf);
                            pbb.Limit      = length;
                            Packet rec     = new Packet(pbb);
                            Logger.Debug("SCTP message parsed\n" + rec.ToString());
                            deal(rec);
                        }
                        catch (SocketException e) {
                            // ignore. it should be a timeout.
                            switch (e.SocketErrorCode)
                            {
                            case SocketError.TimedOut:
                                Logger.Trace("tick time out");
                                break;

                            default:
                                throw e;
                            }
                        }
                    }
                    Logger.Trace("SCTP message recv null\n Shutting down.");

                    _transp.Close();
                }
                catch (EndOfStreamException eof) {
                    unexpectedClose(eof);
                    Logger.Debug(eof.ToString());
                }
                catch (Exception ex) {
                    Logger.Debug("Association rcv failed " + ex.GetType().Name + " " + ex.ToString());
                }
            });
            _rcv.Priority = ThreadPriority.AboveNormal;
            _rcv.Name     = "AssocRcv" + __assocNo;
            _rcv.Start();
        }
Esempio n. 4
0
 public virtual int GetReceiveLimit()
 {
     return(System.Math.Min(this.mPlaintextLimit,
                            mReadEpoch.Cipher.GetPlaintextLimit(mTransport.GetReceiveLimit() - RECORD_HEADER_LENGTH)));
 }
Esempio n. 5
0
 public virtual int GetReceiveLimit()
 {
     return(transport.GetReceiveLimit());
 }
Esempio n. 6
0
 public virtual int GetReceiveLimit()
 {
     return(Math.Min(mPlaintextLimit, mReadEpoch.Cipher.GetPlaintextLimit(mTransport.GetReceiveLimit() - 13)));
 }