Penalize IP relays, explicitly allow onion/local relays
This commit is contained in:
@@ -21,6 +21,9 @@ import {
|
|||||||
import {
|
import {
|
||||||
getFilterId,
|
getFilterId,
|
||||||
isRelayUrl,
|
isRelayUrl,
|
||||||
|
isOnionUrl,
|
||||||
|
isLocalUrl,
|
||||||
|
isIPAddress,
|
||||||
isShareableRelayUrl,
|
isShareableRelayUrl,
|
||||||
PROFILE,
|
PROFILE,
|
||||||
RELAYS,
|
RELAYS,
|
||||||
@@ -227,6 +230,7 @@ export type RouterScenarioOptions = {
|
|||||||
policy?: FallbackPolicy
|
policy?: FallbackPolicy
|
||||||
limit?: number
|
limit?: number
|
||||||
allowLocal?: boolean
|
allowLocal?: boolean
|
||||||
|
allowOnion?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RouterScenario {
|
export class RouterScenario {
|
||||||
@@ -259,6 +263,8 @@ export class RouterScenario {
|
|||||||
|
|
||||||
allowLocal = (allowLocal: boolean) => this.clone({allowLocal})
|
allowLocal = (allowLocal: boolean) => this.clone({allowLocal})
|
||||||
|
|
||||||
|
allowOnion = (allowOnion: boolean) => this.clone({allowOnion})
|
||||||
|
|
||||||
weight = (scale: number) =>
|
weight = (scale: number) =>
|
||||||
this.update(selection => ({...selection, weight: selection.weight * scale}))
|
this.update(selection => ({...selection, weight: selection.weight * scale}))
|
||||||
|
|
||||||
@@ -273,9 +279,11 @@ export class RouterScenario {
|
|||||||
|
|
||||||
for (const {weight, relays} of this.selections) {
|
for (const {weight, relays} of this.selections) {
|
||||||
for (const relay of relays) {
|
for (const relay of relays) {
|
||||||
if (this.options.allowLocal ? isRelayUrl(relay) : isShareableRelayUrl(relay)) {
|
if (!isRelayUrl(relay)) continue
|
||||||
relayWeights.set(relay, add(weight, relayWeights.get(relay)))
|
if (!this.options.allowOnion && isOnionUrl(relay)) continue
|
||||||
}
|
if (!this.options.allowLocal && isLocalUrl(relay)) continue
|
||||||
|
|
||||||
|
relayWeights.set(relay, add(weight, relayWeights.get(relay)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,6 +330,10 @@ export const getRelayQuality = (url: string) => {
|
|||||||
if (relay.stats.recent_errors.filter(n => n > ago(WEEK)).length > 100) return 0
|
if (relay.stats.recent_errors.filter(n => n > ago(WEEK)).length > 100) return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isIPAddress(url)) {
|
||||||
|
return 0.5
|
||||||
|
}
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ export const THREAD = 11
|
|||||||
export const SEAL = 13
|
export const SEAL = 13
|
||||||
export const DIRECT_MESSAGE = 14
|
export const DIRECT_MESSAGE = 14
|
||||||
export const GENERIC_REPOST = 16
|
export const GENERIC_REPOST = 16
|
||||||
|
export const PICTURE_FIRST = 20
|
||||||
export const CHANNEL_CREATE = 40
|
export const CHANNEL_CREATE = 40
|
||||||
export const CHANNEL_UPDATE = 41
|
export const CHANNEL_UPDATE = 41
|
||||||
export const CHANNEL_MESSAGE = 42
|
export const CHANNEL_MESSAGE = 42
|
||||||
|
|||||||
@@ -39,6 +39,10 @@ export const isRelayUrl = (url: string) => {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!url.match(/\./)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
new URL(url)
|
new URL(url)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -48,16 +52,14 @@ export const isRelayUrl = (url: string) => {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isOnionUrl = (url: string) => Boolean(stripProtocol(url).match(/^[a-z2-7]{56}.onion$/))
|
export const isOnionUrl = (url: string) => Boolean(stripProtocol(url).match(/^[a-z2-7]{56}.onion/))
|
||||||
|
|
||||||
export const isLocalhostUrl = (url: string) => Boolean(stripProtocol(url).match(/^localhost:/))
|
export const isLocalUrl = (url: string) =>
|
||||||
|
Boolean(url.match(/\.local(:[\d]+)?\/?$/) || stripProtocol(url).match(/^localhost:/))
|
||||||
export const isLocalUrl = (url: string) => Boolean(url.match(/\.local(:[\d]+)?\/?$/))
|
|
||||||
|
|
||||||
export const isIPAddress = (url: string) => Boolean(url.match(/\d+\.\d+\.\d+\.\d+/))
|
export const isIPAddress = (url: string) => Boolean(url.match(/\d+\.\d+\.\d+\.\d+/))
|
||||||
|
|
||||||
export const isShareableRelayUrl = (url: string) =>
|
export const isShareableRelayUrl = (url: string) => Boolean(isRelayUrl(url) && !isLocalUrl(url))
|
||||||
Boolean(isRelayUrl(url) && !isLocalUrl(url) && !isLocalhostUrl(url))
|
|
||||||
|
|
||||||
export const normalizeRelayUrl = (url: string) => {
|
export const normalizeRelayUrl = (url: string) => {
|
||||||
const prefix = url.match(/^wss?:\/\//)?.[0] || "wss://"
|
const prefix = url.match(/^wss?:\/\//)?.[0] || "wss://"
|
||||||
|
|||||||
Reference in New Issue
Block a user