コード例 #1
0
        private void ReplaceTunnel(Tunnel tunnel, ClientDestination client, TunnelUnderReplacement replace)
        {
            if (tunnel != replace.OldTunnel)
            {
                replace.NewTunnels.RemoveAll(t => t.Equals(tunnel));
            }

            while (replace.NewTunnels.Count < NewTunnelCreationFactor)
            {
                switch (tunnel.Config.Direction)
                {
                case TunnelConfig.TunnelDirection.Outbound:
                    var newouttunnel = CreateOutboundTunnel(client, null);
                    replace.NewTunnels.Add(newouttunnel);
                    DebugUtils.LogDebug(() => string.Format("ClientTunnelProvider: ReplaceTunnel: Started to replace {0} with {1}.",
                                                            tunnel, newouttunnel));
                    break;

                case TunnelConfig.TunnelDirection.Inbound:
                    var newintunnel = CreateInboundTunnel(client, null);
                    replace.NewTunnels.Add(newintunnel);
                    DebugUtils.LogDebug(() => string.Format("ClientTunnelProvider: ReplaceTunnel: Started to replace {0} with {1}.",
                                                            tunnel, newintunnel));
                    break;

                default:
                    throw new NotImplementedException("Only out and inbound tunnels should be reported here.");
                }
            }
        }
コード例 #2
0
        protected void TunnelReplacementNeeded(Tunnel tunnel)
        {
            if (!Destinations.TryGetValue(tunnel, out var client))
            {
                Logging.LogDebug($"ClientTunnelProvider: WARNING. Unable to find client for TunnelReplacementNeeded {tunnel}");
                return;
            }

            if (!RunningReplacements.TryGetValue(tunnel, out var replace))
            {
                return;                                                                // Already being replaced
            }
            // Too many tunnels already?
            if (tunnel is InboundTunnel)
            {
                if (client.InboundTunnelsNeeded < 0)
                {
                    return;
                }
            }
            else
            {
                if (client.OutboundTunnelsNeeded < 0)
                {
                    return;
                }
            }

            replace = new TunnelUnderReplacement(tunnel, client);
            RunningReplacements[tunnel] = replace;

            ReplaceTunnel(tunnel, client, replace);
        }
コード例 #3
0
        internal void TunnelEstablished(Tunnel tunnel)
        {
            TunnelUnderReplacement replace = null;

            ClientDestination client = FindClient(tunnel);

            if (client == null)
            {
                return;
            }

            client.TunnelEstablished(tunnel);

            lock ( RunningReplacements )
            {
                replace = RunningReplacements.Where(p => p.Value.NewTunnels.Any(t => t.Equals(tunnel))).
                          Select(p => p.Value).SingleOrDefault();
                if (replace != null)
                {
                    RunningReplacements.Remove(replace.OldTunnel);
                }
            }

            if (replace != null)
            {
                DebugUtils.LogDebug("ClientTunnelProvider: TunnelEstablished: Successfully replaced old tunnel " + replace.OldTunnel.ToString() +
                                    " with new tunnel " + tunnel.ToString());

                RemoveTunnelUnderReplacement(replace.OldTunnel);
                //client.RemoveTunnel( replace.OldTunnel );
                //TunnelMgr.RemoveTunnel( replace.OldTunnel );
                //replace.OldTunnel.Shutdown();
                return;
            }
        }
コード例 #4
0
        internal void TunnelReplacementNeeded(Tunnel tunnel)
        {
            ClientDestination client = FindClient(tunnel);

            if (client == null)
            {
                return;
            }

            TunnelUnderReplacement replace;

            lock ( RunningReplacements )
            {
                if (!RunningReplacements.TryGetValue(tunnel, out replace))
                {
                    return;                                                            // Already being replaced
                }
                // Too many tunnels already?
                if (tunnel is InboundTunnel)
                {
                    if (client.InboundTunnelsNeeded < 0)
                    {
                        return;
                    }
                }
                else
                {
                    if (client.OutboundTunnelsNeeded < 0)
                    {
                        return;
                    }
                }

                replace = new TunnelUnderReplacement(tunnel, client);
                lock ( RunningReplacements )
                {
                    RunningReplacements[tunnel] = replace;
                }
            }

            ReplaceTunnel(tunnel, client, replace);
        }
コード例 #5
0
        public void TunnelEstablished(Tunnel tunnel)
        {
            TunnelUnderReplacement replace = null;

            if (!PendingTunnels.TryRemove(tunnel, out var client))
            {
                Logging.LogDebug($"ClientTunnelProvider: WARNING. Unable to find client for established tunnel {tunnel}");
                return;
            }
            Destinations[tunnel] = client;

            try
            {
                client.TunnelEstablished(tunnel);
            }
            catch (Exception ex)
            {
                Logging.Log(ex);
            }

            replace = RunningReplacements.Where(p =>
                                                p.Value.NewTunnels.Any(
                                                    t => t.Equals(tunnel)))
                      .Select(p => p.Value)
                      .FirstOrDefault();

            if (replace != null)
            {
                RunningReplacements.TryRemove(replace.OldTunnel, out _);
            }

            if (replace != null)
            {
                Logging.LogDebug($"ClientTunnelProvider: TunnelEstablished: Successfully replaced old tunnel {replace.OldTunnel} with new tunnel {tunnel}");

                RunningReplacements.TryRemove(replace.OldTunnel, out _);
                return;
            }
        }