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."); } } }
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); }
public void TunnelExpired(Tunnel tunnel) { Logging.LogDebug($"TransitProvider: TunnelTimeout: {tunnel}"); RunningGatewayTunnels.TryRemove(tunnel, out _); RunningEndpointTunnels.TryRemove(tunnel, out _); RunningTransitTunnels.TryRemove(tunnel, out _); }
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); } }
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); }
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 }; } }
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); }
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}" ); */ } }
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; } }
internal TestRun2(Tunnel testtunnel) { TunnelUnderTest = testtunnel; }
internal TunnelTestResult(Tunnel tunnel) { TestedTunnel = tunnel; }
public void TunnelFailed(Tunnel tunnel) { TunnelExpired(tunnel); }
public void TunnelEstablished(Tunnel tunnel) { Tunnels[tunnel] = true; }
public void TunnelBuildTimeout(Tunnel tunnel) { }
public void TunnelEstablished(Tunnel tunnel) { }
public void TunnelBuildTimeout(Tunnel tunnel) { Tunnels.TryRemove(tunnel, out _); }
public void TunnelExpired(Tunnel tunnel) { Tunnels.TryRemove(tunnel, out _); }
internal TunnelUnderReplacement(Tunnel old, IClient dest) { OldTunnel = old; Client = dest; }