Skip to content

Commit

Permalink
Merge pull request #131 from nils-ohlmeier/anycast_warning
Browse files Browse the repository at this point in the history
Warn if not connected to Anycast
  • Loading branch information
third774 authored Oct 9, 2024
2 parents d953f06 + c82ea74 commit 222a7c6
Show file tree
Hide file tree
Showing 5 changed files with 345 additions and 324 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/semgrep.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
on:
pull_request: {}
workflow_dispatch: {}
push:
push:
branches:
- main
- master
Expand Down
25 changes: 25 additions & 0 deletions app/utils/rxjs/getPacketLossStats$.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Observable } from 'rxjs'
import { combineLatest, interval, map, pairwise, switchMap } from 'rxjs'
import Ewma from '~/utils/ewma'
import { mode } from '~/utils/mode'

export interface PacketLossStats {
inboundPacketLossPercentage: number
Expand All @@ -12,6 +13,7 @@ export function getPacketLossStats$(
) {
const inboundPacketLossPercentageEwma = new Ewma(2000, 0)
const outboundPacketLossPercentageEwma = new Ewma(2000, 0)
let anycastWarned = false
return combineLatest([peerConnection$, interval(1000)]).pipe(
switchMap(([peerConnection]) => peerConnection.getStats()),
pairwise(),
Expand All @@ -20,11 +22,34 @@ export function getPacketLossStats$(
let inboundPacketsLost = 0
let outboundPacketsSent = 0
let outboundPacketsLost = 0
let candidatePairID: string | undefined = undefined
let remoteCandidateID: string | undefined = undefined
let remoteAddress: string | undefined = undefined

newStatsReport.forEach((report) => {
const previous = previousStatsReport.get(report.id)
if (!previous) return

if (report.type === 'transport') {
candidatePairID = report.selectedCandidatePairId
}
if (candidatePairID) {
remoteCandidateID =
newStatsReport.get(candidatePairID)?.remoteCandidateId
}
if (remoteCandidateID) {
remoteAddress = newStatsReport.get(remoteCandidateID).address
}
if (remoteAddress !== undefined && remoteAddress !== '141.101.90.0') {
console.warn(
"PeerConnection doesn't appear to be connected to anycast 141.101.90.0"
)
if (mode === 'production' && !anycastWarned) {
alert('You are not connected to CF anycast address')
anycastWarned = true
}
}

if (report.type === 'inbound-rtp') {
inboundPacketsLost += report.packetsLost - previous.packetsLost
inboundPacketsReceived +=
Expand Down
230 changes: 115 additions & 115 deletions migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,116 +1,116 @@
{
"version": "6",
"dialect": "sqlite",
"id": "fe0342f9-5cae-44a5-86d3-368c43bf7869",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"AnalyticsRefreshes": {
"name": "AnalyticsRefreshes",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"created": {
"name": "created",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"modified": {
"name": "modified",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"deleted": {
"name": "deleted",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"version": {
"name": "version",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"AnalyticsSimpleCallFeedback": {
"name": "AnalyticsSimpleCallFeedback",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"created": {
"name": "created",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"modified": {
"name": "modified",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"deleted": {
"name": "deleted",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"version": {
"name": "version",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"experiencedIssues": {
"name": "experiencedIssues",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
"version": "6",
"dialect": "sqlite",
"id": "fe0342f9-5cae-44a5-86d3-368c43bf7869",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"AnalyticsRefreshes": {
"name": "AnalyticsRefreshes",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"created": {
"name": "created",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"modified": {
"name": "modified",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"deleted": {
"name": "deleted",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"version": {
"name": "version",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"AnalyticsSimpleCallFeedback": {
"name": "AnalyticsSimpleCallFeedback",
"columns": {
"id": {
"name": "id",
"type": "integer",
"primaryKey": true,
"notNull": true,
"autoincrement": true
},
"created": {
"name": "created",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"modified": {
"name": "modified",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"deleted": {
"name": "deleted",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"version": {
"name": "version",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"experiencedIssues": {
"name": "experiencedIssues",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
Loading

0 comments on commit 222a7c6

Please sign in to comment.