about summary refs log tree commit diff
path: root/LibMatrix
diff options
context:
space:
mode:
authorRory& <root@rory.gay>2024-02-23 11:23:27 +0000
committerRory& <root@rory.gay>2024-02-23 11:23:27 +0000
commit3dfb7b81b0fe19d37a7bf1183e248ca10c56277c (patch)
tree52c36b45c41e32cddd90dfcd110a393158f55675 /LibMatrix
parentApply syntax style to LibMatrix side projects (diff)
downloadLibMatrix-3dfb7b81b0fe19d37a7bf1183e248ca10c56277c.tar.xz
HS emulator
Diffstat (limited to '')
-rw-r--r--LibMatrix.sln7
-rw-r--r--LibMatrix/Homeservers/RemoteHomeServer.cs2
-rw-r--r--LibMatrix/MatrixException.cs2
-rw-r--r--LibMatrix/Services/HomeserverResolverService.cs18
4 files changed, 25 insertions, 4 deletions
diff --git a/LibMatrix.sln b/LibMatrix.sln
index f3eae7d..c068216 100644
--- a/LibMatrix.sln
+++ b/LibMatrix.sln
@@ -35,6 +35,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ArcaneLibs", "ArcaneLibs\Ar
 EndProject

 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.EventTypes", "LibMatrix.EventTypes\LibMatrix.EventTypes.csproj", "{CD13665B-B964-4AB0-991B-12F067B16DA3}"

 EndProject

+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMatrix.HomeserverEmulator", "Tests\LibMatrix.HomeserverEmulator\LibMatrix.HomeserverEmulator.csproj", "{D44DB78D-9BAD-4AB6-A054-839ECA9D68D2}"

+EndProject

 Global

 	GlobalSection(SolutionConfigurationPlatforms) = preSolution

 		Debug|Any CPU = Debug|Any CPU

@@ -92,6 +94,10 @@ Global
 		{CD13665B-B964-4AB0-991B-12F067B16DA3}.Debug|Any CPU.Build.0 = Debug|Any CPU

 		{CD13665B-B964-4AB0-991B-12F067B16DA3}.Release|Any CPU.ActiveCfg = Release|Any CPU

 		{CD13665B-B964-4AB0-991B-12F067B16DA3}.Release|Any CPU.Build.0 = Release|Any CPU

+		{D44DB78D-9BAD-4AB6-A054-839ECA9D68D2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU

+		{D44DB78D-9BAD-4AB6-A054-839ECA9D68D2}.Debug|Any CPU.Build.0 = Debug|Any CPU

+		{D44DB78D-9BAD-4AB6-A054-839ECA9D68D2}.Release|Any CPU.ActiveCfg = Release|Any CPU

+		{D44DB78D-9BAD-4AB6-A054-839ECA9D68D2}.Release|Any CPU.Build.0 = Release|Any CPU

 	EndGlobalSection

 	GlobalSection(NestedProjects) = preSolution

 		{1B1B2197-61FB-416F-B6C8-845F2E5A0442} = {840309F0-435B-43A7-8471-8C2BE643889D}

@@ -103,5 +109,6 @@ Global
 		{0B9B34D1-9362-45A9-9C21-816FD6959110} = {BFE16D8E-EFC5-49F6-9854-DB001309B3B4}

 		{4D9B5227-48DC-4A30-9263-AFB51DC01ABB} = {A6345ECE-4C5E-400F-9130-886E343BF314}

 		{13A797D1-7E13-4789-A167-8628B1641AC0} = {01A126FE-9D50-40F2-817B-E55F4065EA76}

+		{D44DB78D-9BAD-4AB6-A054-839ECA9D68D2} = {BFE16D8E-EFC5-49F6-9854-DB001309B3B4}

 	EndGlobalSection

 EndGlobal

diff --git a/LibMatrix/Homeservers/RemoteHomeServer.cs b/LibMatrix/Homeservers/RemoteHomeServer.cs
index 5c7d254..422a8a9 100644
--- a/LibMatrix/Homeservers/RemoteHomeServer.cs
+++ b/LibMatrix/Homeservers/RemoteHomeServer.cs
@@ -35,7 +35,7 @@ public class RemoteHomeserver(string baseUrl) {
 
         homeserver.ClientHttpClient = new MatrixHttpClient {
             BaseAddress = new Uri(proxy ?? homeserver.WellKnownUris.Client ?? throw new InvalidOperationException($"Failed to resolve homeserver client URI for {baseUrl}")),
-            Timeout = TimeSpan.FromSeconds(120)
+            Timeout = TimeSpan.FromSeconds(300)
         };
 
         homeserver.FederationClient = await FederationClient.TryCreate(baseUrl, proxy);
diff --git a/LibMatrix/MatrixException.cs b/LibMatrix/MatrixException.cs
index 86dbce4..8ec8fd5 100644
--- a/LibMatrix/MatrixException.cs
+++ b/LibMatrix/MatrixException.cs
@@ -20,7 +20,7 @@ public class MatrixException : Exception {
 
     public string RawContent { get; set; }
 
-    public object GetAsObject() => new { ErrorCode, Error, SoftLogout, RetryAfterMs };
+    public object GetAsObject() => new { errcode = ErrorCode, error = Error, soft_logout = SoftLogout, retry_after_ms = RetryAfterMs };
     public string GetAsJson() => GetAsObject().ToJson(ignoreNull: true);
 
     public override string Message =>
diff --git a/LibMatrix/Services/HomeserverResolverService.cs b/LibMatrix/Services/HomeserverResolverService.cs
index a4a18e5..bcef541 100644
--- a/LibMatrix/Services/HomeserverResolverService.cs
+++ b/LibMatrix/Services/HomeserverResolverService.cs
@@ -34,7 +34,14 @@ public class HomeserverResolverService(ILogger<HomeserverResolverService>? logge
     }
 
     private async Task<string?> _tryResolveFromClientWellknown(string homeserver) {
-        if (!homeserver.StartsWith("http")) homeserver = "https://" + homeserver;
+        if (!homeserver.StartsWith("http")) {
+            if (await _httpClient.CheckSuccessStatus($"https://{homeserver}/.well-known/matrix/client"))
+                homeserver = "https://" + homeserver;
+            else if (await _httpClient.CheckSuccessStatus($"http://{homeserver}/.well-known/matrix/client")) {
+                homeserver = "http://" + homeserver;
+            }
+        }
+
         try {
             var resp = await _httpClient.GetFromJsonAsync<JsonElement>($"{homeserver}/.well-known/matrix/client");
             var hs = resp.GetProperty("m.homeserver").GetProperty("base_url").GetString();
@@ -49,7 +56,14 @@ public class HomeserverResolverService(ILogger<HomeserverResolverService>? logge
     }
 
     private async Task<string?> _tryResolveFromServerWellknown(string homeserver) {
-        if (!homeserver.StartsWith("http")) homeserver = "https://" + homeserver;
+        if (!homeserver.StartsWith("http")) {
+            if (await _httpClient.CheckSuccessStatus($"https://{homeserver}/.well-known/matrix/server"))
+                homeserver = "https://" + homeserver;
+            else if (await _httpClient.CheckSuccessStatus($"http://{homeserver}/.well-known/matrix/server")) {
+                homeserver = "http://" + homeserver;
+            }
+        }
+
         try {
             var resp = await _httpClient.GetFromJsonAsync<JsonElement>($"{homeserver}/.well-known/matrix/server");
             var hs = resp.GetProperty("m.server").GetString();