private void ConsumerOnReceivedGeneric(object sender, ReceivedGenericEventArgs <Message> eventArgs)
 {
     if (eventArgs.Generic is TcpBridgeRegistration)
     {
         TcpBridgeRegistration registration = (TcpBridgeRegistration)eventArgs.Generic;
         IPEndPoint            endPoint     = FindEndpoint(registration.SourceIp, registration.SourcePort);
         if (endPoint == null)
         {
             Logger.Error($"Source is not allowed: {registration.SourceIp}:{registration.SourcePort}");
         }
         else
         {
             Register(eventArgs.Socket, endPoint);
             Logger.Info($"Registered new connection: {eventArgs.Socket.RemoteIpAddress}");
         }
     }
     else if (_endPointLookup.ContainsKey(eventArgs.Socket))
     {
         IPEndPoint endPoint = _endPointLookup[eventArgs.Socket];
         HandleMessage(endPoint, eventArgs.Generic);
     }
     else
     {
         Logger.Error($"Received data from unknown source: {eventArgs.Socket.RemoteIpAddress}");
     }
 }
        public override void Send(IPEndPoint receiver, Message message)
        {
            IPEndPoint instance = FindEndpoint(receiver.Address.ToString(), receiver.Port);

            if (instance == null)
            {
                Logger.Error($"Destination is not allowed: {receiver.Address}:{receiver.Port}");
            }
            else if (_socketLookup.ContainsKey(instance) && _socketLookup[instance] != null)
            {
                Send(_socketLookup[instance], message);
            }
            else
            {
                SyncReceiveTcpClient client = new SyncReceiveTcpClient(this);
                client.ConnectError += ClientOnConnectError;
                Register(client, instance);
                TcpBridgeRegistration registration = new TcpBridgeRegistration(_settings.PublicEndPoint);
                Queue(client, registration);
                Queue(client, message);
                client.Connect(receiver.Address, (ushort)receiver.Port, TimeSpan.FromSeconds(30));
            }
        }