internal RemoteParty(LocalParty local, string partyName, RemotePartyKeyScope keyScope, Uri?uri, RemoteIdentityOptions?identityOptions, TrustedPartyConfiguration?partyConfiguration = null) : base(local, partyName, identityOptions, partyConfiguration) { KeyScope = keyScope; Uri = uri; _keyExchangeFailed = new PerfectEventSender <KeyExchangeFailedEventArgs>(); IdentityOptions = identityOptions; }
/// <summary> /// Initializes a new remote and adds it to the <see cref="RemoteParties"/>. /// If a remote party with the same name must already exists it must be identically configured /// (except the <paramref name="initialOutgoingOneTimePassword"/>) otherwise an <see cref="ArgumentException"/> is thrown. /// </summary> /// <param name="partyName">This remote <see cref="ITrustedParty.PartyName"/>.</param> /// <param name="uri">See <see cref="IRemoteParty.Uri"/>.</param> /// <param name="initialOutgoingOneTimePassword">Optional configured one time password to use.</param> /// <param name="keyScope">See <see cref="IRemoteParty.PersistKeys"/>.</param> /// <param name="externalIdentityOptions">Optional identity options.</param> public Task <IRemoteParty> EnsureRemotePartyAsync(IActivityMonitor monitor, string partyName, Uri?uri, OneTimePassword?initialOutgoingOneTimePassword = null, RemotePartyKeyScope keyScope = RemotePartyKeyScope.LocalIdentity, RemoteIdentityOptions?externalIdentityOptions = null, TrustedPartyConfiguration?partyConfiguration = null) { bool exists = false; var p = _remotes.AddOrUpdate(partyName, n => new RemoteParty(this, partyName, keyScope, uri, externalIdentityOptions, partyConfiguration), (n, already) => { Throw.CheckArgument(already.Uri == uri); Throw.CheckArgument(already.KeyScope == keyScope); Throw.CheckArgument(already.IdentityOptions?.RemoteDomainNameOverride == externalIdentityOptions?.RemoteDomainNameOverride); Throw.CheckArgument(already.IdentityOptions?.RemoteEnvironmentNameOverride == externalIdentityOptions?.RemoteEnvironmentNameOverride); Throw.CheckArgument(already.IdentityOptions?.RemotePartyNameOverride == externalIdentityOptions?.RemotePartyNameOverride); exists = true; // We consider here that the call to "Ensure" should honor its semantics... if (initialOutgoingOneTimePassword != null) { already.OneTimePassword = initialOutgoingOneTimePassword; } return(already); }); if (!exists) { if (initialOutgoingOneTimePassword != null) { p.OneTimePassword = initialOutgoingOneTimePassword; } monitor.Info($"Created new RemoteParty '{p}'."); } return(Task.FromResult <IRemoteParty>(p)); }