Class FederationClient
Requests to other servers, signed with this server's key as FederationAuth describes.
Inherited Members
Namespace: Uniform.Matrix.Server.Federation
Assembly: Uniform.Matrix.Server.dll
Syntax
public sealed class FederationClient
Remarks
Errors of the other server come back as MatrixException with its error code; unreachable servers as 502.
Constructors
| Edit this page View SourceFederationClient(IHttpClientFactory, ServerResolver, ServerKeys, IOptionsMonitor<ServerOptions>, IOptionsMonitor<FederationOptions>, ILogger<FederationClient>)
Create the client.
Declaration
public FederationClient(IHttpClientFactory httpClients, ServerResolver resolver, ServerKeys keys, IOptionsMonitor<ServerOptions> server, IOptionsMonitor<FederationOptions> options, ILogger<FederationClient> logger)
Parameters
| Type | Name | Description |
|---|---|---|
| IHttpClientFactory | httpClients | |
| ServerResolver | resolver | |
| ServerKeys | keys | |
| IOptionsMonitor<ServerOptions> | server | |
| IOptionsMonitor<FederationOptions> | options | |
| ILogger<FederationClient> | logger |
Fields
| Edit this page View SourceHttpClientName
Name of the HTTP client that reaches other servers.
Declaration
public const string HttpClientName = "Uniform.Matrix.Server.Federation"
Field Value
| Type | Description |
|---|---|
| string |
Methods
| Edit this page View SourceCreateHandler(IOptionsMonitor<FederationOptions>)
Return the HTTP handler of the federation client: it connects only to public addresses unless AllowPrivateAddresses is on.
Declaration
public static SocketsHttpHandler CreateHandler(IOptionsMonitor<FederationOptions> options)
Parameters
| Type | Name | Description |
|---|---|---|
| IOptionsMonitor<FederationOptions> | options |
Returns
| Type | Description |
|---|---|
| SocketsHttpHandler |
DownloadAsync<T>(string, string, Func<HttpResponseMessage, CancellationToken, Task<T>>, CancellationToken, bool)
Send a GET to destination and hand a successful answer to read while its body streams, e.g. to store media; errors come back as MatrixException as in SendAsync(HttpMethod, string, string, JsonNode?, CancellationToken, bool, TimeSpan?).
Declaration
public Task<T> DownloadAsync<T>(string destination, string pathAndQuery, Func<HttpResponseMessage, CancellationToken, Task<T>> read, CancellationToken cancellationToken, bool signed = true)
Parameters
| Type | Name | Description |
|---|---|---|
| string | destination | Server name. |
| string | pathAndQuery | Escaped path and query. |
| Func<HttpResponseMessage, CancellationToken, Task<T>> | read | Reads the answer; it runs within the time limit. |
| CancellationToken | cancellationToken | Cancellation token. |
| bool | signed | Whether to sign; the legacy media downloads are not signed. |
Returns
| Type | Description |
|---|---|
| Task<T> |
Type Parameters
| Name | Description |
|---|---|
| T |
SendAsync(HttpMethod, string, string, JsonNode?, CancellationToken, bool, TimeSpan?)
Send a request to destination and return its JSON answer.
Declaration
public Task<JsonNode?> SendAsync(HttpMethod method, string destination, string pathAndQuery, JsonNode? content, CancellationToken cancellationToken, bool signed = true, TimeSpan? timeout = null)
Parameters
| Type | Name | Description |
|---|---|---|
| HttpMethod | method | HTTP method. |
| string | destination | Server name. |
| string | pathAndQuery | Escaped path and query, e.g. |
| JsonNode | content | JSON body, or null. |
| CancellationToken | cancellationToken | Cancellation token. |
| bool | signed | Whether to sign; key requests are not signed. |
| TimeSpan? | timeout | How long to wait for the answer; RequestTimeout when null. |
Returns
| Type | Description |
|---|---|
| Task<JsonNode> |