예제 #1
0
        void IsHealthyForU2uSymbiosis_Update(SubtMeasurement measurement)
        {
            if (!LocalPeer.Configuration.RoleAsUser)
            {
                return;
            }

            var isHealthyNow = (measurement.RxBandwidth > Configuration.BandwidthTarget * 0.9 &&
                                measurement.TxBandwidth > Configuration.BandwidthTarget * 0.9 && Configuration.BandwidthTarget > 100000 &&
                                measurement.RxPacketLoss < 0.05 && measurement.TxPacketLoss < 0.05
                                );

            if (isHealthyNow)
            {
                var dt = LocalPeer.DateTimeNowUtc;
                if (_healthySinceUtc == null)
                {
                    _healthySinceUtc = dt;
                }
                else
                {
                    if ((dt - _healthySinceUtc.Value).TotalSeconds > 30)
                    {
                        _isHealthyForU2uSymbiosis = true;
                    }
                }
            }
            else
            {
                _healthySinceUtc          = null;
                _isHealthyForU2uSymbiosis = false;
            }
        }
예제 #2
0
        public SubtMeasurement Measure(SubtLocalPeer subtLocalPeer) // manager thread // used by easyGui
        {
            // measure
            float    rxBandwidth          = 0;
            float    confirmedTxBandwidth = 0;
            TimeSpan?bestRttToPeers       = null;
            float?   averageTxLossG       = null;
            float?   averageRxLossG       = null;

            foreach (var connectedPeer in subtLocalPeer.ConnectedPeers)
            {
                connectedPeer.GetStreamsAveragePacketLoss(out var averageRxLossAverage, out var averageTxLossAverage);

                foreach (var s in connectedPeer.Streams)
                {
                    rxBandwidth += s.RecentRxBandwidth;
                    var rtt = s.RecentRttConsideringP2ptp;
                    if (bestRttToPeers == null || rtt < bestRttToPeers.Value)
                    {
                        bestRttToPeers = rtt;
                    }
                    var st = s.LatestRemoteStatus;
                    if (st != null)
                    {
                        confirmedTxBandwidth += st.RecentRxBandwidth;
                    }
                }
                if (averageRxLossAverage.HasValue)
                {
                    if (averageRxLossG == null || averageRxLossAverage.Value < averageRxLossG.Value)
                    {
                        averageRxLossG = averageRxLossAverage;
                    }
                }
                if (averageTxLossAverage.HasValue)
                {
                    if (averageTxLossG == null || averageTxLossAverage.Value < averageTxLossG.Value)
                    {
                        averageTxLossG = averageTxLossAverage;
                    }
                }
            }

            var r = new SubtMeasurement
            {
                MeasurementTime = subtLocalPeer.LocalPeer.DateTimeNow,
                TargetBandwidth = subtLocalPeer.Configuration.BandwidthTarget,
                RxBandwidth     = rxBandwidth,
                TxBandwidth     = confirmedTxBandwidth,
                BestRttToPeers  = bestRttToPeers,
                TxPacketLoss    = averageTxLossG,
                RxPacketLoss    = averageRxLossG
            };

            return(r);
        }