Exemplo n.º 1
0
        private int findChunk(Chunk.CType bty)
        {
            int ret = 0;

            foreach (Chunk c in _chunks)
            {
                if (c._type == bty)
                {
                    break;
                }
                else
                {
                    ret++;
                }
            }
            return((ret < _chunks.Count) ? ret : -1);
        }
Exemplo n.º 2
0
        /**
         *
         * @param c - Chunk to be processed
         * @return valid - false if the remaining chunks of the packet should be
         * ignored.
         * @throws IOException
         * @throws SctpPacketFormatException
         */
        private bool deal(Chunk c, List <Chunk> replies)
        {
            Chunk.CType ty       = c.getType();
            bool        ret      = true;
            State       oldState = _state;

            Chunk[] reply = null;
            switch (ty)
            {
            case Chunk.CType.INIT:
                if (acceptableStateForInboundInit())
                {
                    InitChunk init = (InitChunk)c;
                    reply = inboundInit(init);
                }
                else
                {
                    Logger.Debug("Got an INIT when state was " + _state.ToString() + " - ignoring it for now ");
                }
                break;

            case Chunk.CType.INITACK:
                Logger.Debug("got initack " + c.ToString());
                if (_state == State.COOKIEWAIT)
                {
                    InitAckChunk iack = (InitAckChunk)c;
                    reply = iackDeal(iack);
                }
                else
                {
                    Logger.Debug("Got an INITACK when not waiting for it - ignoring it");
                }
                break;

            case Chunk.CType.COOKIE_ECHO:
                Logger.Debug("got cookie echo " + c.ToString());
                reply = cookieEchoDeal((CookieEchoChunk)c);
                if (reply.Length > 0)
                {
                    ret = !typeof(ErrorChunk).IsAssignableFrom(reply[0].GetType());                             // ignore any following data chunk.
                }
                break;

            case Chunk.CType.COOKIE_ACK:
                Logger.Debug("got cookie ack " + c.ToString());
                if (_state == State.COOKIEECHOED)
                {
                    _state = State.ESTABLISHED;
                }
                break;

            case Chunk.CType.DATA:
                Logger.Debug("got data " + c.ToString());
                reply = dataDeal((DataChunk)c);
                break;

            case Chunk.CType.ABORT:
                // no reply we should just bail I think.
                _rcv = null;
                _transp.Close();
                break;

            case Chunk.CType.HEARTBEAT:
                reply = ((HeartBeatChunk)c).mkReply();
                break;

            case Chunk.CType.SACK:
                Logger.Debug("got tsak for TSN " + ((SackChunk)c).getCumuTSNAck());
                reply = sackDeal((SackChunk)c);
                // fix the outbound list here
                break;

            case Chunk.CType.RE_CONFIG:
                reply = reconfigState.deal((ReConfigChunk)c);
                break;
            }
            if (reply != null)
            {
                foreach (Chunk r in reply)
                {
                    replies.Add(r);
                }
                // theoretically could be multiple DATA in a single packet -
                // we'd send multiple SACKs in reply - ToDo fix that
            }
            if ((_state == State.ESTABLISHED) && (oldState != State.ESTABLISHED))
            {
                if (null != _al)
                {
                    _al.onAssociated(this);
                }
                reconfigState = new ReconfigState(this, _farTSN);
            }
            if ((oldState == State.ESTABLISHED) && (_state != State.ESTABLISHED))
            {
                if (null != _al)
                {
                    _al.onDisAssociated(this);
                }
            }
            return(ret);
        }