Table of Contents

Class CompositeIpLocationProvider

Namespace
VpnHood.Net.IpLocations
Assembly
VpnHood.Net.IpLocations.dll

Provides locations from the first of several providers that finds one.

public class CompositeIpLocationProvider : IIpLocationProvider, ICurrentIpLocationProvider, IDisposable
Inheritance
CompositeIpLocationProvider
Implements
Inherited Members

Remarks

The providers are tried in order. Each gets a token canceled after its timeout, and the next is tried only once it ends, so the timeout holds only for a provider that observes its token. A failure is logged, except NotSupportedException, and the next provider is tried. Disposing this provider disposes them all.

Constructors

CompositeIpLocationProvider(ILogger, IEnumerable<IIpLocationProvider>, TimeSpan?)

Provides locations from the first of several providers that finds one.

public CompositeIpLocationProvider(ILogger logger, IEnumerable<IIpLocationProvider> providers, TimeSpan? providerTimeout = null)

Parameters

logger ILogger

The logger the failures go to.

providers IEnumerable<IIpLocationProvider>

The providers, in the order they are tried; this provider owns them.

providerTimeout TimeSpan?

How long each provider may take before its token is canceled, or null for no limit on GetLocation(IPAddress, CancellationToken) and 5 seconds on GetCurrentLocation(CancellationToken).

Remarks

The providers are tried in order. Each gets a token canceled after its timeout, and the next is tried only once it ends, so the timeout holds only for a provider that observes its token. A failure is logged, except NotSupportedException, and the next provider is tried. Disposing this provider disposes them all.

Methods

Dispose()

Disposes every provider, in order; a provider that throws stops the rest.

public void Dispose()

GetCurrentLocation(CancellationToken)

Finds where this device's public IP address is.

public Task<IpLocation> GetCurrentLocation(CancellationToken cancellationToken)

Parameters

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<IpLocation>

A task whose result is the location.

Exceptions

NotSupportedException

The provider does not support the lookup.

KeyNotFoundException

No provider found the location.

OperationCanceledException

cancellationToken was canceled.

GetLocation(IPAddress, CancellationToken)

Finds where an IP address is.

public Task<IpLocation> GetLocation(IPAddress ipAddress, CancellationToken cancellationToken)

Parameters

ipAddress IPAddress

The IP address.

cancellationToken CancellationToken

The token to monitor for cancellation requests.

Returns

Task<IpLocation>

A task whose result is the location.

Exceptions

Exception

No provider found the location.

OperationCanceledException

cancellationToken was canceled.