⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rudpstack.cs

📁 破解的飞信源代码
💻 CS
📖 第 1 页 / 共 5 页
字号:
                                double num2 = (microSeconds - socket._bandwidthResponse01TS) / ((long) 0x3e8);
                                if (num2 < 0.001)
                                {
                                    num2 = 0.001;
                                }
                                double num3 = 91 / num2;
                                double num4 = (microSeconds - BinaryHelper.ReadInt(payload, 0)) / ((long) 0x3e8);
                                if (num4 < 0.001)
                                {
                                    num4 = 0.001;
                                }
                                double num5 = (long) (num3 * num4);
                                socket._bandwidth = (long) ((socket._bandwidth * 0.875f) + (num5 * 0.125));
                            }
                            else
                            {
                                if (channel == RUDPPacketChannel.MTUTuning)
                                {
                                    socket._pmtuDiscovery.OnReceiveProbe(payload.Length);
                                    return;
                                }
                                if (channel == RUDPPacketChannel.MTUTuningACK)
                                {
                                    socket._pmtuDiscovery.OnReceiveProbeACK(payload);
                                    return;
                                }
                            }
                            RUDPIngoingPacket packet = new RUDPIngoingPacket(socket, packetId, payload, channel, HiResTimer.MicroSeconds);
                            socket._incomingPackets.AddPacket(packet);
                            socket.HandleNextUserPacket(false);
                        }
                    }
                    else
                    {
                        bool flag = packetId <= socket._incomingPackets.CurrentPacketId;
                        if (!flag)
                        {
                            flag = socket._incomingPackets.ContainsPacket(packetId);
                        }
                        bool flag2 = socket._controlWindow.CanReceive(packetId, payload.Length);
                        if (((channel != RUDPPacketChannel.Ping) && (channel != RUDPPacketChannel.PingRendezVous)) && (flag2 || (!flag2 && flag)))
                        {
                            socket._sackWindow.OnReceivePacket(packetId);
                        }
                        if ((flag2 && !flag) && ((socket._status == RUDPSocketStatus.Connected) || (channel != RUDPPacketChannel.UserPacket)))
                        {
                            if (socket._incomingPackets.Count > 0)
                            {
                                int biggestPacketId = socket._incomingPackets.BiggestPacketId;
                                if (packetId != (biggestPacketId + 1))
                                {
                                    byte[] target = new byte[8];
                                    BinaryHelper.WriteInt(biggestPacketId + 1, target, 0);
                                    BinaryHelper.WriteInt(packetId - 1, target, 4);
                                    PushPacketToSend(socket, false, RUDPPacketChannel.OutOfOrder, target, 0, 8);
                                }
                            }
                            if (channel == RUDPPacketChannel.OutOfOrder)
                            {
                                socket._controlWindow.OnOutOfOrder(BinaryHelper.ReadInt(payload, 0), BinaryHelper.ReadInt(payload, 4));
                            }
                            if (channel == RUDPPacketChannel.TearDown)
                            {
                                if (socket._status == RUDPSocketStatus.Connected)
                                {
                                    socket._controlWindow.OnReceive(null);
                                    AsyncShutdown(socket);
                                }
                            }
                            else
                            {
                                RUDPIngoingPacket packet2 = new RUDPIngoingPacket(socket, packetId, payload, channel, HiResTimer.MicroSeconds);
                                socket._controlWindow.OnReceive(packet2);
                                socket._incomingPackets.AddPacket(packet2);
                                socket.HandleNextUserPacket(false);
                            }
                        }
                    }
                }
            }
        }

        private static RUDPSocket HandlePing(PhysicalSocket physical, IPEndPoint sender, int packetId, RUDPPacketChannel channel)
        {
            RUDPSocket socket = null;
            physical._connectedRDUPsLock.EnterReadLock();
            physical._connectedRDUPs.TryGetValue(sender, ref socket);
            physical._connectedRDUPsLock.ExitReadLock();
            if (channel == RUDPPacketChannel.Ping)
            {
                if (socket != null)
                {
                    socket._sackWindow.OnReceivePacket(packetId);
                    return null;
                }
                if (physical._acceptingRDUP == null)
                {
                    return null;
                }
                socket = physical.OnEndAccept(sender, packetId);
                socket._sackWindow.OnReceivePacket(packetId);
                return socket;
            }
            if (((socket != null) && (socket._status == RUDPSocketStatus.Connecting)) && socket._isRendezVousMode)
            {
                socket._status = RUDPSocketStatus.Connected;
                socket.OnEndConnect(RUDPSocketError.Success);
                socket._sackWindow.OnReceivePacket(packetId);
                return socket;
            }
            return null;
        }

        private static void KeepAliveTimer(RUDPSocket rudp, long now)
        {
            long num = Math.Max(rudp._lastSendTS, rudp._lastACKSendTS);
            if (((rudp._status == RUDPSocketStatus.Connected) && ((now - num) > 0x895440)) && rudp._controlWindow.CanSend(0))
            {
                PushPacketToSend(rudp, true, RUDPPacketChannel.KeepAlive, new byte[0], 0, 0);
            }
        }

        private static void LoadBalancingTimer(ControlThreadInformation controlInformation, long now)
        {
            if (((ProcessorsCount >= 2) && (controlInformation._rudpSockets.get_Count() >= 1)) && ((now - controlInformation.LastCheckThreadCPUUsageTS) >= 0xf4240))
            {
                lock (_loadBalancingSync)
                {
                    long ticks = controlInformation.ProcessThread.TotalProcessorTime.Ticks;
                    long num2 = ticks - controlInformation.PreviousProcessorTime;
                    controlInformation.PreviousProcessorTime = ticks;
                    Thread.VolatileWrite(ref _controlThreadCPUUsages[controlInformation.ControlThreadId], num2);
                    controlInformation.LastCheckThreadCPUUsageTS = now;
                    long num3 = 0x7fffffff;
                    long num4 = -2147483648;
                    int index = -1;
                    int num6 = -1;
                    for (int i = 0; i < ProcessorsCount; i++)
                    {
                        if (_controlThreadCPUUsages[i] > num4)
                        {
                            num4 = _controlThreadCPUUsages[i];
                            num6 = i;
                        }
                        if (_controlThreadCPUUsages[i] < num3)
                        {
                            num3 = _controlThreadCPUUsages[i];
                            index = i;
                        }
                    }
                    float num8 = 6.666667f;
                    if (((num3 * num8) > num4) && (num6 == controlInformation.ControlThreadId))
                    {
                        RUDPSocket socket = controlInformation._rudpSockets.get_Item(0);
                        controlInformation._rudpSockets.RemoveAt(0);
                        _controlThreadInformations[index]._rudpSocketsLock.EnterWriteLock();
                        _controlThreadInformations[index]._rudpSockets.Add(socket);
                        _controlThreadInformations[index]._rudpSocketsLock.ExitWriteLock();
                    }
                }
            }
        }

        internal static IPAddress LocalIPAddress(ProtocolType protocol)
        {
            IPHostEntry entry = Dns.Resolve(Dns.GetHostName());
            if (Socket.get_OSSupportsIPv6() && (protocol == ProtocolType.IPv6))
            {
                foreach (IPAddress address in entry.AddressList)
                {
                    if ((address.AddressFamily == AddressFamily.InterNetworkV6) && (address.ToString() != "::1"))
                    {
                        return address;
                    }
                }
            }
            foreach (IPAddress address2 in entry.AddressList)
            {
                if ((address2.AddressFamily == AddressFamily.InterNetwork) && (address2.ToString() != "127.0.0.1"))
                {
                    return address2;
                }
            }
            return IPAddress.Parse("127.0.0.1");
        }

        internal static byte[] MakePacketPayload(RUDPSocket rudp, int packetId, RUDPPacketChannel channel, SACKSlot slot1, SACKSlot slot2, SACKSlot slot3, SACKSlot slot4, byte[] payload, int offset, int payloadLength)
        {
            int index = 0;
            byte[] dst = PayloadManager.Allocate(channel, 0x3f + payloadLength);
            dst[index] = 1;
            index++;
            byte num2 = 0;
            if (slot1 != null)
            {
                num2 = (byte) (num2 + 1);
            }
            if (slot2 != null)
            {
                num2 = (byte) (num2 + 1);
            }
            if (slot3 != null)
            {
                num2 = (byte) (num2 + 1);
            }
            if (slot4 != null)
            {
                num2 = (byte) (num2 + 1);
            }
            dst[index] = 0;
            dst[index] = (byte) (dst[index] | num2);
            index++;
            if (rudp == null)
            {
                Buffer.BlockCopy(new byte[0x10], 0, dst, index, 0x10);
            }
            else
            {
                Buffer.BlockCopy(rudp._connectionId, 0, dst, index, 0x10);
            }
            index += 0x10;
            dst[index] = (byte) channel;
            index++;
            BinaryHelper.WriteInt(packetId, dst, index);
            index += 4;
            if (rudp == null)
            {
                BinaryHelper.WriteInt(-1, dst, index);
            }
            else
            {
                BinaryHelper.WriteInt(rudp._controlWindow.AdvertisedWindow, dst, index);
            }
            index += 4;
            BinaryHelper.WriteInt(payloadLength, dst, index);
            index += 4;
            if (slot1 != null)
            {
                BinaryHelper.WriteInt(slot1.StartPacketId, dst, index);
                index += 4;
                BinaryHelper.WriteInt(slot1.EndPacketId, dst, index);
                index += 4;
            }
            else
            {
                Buffer.BlockCopy(Clean8Bytes, 0, dst, index, 8);
                index += 8;
            }
            if (slot2 != null)
            {
                BinaryHelper.WriteInt(slot2.StartPacketId, dst, index);
                index += 4;
                BinaryHelper.WriteInt(slot2.EndPacketId, dst, index);
                index += 4;
            }
            else
            {
                Buffer.BlockCopy(Clean8Bytes, 0, dst, index, 8);
                index += 8;
            }
            if (slot3 != null)
            {
                BinaryHelper.WriteInt(slot3.StartPacketId, dst, index);
                index += 4;
                BinaryHelper.WriteInt(slot3.EndPacketId, dst, index);
                index += 4;
            }
            else
            {
                Buffer.BlockCopy(Clean8Bytes, 0, dst, index, 8);
                index += 8;
            }
            if (slot4 != null)
            {
                BinaryHelper.WriteInt(slot4.StartPacketId, dst, index);
                index += 4;
                BinaryHelper.WriteInt(slot4.EndPacketId, dst, index);
                index += 4;
            }
            else
            {
                Buffer.BlockCopy(Clean8Bytes, 0, dst, index, 8);
                index += 8;
            }
            if (payload != null)
            {
                Buffer.BlockCopy(payload, offset, dst, index, payloadLength);
            }
            return dst;
        }

        internal static FragmentInformation NewFragmentInformation(RUDPSocket rudpSocket, bool isReliable, byte[] payload, int offset, int size, RUDPSendIAsyncResult asyncResult)
        {
            if (_fragmentsPools.Count <= 0)
            {
                for (int i = 0; i < 100; i++)
                {
                    _fragmentsPools.Enqueue(new FragmentInformation(null, false, null, -1, -1, null));
                }
                return new FragmentInformation(rudpSocket, isReliable, payload, offset, size, asyncResult);
            }
            FragmentInformation information = (FragmentInformation) _fragmentsPools.Dequeue();
            information.rudp = rudpSocket;
            information.IsReliable = isReliable;
            information.Offset = offset;
            information.Size = size;
            information.Payload = payload;
            information.AsyncResult = asyncResult;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -