public UDTSession(String description, Destination destination) { Random ro = new Random((int)DateTime.Now.Ticks & 0x0000FFFF); nextSocketID = ro.Next(0, 5000) + 20; statistics = new UDTStatistics(description); mySocketID = Interlocked.Increment(ref nextSocketID); this.destination = destination; //this.dgPacket=new DatagramPacket(new byte[0],0,destination.getAddress(),destination.getPort()); //this.dgPacket = new byte[0]; this.dgPacket = new IPEndPoint(destination.getAddress(), destination.getPort()); //UDTCongestionControl _CongestionControl = new UDTCongestionControl(); //String clazzP=_CongestionControl.ToString(); Object ccObject = null; //try //{ // Class<?>clazz=Class.forName(clazzP); // ccObject=clazz.getDeclaredConstructor(UDTSession.class).newInstance(this); //} //catch(Exception e) //{ // Log.Write(this.ToString(),"WARNING","Can't setup congestion control class <"+clazzP+">, using default.",e); // ccObject = new UDTCongestionControl(this); //} ccObject = new UDTCongestionControl(this); cc = (CongestionControl)ccObject; Log.Write(this.ToString(), "Using " + cc.ToString()); }
internal static extern int ZnWriteExt( IntPtr /*zn_session_t*/ rustSession, ResKey.NativeType zResKey, IntPtr payload, uint len, uint encoding, uint kind, CongestionControl congestion);
protected void onAcknowledge(Acknowledgement acknowledgement) { try { waitForAckLatch.Get().CountDown(); waitForSeqAckLatch.Get().CountDown(); CongestionControl cc = session.getCongestionControl(); long rtt = acknowledgement.getRoundTripTime(); if (rtt > 0) { long rttVar = acknowledgement.getRoundTripTimeVar(); cc.setRTT(rtt, rttVar); statistics.setRTT(rtt, rttVar); } long rate = acknowledgement.getPacketReceiveRate(); if (rate > 0) { long linkCapacity = acknowledgement.getEstimatedLinkCapacity(); cc.updatePacketArrivalRate(rate, linkCapacity); statistics.setPacketArrivalRate(cc.getPacketArrivalRate(), cc.getEstimatedLinkCapacity()); } long ackNumber = acknowledgement.getAckNumber(); cc.onACK(ackNumber); statistics.setCongestionWindowSize((long)cc.getCongestionWindowSize()); //need to remove all sequence numbers up the ack number from the sendBuffer bool removed = false; for (long s = lastAckSequenceNumber; s < ackNumber; s++) { lock (sendLock) { removed = sendBuffer.Remove(s); } if (removed) { unacknowledged.DecrementAndGet(); } } lastAckSequenceNumber = (int)Math.Max(lastAckSequenceNumber, ackNumber); //send ACK2 packet to the receiver sendAck2(ackNumber); statistics.incNumberOfACKReceived(); if (storeStatistics) { statistics.storeParameters(); } } catch (Exception ex) { Log.Write(this.ToString(), ex); } }
unsafe public void Write(ResKey reskey, byte[] payload, uint encoding, uint kind, CongestionControl congestionControl) { fixed(byte *p = payload) { ZnWriteExt(this._nativePtr, reskey._key, (IntPtr)p, (uint)payload.Length, encoding, kind, congestionControl); } }