/// <summary> /// Connects to browse server on proxy /// </summary> /// <param name="endpoint">proxy endpoint or null for all proxies</param> /// <param name="ct"></param> /// <returns></returns> public override async Task ConnectAsync(SocketAddress endpoint, CancellationToken ct) { IEnumerable <SocketAddress> addresses; if (endpoint != null && endpoint.Family == AddressFamily.Bound) { // Unwrap bound address endpoint = ((BoundSocketAddress)endpoint).LocalAddress; } if (endpoint == null || endpoint is NullSocketAddress) { _bindList = await Provider.NameService.LookupAsync( Reference.All, NameRecordType.Proxy, ct).ConfigureAwait(false); } else { var bindList = new HashSet <INameRecord>(); if (endpoint.Family == AddressFamily.Collection) { // Unwrap collection addresses = ((SocketAddressCollection)endpoint).Addresses(); } else { addresses = endpoint.AsEnumerable(); } foreach (var address in addresses) { var result = await Provider.NameService.LookupAsync( address.ToString(), NameRecordType.Proxy, ct).ConfigureAwait(false); bindList.AddRange(result); } _bindList = bindList; } if (!_bindList.Any()) { throw new SocketException(SocketError.NoAddress); } // Connect to internal socket _connected = await LinkAllAsync(_bindList, new ProxySocketAddress("", _browsePort, (ushort)_codec), ct); if (!_connected) { throw new SocketException( "Could not link browse socket on proxy", SocketError.NoHost); } }
/// <summary> /// Select the proxy to bind to /// </summary> /// <param name="endpoint"></param> /// <param name="ct"></param> /// <returns></returns> public virtual async Task BindAsync(SocketAddress endpoint, CancellationToken ct) { // Proxy selected, look up name records for the proxy address if (endpoint.Family == AddressFamily.Bound) { // Unwrap bound address endpoint = ((BoundSocketAddress)endpoint).LocalAddress; } IEnumerable <SocketAddress> addresses; if (endpoint.Family == AddressFamily.Collection) { // Unwrap collection addresses = ((SocketAddressCollection)endpoint).Addresses(); } else { addresses = endpoint.AsEnumerable(); } var bindList = new HashSet <INameRecord>(); foreach (var address in addresses) { var result = await Provider.NameService.LookupAsync( address.ToString(), NameRecordType.Proxy, ct).ConfigureAwait(false); bindList.AddRange(result); } if (!bindList.Any()) { throw new SocketException(SocketError.NoAddress); } _bindList = bindList; }