コード例 #1
0
        public async Task RemoveModuleAsync(ModuleIdentifier module, CancellationToken cancellation)
        {
            if (module == default)
            {
                throw new ArgumentDefaultException(nameof(module));
            }

            var session = await _coordinationManager.GetSessionAsync(cancellation);

            var runningModulePath = GetRunningModulePath(module, session);

            var entry = await _coordinationManager.GetAsync(runningModulePath, cancellation);

            if (entry == null)
            {
                return;
            }

            await _coordinationManager.DeleteAsync(runningModulePath, cancellation : cancellation);

            var(endPoint, prefixes) = ReadRunningModuleEntry(entry);

            foreach (var prefix in prefixes)
            {
                var prefixPath = GetPrefixPath(prefix, endPoint, session, normalize: false);
                await _coordinationManager.DeleteAsync(prefixPath, cancellation : cancellation);
            }
        }
コード例 #2
0
ファイル: RouteManager.cs プロジェクト: developeramarish/AI4E
        public async Task RemoveRouteAsync(EndPointAddress endPoint, Route route, CancellationToken cancellation)
        {
            if (endPoint == default)
            {
                throw new ArgumentDefaultException(nameof(endPoint));
            }

            var session = (await _coordinationManager.GetSessionAsync(cancellation)).ToString();
            var path    = GetPath(route, endPoint, session);
            await _coordinationManager.DeleteAsync(path, cancellation : cancellation);

            var reversePath = GetReversePath(session, endPoint, route);
            await _coordinationManager.DeleteAsync(reversePath, cancellation : cancellation);
        }
コード例 #3
0
        public async Task UnmapEndPointAsync(EndPointAddress endPoint, TAddress address, CancellationToken cancellation)
        {
            if (endPoint == default)
            {
                throw new ArgumentDefaultException(nameof(endPoint));
            }

            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            if (address.Equals(default(TAddress)))
            {
                throw new ArgumentDefaultException(nameof(address));
            }

            var endPointEntry = await GetLogicalAddressEntryAsync(endPoint, cancellation);

            var session = (await _coordinationManager.GetSessionAsync(cancellation)).ToString();
            var path    = GetPath(endPoint, session);

            await _coordinationManager.DeleteAsync(path, cancellation : cancellation);
        }
コード例 #4
0
        private async Task <bool> ValidateClientCoreAsync(EndPointAddress endPoint,
                                                          string securityToken,
                                                          CancellationToken cancellation)
        {
            var now  = _dateTimeProvider.GetCurrentTime();
            var path = GetPath(endPoint);

            do
            {
                var entry = await _coordinationManager.GetAsync(path, cancellation : cancellation);

                if (entry == null)
                {
                    _logger?.LogDebug($"Cannot update session for client with end-point '{endPoint.ToString()}'. Session is terminated.");

                    return(false);
                }

                var(comparandSecurityToken, leaseEnd) = DecodePayload(entry.Value.Span);

                // We have to assume that the client is not connected anymore.
                // This is a race condition, that has to be prevented.
                if (now >= leaseEnd)
                {
                    await _coordinationManager.DeleteAsync(entry.Path, cancellation : cancellation);

                    _logger?.LogDebug($"Session for client with end-point '{endPoint.ToString()}' is terminated. Removing entry.");
                    _logger?.LogDebug($"Cannot update session for client with end-point '{endPoint.ToString()}'. Session is terminated.");
                    return(false);
                }

                if (securityToken != comparandSecurityToken)
                {
                    _logger?.LogDebug($"Cannot update session for client with end-point '{endPoint.ToString()}'. Session is terminated.");
                    return(false);
                }

                var newLeaseEnd = now + Timeout;

                if (newLeaseEnd > leaseEnd)
                {
                    leaseEnd = newLeaseEnd;
                }

                var securityTokenBytesCount = Encoding.UTF8.GetByteCount(securityToken);

                using (ArrayPool <byte> .Shared.Rent(8 + 4 + securityTokenBytesCount, out var bytes))
                {
                    var payloadLength = EncodePayload(bytes, securityToken.AsSpan(), leaseEnd);
                    var payload       = bytes.AsMemory().Slice(start: 0, payloadLength);
                    endPoint = new EndPointAddress("client/" + Guid.NewGuid().ToString());

                    var version = await _coordinationManager.SetValueAsync(path, payload, version : entry.Version, cancellation : cancellation);

                    if (version == entry.Version)
                    {
                        _logger?.LogDebug($"Updated session for client with end-point '{endPoint.ToString()}'.");

                        return(true);
                    }
                }
            }while (true);
        }