public InboundBufferVec Send(NetworkPipelineContext ctx, InboundBufferVec inboundBuffer, ref bool needsResume, ref bool needsUpdate) { var simulator = new SimulatorUtility(m_SimulatorParams.MaxPacketCount, m_SimulatorParams.MaxPacketSize, m_SimulatorParams.PacketDelayMs); if (inboundBuffer.buffer1.Length + inboundBuffer.buffer2.Length > m_SimulatorParams.MaxPacketSize) { //UnityEngine.Debug.LogWarning("Incoming packet too large for internal storage buffer. Passing through. [buffer=" + (inboundBuffer.buffer1.Length+inboundBuffer.buffer2.Length) + " packet=" + param->MaxPacketSize + "]"); return(inboundBuffer); } var timestamp = ctx.timestamp; // Packet always delayed atm bool delayPacket = true; // Inbound buffer is empty if this is a resumed receive if (delayPacket && inboundBuffer.buffer1.Length > 0) { if (!simulator.DelayPacket(ref ctx, inboundBuffer, ref needsUpdate, timestamp)) { return(inboundBuffer); } } NativeSlice <byte> returnPacket = default(NativeSlice <byte>); if (simulator.GetDelayedPacket(ref ctx, ref returnPacket, ref needsResume, ref needsUpdate, timestamp)) { inboundBuffer.buffer1 = returnPacket; inboundBuffer.buffer2 = default(NativeSlice <byte>); return(inboundBuffer); } return(default(InboundBufferVec)); }
public unsafe void InitializeConnection(NativeSlice <byte> sendProcessBuffer, NativeSlice <byte> recvProcessBuffer, NativeSlice <byte> sharedProcessBuffer) { if (sharedProcessBuffer.Length >= UnsafeUtility.SizeOf <SimulatorUtility.Parameters>()) { SimulatorUtility.InitializeContext(m_SimulatorParams, sharedProcessBuffer); } }
private static void InitializeConnection(byte *staticInstanceBuffer, int staticInstanceBufferLength, byte *sendProcessBuffer, int sendProcessBufferLength, byte *recvProcessBuffer, int recvProcessBufferLength, byte *sharedProcessBuffer, int sharedProcessBufferLength) { SimulatorUtility.Parameters param = default; UnsafeUtility.MemCpy(¶m, staticInstanceBuffer, UnsafeUtility.SizeOf <SimulatorUtility.Parameters>()); if (sharedProcessBufferLength >= UnsafeUtility.SizeOf <SimulatorUtility.Parameters>()) { SimulatorUtility.InitializeContext(param, sharedProcessBuffer); } }
public unsafe NativeSlice <byte> Receive(NetworkPipelineContext ctx, NativeSlice <byte> inboundBuffer, ref bool needsResume, ref bool needsUpdate, ref bool needsSendUpdate) { var param = (SimulatorUtility.Context *)ctx.internalSharedProcessBuffer.GetUnsafePtr(); var simulator = new SimulatorUtility(m_SimulatorParams.MaxPacketCount, m_SimulatorParams.MaxPacketSize, m_SimulatorParams.PacketDelayMs); if (inboundBuffer.Length > m_SimulatorParams.MaxPacketSize) { //UnityEngine.Debug.LogWarning("Incoming packet too large for internal storage buffer. Passing through. [buffer=" + inboundBuffer.Length + " packet=" + param->MaxPacketSize + "]"); // TODO: Add error code for this return(inboundBuffer); } var timestamp = ctx.timestamp; if (inboundBuffer.Length > 0) { param->PacketCount++; } bool delayPacket = param->PacketDelayMs > 0; // Inbound buffer is empty if this is a resumed receive if (delayPacket && inboundBuffer.Length > 0) { var bufferVec = default(InboundBufferVec); bufferVec.buffer1 = inboundBuffer; if (!simulator.DelayPacket(ref ctx, bufferVec, ref needsUpdate, timestamp)) { return(inboundBuffer); } } if (simulator.ShouldDropPacket(param, m_SimulatorParams, timestamp)) { param->PacketDropCount++; return(new NativeSlice <byte>()); } NativeSlice <byte> returnPacket = default(NativeSlice <byte>); if (simulator.GetDelayedPacket(ref ctx, ref returnPacket, ref needsResume, ref needsUpdate, timestamp)) { return(returnPacket); } // Pass packet through, nothing was done with it. Or return empty buffer if no inbound buffer is here (then nothing is being resurrected) if (!delayPacket && inboundBuffer.Length > 0) { return(inboundBuffer); } return(new NativeSlice <byte>()); }
private static void Receive(ref NetworkPipelineContext ctx, ref InboundRecvBuffer inboundBuffer, ref NetworkPipelineStage.Requests requests) { var context = (SimulatorUtility.Context *)ctx.internalSharedProcessBuffer; var param = *(SimulatorUtility.Parameters *)ctx.staticInstanceBuffer; var simulator = new SimulatorUtility(param.MaxPacketCount, param.MaxPacketSize, param.PacketDelayMs, param.PacketJitterMs); if (inboundBuffer.bufferLength > param.MaxPacketSize) { //UnityEngine.Debug.LogWarning("Incoming packet too large for internal storage buffer. Passing through. [buffer=" + inboundBuffer.Length + " packet=" + param->MaxPacketSize + "]"); // TODO: Add error code for this return; } var timestamp = ctx.timestamp; // Inbound buffer is empty if this is a resumed receive if (inboundBuffer.bufferLength > 0) { context->PacketCount++; if (simulator.ShouldDropPacket(context, param, timestamp)) { context->PacketDropCount++; inboundBuffer = default; return; } var bufferVec = default(InboundSendBuffer); bufferVec.bufferWithHeaders = inboundBuffer.buffer; bufferVec.bufferWithHeadersLength = inboundBuffer.bufferLength; bufferVec.buffer = inboundBuffer.buffer; bufferVec.bufferLength = inboundBuffer.bufferLength; bufferVec.headerPadding = 0; if (context->PacketDelayMs == 0 || !simulator.DelayPacket(ref ctx, bufferVec, ref requests, timestamp)) { return; } } InboundSendBuffer returnPacket = default; if (simulator.GetDelayedPacket(ref ctx, ref returnPacket, ref requests, timestamp)) { inboundBuffer.buffer = returnPacket.bufferWithHeaders; inboundBuffer.bufferLength = returnPacket.bufferWithHeadersLength; return; } inboundBuffer = default; }
private static int Send(ref NetworkPipelineContext ctx, ref InboundSendBuffer inboundBuffer, ref NetworkPipelineStage.Requests requests) { var context = (SimulatorUtility.Context *)ctx.internalSharedProcessBuffer; var param = *(SimulatorUtility.Parameters *)ctx.staticInstanceBuffer; var simulator = new SimulatorUtility(param.MaxPacketCount, param.MaxPacketSize, param.PacketDelayMs, param.PacketJitterMs); if (inboundBuffer.headerPadding + inboundBuffer.bufferLength > param.MaxPacketSize) { //UnityEngine.Debug.LogWarning("Incoming packet too large for internal storage buffer. Passing through. [buffer=" + (inboundBuffer.headerPadding+inboundBuffer.buffer.Length) + " packet=" + param.MaxPacketSize + "]"); return((int)Error.StatusCode.NetworkPacketOverflow); } var timestamp = ctx.timestamp; if (inboundBuffer.bufferLength > 0) { context->PacketCount++; if (simulator.ShouldDropPacket(context, param, timestamp)) { context->PacketDropCount++; inboundBuffer = default; return((int)Error.StatusCode.Success); } if (context->FuzzFactor > 0) { simulator.FuzzPacket(context, ref inboundBuffer); } if (context->PacketDelayMs == 0 || !simulator.DelayPacket(ref ctx, inboundBuffer, ref requests, timestamp)) { return((int)Error.StatusCode.Success); } } InboundSendBuffer returnPacket = default; if (simulator.GetDelayedPacket(ref ctx, ref returnPacket, ref requests, timestamp)) { inboundBuffer = returnPacket; return((int)Error.StatusCode.Success); } inboundBuffer = default; return((int)Error.StatusCode.Success); }
public unsafe NativeSlice <byte> Receive(NetworkPipelineContext ctx, NativeSlice <byte> inboundBuffer, ref bool needsResume, ref bool needsUpdate, ref bool needsSendUpdate) { var param = (SimulatorUtility.Context *)ctx.internalSharedProcessBuffer.GetUnsafePtr(); var simulator = new SimulatorUtility(m_SimulatorParams.MaxPacketCount, m_SimulatorParams.MaxPacketSize, m_SimulatorParams.PacketDelayMs, m_SimulatorParams.PacketJitterMs); if (inboundBuffer.Length > m_SimulatorParams.MaxPacketSize) { //UnityEngine.Debug.LogWarning("Incoming packet too large for internal storage buffer. Passing through. [buffer=" + inboundBuffer.Length + " packet=" + param->MaxPacketSize + "]"); // TODO: Add error code for this return(inboundBuffer); } var timestamp = ctx.timestamp; // Inbound buffer is empty if this is a resumed receive if (inboundBuffer.Length > 0) { param->PacketCount++; if (simulator.ShouldDropPacket(param, m_SimulatorParams, timestamp)) { param->PacketDropCount++; return(default);