# Multihop

## Overview

See [MultiHop](/paas/sdk/unified-vpn-sdk/features/multihop.md)

## Implementing MultiHop

To enable multihop routing, you need to pass an additional location to the `withLocation` method of the `SessionConfig.Builder` class. Both the main location and the proxy location can be fetched using the Backend API.

```kotlin
import unified.vpn.sdk.*

val sdk = UnifiedSdk.getInstance()

sdk.vpn.start(SessionConfig.Builder()
    // ...
    .withLocation("US", "YOUR_ACTUAL_PROXY_LOCATION")
    // ...
    .build(), object : CompletableCallback {
    override fun complete() {}
    override fun error(e: VpnException) {}
})
```

In this example, `"US"` is the main location, and `"YOUR_ACTUAL_PROXY_LOCATION"` is the proxy location.

## Fetching Available Virtual Locations

To fetch the available locations for multihop routing, you can use the `locations` method of the `Backend` class, specifying the `ConnectionType.HYDRA_TCP` parameter.

```kotlin
import unified.vpn.sdk.*

val sdk = UnifiedSdk.getInstance()

sdk.backend.locations(ConnectionType.HYDRA_TCP, object : Callback<AvailableLocations> {
    override fun success(availableLocations: AvailableLocations) {
        // Handle the available locations
    }

    override fun failure(e: VpnException) {
        // Handle any errors
    }
})
```

## Optimal Proxy

To automatically select the optimal proxy location based on network conditions and server load, you can pass an empty string (`""`) as the proxy parameter in the `withLocation` method. Passing `null` as the proxy parameter means that no proxy location is used.

```kotlin
import unified.vpn.sdk.*

val sdk = UnifiedSdk.getInstance()

val sessionConfig = SessionConfig.Builder()
    // ...
    .withLocation("US", "")  // Use optimal proxy
    // ...
    .build()

sdk.vpn.start(sessionConfig, object : CompletableCallback {
    override fun complete() {}
    override fun error(e: VpnException) {}
})
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pango.gitbook.io/paas/sdk/vpn-sdk-for-android/features/multihop.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
