@@ -36,7 +36,6 @@ public ClientConfiguration(ClientConfigurationList parentList)
3636 // Server properties
3737 PresharedKeyProperty . TargetTypes . Add ( typeof ( ServerConfiguration ) ) ;
3838 PublicKeyProperty . TargetTypes . Add ( typeof ( ServerConfiguration ) ) ;
39- ServerPersistentKeepaliveProperty . TargetTypes . Add ( typeof ( ServerConfiguration ) ) ;
4039
4140 ServerConfigurationPrerequisite . EnsureConfigFile ( ) ;
4241 var serverConfiguration = new ServerConfiguration ( ) . Load < ServerConfiguration > ( Configuration . LoadFromFile ( ServerConfigurationPrerequisite . ServerDataPath ) ) ;
@@ -195,6 +194,39 @@ public ClientConfiguration(ClientConfigurationList parentList)
195194 } ;
196195 Properties . Add ( allowedIpsProperty ) ;
197196
197+ // This is a client property which goes in the client's (peer) section of the server's config,
198+ // so it should be defined and configured here, and should be targeted to the server's config.
199+ ConfigurationProperty PersistentKeepaliveProperty = new ConfigurationProperty ( this )
200+ {
201+ PersistentPropertyName = "PersistentKeepalive" ,
202+ Name = nameof ( PersistentKeepaliveProperty ) ,
203+ DefaultValue = 0 . ToString ( ) ,
204+ Validation = new ConfigurationPropertyValidation
205+ {
206+ Validate = prop =>
207+ {
208+ string result = default ;
209+
210+ if ( string . IsNullOrEmpty ( prop . Value ) || int . TryParse ( prop . Value , out _ ) == false )
211+ {
212+ result = Resources . PersistentKeepaliveValidationError ;
213+ }
214+
215+ return result ;
216+ }
217+ }
218+ } ;
219+ // On load, do a migration of the old value from the server config, if needed.
220+ PersistentKeepaliveProperty . OnLoadAction = _ =>
221+ {
222+ if ( string . IsNullOrEmpty ( PersistentKeepaliveProperty . Value ) )
223+ {
224+ PersistentKeepaliveProperty . Value = serverConfiguration . ServerPersistentKeepaliveProperty . Value ?? 0 . ToString ( ) ;
225+ }
226+ } ;
227+ Properties . Add ( PersistentKeepaliveProperty ) ;
228+ PersistentKeepaliveProperty . TargetTypes . Add ( typeof ( ServerConfiguration ) ) ;
229+
198230 // Adjust index of properties and resort
199231 AddressProperty . Index = 1 ;
200232 DnsProperty . Index = 2 ;
@@ -347,16 +379,6 @@ public ClientConfiguration(ClientConfigurationList parentList)
347379 } ;
348380 private ConfigurationProperty _fullDnsProperty ;
349381
350- // Note: This is really a server property, but it goes in the in the (peer) client section of the server's config.
351- // So we'll trick the config generator by putting it in the client, targeting it to the server, and returning the server's value,
352- // which the server will set on the client while saving
353- public ConfigurationProperty ServerPersistentKeepaliveProperty => _persistentKeepaliveProperty ??= new ConfigurationProperty ( this )
354- {
355- PersistentPropertyName = "PersistentKeepalive" ,
356- IsHidden = true
357- } ;
358- private ConfigurationProperty _persistentKeepaliveProperty ;
359-
360382 // Note: This is a client-specific property. It goes in the peer (client) section of the server's config, and is thus targeted to the server config type.
361383 // However, it also goes in the peer (server) section of the client config.
362384 // Therefore, it must also be defined on the server, targeted to the client, and return this client's value.
0 commit comments