Skip to content

Commit 5ec54db

Browse files
committed
Adding KeepAliveInterval option and settings for ctrl channel
1 parent 81cf5b6 commit 5ec54db

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-1
lines changed

CONFIG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,14 @@ file.
254254
The connection string can be set via the AZURE_BRIDGE_CONNECTIONSTRING
255255
environment variable.
256256

257+
### **-a keepalive_interval**
258+
259+
Specifies the interval (in seconds) between keepalive messages sent on the
260+
"control connection" through which the listener accepts new connections.
261+
The default is 30 seconds. The value is the maximum interval during which
262+
a disconnected listener can go unnoticed by the remote forwarder and the
263+
automatic reconnection mechanism is triggered.
264+
257265
### -h
258266

259267
**-?**
@@ -325,6 +333,11 @@ the -L and -T command line options above.
325333
should bind local port forwardings to the wildcard address, thus allowing remote
326334
hosts to connect to forwarded ports. The argument must be "true" or "false".
327335
The default is "false".
336+
* **KeepAliveInterval** - Specifies the interval (in seconds) between keepalive
337+
messages sent on the "control connection" through which the listener accepts
338+
new connections. The default is 30 seconds. The value is the maximum interval
339+
during which a disconnected listener can go unnoticed by the remote forwarder and
340+
the automatic reconnection mechanism is triggered.
328341
* **LocalForward** - Specifies that a (set of) TCP ports on the local machine
329342
shall be forwarded via the Azure Relay. Each entry can have four properties,
330343
"BindAddress", "Port", "LocalSocket", and "RelayName". See [below](#localforward-properties) for

src/Microsoft.Azure.Relay.Bridge/Configuration/CommandLineSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class CommandLineSettings
2222
#endif
2323
[Option(CommandOptionType.NoValue, LongName = "svc", ShortName = "svc", Description = "Reserved for background service invocation")]
2424
public bool? ServiceRun { get; set; }
25+
[Option(CommandOptionType.SingleValue, ShortName = "a", Description = "Keepalive interval in seconds (default 30)")]
26+
public int? KeepAliveInterval { get; set; }
2527
[Option(CommandOptionType.SingleValue, ShortName = "b", Description = "Source address of forwarding connections.")]
2628
public string BindAddress { get; set; }
2729
[Option(CommandOptionType.SingleValue, ShortName = "e", Description = "Relay endpoint URI")]

src/Microsoft.Azure.Relay.Bridge/Configuration/Config.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,16 @@ public string LogFileName
432432
}
433433
}
434434

435+
/// <summary>
436+
/// Specifies the number of seconds that the control connection to the
437+
/// Azure Relay server may be inactive before it is "pinged" and therefore
438+
/// checked. The default is 30 seconds. You can specify a shorter interval
439+
/// if you are using a problematic network that disconnects idle connections
440+
/// frequently. The value is the maximum number of seconds that a disconnected
441+
/// listener will go undetected.
442+
/// </summary>
443+
public int KeepAliveInterval { get; set; } = 30;
444+
435445
/// <summary>
436446
/// Specifies that a TCP port on the remote machine be bound to
437447
/// a name on the Azure Relay.
@@ -573,6 +583,10 @@ public static Config LoadConfig(CommandLineSettings commandLineSettings)
573583
{
574584
config.AzureRelayConnectionString = commandLineSettings.ConnectionString;
575585
}
586+
if (commandLineSettings.KeepAliveInterval.HasValue)
587+
{
588+
config.KeepAliveInterval = commandLineSettings.KeepAliveInterval.Value;
589+
}
576590

577591
if (commandLineSettings.LocalForward != null)
578592
{
@@ -1132,6 +1146,10 @@ private void Merge(Config otherConfig)
11321146
{
11331147
this.LogLevel = otherConfig.LogLevel;
11341148
}
1149+
if (otherConfig.KeepAliveInterval != 30)
1150+
{
1151+
this.KeepAliveInterval = otherConfig.KeepAliveInterval;
1152+
}
11351153

11361154
if (this.ClearAllForwardings.HasValue && this.ClearAllForwardings.Value)
11371155
{

src/Microsoft.Azure.Relay.Bridge/RemoteForwardBridge.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public async Task Open()
8686
{
8787
this.listener = new HybridConnectionListener(connectionString.ToString());
8888
}
89+
this.listener.KeepAliveInterval = TimeSpan.FromSeconds(config.KeepAliveInterval);
8990
this.listener.Online += (s, e) => { Online?.Invoke(this, e); };
9091
this.listener.Offline += (s, e) => { Offline?.Invoke(this, e); };
9192
this.listener.Connecting += (s, e) => { Connecting?.Invoke(this, e); };

test/unit/Microsoft.Azure.Relay.Bridge.Tests/ConfigTest.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ string CreateMaxCommandLine()
5252
" -H baz5:http/service.example.com" +
5353
" -H abc/def:http/service.example.com/foo" +
5454
" -H ghi/jkl:http/service1.example.com/foo;http/service2.example.com/foo" +
55-
" -v";
55+
" -v" +
56+
" -a 60";
5657
}
5758

5859
string CreateMaxConfig()
@@ -69,6 +70,7 @@ string CreateMaxConfig()
6970
"ClearAllForwardings : false " + textWriter.NewLine +
7071
"ConnectionAttempts : 1 " + textWriter.NewLine +
7172
"ConnectTimeout : 60 " + textWriter.NewLine +
73+
"KeepAliveInterval : 60 " + textWriter.NewLine +
7274
"ExitOnForwardFailure : true " + textWriter.NewLine +
7375
"LocalForward : " + textWriter.NewLine +
7476
" - BindAddress : 127.0.100.1" + textWriter.NewLine +
@@ -700,6 +702,7 @@ public void ConfigBadConnectTimeoutTest()
700702
}
701703
private static void CheckMaxCommandLine(Config config)
702704
{
705+
Assert.Equal(60, config.KeepAliveInterval);
703706
Assert.Equal("Endpoint=sb://cvrelay.servicebus.windows.net/;SharedAccessKeyName=send;SharedAccessKey=abcdefgh;", config.AzureRelayConnectionString);
704707
Assert.Equal("sb://cvrelay.servicebus.windows.net/", config.AzureRelayEndpoint);
705708
Assert.Equal("send", config.AzureRelaySharedAccessKeyName);
@@ -778,6 +781,7 @@ private static void CheckMaxCommandLine(Config config)
778781

779782
private static void CheckMaxConfig(Config config)
780783
{
784+
Assert.Equal(60, config.KeepAliveInterval);
781785
Assert.Equal("inet", config.AddressFamily);
782786
Assert.Equal("Endpoint=sb://cvrelay.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=P0CQgKxRl8S0ABAlmbitHDEWfwWUQzKB34J0w48SB/w=;", config.AzureRelayConnectionString);
783787
Assert.Equal("sb://cvrelay.servicebus.windows.net/", config.AzureRelayEndpoint);

0 commit comments

Comments
 (0)