mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-09 22:42:58 +00:00
ff21675c5b
* Initial work on signing key update EDUs * Fix build * Produce/consume EDUs * Producer logging * Only produce key change notifications for local users * Better naming * Try to notify sync * Enable feature * Use key change topic * Don't bother verifying signatures, validate key lengths if we can, notifier fixes * Copyright notices * Remove tests from whitelist until matrix-org/sytest#1117 * Some review comment fixes * Update to matrix-org/gomatrixserverlib@f9416ac * Remove unneeded parameter
85 lines
2.8 KiB
Go
85 lines
2.8 KiB
Go
package inthttp
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"net/http"
|
|
|
|
"github.com/matrix-org/dendrite/eduserver/api"
|
|
"github.com/matrix-org/dendrite/internal/httputil"
|
|
"github.com/opentracing/opentracing-go"
|
|
)
|
|
|
|
// HTTP paths for the internal HTTP APIs
|
|
const (
|
|
EDUServerInputTypingEventPath = "/eduserver/input"
|
|
EDUServerInputSendToDeviceEventPath = "/eduserver/sendToDevice"
|
|
EDUServerInputReceiptEventPath = "/eduserver/receipt"
|
|
EDUServerInputCrossSigningKeyUpdatePath = "/eduserver/crossSigningKeyUpdate"
|
|
)
|
|
|
|
// NewEDUServerClient creates a EDUServerInputAPI implemented by talking to a HTTP POST API.
|
|
func NewEDUServerClient(eduServerURL string, httpClient *http.Client) (api.EDUServerInputAPI, error) {
|
|
if httpClient == nil {
|
|
return nil, errors.New("NewEDUServerClient: httpClient is <nil>")
|
|
}
|
|
return &httpEDUServerInputAPI{eduServerURL, httpClient}, nil
|
|
}
|
|
|
|
type httpEDUServerInputAPI struct {
|
|
eduServerURL string
|
|
httpClient *http.Client
|
|
}
|
|
|
|
// InputTypingEvent implements EDUServerInputAPI
|
|
func (h *httpEDUServerInputAPI) InputTypingEvent(
|
|
ctx context.Context,
|
|
request *api.InputTypingEventRequest,
|
|
response *api.InputTypingEventResponse,
|
|
) error {
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "InputTypingEvent")
|
|
defer span.Finish()
|
|
|
|
apiURL := h.eduServerURL + EDUServerInputTypingEventPath
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
}
|
|
|
|
// InputSendToDeviceEvent implements EDUServerInputAPI
|
|
func (h *httpEDUServerInputAPI) InputSendToDeviceEvent(
|
|
ctx context.Context,
|
|
request *api.InputSendToDeviceEventRequest,
|
|
response *api.InputSendToDeviceEventResponse,
|
|
) error {
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "InputSendToDeviceEvent")
|
|
defer span.Finish()
|
|
|
|
apiURL := h.eduServerURL + EDUServerInputSendToDeviceEventPath
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
}
|
|
|
|
// InputSendToDeviceEvent implements EDUServerInputAPI
|
|
func (h *httpEDUServerInputAPI) InputReceiptEvent(
|
|
ctx context.Context,
|
|
request *api.InputReceiptEventRequest,
|
|
response *api.InputReceiptEventResponse,
|
|
) error {
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "InputReceiptEventPath")
|
|
defer span.Finish()
|
|
|
|
apiURL := h.eduServerURL + EDUServerInputReceiptEventPath
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
}
|
|
|
|
// InputCrossSigningKeyUpdate implements EDUServerInputAPI
|
|
func (h *httpEDUServerInputAPI) InputCrossSigningKeyUpdate(
|
|
ctx context.Context,
|
|
request *api.InputCrossSigningKeyUpdateRequest,
|
|
response *api.InputCrossSigningKeyUpdateResponse,
|
|
) error {
|
|
span, ctx := opentracing.StartSpanFromContext(ctx, "InputCrossSigningKeyUpdate")
|
|
defer span.Finish()
|
|
|
|
apiURL := h.eduServerURL + EDUServerInputCrossSigningKeyUpdatePath
|
|
return httputil.PostJSON(ctx, span, h.httpClient, apiURL, request, response)
|
|
}
|