Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FinClip
ligase
提交
90396b56
ligase
项目概览
FinClip
/
ligase
通知
33
Star
8
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
ligase
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
90396b56
编写于
11月 09, 2017
作者:
M
Michael Telatynski
提交者:
Erik Johnston
11月 09, 2017
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
implement voip/turnServer API endpoint (#323)
Signed-off-by:
N
Michael Telatynski
<
7t3chguy@gmail.com
>
上级
b7cfc2e0
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
135 addition
and
6 deletion
+135
-6
dendrite-config.yaml
dendrite-config.yaml
+18
-0
src/github.com/matrix-org/dendrite/clientapi/routing/routing.go
...thub.com/matrix-org/dendrite/clientapi/routing/routing.go
+2
-6
src/github.com/matrix-org/dendrite/clientapi/routing/voip.go
src/github.com/matrix-org/dendrite/clientapi/routing/voip.go
+85
-0
src/github.com/matrix-org/dendrite/common/config/config.go
src/github.com/matrix-org/dendrite/common/config/config.go
+30
-0
未找到文件。
dendrite-config.yaml
浏览文件 @
90396b56
...
...
@@ -54,6 +54,24 @@ media:
height
:
600
method
:
scale
# The config for the TURN server
turn
:
# Whether or not guests can request TURN credentials
turn_allow_guests
:
true
# How long the authorization should last
turn_user_lifetime
:
"
1h"
# The list of TURN URIs to pass to clients
turn_uris
:
[]
# Authorization via Shared Secret
# The shared secret from coturn
turn_shared_secret
:
"
<SECRET
STRING
GOES
HERE>"
# Authorization via Static Username & Password
# Hardcoded Username and Password
turn_username
:
"
"
turn_password
:
"
"
# The config for communicating with kafka
kafka
:
# Where the kafka servers are running.
...
...
src/github.com/matrix-org/dendrite/clientapi/routing/routing.go
浏览文件 @
90396b56
...
...
@@ -284,12 +284,8 @@ func Setup(
)
.
Methods
(
"PUT"
,
"OPTIONS"
)
r0mux
.
Handle
(
"/voip/turnServer"
,
common
.
MakeExternalAPI
(
"turn_server"
,
func
(
req
*
http
.
Request
)
util
.
JSONResponse
{
// TODO: Return credentials for a turn server if one is configured.
return
util
.
JSONResponse
{
Code
:
200
,
JSON
:
struct
{}{},
}
common
.
MakeAuthAPI
(
"turn_server"
,
deviceDB
,
func
(
req
*
http
.
Request
,
device
*
authtypes
.
Device
)
util
.
JSONResponse
{
return
RequestTurnServer
(
req
,
device
,
cfg
)
}),
)
.
Methods
(
"GET"
)
...
...
src/github.com/matrix-org/dendrite/clientapi/routing/voip.go
0 → 100644
浏览文件 @
90396b56
// Copyright 2017 Michael Telatysnki <7t3chguy@gmail.com>
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package
routing
import
(
"net/http"
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"fmt"
"time"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/common/config"
"github.com/matrix-org/util"
"github.com/matrix-org/dendrite/clientapi/httputil"
)
type
turnServerResponse
struct
{
Username
string
`json:"username"`
Password
string
`json:"password"`
URIs
[]
string
`json:"uris"`
TTL
int
`json:"ttl"`
}
// RequestTurnServer implements:
// GET /voip/turnServer
func
RequestTurnServer
(
req
*
http
.
Request
,
device
*
authtypes
.
Device
,
cfg
config
.
Dendrite
)
util
.
JSONResponse
{
turnConfig
:=
cfg
.
TURN
// TODO Guest Support
if
len
(
turnConfig
.
URIs
)
==
0
||
turnConfig
.
UserLifetime
==
""
{
return
util
.
JSONResponse
{
Code
:
200
,
JSON
:
struct
{}{},
}
}
// Duration checked at startup, err not possible
duration
,
_
:=
time
.
ParseDuration
(
turnConfig
.
UserLifetime
)
resp
:=
turnServerResponse
{
URIs
:
turnConfig
.
URIs
,
TTL
:
int
(
duration
.
Seconds
()),
}
if
turnConfig
.
SharedSecret
!=
""
{
expiry
:=
time
.
Now
()
.
Add
(
duration
)
.
Unix
()
mac
:=
hmac
.
New
(
sha1
.
New
,
[]
byte
(
turnConfig
.
SharedSecret
))
_
,
err
:=
mac
.
Write
([]
byte
(
resp
.
Username
))
if
err
!=
nil
{
return
httputil
.
LogThenError
(
req
,
err
)
}
resp
.
Username
=
fmt
.
Sprintf
(
"%d:%s"
,
expiry
,
device
.
UserID
)
resp
.
Password
=
base64
.
StdEncoding
.
EncodeToString
(
mac
.
Sum
(
nil
))
}
else
if
turnConfig
.
Username
!=
""
&&
turnConfig
.
Password
!=
""
{
resp
.
Username
=
turnConfig
.
Username
resp
.
Password
=
turnConfig
.
Password
}
else
{
return
util
.
JSONResponse
{
Code
:
200
,
JSON
:
struct
{}{},
}
}
return
util
.
JSONResponse
{
Code
:
200
,
JSON
:
resp
,
}
}
src/github.com/matrix-org/dendrite/common/config/config.go
浏览文件 @
90396b56
...
...
@@ -150,6 +150,26 @@ type Dendrite struct {
PublicRoomsAPI
DataSource
`yaml:"public_rooms_api"`
}
`yaml:"database"`
// TURN Server Config
TURN
struct
{
// TODO Guest Support
// Whether or not guests can request TURN credentials
//AllowGuests bool `yaml:"turn_allow_guests"`
// How long the authorization should last
UserLifetime
string
`yaml:"turn_user_lifetime"`
// The list of TURN URIs to pass to clients
URIs
[]
string
`yaml:"turn_uris"`
// Authorization via Shared Secret
// The shared secret from coturn
SharedSecret
string
`yaml:"turn_shared_secret"`
// Authorization via Static Username & Password
// Hardcoded Username and Password
Username
string
`yaml:"turn_username"`
Password
string
`yaml:"turn_password"`
}
// The internal addresses the components will listen on.
// These should not be exposed externally as they expose metrics and debugging APIs.
Listen
struct
{
...
...
@@ -341,10 +361,20 @@ func (config *Dendrite) check(monolithic bool) error {
}
}
checkValidDuration
:=
func
(
key
,
value
string
)
{
if
_
,
err
:=
time
.
ParseDuration
(
config
.
TURN
.
UserLifetime
);
err
!=
nil
{
problems
=
append
(
problems
,
fmt
.
Sprintf
(
"invalid duration for config key %q: %s"
,
key
,
value
))
}
}
checkNotEmpty
(
"matrix.server_name"
,
string
(
config
.
Matrix
.
ServerName
))
checkNotEmpty
(
"matrix.private_key"
,
string
(
config
.
Matrix
.
PrivateKeyPath
))
checkNotZero
(
"matrix.federation_certificates"
,
int64
(
len
(
config
.
Matrix
.
FederationCertificatePaths
)))
if
config
.
TURN
.
UserLifetime
!=
""
{
checkValidDuration
(
"turn.turn_user_lifetime"
,
config
.
TURN
.
UserLifetime
)
}
checkNotEmpty
(
"media.base_path"
,
string
(
config
.
Media
.
BasePath
))
checkPositive
(
"media.max_file_size_bytes"
,
int64
(
*
config
.
Media
.
MaxFileSizeBytes
))
checkPositive
(
"media.max_thumbnail_generators"
,
int64
(
config
.
Media
.
MaxThumbnailGenerators
))
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录