internal void RecalculateMTU() { lastMTUTest = (int)(lastMTUTest * MTU_TryDec); mtu_status = MTUStatus.Setting; }
void MTUHeartbeat(int now) { if (mtu_status == MTUStatus.Unset) { // Prep next MTU test mtu_status = MTUStatus.Setting; nextMTUTest = now + MTU_UnsetTry_Delay + 1.5f + Stats.Ping; if (NetLogger.LogFlowControl) { NetLogger.LogVerbose("[FlowControl] Expanding MTU for {0}...", EndPoint); } } else if (now >= nextMTUTest) { if (mtu_status == MTUStatus.Setting) { // Try and send an MTU packet if (lastMTUTest < NetMessenger.MAX_UDP_PACKET_SIZE && TrySendMTU(lastMTUTest)) { // If it succeeds then continue lastMTUTest = (int)(lastMTUTest * MTU_TryInc); now += MTU_UnsetTry_Delay; } else { // If it fails, set the MTU and stop trying to expand it if (lastMTUTest > NetMessenger.MAX_UDP_PACKET_SIZE) { lastMTUTest = NetMessenger.MAX_UDP_PACKET_SIZE; } // Use 75% of the MTU as the max chunk size, and cap it at 5000 bytes. maxChunkSize = (int)Math.Min(MaxUDP_MTU, lastMTUTest * 0.75f); MTU = maxChunkSize; Stats.MTU = MTU; MTUEventNeedsCall = true; if (NetLogger.LogFlowControl) { NetLogger.LogVerbose("[FlowControl] MTU for {0} set to {1}", EndPoint, MTU); } mtu_status = MTUStatus.Set; now += MTU_SetTry_Delay; } } // No need. /*else if (status == MTUStatus.Set) * { * int tryExpandAmount = Math.Min((int)(lastMTUTest * MTU_TryInc), MaxUDP_MTU); * * if (TrySendMTU(tryExpandAmount)) * { * lastMTUTest = (int)(lastMTUTest * MTU_TryInc); * now += MTU_UnsetTry_Delay; * MTU_Status = MTUStatus.Setting; * NetLogger.LogVerbose("Expanding MTU further for {0}...", EndPoint); * } * else * now += MTU_SetTry_Delay; * }*/ } }