Пример #1
0
        private void ReplaceTunnel(Tunnel tunnel, IClient 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);
                    Logging.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);
                    Logging.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
 public void TunnelExpired(Tunnel tunnel)
 {
     Logging.LogDebug($"TransitProvider: TunnelTimeout: {tunnel}");
     RunningGatewayTunnels.TryRemove(tunnel, out _);
     RunningEndpointTunnels.TryRemove(tunnel, out _);
     RunningTransitTunnels.TryRemove(tunnel, out _);
 }
Пример #4
0
        public void TunnelExpired(Tunnel tunnel)
        {
            if (!Destinations.TryRemove(tunnel, out var client))
            {
                Logging.LogDebug($"ClientTunnelProvider: WARNING. Unable to find client for TunnelExpired {tunnel}");
                return;
            }

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

            var replace = FindReplaceRecord(tunnel);

            if (replace != null)
            {
                Logging.LogDebug($"ClientTunnelProvider: TunnelTimeout: Failed replacing {replace.OldTunnel }" +
                                 $" with {tunnel}");

                /*
                 * if ( replace.OldTunnel.Expired )
                 * {
                 *  Logging.LogDebug( "ClientTunnelProvider: TunnelTimeout: Old tunnel expired. " + replace.OldTunnel.ToString() );
                 *
                 *  client.RemovePoolTunnel( replace.OldTunnel );
                 * }*/

                ReplaceTunnel(tunnel, client, replace);
            }
        }
Пример #5
0
        private TunnelUnderReplacement FindReplaceRecord(Tunnel newtunnel)
        {
            var replace = RunningReplacements
                          .Where(p =>
                                 p.Value.NewTunnels.Any(t => t.Equals(newtunnel)))
                          .Select(p => p.Value)
                          .FirstOrDefault();

            return(replace);
        }
Пример #6
0
        public void Add(uint id, Tunnel tunnel)
        {
            Logging.LogDebug($"TunnelIdSubsriptions: Added {id} to {tunnel}");

            if (TunnelIds.TryGetValue(id, out var tunnels))
            {
                tunnels.Add(tunnel);
            }
            else
            {
                TunnelIds[id] = new HashSet <Tunnel> {
                    tunnel
                };
            }
        }
Пример #7
0
        public Tunnel Remove(uint id, Tunnel tunnel)
        {
            if (!TunnelIds.TryGetValue(id, out var tunnels))
            {
                return(null);
            }

            tunnels.Remove(tunnel);
            if (!tunnels.Any())
            {
                TunnelIds.TryRemove(id, out _);
            }

            return(tunnel);
        }
Пример #8
0
        public void TunnelBuildTimeout(Tunnel tunnel)
        {
            if (!PendingTunnels.TryRemove(tunnel, out var client))
            {
                Logging.LogDebug($"ClientTunnelProvider: WARNING. Unable to find client TunnelBuildTimeout! {tunnel}");
                return;
            }

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

            var replace = FindReplaceRecord(tunnel);

            if (replace != null)
            {
                Logging.LogDebug($"ClientTunnelProvider: TunnelBuildTimeout: " +
                                 $"Failed replacing {replace.OldTunnel} with {tunnel}");

                if (replace.OldTunnel.Expired)
                {
                    Logging.LogDebug($"ClientTunnelProvider: TunnelBuildTimeout: " +
                                     $"Old tunnel expired. {replace.OldTunnel}");

                    client.RemoveTunnel(replace.OldTunnel);
                }

                tunnel.Shutdown();
                ReplaceTunnel(tunnel, client, replace);
            }
            else
            {
/*
 *              Logging.LogDebug( $"ClientTunnelProvider: TunnelBuildTimeout: " +
 *                  $"Unable to find a matching tunnel under replacement for {tunnel}" );
 */
            }
        }
Пример #9
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;
            }
        }
Пример #10
0
 internal TestRun2(Tunnel testtunnel)
 {
     TunnelUnderTest = testtunnel;
 }
Пример #11
0
 internal TunnelTestResult(Tunnel tunnel)
 {
     TestedTunnel = tunnel;
 }
Пример #12
0
 public void TunnelFailed(Tunnel tunnel)
 {
     TunnelExpired(tunnel);
 }
Пример #13
0
 public void TunnelEstablished(Tunnel tunnel)
 {
     Tunnels[tunnel] = true;
 }
Пример #14
0
 public void TunnelBuildTimeout(Tunnel tunnel)
 {
 }
Пример #15
0
 public void TunnelEstablished(Tunnel tunnel)
 {
 }
Пример #16
0
 public void TunnelBuildTimeout(Tunnel tunnel)
 {
     Tunnels.TryRemove(tunnel, out _);
 }
Пример #17
0
 public void TunnelExpired(Tunnel tunnel)
 {
     Tunnels.TryRemove(tunnel, out _);
 }
Пример #18
0
 internal TunnelUnderReplacement(Tunnel old, IClient dest)
 {
     OldTunnel = old;
     Client    = dest;
 }