private async Task GetClusterMap(IConnection connection, IPEndPoint endPoint) { var completionSource = new TaskCompletionSource <byte[]>(); var configOp = new Config { CurrentHost = endPoint, Converter = new DefaultConverter(), Transcoder = new DefaultTranscoder(new DefaultConverter()), Opaque = SequenceGenerator.GetNext(), EndPoint = endPoint, Completed = s => { //Status will be Success if bucket select was bueno completionSource.SetResult(s.Data.ToArray()); return(completionSource.Task); } }; await connection.SendAsync(configOp.Write(), configOp.Completed).ConfigureAwait(false); var clusterMapBytes = await completionSource.Task.ConfigureAwait(false); await configOp.ReadAsync(clusterMapBytes).ConfigureAwait(false); var configResult = configOp.GetResultWithValue(); _bucketConfig = configResult.Content; //the cluster map _keyMapper = new VBucketKeyMapper(_bucketConfig); //for vbucket key mapping }
private async Task Negotiate(IConnection connection) { var features = new List <short> { (short)ServerFeatures.SelectBucket, (short)ServerFeatures.Collections, (short)ServerFeatures.AlternateRequestSupport, (short)ServerFeatures.SynchronousReplication }; var completionSource = new TaskCompletionSource <byte[]>(); var heloOp = new Hello { Key = Hello.BuildHelloKey(1),//temp Content = features.ToArray(), Converter = new DefaultConverter(), Transcoder = new DefaultTranscoder(new DefaultConverter()), Opaque = SequenceGenerator.GetNext(), Completed = s => { //Status will be Success if bucket select was bueno completionSource.SetResult(s.Data.ToArray()); return(completionSource.Task); } }; await connection.SendAsync(heloOp.Write(), heloOp.Completed).ConfigureAwait(false); var result = await completionSource.Task.ConfigureAwait(false); await heloOp.ReadAsync(result).ConfigureAwait(false); var supported = heloOp.GetResultWithValue(); }
internal static async Task <uint?> GetCid(this IConnection connection, string name, ITypeTranscoder transcoder) { var completionSource = new TaskCompletionSource <IMemoryOwner <byte> >(); using var getCid = new GetCid { Key = name, Transcoder = transcoder, Opaque = SequenceGenerator.GetNext(), Content = null, Completed = s => { completionSource.TrySetResult(s.ExtractData()); return(completionSource.Task); } }; await getCid.SendAsync(connection).ConfigureAwait(false); var gitCidBytes = await completionSource.Task.ConfigureAwait(false); await getCid.ReadAsync(gitCidBytes).ConfigureAwait(false); var resultWithValue = getCid.GetResultWithValue(); return(resultWithValue.Content); }
internal static async Task <short[]> Hello(this IConnection connection, ITypeTranscoder transcoder) { //TODO missing MutationSeqno (0x04) and ServerDuration (0x0f) var features = new List <short> { (short)ServerFeatures.SelectBucket, (short)ServerFeatures.Collections, (short)ServerFeatures.AlternateRequestSupport, (short)ServerFeatures.SynchronousReplication, (short)ServerFeatures.SubdocXAttributes, (short)ServerFeatures.XError }; var completionSource = new TaskCompletionSource <IMemoryOwner <byte> >(); using var heloOp = new Hello { Key = Core.IO.Operations.Hello.BuildHelloKey(connection.ConnectionId), Content = features.ToArray(), Transcoder = transcoder, Opaque = SequenceGenerator.GetNext(), Completed = s => { completionSource.TrySetResult(s.ExtractData()); return(completionSource.Task); } }; await heloOp.SendAsync(connection).ConfigureAwait(false); var result = await completionSource.Task.ConfigureAwait(false); await heloOp.ReadAsync(result).ConfigureAwait(false); //returns all supported features return(heloOp.GetResultWithValue().Content); }
public static async Task <ErrorMap> GetErrorMap(this IConnection connection) { var completionSource = new TaskCompletionSource <IMemoryOwner <byte> >(); using (var errorMapOp = new GetErrorMap { Converter = new DefaultConverter(), Transcoder = new DefaultTranscoder(new DefaultConverter()), Opaque = SequenceGenerator.GetNext(), Completed = s => { completionSource.TrySetResult(s.ExtractData()); return(completionSource.Task); } }) { await errorMapOp.SendAsync(connection).ConfigureAwait(false); var result = await completionSource.Task.ConfigureAwait(false); await errorMapOp.ReadAsync(result).ConfigureAwait(false); return(errorMapOp.GetResultWithValue().Content); } }
internal static async Task <Manifest> GetManifest(this IConnection connection) { var completionSource = new TaskCompletionSource <IMemoryOwner <byte> >(); using (var manifestOp = new GetManifest { Converter = new DefaultConverter(), Transcoder = new DefaultTranscoder(new DefaultConverter()), Opaque = SequenceGenerator.GetNext(), Completed = s => { completionSource.TrySetResult(s.ExtractData()); return(completionSource.Task); } }) { await manifestOp.SendAsync(connection).ConfigureAwait(false); var manifestBytes = await completionSource.Task.ConfigureAwait(false); await manifestOp.ReadAsync(manifestBytes).ConfigureAwait(false); var manifestResult = manifestOp.GetResultWithValue(); return(manifestResult.Content); } }
internal static async Task <BucketConfig> GetClusterMap(this IConnection connection, IPEndPoint endPoint) { var completionSource = new TaskCompletionSource <IMemoryOwner <byte> >(); using (var configOp = new Config { CurrentHost = endPoint, Converter = new DefaultConverter(), Transcoder = new DefaultTranscoder(new DefaultConverter()), Opaque = SequenceGenerator.GetNext(), EndPoint = endPoint, Completed = s => { completionSource.SetResult(s.ExtractData()); return(completionSource.Task); } }) { await configOp.SendAsync(connection).ConfigureAwait(false); var clusterMapBytes = await completionSource.Task.ConfigureAwait(false); await configOp.ReadAsync(clusterMapBytes).ConfigureAwait(false); var configResult = configOp.GetResultWithValue(); var config = configResult.Content; var json = JsonConvert.SerializeObject(config); return(config); } }
public override async Task AuthenticateAsync(IConnection connection, CancellationToken cancellationToken = default) { using var rootSpan = Tracer.RootSpan(CouchbaseTags.Service, OperationNames.AuthenticatePlain); using var op = new SaslStart { Key = MechanismType.GetDescription(), Content = GetAuthData(_username, _password), Opaque = SequenceGenerator.GetNext(), Span = rootSpan, }; OperationConfigurator.Configure(op, SaslOptions.Instance); await SendAsync(op, connection, cancellationToken).ConfigureAwait(false); }
internal static async Task <BucketConfig> GetClusterMap(this IConnection connection, IPEndPoint endPoint, Uri bootstrapUri) { var completionSource = new TaskCompletionSource <IMemoryOwner <byte> >(); using (var configOp = new Config { CurrentHost = endPoint, Converter = new DefaultConverter(), Transcoder = new DefaultTranscoder(new DefaultConverter()), Opaque = SequenceGenerator.GetNext(), EndPoint = endPoint, Completed = s => { if (s.Status == ResponseStatus.Success) { completionSource.SetResult(s.ExtractData()); } else { if (s.Status == ResponseStatus.KeyNotFound || s.Status == ResponseStatus.BucketNotConnected) { //completionSource.SetException(new KeyNotFoundException("CCCP or G3CP not supported.")); completionSource.SetResult(s.ExtractData()); } else { completionSource.SetException(new KeyValueException(s.Status.ToString())); } } return(completionSource.Task); } }) { await configOp.SendAsync(connection).ConfigureAwait(false); var clusterMapBytes = await completionSource.Task.ConfigureAwait(false); await configOp.ReadAsync(clusterMapBytes).ConfigureAwait(false); var configResult = configOp.GetResultWithValue(); var config = configResult.Content; if (config != null) { config.ReplacePlaceholderWithBootstrapHost(bootstrapUri); } return(config); } }
internal static async Task <BucketConfig> GetClusterMap(this IConnection connection, IPEndPoint endPoint, Uri bootstrapUri) { var completionSource = new TaskCompletionSource <IMemoryOwner <byte> >(); using (var configOp = new Config { CurrentHost = endPoint, Transcoder = new DefaultTranscoder(), Opaque = SequenceGenerator.GetNext(), EndPoint = endPoint, Completed = s => { if (s.Status == ResponseStatus.Success) { completionSource.TrySetResult(s.ExtractData()); } else { if (s.Status == ResponseStatus.KeyNotFound || s.Status == ResponseStatus.BucketNotConnected) { completionSource.TrySetResult(s.ExtractData()); } else { completionSource.TrySetException(new Exception($"Cannot fetch cluster map. Reason: {s.Status}", s.Exception));//TODO change in later commit } } return(completionSource.Task); } }) { await configOp.SendAsync(connection).ConfigureAwait(false); var clusterMapBytes = await completionSource.Task.ConfigureAwait(false); await configOp.ReadAsync(clusterMapBytes).ConfigureAwait(false); var configResult = configOp.GetResultWithValue(); var config = configResult.Content; if (config != null && bootstrapUri != null) { config.ReplacePlaceholderWithBootstrapHost(bootstrapUri); } return(config); } }
public override async Task AuthenticateAsync(IConnection connection, CancellationToken cancellationToken = default) { using var rootSpan = Tracer.RequestSpan(OuterRequestSpans.Attributes.Service, OuterRequestSpans.ServiceSpan.Internal.AuthenticatePlain); using var op = new SaslStart { Key = MechanismType.GetDescription() !, Content = GetAuthData(_username, _password), Opaque = SequenceGenerator.GetNext(), Span = rootSpan, Timeout = Timeout }; OperationConfigurator.Configure(op, SaslOptions.Instance); using var ctp = CancellationTokenPairSource.FromTimeout(Timeout, cancellationToken); await SendAsync(op, connection, cancellationToken).ConfigureAwait(false); }
public async Task <bool> AuthenticateAsync(IConnection connection, CancellationToken cancellationToken = default) { var tcs = new TaskCompletionSource <bool>(); using var op = new SaslStart { Key = MechanismType, Content = GetAuthData(Username, Password), Opaque = SequenceGenerator.GetNext(), Transcoder = new DefaultTranscoder(), Completed = s => { //Status will be AuthenticationError if auth failed otherwise false tcs.TrySetResult(s.Status == ResponseStatus.Success); return(tcs.Task); } }; IDisposable?cancellationTokenRegistration = null; if (cancellationToken.CanBeCanceled) { // Not the default, so register the callback cancellationTokenRegistration = cancellationToken.Register(() => { tcs.TrySetCanceled(cancellationToken); }); } try { await op.SendAsync(connection).ConfigureAwait(false); return(await tcs.Task.ConfigureAwait(false)); } finally { cancellationTokenRegistration?.Dispose(); } }
private async Task GetManifest(IConnection connection) { var completionSource = new TaskCompletionSource <IMemoryOwner <byte> >(); using (var manifestOp = new GetManifest { Converter = new DefaultConverter(), Transcoder = new DefaultTranscoder(new DefaultConverter()), Opaque = SequenceGenerator.GetNext(), Completed = s => { //Status will be Success if bucket select was bueno completionSource.SetResult(s.ExtractData()); return(completionSource.Task); } }) { await manifestOp.SendAsync(connection).ConfigureAwait(false); var manifestBytes = await completionSource.Task.ConfigureAwait(false); await manifestOp.ReadAsync(manifestBytes).ConfigureAwait(false); var manifestResult = manifestOp.GetResultWithValue(); _manifest = manifestResult.Content; } //warmup the scopes/collections and cache them foreach (var scopeDef in _manifest.scopes) { var collections = new List <ICollection>(); foreach (var collectionDef in scopeDef.collections) { collections.Add(new CouchbaseCollection(this, Convert.ToUInt32(collectionDef.uid), collectionDef.name)); } _scopes.TryAdd(scopeDef.name, new Scope(scopeDef.name, scopeDef.uid, collections, this)); } }
internal static async Task <BucketConfig> GetClusterMap(this IConnection connection, IPEndPoint endPoint) { var completionSource = new TaskCompletionSource <IMemoryOwner <byte> >(); using (var configOp = new Config { CurrentHost = endPoint, Converter = new DefaultConverter(), Transcoder = new DefaultTranscoder(new DefaultConverter()), Opaque = SequenceGenerator.GetNext(), EndPoint = endPoint, Completed = s => { completionSource.SetResult(s.ExtractData()); return(completionSource.Task); } }) { await configOp.SendAsync(connection).ConfigureAwait(false); var clusterMapBytes = await completionSource.Task.ConfigureAwait(false); await configOp.ReadAsync(clusterMapBytes).ConfigureAwait(false); var configResult = configOp.GetResultWithValue(); var config = configResult.Content; if (config != null) { // fixes single node cluster where config doesn't know hostname foreach (var nodesExt in config.NodesExt.Where(x => x.thisNode && string.IsNullOrWhiteSpace(x.hostname))) { nodesExt.hostname = endPoint.Address.ToString(); } } return(config); } }
public async Task <bool> AuthenticateAsync(IConnection connection) { var tcs = new TaskCompletionSource <bool>(); using (var op = new SaslStart { Key = MechanismType, Content = GetAuthData(Username, Password), Opaque = SequenceGenerator.GetNext(), Converter = new DefaultConverter(), Transcoder = new DefaultTranscoder(new DefaultConverter()), Completed = s => { //Status will be AuthenticationError if auth failed otherwise false tcs.TrySetResult(s.Status == ResponseStatus.Success); return(tcs.Task); } }) { await op.SendAsync(connection).ConfigureAwait(false); return(await tcs.Task.ConfigureAwait(false)); } }