MCPcopy Create free account
hub / github.com/daodst/chat / Setup

Function Setup

federationapi/routing/routing.go:51–500  ·  view source on GitHub ↗

Setup registers HTTP handlers with the given ServeMux. The provided publicAPIMux MUST have `UseEncodedPath()` enabled or else routes will incorrectly path unescape twice (once from the router, once from MakeFedAPI). We need to have this enabled so we can decode paths like foo/bar%2Fbaz as [foo, bar/

(
	fedMux, keyMux, wkMux *mux.Router,
	cfg *config.FederationAPI,
	rsAPI roomserverAPI.FederationRoomserverAPI,
	fsAPI *fedInternal.FederationInternalAPI,
	keys gomatrixserverlib.JSONVerifier,
	federation federationAPI.FederationClient,
	userAPI userapi.FederationUserAPI,
	keyAPI keyserverAPI.FederationKeyAPI,
	mscCfg *config.MSCs,
	servers federationAPI.ServersInRoomProvider,
	producer *producers.SyncAPIProducer,
)

Source from the content-addressed store, hash-verified

49// applied:
50// nolint: gocyclo
51func Setup(
52 fedMux, keyMux, wkMux *mux.Router,
53 cfg *config.FederationAPI,
54 rsAPI roomserverAPI.FederationRoomserverAPI,
55 fsAPI *fedInternal.FederationInternalAPI,
56 keys gomatrixserverlib.JSONVerifier,
57 federation federationAPI.FederationClient,
58 userAPI userapi.FederationUserAPI,
59 keyAPI keyserverAPI.FederationKeyAPI,
60 mscCfg *config.MSCs,
61 servers federationAPI.ServersInRoomProvider,
62 producer *producers.SyncAPIProducer,
63) {
64 prometheus.MustRegister(
65 pduCountTotal, eduCountTotal,
66 )
67
68 v2keysmux := keyMux.PathPrefix("/v2").Subrouter()
69 v1fedmux := fedMux.PathPrefix("/v1").Subrouter()
70 v2fedmux := fedMux.PathPrefix("/v2").Subrouter()
71
72 wakeup := &FederationWakeups{
73 FsAPI: fsAPI,
74 }
75
76 localKeys := httputil.MakeExternalAPI("localkeys", func(req *http.Request) util.JSONResponse {
77 return LocalKeys(cfg)
78 })
79
80 notaryKeys := httputil.MakeExternalAPI("notarykeys", func(req *http.Request) util.JSONResponse {
81 vars, err := httputil.URLDecodeMapValues(mux.Vars(req))
82 if err != nil {
83 return util.ErrorResponse(err)
84 }
85 var pkReq *gomatrixserverlib.PublicKeyNotaryLookupRequest
86 serverName := gomatrixserverlib.ServerName(vars["serverName"])
87 keyID := gomatrixserverlib.KeyID(vars["keyID"])
88 if serverName != "" && keyID != "" {
89 pkReq = &gomatrixserverlib.PublicKeyNotaryLookupRequest{
90 ServerKeys: map[gomatrixserverlib.ServerName]map[gomatrixserverlib.KeyID]gomatrixserverlib.PublicKeyNotaryQueryCriteria{
91 serverName: {
92 keyID: gomatrixserverlib.PublicKeyNotaryQueryCriteria{},
93 },
94 },
95 }
96 }
97 return NotaryKeys(req, cfg, fsAPI, pkReq)
98 })
99
100 if cfg.Matrix.WellKnownServerName != "" {
101 logrus.Infof("Setting m.server as %s at /.well-known/matrix/server", cfg.Matrix.WellKnownServerName)
102 wkMux.Handle("/server", httputil.MakeExternalAPI("wellknown", func(req *http.Request) util.JSONResponse {
103 return util.JSONResponse{
104 Code: http.StatusOK,
105 JSON: struct {
106 ServerName string `json:"m.server"`
107 }{
108 ServerName: cfg.Matrix.WellKnownServerName,

Callers

nothing calls this directly

Calls 15

LocalKeysFunction · 0.85
NotaryKeysFunction · 0.85
MakeFedAPIFunction · 0.85
SendFunction · 0.85
InviteV1Function · 0.85
InviteV2Function · 0.85
ExchangeThirdPartyInviteFunction · 0.85
GetStateFunction · 0.85
GetStateIDsFunction · 0.85
GetEventAuthFunction · 0.85
RoomAliasToIDFunction · 0.85

Tested by

no test coverage detected