Change server list to joinmatrix.org's

This commit is contained in:
plate 2022-08-29 11:03:32 +00:00 committed by Maze
parent 7e9cc8df50
commit 4869c3b019
3 changed files with 9 additions and 79 deletions

View File

@ -507,33 +507,6 @@ class Backend:
ping=sum(times) // len(times), status=PingStatus.Done,
)
def _get_homeserver_stability(
self, logs: List[Dict[str, Any]],
) -> Tuple[float, List[timedelta]]:
"""Return server stability % and a list of downtime durations."""
stability = 100.0
durations = []
for period in logs:
started_at = datetime.fromtimestamp(period["datetime"])
time_since_now = datetime.now() - started_at
if time_since_now.days > 30 or period["type"] != 1: # 1 = downtime
continue
lasted_minutes = period["duration"] / 60
durations.append(timedelta(seconds=period["duration"]))
stability -= (
(lasted_minutes * stability / 1000) /
max(1, time_since_now.days / 3)
)
return (stability, durations)
async def fetch_homeservers(self) -> None:
"""Retrieve a list of public homeservers and add them to our model."""
@ -557,7 +530,7 @@ class Backend:
connector = session.connector,
)
api_list = "https://publiclist.anchel.nl/publiclist.json"
api_list = "https://joinmatrix.org/servers.json"
try:
response = await session.get(api_list)
except:
@ -568,27 +541,19 @@ class Backend:
coros = []
for server in (await response.json()):
homeserver_url = server["homeserver"]
homeserver_url = "https://" + server["domain"]
if homeserver_url.startswith("http://"): # insecure server
if not server["open"]: # ignore closed servers
continue
if not re.match(r"^https?://.+", homeserver_url):
homeserver_url = f"https://{homeserver_url}"
if server["country"] == "USA":
server["country"] = "United States"
stability, durations = \
self._get_homeserver_stability(server["monitor"]["logs"])
self.models["homeservers"][homeserver_url] = Homeserver(
id = homeserver_url,
name = server["name"],
site_url = server["url"],
country = server["country"],
stability = stability,
downtimes_ms = [d.total_seconds() * 1000 for d in durations],
site_url = server["domain"],
country = server["jurisdiction"],
stability = 0,
downtimes_ms = 0,
# austin's list doesn't have stability/downtime
)
coros.append(self._ping_homeserver(session, homeserver_url))

View File

@ -115,7 +115,6 @@ HBox {
model: [
qsTr("Ping"),
qsTr("Name & location"),
qsTr("Stability"),
qsTr("Site"),
]

View File

@ -66,44 +66,10 @@ HTile {
}
}
TitleRightInfoLabel {
tile: root
font.pixelSize: theme.fontSize.normal
text:
model.stability === -1 ?
"" :
qsTr("%1%").arg(Math.max(0, parseInt(model.stability, 10)))
color:
model.stability >= 95 ? theme.colors.positiveText :
model.stability >= 85 ? theme.colors.warningText :
theme.colors.errorText
HoverHandler { id: rightInfoHover }
HToolTip {
readonly property var times: JSON.parse(model.downtimes_ms)
readonly property real total: utils.sum(times)
visible: model.stability !== -1 && rightInfoHover.hovered
text:
total === 0 ?
qsTr("No downtimes in the last 30 days") :
qsTr(
"Last 30 days downtimes: %1, average: %2, " +
"longest: %3, total: %4"
).arg(times.length)
.arg(utils.formatRelativeTime(total / times.length))
.arg(utils.formatRelativeTime(Math.max.apply(Math,times)))
.arg(utils.formatRelativeTime(total))
}
}
HButton {
icon.name: "server-visit-website"
backgroundColor: "transparent"
onClicked: Qt.openUrlExternally(model.site_url)
onClicked: Qt.openUrlExternally("https://"+model.site_url)
Layout.fillHeight: true
}