mirror of
https://github.com/schlagmichdoch/PairDrop.git
synced 2025-04-24 08:46:20 -04:00
Merge pull request #110 from luckman212/luckman212-patch-1
Add new env var `IPV6_LOCALIZE` to enable auto discovery for IPv6 addresses
This commit is contained in:
commit
c9e1c2504a
2 changed files with 32 additions and 0 deletions
|
@ -35,6 +35,14 @@ Set options by using the following flags in the `docker run` command:
|
||||||
```
|
```
|
||||||
> Limits clients to 1000 requests per 5 min
|
> Limits clients to 1000 requests per 5 min
|
||||||
|
|
||||||
|
##### IPv6 Localization
|
||||||
|
```bash
|
||||||
|
-e IPV6_LOCALIZE=4
|
||||||
|
```
|
||||||
|
> To enable Peer Discovery among IPv6 peers, you can specify a reduced number of segments of the client IPv6 address to be evaluated as the peer's IP. This can be especially useful when using Cloudflare as a proxy.
|
||||||
|
>
|
||||||
|
> The flag must be set to an **integer** between `1` and `7`. The number represents the number of IPv6 [hextets](https://en.wikipedia.org/wiki/IPv6#Address_representation) to match the client IP against. The most common value would be `4`, which will group peers within the same `/64` subnet.
|
||||||
|
|
||||||
##### Websocket Fallback (for VPN)
|
##### Websocket Fallback (for VPN)
|
||||||
```bash
|
```bash
|
||||||
-e WS_FALLBACK=true
|
-e WS_FALLBACK=true
|
||||||
|
@ -200,6 +208,12 @@ $env:PORT=3010; npm start
|
||||||
```
|
```
|
||||||
> Specify the port PairDrop is running on. (Default: 3000)
|
> Specify the port PairDrop is running on. (Default: 3000)
|
||||||
|
|
||||||
|
#### IPv6 Localization
|
||||||
|
```bash
|
||||||
|
IPV6_LOCALIZE=4
|
||||||
|
```
|
||||||
|
> Truncate a portion of the client IPv6 address to make peers more discoverable. See [Options/Flags](#options--flags) above.
|
||||||
|
|
||||||
#### Specify STUN/TURN Server
|
#### Specify STUN/TURN Server
|
||||||
On Unix based systems
|
On Unix based systems
|
||||||
```bash
|
```bash
|
||||||
|
|
18
index.js
18
index.js
|
@ -96,6 +96,16 @@ if (debugMode) {
|
||||||
console.log("DEBUG_MODE is active. To protect privacy, do not use in production.")
|
console.log("DEBUG_MODE is active. To protect privacy, do not use in production.")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (process.env.IPV6_LOCALIZE) {
|
||||||
|
let ipv6_lcl = parseInt(process.env.IPV6_LOCALIZE);
|
||||||
|
if (!ipv6_lcl || !(0 < ipv6_lcl && ipv6_lcl < 8)) {
|
||||||
|
console.error("IPV6_LOCALIZE must be an integer between 1 and 7");
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
console.log("IPv6 client IPs will be localized to", ipv6_lcl, ipv6_lcl > 1 ? "segments" : "segment");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
app.use(function(req, res) {
|
app.use(function(req, res) {
|
||||||
res.redirect('/');
|
res.redirect('/');
|
||||||
});
|
});
|
||||||
|
@ -516,11 +526,19 @@ class Peer {
|
||||||
if (this.ip.substring(0,7) === "::ffff:")
|
if (this.ip.substring(0,7) === "::ffff:")
|
||||||
this.ip = this.ip.substring(7);
|
this.ip = this.ip.substring(7);
|
||||||
|
|
||||||
|
let ipv6_was_localized = false;
|
||||||
|
if (ipv6_lcl && this.ip.includes(':')) {
|
||||||
|
this.ip = this.ip.split(':',ipv6_lcl).join(':');
|
||||||
|
ipv6_was_localized = true;
|
||||||
|
}
|
||||||
|
|
||||||
if (debugMode) {
|
if (debugMode) {
|
||||||
console.debug("----DEBUGGING-PEER-IP-START----");
|
console.debug("----DEBUGGING-PEER-IP-START----");
|
||||||
console.debug("remoteAddress:", request.connection.remoteAddress);
|
console.debug("remoteAddress:", request.connection.remoteAddress);
|
||||||
console.debug("x-forwarded-for:", request.headers['x-forwarded-for']);
|
console.debug("x-forwarded-for:", request.headers['x-forwarded-for']);
|
||||||
console.debug("cf-connecting-ip:", request.headers['cf-connecting-ip']);
|
console.debug("cf-connecting-ip:", request.headers['cf-connecting-ip']);
|
||||||
|
if (ipv6_was_localized)
|
||||||
|
console.debug("IPv6 client IP was localized to", ipv6_lcl, ipv6_lcl > 1 ? "segments" : "segment");
|
||||||
console.debug("PairDrop uses:", this.ip);
|
console.debug("PairDrop uses:", this.ip);
|
||||||
console.debug("IP is private:", this.ipIsPrivate(this.ip));
|
console.debug("IP is private:", this.ipIsPrivate(this.ip));
|
||||||
console.debug("if IP is private, '127.0.0.1' is used instead");
|
console.debug("if IP is private, '127.0.0.1' is used instead");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue