private static int BuildCFAPackgage(byte[] dgram, int bytes, SendControlTypes sendControlType, int package_id, byte[] copy_to) { ClearBuffer(copy_to); copy_to[0] = 67; // C copy_to[1] = 70; // F copy_to[2] = 65; // A copy_to[3] = (byte)sendControlType; copy_to[4] = (byte)((package_id >> 24) & 255); copy_to[5] = (byte)((package_id >> 16) & 255); copy_to[6] = (byte)((package_id >> 8) & 255); copy_to[7] = (byte)((package_id) & 255); ByteWrite(dgram, bytes, copy_to, 8); return(bytes + 8); }
private void ProccessACKPackage(IPEndPoint remote_ep, byte[] package) { if (package[0] == 67 && package[1] == 70 && package[2] == 65) { // Is a CFA package SendControlTypes control_type = (SendControlTypes)package[3]; int package_id = 0; package_id = (package[4] << 24); package_id = package_id | (package[5] << 16); package_id = package_id | (package[6] << 8); package_id = package_id | (package[7]); switch (control_type) { case SendControlTypes.None: break; case SendControlTypes.Ordered: break; case SendControlTypes.Arrival: case SendControlTypes.Both: { lock (m_remoteTunnels) { if (m_remoteTunnels.ContainsKey(remote_ep)) { m_remoteTunnels[remote_ep].ACKPackage(package_id); } } } break; default: break; } } }
public void Send(byte[] dgram, int bytes, IPEndPoint endPoint, SendControlTypes sendControlType) { switch (sendControlType) { case SendControlTypes.None: { m_udpClient.Send(dgram, bytes, endPoint); } break; case SendControlTypes.Ordered: break; case SendControlTypes.Arrival: case SendControlTypes.Both: { lock (m_remoteTunnels) { if (m_remoteTunnels.ContainsKey(endPoint)) { m_remoteTunnels[endPoint].SendPackage(dgram, bytes, m_udpClient, endPoint); } else { CreateNewTunnel(endPoint).SendPackage(dgram, bytes, m_udpClient, endPoint); } } } break; default: break; } // Will automaticlly close when all packages are acked. StartTunnelWork(); }