public void SecondTimer() { Core.Context.Bandwidth.InPerSec += Bandwidth.InPerSec; Core.Context.Bandwidth.OutPerSec += Bandwidth.OutPerSec; Bandwidth.NextSecond(); }
public void SecondTimer_Tick(object state) { // flag set, actual timer code run in thread per core if (Lookup != null) { Lookup.SecondTimer(); } Cores.SafeForEach(c => c.SecondTimer()); // bandwidth Bandwidth.NextSecond(); // fastest degrades over time, min is 10kb/s FastestUploadSpeed--; FastestUploadSpeed = Math.Max(Bandwidth.Average(Bandwidth.Out, 10), FastestUploadSpeed); FastestUploadSpeed = Math.Max(10, FastestUploadSpeed); AssignUploadSlots(); }
public void SecondTimer() { if (State == TcpState.Closed) { return; } // update bandwidth SecondsDead = (BytesReceivedinSec > 0) ? 0 : SecondsDead + 1; BytesSentinSec = 0; BytesReceivedinSec = 0; Core.Context.Bandwidth.InPerSec += Bandwidth.InPerSec; Core.Context.Bandwidth.OutPerSec += Bandwidth.OutPerSec; Bandwidth.NextSecond(); if (Age < 60) { Age++; } // if proxy not set after 10 secs disconnect if (Age > 10 && Proxy == ProxyType.Unset) { if (State == TcpState.Connecting) { CleanClose("Timed out"); } else { CleanClose("No proxy request"); } return; } // replicate if (Age == 15 && !Network.IsLookup) { Network.Store.Replicate(new DhtContact(this, RemoteIP)); } // new global proxy if (Proxy == ProxyType.Server) { if (Age == 5) { // announce to rudp connections new proxy if blocked/nat, or using a global proxy if (Network.IsLookup) { Core.Context.Cores.LockReading(delegate() { foreach (OpCore core in Core.Context.Cores) { if (core.Network.UseLookupProxies) { core.Network.RudpControl.AnnounceProxy(this); } } }); } else { Network.RudpControl.AnnounceProxy(this); } } else if (Age == 15) { if (!Network.IsLookup) { Core.Locations.UpdateLocation(); } if (Network.UseLookupProxies) { Core.Locations.PublishGlobal(); } } } // new proxied host else if (Age == 15) { // proxied replicates to server naturally by adding server to routing table // server replicates to proxy here Network.Store.Replicate(new DhtContact(this, RemoteIP)); } // send ping if dead for x secs if (SecondsDead > 30 && SecondsDead % 5 == 0) { SendPacket(new Ping()); } else if (SecondsDead > 60) { CleanClose("Minute dead"); return; } // flush send buffer TrySend(); }
public void SecondTimer() { int packetLoss = 0; if (State == RudpState.Connected) { //Debug.WriteLine(Core.User.Settings.UserName + ":" + Core.TimeNow.Second + " - Send Window: " + SendWindowSize + ", Packets Sent: " + PacketsCompleted + ", Retransmits: " + ReTransmits); //crit delete PacketsCompleted = 0; // manage send window packetLoss = 0; if (InOrderAcks > 0) { packetLoss = ReTransmits * 100 / InOrderAcks; } ReTransmits = 0; InOrderAcks = 0; //Session.Log("PL: " + packetLoss.ToString() + // ", SW: " + SendWindowSize.ToString() + // ", SQ: " + SendPacketMap.Count.ToString() + // ", SB: " + SendBuffLength.ToString()); if (packetLoss < 10 && SendWindowSize < MAX_WINDOW_SIZE) { SendWindowSize++; } if (packetLoss > 20 && SendWindowSize > 1) { SendWindowSize /= 2; } // if data waiting to be read if (State == RudpState.Connected && RecvBuffLength > 0) { Session.OnReceive(); } // dead - 5 secs send ping, 10 secs reset primary addr, 15 secs close DateTime lastRecv = PrimaryAddress.LastAck; // if nothing received for 15 seconds disconnect if (Core.TimeNow > lastRecv.AddSeconds(15)) { RudpClose(CloseReason.TIMEOUT); } // re-analyze alternate routes after 10 secs dead, or half min interval else if (Core.TimeNow > lastRecv.AddSeconds(10) || Core.TimeNow > NextCheckRoutes) { // after connection this should immediately be called to find best route CheckRoutes(); NextCheckRoutes = Core.TimeNow.AddSeconds(30); } // send keep alive if nothing received after 5 secs else if (Core.TimeNow > lastRecv.AddSeconds(5)) { SendPing(PrimaryAddress); } } // prune addressMap to last 6 addresses seen while (AddressMap.Count > 6) { RudpAddress lastSeen = null; foreach (RudpAddress address in AddressMap.Values) { if (lastSeen == null || address.LastAck < lastSeen.LastAck) { lastSeen = address; } } AddressMap.Remove(lastSeen.GetHashCode()); } // finishing if (State == RudpState.Finishing) { if (!FinSent) { TrySendFin(); } if (FinTimeout > 0) { FinTimeout--; } if (FinTimeout == 0) { ChangeState(RudpState.Closed); } // buffer clear, all packets acked in sequence including fins if (FinSent && FinReceived && SendPacketMap.Count == 0) { ChangeState(RudpState.Closed); } } // re-send packets in out buffer if (State != RudpState.Closed) { ManageSendWindow(); } // update bandwidth rate used for determining public send buffer AvgBytesSent.Next(); // bandwidth stats Bandwidth.NextSecond(); }