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