Exemple #1
0
        private void _heartbeatTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            DataContent dataContent = new DataContent();

            dataContent.Data = new byte[0];  // send empty message
            NextLowLayerEvent?.Invoke(dataContent);
        }
Exemple #2
0
        public void FromHighLayerToHere(DataContent dataContent)
        {
            SmallFileDataObject dataObject = (SmallFileDataObject)dataContent.Data;

            // Convert an object to a byte array
            dataContent.Data = Util.ObjectByteConverter.ObjectToByteArray(dataObject);
            NextLowLayerEvent?.Invoke(dataContent);
        }
 // forwarding
 public void FromHighLayerToHere(DataContent dataContent)
 {
     // server relay the message
     if (dataContent.Data.GetType() == typeof(byte[]))
     {
         NextLowLayerEvent?.Invoke(dataContent);
     }
     // discard string message
 }
Exemple #4
0
 public void FromHighLayerToHere(DataContent dataContent)
 {
     if (_state.Enabled && dataContent.Data != null)
     {
         byte[] encrypted = Encrypt((byte[])dataContent.Data);
         dataContent.Data = encrypted;
     }
     NextLowLayerEvent?.Invoke(dataContent);
 }
        public void FromHighLayerToHere(DataContent dataContent)
        {
            List <byte> header_data = new List <byte>();

            byte[] now = BitConverter.GetBytes(DateTime.Now.ToBinary());
            header_data.AddRange(now);
            header_data.AddRange((byte[])dataContent.Data);
            dataContent.Data = header_data.ToArray();
            NextLowLayerEvent?.Invoke(dataContent);
        }
Exemple #6
0
        public void FromHighLayerToHere(DataContent dataContent)
        {
            byte[] typeHeader;
            typeHeader = BitConverter.GetBytes((int)dataContent.Type);
            List <byte> header_body = new List <byte>();

            header_body.AddRange(typeHeader);
            header_body.AddRange((byte[])dataContent.Data);
            dataContent.Data = header_body.ToArray();
            NextLowLayerEvent?.Invoke(dataContent);
        }
Exemple #7
0
 public void FromHighLayerToHere(DataContent dataContent)
 {
     byte[] data = (byte[])dataContent.Data;
     int length = data.Length;
     byte[] lengthByte = BitConverter.GetBytes(length);  // 4 Bytes
     List<byte> prefix_data = new List<byte>();
     prefix_data.AddRange(lengthByte);
     prefix_data.AddRange(data);
     dataContent.Data = prefix_data.ToArray();
     NextLowLayerEvent?.Invoke(dataContent);
 }
Exemple #8
0
        public void FromHighLayerToHere(DataContent dataContent)
        {
            byte[] seqHeader;
            seqHeader = BitConverter.GetBytes(_thisSeq.Value);
            List <byte> header_body = new List <byte>();

            header_body.AddRange(seqHeader);
            header_body.AddRange((byte[])dataContent.Data);
            dataContent.Data = header_body.ToArray();
            ++_thisSeq;
            NextLowLayerEvent?.Invoke(dataContent);
        }
Exemple #9
0
        public void FromLowLayerToHere(DataContent dataContent)
        {
            TransportState state = dataContent.TransportState;

            // not receiving enough (this is receiver)
            if (dataContent.Data == null)
            {
                //  reset
                if (state.PendingLength == 0)
                {
                    _prevReceivedLength = state.ReceivedLength;
                    _prevTime           = DateTime.Now;
                    _prevSpeed          = 0;
                    return;
                }
                //  count speed
                if (DateTime.Now == _prevTime)
                {
                    state.Speed = double.MaxValue;
                }
                else
                {
                    state.Speed = (1 - alpha) * _prevSpeed + alpha * (state.ReceivedLength - _prevReceivedLength) / 1024 / (DateTime.Now - _prevTime).TotalSeconds;
                }
                //  update
                _prevSpeed          = state.Speed;
                _prevReceivedLength = state.ReceivedLength;
                _prevTime           = DateTime.Now;
                // write state in dataContent
                Byte[] data = Util.ObjectByteConverter.ObjectToByteArray(state);
                dataContent.Data = data;
                // tell peer about the transport process
                NextLowLayerEvent?.Invoke((DataContent)dataContent.Clone());
            }
            // still sending (this is sender)
            else
            {
                // get tranport process info from receiver
                dataContent.TransportState = (TransportState)Util.ObjectByteConverter.ByteArrayToObject((byte[])dataContent.Data);
            }
            // tell this app
            NextHighLayerEvent?.Invoke(dataContent);
        }
Exemple #10
0
 public void FromHighLayerToHere(DataContent dataContent)
 {
     NextLowLayerEvent?.Invoke(dataContent);
 }
Exemple #11
0
 public void FromHighLayerToHere(DataContent dataContent)
 {
     byte[] data = Encoding.UTF8.GetBytes((string)dataContent.Data);
     dataContent.Data = data;
     NextLowLayerEvent?.Invoke(dataContent);
 }
Exemple #12
0
 public void FromHighLayerToHere(DataContent dataContent)
 {
     _heartbeatTimer.Stop();
     NextLowLayerEvent?.Invoke(dataContent);
     _heartbeatTimer.Start();
 }
Exemple #13
0
 private void OnNextLowLayerEvent(DataContent data)
 {
     NextLowLayerEvent?.Invoke(data);
 }
Exemple #14
0
 private void Branch_NextLowLayerEvent(DataContent dataContent)
 {
     NextLowLayerEvent?.Invoke(dataContent);
 }
 private void OnNextLowLayerEvent_stackForClient(DataContent dataContent)
 {
     NextLowLayerEvent?.Invoke(dataContent);
 }