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:
KapeDedicatedIPKind | What it is | License |
|---|---|---|
.anonymous | Unlocked on the device with a backup password (dipSetupRegisterBackupPassword, dipSetupAssignLocation) | CategoryDedicatedIp |
.simple | Reserved on the account. Needs no setup and carries real coordinates | CategorySimpleDedicatedIp |
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
idanddip.idare its reservation ID. - The call throws
KapeVPNError.simpleDipFetchFailedwhen 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)
KapeDipSetupStage | Meaning | Next call |
|---|---|---|
.notEntitled | The subscription has no Dedicated IP licenses | — |
.backupPasswordRequired | Not unlocked on this device yet: a first-time setup, or a Dedicated IP assigned on another device | KapeVPNManager.dipSetupRegisterBackupPassword(subscriptionId:backupPassword:) |
.locationAssignmentRequired(pendingDipAssignment:) | Unlocked, but no address assigned. pendingDipAssignment means a previous attempt did not finish: assign the same location again | KapeVPNManager.dipSetupAssignLocation(subscriptionId:location:) |
.done | Assigned and unlocked, ready to connect | KapeVPNManager.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])
dipSetupRegisterBackupPasswordis safe to call again on a device that is already unlocked.dipSetupRegisterBackupPasswordreturns the subscription's expired addresses, or[]when none expired. It throws.dipWrongBackupPasswordfor a wrong access code and.dipSubscriptionLockedafter too many failed attempts.- Both calls throw
KapeVPNError.dipNotEntitledwhen the subscription has no Dedicated IP licenses or the SDK license does not grantCategoryDedicatedIp, 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)
| Anonymous | Simple | |
|---|---|---|
| License | CategoryDedicatedIp and VpnProtocolLightway | CategorySimpleDedicatedIp |
| Protocols | Lightway only | Those its endpoints serve (Lightway today), with the same transport rules as a regular location |
| HTTPS proxy | Not applied | Applied |
| Renewal | Renewed by the SDK while connected | Not 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:
PacketTunnelError | Cause | Fix |
|---|---|---|
.dipExpired | Anonymous: the address expired, or support reset the subscription | Run setup again |
.dipUnderMaintenance | Anonymous: the Dedicated IP server is offline | Retry later |
.dipUnavailable | Anonymous: the server's health is unknown, or no access token is cached for the address. Simple: no longer reserved | Retry; run setup again (Anonymous) or reserve again (Simple) if it persists |
.dipProtocolNotSupported | The Dedicated IP does not serve the selected protocol | Select .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 == 0means 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, soavailablecan be too high..slotsExhaustedfromreserveSimpleDedicatedIP(at:)stays the authoritative answer. - It throws
KapeVPNError.simpleDipFetchFailedwhen 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)
}
}
KapeDipConnectionStatus | Meaning |
|---|---|
.notEntitled | The subscription has no Dedicated IP licenses |
.needsSetup | Setup has not reached .done |
.locked | Set up, but no access token for the address is cached on this device |
.expired | The 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:
- At connect time. The tunnel renews before connecting, and refuses an expired address with
PacketTunnelError.dipExpired. - 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.
- At app launch. Creating
KapeVPNManagerrenews 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:
| Call | Result |
|---|---|
fetchDipStatus | All counters 0 |
fetchDipSetupStage | .notEntitled |
fetchAvailableDipLocations, fetchAssignedDips | Empty list |
fetchDedicatedIPs | Simple Dedicated IPs only, if CategorySimpleDedicatedIp is granted |
fetchDipConnectionStatuses | .notEntitled for every Dedicated IP subscription, then any Simple Dedicated IPs |
dipSetupRegisterBackupPassword, dipSetupAssignLocation | Throw KapeVPNError.dipNotEntitled |
KapeVPNManager.connect(to:) with an Anonymous Dedicated IP | Throws KapeVPNError.dipNotEntitled |
| Renewal | Nothing 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.