private void Relay_Relay(object sender, RelayEventArgs e)
        {
            if (this.Disposing || this.IsDisposed)
            {
                return;
            }
            Traffic t = e.SockType == RelaySockType.Local ? localTrafficStatistics : remoteTrafficStatistics;

            if (e.SockAction == RelaySockAction.Recv)
            {
                t.onRecv(e.Length);
            }
            else
            {
                t.onSend(e.Length);
            }
            if ((printLocalPayload && e.SockType == RelaySockType.Local) || (printRemotePayload && e.SockType == RelaySockType.Remote))
            {
                string str = GetBufferHexString(e.Buffer, e.Offset, e.Length);
                if (e.SockAction == RelaySockAction.Recv)
                {
                    AppendLog($"\r\n{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")} [{e.SockType}] recv {e.Length} bytes from {(e.EndPoint == null ? e.Sock.RemoteEndPoint : e.EndPoint)}\r\n" +
                              $"--------------------------------------------------------------------------\r\n" +
                              $"{str}\r\n");
                }
                else
                {
                    AppendLog($"\r\n{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")} [{e.SockType}] send {e.Length} bytes to {(e.EndPoint == null ? e.Sock.RemoteEndPoint : e.EndPoint)}\r\n" +
                              $"--------------------------------------------------------------------------\r\n" +
                              $"{str}\r\n");
                }
            }
        }
Ejemplo n.º 2
0
        public void UpdateTrafficList(Traffic traffic)
        {
            long maxSpeedValue = 0;

            inboundPoints.Clear();
            outboundPoints.Clear();

            lock (logList)
            {
                if (traffic != null)
                {
                    this.traffic = traffic;
                    #region Add to trafficLogList
                    TrafficLog previous = logList.Last.Value;
                    TrafficLog current  = new TrafficLog(
                        new Traffic(traffic),
                        new Traffic(traffic, previous.total)
                        );
                    logList.AddLast(current);

                    while (logList.Count > trafficLogSize)
                    {
                        logList.RemoveFirst();
                    }
                    while (logList.Count < trafficLogSize)
                    {
                        logList.AddFirst(new TrafficLog());
                    }
                    #endregion
                }

                lastLog = logList.Last.Value;
                foreach (TrafficLog item in logList)
                {
                    inboundPoints.Add(item.speed.inbound);
                    outboundPoints.Add(item.speed.outbound);

                    maxSpeedValue = Math.Max(maxSpeedValue,
                                             Math.Max(item.speed.inbound, item.speed.outbound)
                                             );
                }
            }

            maxSpeed = new FormattedSize(maxSpeedValue);

            for (int i = 0; i < inboundPoints.Count; i++)
            {
                inboundPoints[i]  /= maxSpeed.scale;
                outboundPoints[i] /= maxSpeed.scale;
            }

            if (TrafficChart.InvokeRequired)
            {
                TrafficChart.Invoke(new Action(UpdateTrafficChart));
            }
            else
            {
                UpdateTrafficChart();
            }
        }
Ejemplo n.º 3
0
 public Traffic(Traffic t1, Traffic t2)
 {
     if (t2.inbound > 0 && t1.inbound >= t2.inbound)
     {
         inbound = t1.inbound - t2.inbound;
     }
     if (t2.outbound > 0 && t1.outbound >= t2.outbound)
     {
         outbound = t1.outbound - t2.outbound;
     }
 }
Ejemplo n.º 4
0
 public TrafficLog(Traffic raw, Traffic rawspeed)
 {
     this.raw      = raw;
     this.rawSpeed = rawspeed;
 }
Ejemplo n.º 5
0
 public TrafficLog()
 {
     raw      = new Traffic();
     rawSpeed = new Traffic();
 }
Ejemplo n.º 6
0
 public Traffic(Traffic t)
 {
     inbound  = t.inbound;
     outbound = t.outbound;
 }
Ejemplo n.º 7
0
 public TrafficLog(Traffic total, Traffic speed)
 {
     this.total = total;
     this.speed = speed;
 }
Ejemplo n.º 8
0
 public TrafficLog()
 {
     total = new Traffic();
     speed = new Traffic();
 }