public static DataChunk mkDCOpen(string label) { DataChunk open = new DataChunk(); DCOpen dope = new DCOpen(label); open.setData(dope.getBytes()); open._ppid = WEBRTCCONTROL; open.setFlags(DataChunk.SINGLEFLAG); return(open); }
public DataChunk mkAck(DCOpen dcep) { DataChunk ack = new DataChunk(); ack.setData(dcep.mkAck()); ack._ppid = WEBRTCCONTROL; ack.setFlags(DataChunk.SINGLEFLAG); return(ack); }
public DataChunk(CType type, byte flags, int length, ByteBuffer pkt) : base(type, flags, length, pkt) { Logger.Debug("read in chunk header " + length); Logger.Debug("body remaining " + _body.remaining()); if (_body.remaining() >= 12) { _tsn = _body.GetUInt(); _streamId = _body.GetUShort(); _sSeqNo = _body.GetUShort(); _ppid = _body.GetInt(); Logger.Debug(" _tsn : " + _tsn + " _streamId : " + _streamId + " _sSeqNo : " + _sSeqNo + " _ppid : " + _ppid); Logger.Debug("data size remaining " + _body.remaining()); switch (_ppid) { case WEBRTCCONTROL: ByteBuffer bb = _body.slice(); try { _open = new DCOpen(bb); } catch (InvalidDataChunkException ex) { _invalid = ex; } Logger.Trace("Got an DCEP " + _open); break; case WEBRTCstring: // what format is a string ? _data = new byte[_body.remaining()]; _body.GetBytes(_data, _data.Length); _dataOffset = 0; _dataLength = _data.Length; Logger.Trace("string data is " + Encoding.ASCII.GetString(_data)); break; case WEBRTCBINARY: _data = new byte[_body.remaining()]; _body.GetBytes(_data, _data.Length); _dataOffset = 0; _dataLength = _data.Length; Logger.Trace("data is " + Packet.getHex(_data)); break; default: _invalid = new InvalidDataChunkException("Invalid Protocol Id in data Chunk " + _ppid); break; } } }
// todo should be in a behave block // then we wouldn't be messing with stream seq numbers. private Chunk[] dcepDeal(SCTPStream s, DataChunk dc, DCOpen dcep) { Chunk[] rep = null; Logger.Debug("dealing with a decp for stream " + dc.getDataAsString()); if (!dcep.isAck()) { Logger.Debug("decp is not an ack... "); SCTPStreamBehaviour behave = dcep.mkStreamBehaviour(); s.setBehave(behave); s.setLabel(dcep.getLabel()); lock (s) { int seqIn = s.getNextMessageSeqIn(); s.setNextMessageSeqIn(seqIn + 1); int seqOut = s.getNextMessageSeqOut(); s.setNextMessageSeqOut(seqOut + 1); } rep = new Chunk[1]; DataChunk ack = dc.mkAck(dcep); s.outbound(ack); ack.setTsn(_nearTSN++); // check rollover - will break at maxint. rep[0] = ack; } else { Logger.Debug("got a dcep ack for " + s.getLabel()); SCTPStreamBehaviour behave = dcep.mkStreamBehaviour(); s.setBehave(behave); lock (s) { int seqIn = s.getNextMessageSeqIn(); s.setNextMessageSeqIn(seqIn + 1); int seqOut = s.getNextMessageSeqOut(); s.setNextMessageSeqOut(seqOut + 1); } } return(rep); }