Skip to main content

Dedicated IP

A Dedicated IP (DIP) is an address reserved for one subscription. In the SDK it is a KapeServerLocation whose dip is set.

Listing Dedicated IPs​

There are two kinds of Dedicated IP, and KapeLocationService.fetchDedicatedIPs() lists both in one call, so the app does not need to work out which kind an account has:

KapeDedicatedIPKindWhat it isLicense
.anonymousUnlocked on the device with a backup password (dipSetupRegisterBackupPassword, dipSetupAssignLocation)CategoryDedicatedIp
.simpleReserved on the account. Needs no setup and carries real coordinatesCategorySimpleDedicatedIp
let locations = KapeLocationService(handle: handle)
for dip in try await locations.fetchDedicatedIPs() {
// dip.dip?.kind is .anonymous or .simple; dip.dip?.ip is the address.
}
  • A kind your license does not grant contributes nothing. The call does not throw for it.
  • An account with no Dedicated IP gets an empty list, not an error.
  • When both kinds report the same address, it appears once, as .anonymous.
  • A Simple Dedicated IP's id and dip.id are its reservation ID.
  • The call throws KapeVPNError.simpleDipFetchFailed when the backend cannot list Simple Dedicated IPs, even if Anonymous ones loaded.
  • fetchDipConnectionStatuses() reports each Simple Dedicated IP as .unlocked(location:), after the per-subscription Anonymous statuses.

Setup stages​

An Anonymous Dedicated IP is set up once per device. It belongs to a separate Dedicated IP subscription, so resolve that subscription's ID first, then ask KapeLocationService.fetchDipSetupStage(subscriptionId:) where it stands:

guard let subscriptionId = try await handle.subscriptionIds(for: .dip).first else { return }
let stage = try await locations.fetchDipSetupStage(subscriptionId: subscriptionId)
KapeDipSetupStageMeaningNext call
.notEntitledThe subscription has no Dedicated IP licenses—
.backupPasswordRequiredNot unlocked on this device yet: a first-time setup, or a Dedicated IP assigned on another deviceKapeVPNManager.dipSetupRegisterBackupPassword(subscriptionId:backupPassword:)
.locationAssignmentRequired(pendingDipAssignment:)Unlocked, but no address assigned. pendingDipAssignment means a previous attempt did not finish: assign the same location againKapeVPNManager.dipSetupAssignLocation(subscriptionId:location:)
.doneAssigned and unlocked, ready to connectKapeVPNManager.connect(to:)
// 1. Register the subscription's access code on this device.
do {
let expiredIps = try await manager.dipSetupRegisterBackupPassword(
subscriptionId: subscriptionId, backupPassword: accessCode)
showExpired(expiredIps) // empty when none expired
} catch KapeVPNError.dipWrongBackupPassword {
show("Wrong access code")
} catch KapeVPNError.dipSubscriptionLocked {
show("Too many attempts — try again later")
} catch KapeVPNError.dipNotEntitled {
hideFeature()
} catch let KapeVPNError.dipSetupFailed(underlyingError) {
show(underlyingError.localizedDescription)
}

// 2. Pick a location and assign an address to it.
let catalog = try await locations.fetchAvailableDipLocations(subscriptionId: subscriptionId)
// Catalog entries: `id` is a location ID, `dip?.ip` is nil.
try await manager.dipSetupAssignLocation(subscriptionId: subscriptionId, location: catalog[0])
  • dipSetupRegisterBackupPassword is safe to call again on a device that is already unlocked.
  • dipSetupRegisterBackupPassword returns the subscription's expired addresses, or [] when none expired. It throws .dipWrongBackupPassword for a wrong access code and .dipSubscriptionLocked after too many failed attempts.
  • Both calls throw KapeVPNError.dipNotEntitled when the subscription has no Dedicated IP licenses or the SDK license does not grant CategoryDedicatedIp, and .dipSetupFailed(underlyingError:) for anything else.

Connecting​

Pass any location from fetchDedicatedIPs() to KapeVPNManager.connect(to:), the same call used for regular locations. Switching between a regular location and either kind works while connected.

try await manager.connect(to: dip)
AnonymousSimple
LicenseCategoryDedicatedIp and VpnProtocolLightwayCategorySimpleDedicatedIp
ProtocolsLightway onlyThose its endpoints serve (Lightway today), with the same transport rules as a regular location
HTTPS proxyNot appliedApplied
RenewalRenewed by the SDK while connectedNot needed

An Anonymous Dedicated IP from fetchAssignedDips(subscriptionId:) carries the address in both id and dip?.ip, so connect(to:) targets exactly that address.

An unlicensed Dedicated IP throws KapeVPNError.dipNotEntitled (or KapeFeatureNotLicensedError for Lightway) before anything is persisted. Other failures surface from the tunnel instead:

PacketTunnelErrorCauseFix
.dipExpiredAnonymous: the address expired, or support reset the subscriptionRun setup again
.dipUnderMaintenanceAnonymous: the Dedicated IP server is offlineRetry later
.dipUnavailableAnonymous: the server's health is unknown, or no access token is cached for the address. Simple: no longer reservedRetry; run setup again (Anonymous) or reserve again (Simple) if it persists
.dipProtocolNotSupportedThe Dedicated IP does not serve the selected protocolSelect .lightway or .automatic

Like any configuration failure, the tunnel keeps retrying with backoff and the status stays .connecting, while connectionError is .tunnelStartFailed, carrying the error's description only. To tell an expired Dedicated IP apart, check fetchDipConnectionStatuses().

Reserving a Simple Dedicated IP​

A Simple Dedicated IP needs no setup: pick a location and reserve it. Both calls need CategorySimpleDedicatedIp.

let catalog = try await locations.fetchSimpleDedicatedIPLocations()
// Catalog entries: `id` is a location ID, `dip?.ip` is nil. Locations with nothing left are omitted.

do {
let reservation = try await locations.reserveSimpleDedicatedIP(at: catalog[0])
// reservation.ip now appears in fetchDedicatedIPs()
} catch let error as KapeSimpleDedicatedIPReservationError {
switch error {
case .notEntitled: hideFeature()
case .slotsExhausted, .noCapacity, .entitlementEnded: show(error.localizedDescription)
case .invalidLocation: refreshCatalog()
case .temporarilyUnavailable: retryLater()
}
}

Without the license, or with no active subscription, fetchSimpleDedicatedIPLocations() returns an empty list and reserveSimpleDedicatedIP(at:) throws .notEntitled without calling the backend. Any other failure throws KapeError.

How many can be reserved​

let slots = try await locations.fetchSimpleDedicatedIPSlots()
// slots.total: slots the subscription grants. slots.reserved: addresses already reserved.
// slots.available: total - reserved, never negative.
  • total == 0 means the subscription is not entitled. The same zeros come back without the license or an active subscription; the call does not throw for them.
  • It reads the cached subscription token, so it makes no network call while the token is valid. A change made by billing or support appears once the token refreshes; call KapeSdkHandle.refreshEntitlements() to force it. A successful reservation refreshes it.
  • A reservation the token does not list yet is not counted in reserved, so available can be too high. .slotsExhausted from reserveSimpleDedicatedIP(at:) stays the authoritative answer.
  • It throws KapeVPNError.simpleDipFetchFailed when the token's entitlements cannot be read.

Status overview​

KapeLocationService.fetchDipConnectionStatuses() reports every Dedicated IP subscription at once: one entry per subscription, in the order handle.subscriptionIds(for: .dip) returns them, followed by each Simple Dedicated IP as .unlocked(location:). It renews each set-up subscription's access tokens as part of the check, so it also detects expiry.

for status in try await locations.fetchDipConnectionStatuses() {
switch status {
case .notEntitled: break
case .needsSetup, .locked, .expired: startSetup()
case let .unlocked(location): offer(location)
}
}
KapeDipConnectionStatusMeaning
.notEntitledThe subscription has no Dedicated IP licenses
.needsSetupSetup has not reached .done
.lockedSet up, but no access token for the address is cached on this device
.expiredThe address expired, or support reset the subscription
.unlocked(location:)Ready to pass to connect(to:)

It throws KapeVPNError.sdkError when a renewal fails for any other reason.

fetchDipStatus(subscriptionId:) exposes the license counters behind the setup stages: totalLicenses, licensesAssigned, unlockedLicenses and pendingDipAssignment.

Subscriptions with more than one Dedicated IP​

The setup stage covers the whole subscription: it reaches .done as soon as one address is assigned and unlocked on this device, even when licenses remain. Use KapeDipStatus to assign the rest:

let status = try await locations.fetchDipStatus(subscriptionId: subscriptionId)
if status.licensesAssigned < status.totalLicenses {
try await manager.dipSetupAssignLocation(subscriptionId: subscriptionId, location: anotherLocation)
}

pendingDipAssignment is also a single flag for the whole subscription. It does not say which assignment stalled, so the only safe prompt is "assign the same location again".

Choosing between addresses happens when connecting: fetchAssignedDips(subscriptionId:) returns one location per address unlocked on this device, each with its own dip?.ip. fetchDipConnectionStatuses() reports only the first, so call fetchAssignedDips when a subscription can hold several.

Renewal​

This applies to Anonymous Dedicated IPs; a Simple Dedicated IP has no access token to renew. The access token expires after three days. The SDK renews it:

  1. At connect time. The tunnel renews before connecting, and refuses an expired address with PacketTunnelError.dipExpired.
  2. While connected. The tunnel renews every 12 hours for the whole Dedicated IP session. It stops once the address expires or the subscription is reset.
  3. At app launch. Creating KapeVPNManager renews every Dedicated IP subscription. Failures are ignored.

None of these needs a call from the app. To also renew while the app is not connected, on foreground and in background tasks, create one KapeServicesRefresher at launch:

let refresher = KapeServicesRefresher(handle: handle)
refresher.start() // Renews now, and again each time the app becomes active.

// iOS and tvOS: from a BGTaskScheduler task the app registered and declared
// in BGTaskSchedulerPermittedIdentifiers.
BGTaskScheduler.shared.register(forTaskWithIdentifier: "com.example.refresh", using: nil) { task in
refresher.handleBackgroundRefresh(task: task)
}

KapeServicesRefresher is @MainActor. Call register(_:) before start() to refresh other services alongside it, each as a KapeRefreshableService. Its failures are ignored too.

Unlicensed SDKs​

Anonymous Dedicated IPs require CategoryDedicatedIp on your SDK license. Without it the calls report exactly what a subscription with no Dedicated IP licenses reports, so an app written against the flow above needs no extra error handling:

CallResult
fetchDipStatusAll counters 0
fetchDipSetupStage.notEntitled
fetchAvailableDipLocations, fetchAssignedDipsEmpty list
fetchDedicatedIPsSimple Dedicated IPs only, if CategorySimpleDedicatedIp is granted
fetchDipConnectionStatuses.notEntitled for every Dedicated IP subscription, then any Simple Dedicated IPs
dipSetupRegisterBackupPassword, dipSetupAssignLocationThrow KapeVPNError.dipNotEntitled
KapeVPNManager.connect(to:) with an Anonymous Dedicated IPThrows KapeVPNError.dipNotEntitled
RenewalNothing renewed

To hide the Dedicated IP UI rather than show an unentitled state, check handle.hasLicensedFeature(.categoryDedicatedIp). See Licensed features.

VpnProtocolLightway gates Anonymous Dedicated IPs too, since they are Lightway-only. Without it connect(to:) throws KapeFeatureNotLicensedError instead, checked before dipNotEntitled.

A Dedicated IP selection saved by an earlier, licensed build fails in the tunnel with PacketTunnelError.dipNotEntitled.