bool RespondersToRetransmittedRequests_ProcessPacket(IPEndPoint requesterEndpoint, byte[] udpData) { var key = new RequestKey(udpData, requesterEndpoint); if (_respondersToRetransmittedRequests.TryGetValue(key, out var responder)) { if (WriteToLog_udp_deepDetail_enabled) { WriteToLog_udp_deepDetail($"responding {(PacketTypes)responder.ResponseUdpPayloadData[0]} to retransmitted request {(PacketTypes)udpData[0]} (hash={MiscProcedures.GetArrayHashCodeString(udpData)})"); } SendPacket(responder.ResponseUdpPayloadData, requesterEndpoint); return(true); } else { return(false); } }
/// <summary> /// sends response to requests /// creates an object "ResponderToRetransmittedRequests" which handles further restransmitted requests (in case if the sent response gets lost) /// </summary> internal void RespondToRequestAndRetransmissions(byte[] requestUdpPayloadData, byte[] responseUdpPayloadData, IPEndPoint requesterEndpoint) { SendPacket(responseUdpPayloadData, requesterEndpoint); var key = new RequestKey(requestUdpPayloadData, requesterEndpoint); var responder = new ResponderToRetransmittedRequests { RequestKey = key, ExpirationTimeUTC = DateTimeNowUtc + Configuration.ResponderToRetransmittedRequestsTimeout, ResponseUdpPayloadData = responseUdpPayloadData }; _respondersToRetransmittedRequests.Remove(key); // remove in case if responder s=to same request is already added _respondersToRetransmittedRequests.Add(key, responder); _respondersToRetransmittedRequestsOldestFirst.AddLast(responder); if (_respondersToRetransmittedRequests.Count > 200) { WriteToLog_udp_lightPain($"_respondersToRetransmittedRequests.Count={_respondersToRetransmittedRequests.Count}"); } }