Ejemplo n.º 1
0
        public void ReceiveMessageFromServiceBinding(IServiceBinding sender, KeyValuePair <string, int> remoteBinding, byte[] data)
        {
            var tunnelToUse = TunnelManager.GetTunnelByRemoteBinding(remoteBinding);

            if (tunnelToUse == null)
            {
                sender.ServiceDispatchFail(1, string.Format("An active tunnel does not exist for remote client {0}:{1}", remoteBinding.Key, remoteBinding.Value));
            }
            else
            {
                tunnelToUse.EnqueueMessage(new Message(data, new Random(PwUtils.SecondsSinceEpoch()).NextLong(Int64.MaxValue)));
            }
        }
Ejemplo n.º 2
0
        public void ReceiveTunnelCreationRequestFromServiceBinding(IServiceBinding sender, string friendlyName, KeyValuePair <string, int> remoteBinding)
        {
            var tunnel = TunnelManager.GetTunnelByRemoteBinding(remoteBinding);

            if (tunnel == null)
            {
                try
                {
                    var t = TunnelManager.CreateTunnel(friendlyName, remoteBinding);
                    sender.TunnelCreationSucceed(t);
                }
                catch (Exception ex)
                {
                    Logger.ErrorFormat("Failed to create tunnel. Error was: {0}", ex.Message);
                    sender.TunnelCreationFail(2, ex.Message);
                }
            }
            else
            {
                var message = string.Format("Tunnel with remote binding {0}:{1} already exists.", remoteBinding.Key, remoteBinding.Value);
                Logger.Error(message);
                sender.TunnelCreationFail(2, message);
            }
        }