Skip to content

Commit

Permalink
Update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
atavism committed Dec 6, 2024
1 parent 4568946 commit f952951
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 27 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,31 @@ else.
### Starting Lantern
After starting Lantern, all HTTP traffic will be proxied.

```java
import android.content.Context;
import io.lantern.sdk.Lantern;
```kotlin
import android.content.Context
import io.lantern.sdk.Lantern

...

Context context = ...;
String appName = "your app name assigned by Lantern";
long startTimeoutMillis = 60000; // 60 seconds
bool proxyAllTraffic = true;
Lantern.start(context, appName, proxyAllTraffic, startTimeoutMillis);
val context: Context = ...
val appName = "your app name assigned by Lantern"
val proxyAddr = ":8080"
val startTimeoutMillis = 60000L // 60 seconds
val proxyAllTraffic = true
Lantern.start(context, appName, proxyAddr, proxyAllTraffic, startTimeoutMillis)
```

### Stopping Lantern
After stopping Lantern, Lantern will continue to run in the background to keep fetching updated
configuration maintain its state, but no traffic will be proxied.

...
Lantern.stop();
Lantern.stop()
```
### Starting Lantern Again
Lantern can be started again after stopping it. This will be a fast start since Lantern is already
running.
### Restarting Lantern Again
Lantern can be restarted again after stopping it. This will be a fast start since Lantern is already
running
```
Lantern.start(context, appName, startTimeoutMillis);
Lantern.restart(context, startTimeoutMillis)
```
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ class MainActivity : AppCompatActivity() {
startProxyButton.visibility = View.VISIBLE
stopProxyButton.visibility = View.GONE
testRequestButton.visibility = View.GONE
launchWebViewButton.visibility = View.GONE
webView.visibility = View.GONE
logsView.text = ""
}

private fun openWebView() {
Expand All @@ -101,6 +104,9 @@ class MainActivity : AppCompatActivity() {
settings.pluginState = PluginState.ON
visibility = View.VISIBLE
webViewClient = object : WebViewClient() {
override fun shouldOverrideUrlLoading(view: WebView, request: WebResourceRequest): Boolean {
return false
}
override fun shouldInterceptRequest(view: WebView?, request: WebResourceRequest): WebResourceResponse? {
val url = request.url.toString()
val proxyResponse = ProxyHelper.proxyRequest(url) ?: return null
Expand Down
7 changes: 3 additions & 4 deletions example/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
android:id="@+id/startProxyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Start Proxy" />
android:text="Start Lantern" />

<Button
android:id="@+id/stopProxyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stop Proxy"
android:text="Stop Lantern"
android:visibility="gone" />

<Button
Expand All @@ -41,12 +41,11 @@
android:layout_weight="1"
android:visibility="gone" />

<!-- Log Title -->
<TextView
android:id="@+id/logTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Proxy Logs"
android:text="Lantern Logs"
android:textStyle="bold"
android:paddingTop="16dp" />

Expand Down
2 changes: 1 addition & 1 deletion lantern
Submodule lantern updated 1 files
+44 −28 sdk/sdk.go
27 changes: 19 additions & 8 deletions sdk/src/main/java/io/lantern/sdk/Lantern.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,24 @@ import sdk.Sdk
*/
object Lantern {
private var lanternAddr: InetSocketAddress? = null
private val proxyAddr = AtomicReference<SocketAddress?>()

// setup is used to initially configure the Lantern SDK and specifies the config directory
// and app name to use
fun setup(
context: Context,
appName: String,
configDir: String,
) {
Sdk.setup(appName, configDir)
}

fun _setProxy(
proxyAddr: String,
) {
Sdk.setup("", configDir(context), "")
ProxySelector.setDefault(object : ProxySelector() {
override fun select(uri: URI?): List<Proxy> {
val result = mutableListOf<Proxy>()
val addr = proxyAddr.get()
val addr = addrFromString(proxyAddr)
if (addr == null) {
result.add(Proxy.NO_PROXY)
} else {
Expand Down Expand Up @@ -52,13 +60,16 @@ object Lantern {
*/
@Synchronized
@Throws(Exception::class)
fun startHTTPProxy(
fun start(
context: Context,
appName: String,
addr: String,
proxyAll: Boolean,
startTimeoutMillis: Long,
): InetSocketAddress {
val result = Sdk.startHTTPProxy(addr)
val result = Sdk.start(appName, addr, proxyAll, startTimeoutMillis)
lanternAddr = addrFromString(result.addr)
proxyAddr.set(lanternAddr)
_setProxy(lanternAddr)
return lanternAddr!!
}

Expand All @@ -69,8 +80,8 @@ object Lantern {
*/
@Synchronized
fun stop() {
Sdk.stopHTTPProxy()
proxyAddr.set(null)
Sdk.stop()
_setProxy("")
}

fun getProxyPort(): Int {
Expand Down

0 comments on commit f952951

Please sign in to comment.