Ejemplo n.º 1
0
        public override void SendPacketConnless(IPEndPoint endPoint, byte[] data,
                                                int dataSize, SendCallbackData callbackData = null)
        {
            var token = GetToken(endPoint);

            if (token != TokenHelper.TokenNone)
            {
                NetworkHelper.SendPacketConnless(Client, endPoint, token,
                                                 TokenManager.GenerateToken(endPoint), data, dataSize);
            }
            else
            {
                FetchToken(endPoint);

                var now  = Time.Get();
                var info = new ConnlessPacketInfo(dataSize)
                {
                    EndPoint         = endPoint,
                    Expiry           = now + Time.Freq() * TokenHelper.TokenCachePacketExpiry,
                    LastTokenRequest = now,
                };

                if (callbackData != null)
                {
                    info.SendCallback    = callbackData.Callback;
                    info.CallbackContext = callbackData.Context;

                    callbackData.TrackID = info.TrackID;
                }
                else
                {
                    info.SendCallback    = null;
                    info.CallbackContext = null;
                }

                Buffer.BlockCopy(data, 0, info.Data, 0, dataSize);
                ConnlessPacketList.Add(info);
            }
        }
Ejemplo n.º 2
0
 public abstract void Send(Chunk packet,
                           uint token = TokenHelper.TokenNone,
                           SendCallbackData callbackData = null);
Ejemplo n.º 3
0
        public override void Send(Chunk packet, uint token      = TokenHelper.TokenNone,
                                  SendCallbackData callbackData = null)
        {
            if (packet.Flags.HasFlag(SendFlags.Connless))
            {
                if (packet.DataSize > NetworkHelper.MaxPayload)
                {
                    Debug.Warning("network", $"packet payload too big, length={packet.DataSize}");
                    return;
                }

                if (packet.ClientId == -1 && Connection.EndPoint != null &&
                    packet.EndPoint.Compare(Connection.EndPoint, true))
                {
                    packet.ClientId = 0;
                }

                if (token != TokenHelper.TokenNone)
                {
                    NetworkHelper.SendPacketConnless(UdpClient, packet.EndPoint,
                                                     token, TokenManager.GenerateToken(packet.EndPoint),
                                                     packet.Data, packet.DataSize);
                }
                else
                {
                    if (packet.ClientId == -1)
                    {
                        TokenCache.SendPacketConnless(packet.EndPoint,
                                                      packet.Data, packet.DataSize, callbackData);
                    }
                    else
                    {
                        Debug.Assert(packet.ClientId == 0, "errornous client id");
                        Connection.SendPacketConnless(packet.Data, packet.DataSize);
                    }
                }
            }
            else
            {
                if (packet.DataSize + NetworkHelper.MaxChunkHeaderSize >= NetworkHelper.MaxPayload)
                {
                    Debug.Warning("network", $"chunk payload too big, length={packet.DataSize} dropping chunk");
                    return;
                }

                Debug.Assert(packet.ClientId == 0, "errornous client id");

                var flags = ChunkFlags.None;
                if (packet.Flags.HasFlag(SendFlags.Vital))
                {
                    flags = ChunkFlags.Vital;
                }

                Connection.QueueChunk(flags, packet.Data, packet.DataSize);

                if (packet.Flags.HasFlag(SendFlags.Flush))
                {
                    Connection.Flush();
                }
            }
        }
Ejemplo n.º 4
0
 public abstract void SendPacketConnless(IPEndPoint endPoint,
                                         byte[] data, int dataSize, SendCallbackData callbackData = null);