Skip to content

Commit

Permalink
text changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AtibQur committed Dec 17, 2024
1 parent 2e35ea7 commit 1345312
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 101 deletions.
8 changes: 4 additions & 4 deletions sites/cheerpx/src/content/docs/11-guides/Networking.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ const cx = await CheerpX.Linux.create({
What is happening here?

- [controlUrl] is the URL of the Tailscale control plane which verifies the user's identity. You only need to pass this option if you are [self-hosting Tailscale](/docs/guides/Networking#self-hosting-headscale).
- [authKey] is a string containing an authentication key used to register new users or devices that are pre-authenticated. You can create an auth key [here](https://login.tailscale.com/admin/settings/keys).
- [stateUpdateCb] is a callback function that receives the current state of the network, and is required for monitoring any changes in the network status.
- [netmapUpdateCb] is a callback function that receives updates regarding the network map, and is necessary for obtaining network mapping information.
- [authKey]: A string containing an authentication key for registering pre-authenticated users or devices. You can generate one [here](https://login.tailscale.com/admin/settings/keys).
- [controlUrl]: The Tailscale control plane URL for identity verification. This is only needed if you are [self-hosting Tailscale](/docs/guides/Networking#self-hosting-headscale).
- [stateUpdateCb]: A required callback function that monitors and reports changes in network status.
- [netmapUpdateCb]: A callback function that provides updates on the network map, enabling access to network mapping information.

Example to prompt the user for manual login on a different tab:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,53 +84,32 @@ This option configures network settings, which allows CheerpX to communicate ove
authKey?: string;
```

The `authKey` is an optional string used for authentication. It is usually taken from the URL, allowing the CheerpX Linux environment to be set up automatically without the user needing to enter it manually.
The `authKey` is an optional string used for authentication and should be passed directly in the `create` call.

**Example of usage:**

```js
let authKey = undefined;
if (browser) {
let params = new URLSearchParams("?" + window.location.hash.substr(1));
authKey = params.get("authKey") || undefined;
}
const networkInterface = { authKey };

```

**Explanation**

1. The `authKey` is taken from the URL, allowing the application to automatically use the authentication key provided by the browser.

2. The `authKey` is added to the `networkInterface` object, ensuring the application can access the authentication data whenever needed in the CheerpX environment.

### `controlUrl`

```ts
controlUrl?: string;
```

The `controlUrl` is an optional string parameter representing a URL used to manage or monitor the connection. It is typically fetched from the URL parameters and can be utilized for dashboard or configuration purposes.
The `controlUrl` is an optional string used to specify the URL of a self-hosted server.

**Example of usage:**

```js
let controlUrl = undefined;
if (browser) {
let params = new URLSearchParams("?" + window.location.hash.substr(1));
controlUrl = params.get("controlUrl") || undefined;
}
const dashboardUrl = controlUrl
? null
: "https://login.tailscale.com/admin/machines";
const networkInterface = { controlUrl };

```

**Explanation**

1. The `controlUrl` is taken from the URL and added to the `networkInterface` object, making it easy to connect to the appropriate control dashboard.

2. If `controlUrl` isn’t provided, the app automatically uses a default URL (`dashboardUrl`) for monitoring or setup.

### `loginUrlCb`

```ts
Expand All @@ -142,44 +121,10 @@ The `loginUrlCb` is a callback function designed to handle login URLs during the
**Example of usage:**

```js
function loginUrlCb(url) {
connectionState.set("LOGINREADY");
resolveLogin(url);
}
```

**Explanation**

1. **State update**

- The function updates the connectionState writable store to "LOGINREADY", signaling that the system is prepared for the user to initiate the login process.

```js
connectionState.set("LOGINREADY");
```

2. **URL resolution**

- The callback resolves the `loginPromise` with the provided URL. This promise is awaited during the login initiation process (`startLogin`) to fetch and use the login URL.

```js
resolveLogin(url);
```

**How it works**

The `loginUrlCb` is part of the `networkInterface` object, which organizes the key callbacks and functions for managing the network state. It interacts with:

- `startLogin`: The function that initiates the login process. It depends on the `loginUrlCb` to resolve the login URL and update networkData.

```js
export async function startLogin() {
connectionState.set("LOGINSTARTING");
const url = await loginPromise; // Waits for `loginUrlCb` to resolve the URL.
networkData.loginUrl = url; // Stores the resolved URL for application-wide access.
return url;
}
```
**Explanation**

### StateUpdateCb

Expand All @@ -192,26 +137,11 @@ This callback function is invoked whenever the connection state changes, enablin
**Example of usage:**

```js
function stateUpdateCb(state) {
switch (state) {
case 6: // Running
connectionState.set("CONNECTED");
break;
default:
connectionState.set("DISCONNECTED");
}
}

```

**Explanation**

- **State** `6` (Running): The callback sets the application's `connectionState` to `"CONNECTED"`, indicating the system is online.
- **Other states**: The default case handles all non-running states, setting `connectionState` to `"DISCONNECTED"`.

**How it works**

The `stateUpdateCb` is part of the `networkInterface` object and is triggered internally during connection events. It enables you to synchronize the application's user interface or internal state with the current connection status.

### NetmapUpdateCb

```ts
Expand All @@ -223,29 +153,9 @@ This callback is triggered whenever the network map is updated. The `map` parame
**Example of usage:**

```ts
function netmapUpdateCb(map) {
networkData.currentIp = map.self.addresses[0];
var exitNodeFound = false;
for (var i = 0; i < map.peers.length; i++) {
if (map.peers[i].exitNode) {
exitNodeFound = true;
break;
}
}
if (exitNodeFound) {
exitNode.set(true);
}
}

```

**Explanation**

**IP address update**: Updates `networkData.currentIp` with the first address of the current device.

**Exit node detection**: Iterates through `map.peers` to determine if an exit node exists in the network and updates the `exitNode` writable store to `true` if an exit node is found, otherwise sets it to `false`.

**How it works**

The `netmapUpdateCb` interacts with the network map provided by the CheerpX environment. It ensures that the current IP and exit node status is kept up to date with the latest network configuration.

[Promise]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise

0 comments on commit 1345312

Please sign in to comment.