Merge branch 'new-server-list' into 'dev'

Change server list to joinmatrix.org's

See merge request mx-moment/moment!18
This commit is contained in:
Maze 2022-08-29 11:03:32 +00:00
commit 6ec7efc35e
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, 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: async def fetch_homeservers(self) -> None:
"""Retrieve a list of public homeservers and add them to our model.""" """Retrieve a list of public homeservers and add them to our model."""
@ -557,7 +530,7 @@ class Backend:
connector = session.connector, connector = session.connector,
) )
api_list = "https://publiclist.anchel.nl/publiclist.json" api_list = "https://joinmatrix.org/servers.json"
try: try:
response = await session.get(api_list) response = await session.get(api_list)
except: except:
@ -568,27 +541,19 @@ class Backend:
coros = [] coros = []
for server in (await response.json()): 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 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( self.models["homeservers"][homeserver_url] = Homeserver(
id = homeserver_url, id = homeserver_url,
name = server["name"], name = server["name"],
site_url = server["url"], site_url = server["domain"],
country = server["country"], country = server["jurisdiction"],
stability = stability, stability = 0,
downtimes_ms = [d.total_seconds() * 1000 for d in durations], downtimes_ms = 0,
# austin's list doesn't have stability/downtime
) )
coros.append(self._ping_homeserver(session, homeserver_url)) coros.append(self._ping_homeserver(session, homeserver_url))

View File

@ -115,7 +115,6 @@ HBox {
model: [ model: [
qsTr("Ping"), qsTr("Ping"),
qsTr("Name & location"), qsTr("Name & location"),
qsTr("Stability"),
qsTr("Site"), 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 { HButton {
icon.name: "server-visit-website" icon.name: "server-visit-website"
backgroundColor: "transparent" backgroundColor: "transparent"
onClicked: Qt.openUrlExternally(model.site_url) onClicked: Qt.openUrlExternally("https://"+model.site_url)
Layout.fillHeight: true Layout.fillHeight: true
} }