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

Function AddTmpAuthInfo

clientapi/routing/voip.go:142–201  ·  view source on GitHub ↗

AddTmpAuthInfo implements: POST /voip/turnAuthTmpAdd

(profileAPI userapi.ClientUserAPI, req *http.Request, device *api.Device, cfg *config.ClientAPI)

Source from the content-addressed store, hash-verified

140
141// POST /voip/turnAuthTmpAdd
142func AddTmpAuthInfo(profileAPI userapi.ClientUserAPI, req *http.Request, device *api.Device, cfg *config.ClientAPI) util.JSONResponse {
143 turnConfig := cfg.TURN
144 // Duration checked at startup, err not possible
145 if len(turnConfig.URIs) == 0 || turnConfig.UserLifetime == "" {
146 return jsonerror.InternalServerError()
147 }
148 turnHost = strings.Split(turnConfig.URIs[0], ":")[1]
149 duration, _ := time.ParseDuration(turnConfig.UserLifetime)
150 resp := gomatrix.RespTurnServer{
151 URIs: turnConfig.URIs,
152 TTL: int(duration.Seconds()),
153 }
154 resp.Username = device.UserID
155 resp.Password = util.RandomString(8)
156
157 // limit ,limit
158 limit := int64(5)
159 if cfg.Matrix.Mode == "chain" {
160 res := &userapi.QueryProfileResponse{}
161 err := profileAPI.QueryProfile(req.Context(), &userapi.QueryProfileRequest{UserID: device.UserID}, res)
162 if err != nil {
163 return util.JSONResponse{
164 Code: http.StatusInternalServerError,
165 JSON: jsonerror.Unknown("QueryProfile"),
166 }
167 }
168 limit, err = internal.CalcLimit(res.MortgageFee)
169 if err != nil {
170 return util.JSONResponse{
171 Code: http.StatusInternalServerError,
172 JSON: jsonerror.Unknown("CalcLimit"),
173 }
174 }
175 }
176 apiClient := getHttpClient(time.Second * 5)
177 defer apiClient.CloseIdleConnections()
178 reqHttp := turnReq{}
179 reqHttp.Username = device.UserID
180 reqHttp.Realm = "dendrite"
181 reqHttp.Password = resp.Password
182 reqHttp.Limit = limit
183
184 respHttp := turnReq{}
185
186 if err := PostJSON(req.Context(), &apiClient, fmt.Sprintf("http://%s:23478/turn/addTmpAuth", turnHost), reqHttp, &respHttp); err != nil {
187 return util.JSONResponse{
188 Code: http.StatusInternalServerError,
189 JSON: jsonerror.Unknown("PostJSON"),
190 }
191 }
192
193 //if err := turn_server.AddTmpAuth(resp.Username, "dendrite", resp.Password, 5); err != nil {
194 // return jsonerror.InternalServerError()
195 //}
196
197 return util.JSONResponse{
198 Code: http.StatusOK,
199 JSON: resp,

Callers 1

SetupFunction · 0.85

Calls 5

getHttpClientFunction · 0.85
SplitMethod · 0.80
ContextMethod · 0.80
PostJSONFunction · 0.70
QueryProfileMethod · 0.65

Tested by

no test coverage detected