Skip to content

Commit ff65890

Browse files
committed
Add id parameter to appservice ping
1 parent c036250 commit ff65890

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

appservice/http.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,19 @@ func (as *AppService) PostPing(w http.ResponseWriter, r *http.Request) {
295295
if !as.CheckServerToken(w, r) {
296296
return
297297
}
298+
body, err := io.ReadAll(r.Body)
299+
if err != nil || len(body) == 0 || !json.Valid(body) {
300+
Error{
301+
ErrorCode: ErrNotJSON,
302+
HTTPStatus: http.StatusBadRequest,
303+
Message: "Missing request body",
304+
}.Write(w)
305+
return
306+
}
307+
308+
var txn mautrix.ReqAppservicePing
309+
_ = json.Unmarshal(body, &txn)
310+
as.Log.Debug().Str("txn_id", txn.TxnID).Msg("Received ping from homeserver")
298311

299312
w.Header().Add("Content-Type", "application/json")
300313
w.WriteHeader(http.StatusOK)

bridge/bridge.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,9 +302,10 @@ func (br *Bridge) ensureConnection() {
302302
}
303303

304304
if br.SpecVersions.UnstableFeatures["fi.mau.msc2659"] && br.AS.Host.Port != 0 {
305-
resp, err := br.Bot.AppservicePing()
305+
txnID := br.Bot.TxnID()
306+
resp, err := br.Bot.AppservicePing(br.Config.AppService.ID, txnID)
306307
if err != nil {
307-
evt := br.ZLog.WithLevel(zerolog.FatalLevel).Err(err)
308+
evt := br.ZLog.WithLevel(zerolog.FatalLevel).Err(err).Str("txn_id", txnID)
308309
var httpErr mautrix.HTTPError
309310
if errors.As(err, &httpErr) && httpErr.RespError != nil {
310311
if val, ok := httpErr.RespError.ExtraData["body"].(string); ok {
@@ -320,7 +321,10 @@ func (br *Bridge) ensureConnection() {
320321
evt.Msg("Homeserver -> bridge connection is not working")
321322
os.Exit(13)
322323
}
323-
br.ZLog.Debug().Int64("duration_ms", resp.DurationMS).Msg("Homeserver -> bridge connection works")
324+
br.ZLog.Debug().
325+
Str("txn_id", txnID).
326+
Int64("duration_ms", resp.DurationMS).
327+
Msg("Homeserver -> bridge connection works")
324328
} else {
325329
br.ZLog.Debug().Msg("Homeserver does not support checking status of homeserver -> bridge connection")
326330
}

client.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,10 +1963,11 @@ func (cli *Client) BatchSend(roomID id.RoomID, req *ReqBatchSend) (resp *RespBat
19631963
return
19641964
}
19651965

1966-
func (cli *Client) AppservicePing() (resp *RespAppservicePing, err error) {
1966+
func (cli *Client) AppservicePing(id, txnID string) (resp *RespAppservicePing, err error) {
19671967
_, err = cli.MakeFullRequest(FullRequest{
19681968
Method: http.MethodPost,
1969-
URL: cli.BuildClientURL("unstable", "fi.mau.msc2659", "appservice", "ping"),
1969+
URL: cli.BuildClientURL("unstable", "fi.mau.msc2659", "appservice", id, "ping"),
1970+
RequestJSON: &ReqAppservicePing{TxnID: txnID},
19701971
ResponseJSON: &resp,
19711972
// This endpoint intentionally returns 50x, so don't retry
19721973
MaxAttempts: 1,

requests.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,10 @@ func (req *ReqHierarchy) Query() map[string]string {
392392
return query
393393
}
394394

395+
type ReqAppservicePing struct {
396+
TxnID string `json:"transaction_id,omitempty"`
397+
}
398+
395399
type ReqBeeperMergeRoom struct {
396400
NewRoom ReqCreateRoom `json:"create"`
397401
Key string `json:"key"`

0 commit comments

Comments
 (0)