mirror of
https://github.com/Monibuca/plugin-gb28181.git
synced 2025-12-24 13:27:57 +08:00
Compare commits
166 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
538e96a5c2 | ||
|
|
c2003d53e8 | ||
|
|
64ac75905f | ||
|
|
d2cc62ff9e | ||
|
|
2e8aa47bc5 | ||
|
|
585d5949d3 | ||
|
|
0285236cce | ||
|
|
12895fa2cc | ||
|
|
c66303e7e8 | ||
|
|
5435c2ef1c | ||
|
|
d8c6ad30dd | ||
|
|
86fa7cc7e6 | ||
|
|
692ec21877 | ||
|
|
71f2b36d2d | ||
|
|
b068bd9e5b | ||
|
|
78ac89e7af | ||
|
|
1cec5301c3 | ||
|
|
319f7fc636 | ||
|
|
7a75810203 | ||
|
|
bbc7b09835 | ||
|
|
1dbdff1fe5 | ||
|
|
952c8f0ff8 | ||
|
|
730f3014f8 | ||
|
|
682aec656b | ||
|
|
fbd8683f5b | ||
|
|
b15e4ee89c | ||
|
|
3c7b3a042d | ||
|
|
858df1377e | ||
|
|
60021d3cd9 | ||
|
|
d8061cd7c3 | ||
|
|
ed397063c4 | ||
|
|
5853120d30 | ||
|
|
4c47df0695 | ||
|
|
37fd121d11 | ||
|
|
05fd8c38f7 | ||
|
|
2d85e46a8b | ||
|
|
4a90d7bf91 | ||
|
|
a020f3ea81 | ||
|
|
c68862160f | ||
|
|
9db29a9280 | ||
|
|
5d5dae8939 | ||
|
|
a0f16d1184 | ||
|
|
53ddc0cb63 | ||
|
|
d156974f73 | ||
|
|
f3046bcde3 | ||
|
|
9c970ad282 | ||
|
|
c4de92e9f6 | ||
|
|
cf5a803971 | ||
|
|
f487be5fdb | ||
|
|
bd70d24a16 | ||
|
|
708cd042df | ||
|
|
a69b739e5e | ||
|
|
4e96efa9ff | ||
|
|
3a704b68cc | ||
|
|
c8f51a7ec5 | ||
|
|
b7bad99292 | ||
|
|
7b6b827899 | ||
|
|
d121927c96 | ||
|
|
9a3ad6a51c | ||
|
|
e0c6fbefcd | ||
|
|
b924977085 | ||
|
|
521ee36769 | ||
|
|
583754ea82 | ||
|
|
58b6a818bd | ||
|
|
8b1b176f51 | ||
|
|
68d6cbaab9 | ||
|
|
f88d4d264e | ||
|
|
55aa20e868 | ||
|
|
9f4ad83da7 | ||
|
|
68ff4dba5b | ||
|
|
e9f576e3f4 | ||
|
|
b271cb8e50 | ||
|
|
2b82a0ffc4 | ||
|
|
940d7c5e59 | ||
|
|
2142a474a3 | ||
|
|
86e9bccb85 | ||
|
|
bb3a679a60 | ||
|
|
ecd97c8439 | ||
|
|
bfd71a72d8 | ||
|
|
c6bef8ccd8 | ||
|
|
20c0ac52cb | ||
|
|
34f5b7da79 | ||
|
|
0d3a795dc2 | ||
|
|
b52d457990 | ||
|
|
4a214cebeb | ||
|
|
8f78f992ca | ||
|
|
228d7b0cd2 | ||
|
|
e99150b0be | ||
|
|
31112e0052 | ||
|
|
8663b8e171 | ||
|
|
5960f07fc3 | ||
|
|
eb6004d6ef | ||
|
|
cce5f67ab9 | ||
|
|
fdfb462d46 | ||
|
|
c05adce562 | ||
|
|
aa3727f582 | ||
|
|
6e8709176e | ||
|
|
3e6c43f6ff | ||
|
|
4a7aa94bd2 | ||
|
|
fd13c6d9ab | ||
|
|
085d413d2b | ||
|
|
4eba0e23f9 | ||
|
|
f0324c4283 | ||
|
|
f6b5f15b83 | ||
|
|
a6de68496b | ||
|
|
709988cf09 | ||
|
|
9cf8c1acc1 | ||
|
|
03bd17bd24 | ||
|
|
ed0b751e89 | ||
|
|
b8a2812c40 | ||
|
|
abd7b6ba77 | ||
|
|
a09080641d | ||
|
|
cf761e09d7 | ||
|
|
e4569c1dd7 | ||
|
|
50bfd5b390 | ||
|
|
e937325058 | ||
|
|
158c317511 | ||
|
|
e1a2587b48 | ||
|
|
8f2a90e8ac | ||
|
|
179280b67a | ||
|
|
35c8d5171f | ||
|
|
75342e5bb3 | ||
|
|
c742f226e9 | ||
|
|
11b9da4c9d | ||
|
|
490c85b46a | ||
|
|
5d7d81a46b | ||
|
|
eb53a9594a | ||
|
|
37b4774e9a | ||
|
|
64861c37b1 | ||
|
|
16b5fa375c | ||
|
|
ee419570a2 | ||
|
|
e110acfb56 | ||
|
|
07c4dd0c21 | ||
|
|
0299a9ef7e | ||
|
|
bbeae2bc9c | ||
|
|
b0a23ac3d2 | ||
|
|
7f69c61eaf | ||
|
|
d795e7c80a | ||
|
|
2033bdf04f | ||
|
|
79538986e5 | ||
|
|
438b0d2bd0 | ||
|
|
47c916e131 | ||
|
|
748c4117c6 | ||
|
|
11444a6398 | ||
|
|
ae6cb14536 | ||
|
|
957bdee6a4 | ||
|
|
9cf4607478 | ||
|
|
74241c20ab | ||
|
|
9d7b5feaf0 | ||
|
|
53551f3514 | ||
|
|
6e2bd0c146 | ||
|
|
60f9a18aca | ||
|
|
4bfd3103cc | ||
|
|
98bf9c6b32 | ||
|
|
cfed8a9d2f | ||
|
|
6cd4d8e51a | ||
|
|
dd5617737a | ||
|
|
616df4c2b1 | ||
|
|
b8fcfb0213 | ||
|
|
01c36d591c | ||
|
|
2143cc4911 | ||
|
|
931f8d888d | ||
|
|
c9709d0e48 | ||
|
|
61441cc372 | ||
|
|
803543fbdf | ||
|
|
03a2aeec2c |
145
README.md
145
README.md
@@ -10,41 +10,38 @@ github.com/Monibuca/plugin-gb28181
|
||||
|
||||
```go
|
||||
import (
|
||||
_ "github.com/Monibuca/plugin-gb28181"
|
||||
_ "m7s.live/plugin/gb28181/v4"
|
||||
)
|
||||
```
|
||||
|
||||
## 默认插件配置
|
||||
|
||||
```toml
|
||||
[GB28181]
|
||||
Serial = "34020000002000000001"
|
||||
Realm = "3402000000"
|
||||
Expires = 3600
|
||||
ListenAddr = "127.0.0.1:5060"
|
||||
AutoCloseAfter = -1
|
||||
AutoInvite = false
|
||||
MediaPort = 58200
|
||||
CatalogInterval = 30
|
||||
RemoveBanInterval = 600
|
||||
Username = ""
|
||||
Password = ""
|
||||
UdpCacheSize = 0
|
||||
TCP = false
|
||||
```yaml
|
||||
gb28181:
|
||||
invitemode: 1 #0、手动invite 1、表示自动发起invite,当Server(SIP)接收到设备信息时,立即向设备发送invite命令获取流,2、按需拉流,既等待订阅者触发
|
||||
position:
|
||||
autosubposition: false #是否自动订阅定位
|
||||
expires: 3600s #订阅周期(单位:秒),默认3600
|
||||
interval: 6s #订阅间隔(单位:秒),默认6
|
||||
udpcachesize: 0 #表示UDP缓存大小,默认为0,不开启。仅当TCP关闭,切缓存大于0时才开启
|
||||
sipip: "" #sip服务器地址 默认 自动适配设备网段
|
||||
serial: "34020000002000000001"
|
||||
realm: "3402000000"
|
||||
username: ""
|
||||
password: ""
|
||||
|
||||
registervalidity: 60s #注册有效期
|
||||
|
||||
mediaip: "" #媒体服务器地址 默认 自动适配设备网段
|
||||
port:
|
||||
sip: udp:5060 #sip服务器端口
|
||||
media: tcp:58200-59200 #媒体服务器端口,用于接收设备的流
|
||||
|
||||
removebaninterval: 10m #定时移除注册失败的设备黑名单,单位秒,默认10分钟(600秒)
|
||||
loglevel: info
|
||||
```
|
||||
|
||||
- `ListenAddr`是监听的地址,这里需要注意的是必须要带上Server的IP地址,这个IP地址是向设备发送信息的时候需要带上的。
|
||||
- `Serial` Server(SIP)的编号
|
||||
- `Realm` Server(SIP)的域
|
||||
- `AutoCloseAfter` 如果设置大于等于0,则当某个流最后一个订阅者取消订阅时会延迟N秒,会自动发送bye,节省流量。如果为了响应及时,可以设置成-1,保持流的连接
|
||||
- `AutoInvite` 表示自动发起invite,当Server(SIP)接收到设备信息时,立即向设备发送invite命令获取流
|
||||
- `MediaPort` 表示用于接收设备流的端口号
|
||||
- `CatalogInterval` 定时获取设备目录的间隔,单位秒
|
||||
- `RemoveBanInterval` 定时移除注册失败的设备黑名单,单位秒,默认10分钟(600秒)
|
||||
- `Username` 国标用户名
|
||||
- `Password` 国标密码
|
||||
- `TCP` 是否开启TCP接收国标流,默认false
|
||||
- `UdpCacheSize` 表示UDP缓存大小,默认为0,不开启。仅当TCP关闭,切缓存大于0时才开启,会最多缓存最多N个包,并排序,修复乱序造成的无法播放问题,注意开启后,会有一定的性能损耗,并丢失部分包。
|
||||
**如果配置了端口范围,将采用范围端口机制,每一个流对应一个端口
|
||||
|
||||
**注意某些摄像机没有设置用户名的地方,摄像机会以自身的国标id作为用户名,这个时候m7s会忽略使用摄像机的用户名,忽略配置的用户名**
|
||||
如果设备配置了错误的用户名和密码,连续三次上报错误后,m7s会记录设备id,并在10分钟内禁止设备注册
|
||||
@@ -58,6 +55,7 @@ TCP = false
|
||||
- 发送RecordInfo命令查询设备对录像数据
|
||||
- 发送Invite命令获取设备的实时视频或者录像视频
|
||||
- 发送PTZ命令来控制摄像头云台
|
||||
- 自动同步设备位置
|
||||
|
||||
### 作为GB28281的流媒体服务器接受设备的媒体流
|
||||
|
||||
@@ -72,25 +70,22 @@ TCP = false
|
||||
|
||||
### 罗列所有的gb28181协议的设备
|
||||
|
||||
`/api/gb28181/list`
|
||||
`/gb28181/api/list`
|
||||
设备的结构体如下
|
||||
|
||||
```go
|
||||
type Device struct {
|
||||
*transaction.Core `json:"-"`
|
||||
ID string
|
||||
RegisterTime time.Time
|
||||
UpdateTime time.Time
|
||||
Status string
|
||||
Channels []*Channel
|
||||
queryChannel bool
|
||||
sn int
|
||||
from *sip.Contact
|
||||
to *sip.Contact
|
||||
Addr string
|
||||
SipIP string //暴露的IP
|
||||
channelMap map[string]*Channel
|
||||
channelMutex sync.RWMutex
|
||||
ID string
|
||||
Name string
|
||||
Manufacturer string
|
||||
Model string
|
||||
Owner string
|
||||
RegisterTime time.Time
|
||||
UpdateTime time.Time
|
||||
LastKeepaliveAt time.Time
|
||||
Status string
|
||||
Channels []*Channel
|
||||
NetAddr string
|
||||
}
|
||||
```
|
||||
|
||||
@@ -98,43 +93,55 @@ channelMutex sync.RWMutex
|
||||
|
||||
### 从设备拉取视频流
|
||||
|
||||
`/api/gb28181/invite`
|
||||
`/gb28181/api/invite`
|
||||
|
||||
参数名 | 必传 | 含义
|
||||
|----|---|---
|
||||
id|是 | 设备ID
|
||||
channel|是|通道编号
|
||||
startTime|否|开始时间(纯数字Unix时间戳)
|
||||
endTime|否|结束时间(纯数字Unix时间戳)
|
||||
| 参数名 | 必传 | 含义 |
|
||||
| --------- | ---- | ---------------------------- |
|
||||
| id | 是 | 设备ID |
|
||||
| channel | 是 | 通道编号 |
|
||||
| startTime | 否 | 开始时间(纯数字Unix时间戳) |
|
||||
| endTime | 否 | 结束时间(纯数字Unix时间戳) |
|
||||
|
||||
返回200代表成功
|
||||
返回200代表成功, 304代表已经在拉取中,不能重复拉(仅仅针对直播流)
|
||||
|
||||
### 停止从设备拉流
|
||||
|
||||
`/api/gb28181/bye`
|
||||
`/gb28181/api/bye`
|
||||
|
||||
参数名 | 必传 | 含义
|
||||
|----|---|---
|
||||
id|是 | 设备ID
|
||||
channel|是|通道编号
|
||||
| 参数名 | 必传 | 含义 |
|
||||
| ------- | ---- | -------- |
|
||||
| id | 是 | 设备ID |
|
||||
| channel | 是 | 通道编号 |
|
||||
|
||||
http 200 表示成功,404流不存在
|
||||
|
||||
### 发送控制命令
|
||||
|
||||
`/api/gb28181/control`
|
||||
`/gb28181/api/control`
|
||||
|
||||
参数名 | 必传 | 含义
|
||||
|----|---|---
|
||||
id|是 | 设备ID
|
||||
channel|是|通道编号
|
||||
ptzcmd|是|PTZ控制指令
|
||||
| 参数名 | 必传 | 含义 |
|
||||
| ------- | ---- | ----------- |
|
||||
| id | 是 | 设备ID |
|
||||
| channel | 是 | 通道编号 |
|
||||
| ptzcmd | 是 | PTZ控制指令 |
|
||||
|
||||
### 查询录像
|
||||
|
||||
`/api/gb28181/query/records`
|
||||
`/gb28181/api/records`
|
||||
|
||||
参数名 | 必传 | 含义
|
||||
|----|---|---
|
||||
id|是 | 设备ID
|
||||
channel|是|通道编号
|
||||
startTime|否|开始时间(字符串,格式:2021-7-23T12:00:00)
|
||||
endTime|否|结束时间(字符串格式同上)
|
||||
| 参数名 | 必传 | 含义 |
|
||||
| --------- | ---- | -------------------------------------------- |
|
||||
| id | 是 | 设备ID |
|
||||
| channel | 是 | 通道编号 |
|
||||
| startTime | 否 | 开始时间(Unix时间戳) |
|
||||
| endTime | 否 | 结束时间(Unix时间戳) |
|
||||
|
||||
### 移动位置订阅
|
||||
|
||||
`/gb28181/api/position`
|
||||
|
||||
| 参数名 | 必传 | 含义 |
|
||||
| -------- | ---- | -------------- |
|
||||
| id | 是 | 设备ID |
|
||||
| expires | 是 | 订阅周期(秒) |
|
||||
| interval | 是 | 订阅间隔(秒) |
|
||||
|
||||
644
channel.go
644
channel.go
@@ -2,37 +2,126 @@ package gb28181
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/engine/v3"
|
||||
. "github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
"sync/atomic"
|
||||
|
||||
"github.com/ghettovoice/gosip/sip"
|
||||
"go.uber.org/zap"
|
||||
. "m7s.live/engine/v4"
|
||||
"m7s.live/engine/v4/log"
|
||||
"m7s.live/plugin/gb28181/v4/utils"
|
||||
"m7s.live/plugin/ps/v4"
|
||||
)
|
||||
|
||||
type ChannelEx struct {
|
||||
device *Device
|
||||
inviteRes *Response
|
||||
recordInviteRes *Response
|
||||
RecordPublisher *Publisher
|
||||
LivePublisher *Publisher
|
||||
LiveSubSP string //实时子码流
|
||||
Records []*Record
|
||||
RecordStartTime string
|
||||
RecordEndTime string
|
||||
recordStartTime time.Time
|
||||
recordEndTime time.Time
|
||||
state int32
|
||||
tcpPortIndex uint16
|
||||
var QUERY_RECORD_TIMEOUT = time.Second * 5
|
||||
|
||||
type PullStream struct {
|
||||
opt *InviteOptions
|
||||
channel *Channel
|
||||
inviteRes sip.Response
|
||||
}
|
||||
|
||||
func (p *PullStream) CreateRequest(method sip.RequestMethod) (req sip.Request) {
|
||||
res := p.inviteRes
|
||||
req = p.channel.CreateRequst(method)
|
||||
from, _ := res.From()
|
||||
to, _ := res.To()
|
||||
callId, _ := res.CallID()
|
||||
req.ReplaceHeaders(from.Name(), []sip.Header{from})
|
||||
req.ReplaceHeaders(to.Name(), []sip.Header{to})
|
||||
req.ReplaceHeaders(callId.Name(), []sip.Header{callId})
|
||||
return
|
||||
}
|
||||
|
||||
func (p *PullStream) Bye() int {
|
||||
req := p.CreateRequest(sip.BYE)
|
||||
resp, err := p.channel.device.SipRequestForResponse(req)
|
||||
if p.opt.IsLive() {
|
||||
p.channel.status.Store(0)
|
||||
}
|
||||
if p.opt.recyclePort != nil {
|
||||
p.opt.recyclePort(p.opt.MediaPort)
|
||||
}
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
return int(resp.StatusCode())
|
||||
}
|
||||
|
||||
func (p *PullStream) info(body string) int {
|
||||
d := p.channel.device
|
||||
req := p.CreateRequest(sip.INFO)
|
||||
contentType := sip.ContentType("Application/MANSRTSP")
|
||||
req.AppendHeader(&contentType)
|
||||
req.SetBody(body, true)
|
||||
|
||||
resp, err := d.SipRequestForResponse(req)
|
||||
if err != nil {
|
||||
log.Warnf("Send info to stream error: %v, stream=%s, body=%s", err, p.opt.StreamPath, body)
|
||||
return getSipRespErrorCode(err)
|
||||
}
|
||||
return int(resp.StatusCode())
|
||||
}
|
||||
|
||||
// 暂停播放
|
||||
func (p *PullStream) Pause() int {
|
||||
body := fmt.Sprintf(`PAUSE RTSP/1.0
|
||||
CSeq: %d
|
||||
PauseTime: now
|
||||
`, p.channel.device.sn)
|
||||
return p.info(body)
|
||||
}
|
||||
|
||||
// 恢复播放
|
||||
func (p *PullStream) Resume() int {
|
||||
d := p.channel.device
|
||||
body := fmt.Sprintf(`PLAY RTSP/1.0
|
||||
CSeq: %d
|
||||
Range: npt=now-
|
||||
`, d.sn)
|
||||
return p.info(body)
|
||||
}
|
||||
|
||||
// 跳转到播放时间
|
||||
// second: 相对于起始点调整到第 sec 秒播放
|
||||
func (p *PullStream) PlayAt(second uint) int {
|
||||
d := p.channel.device
|
||||
body := fmt.Sprintf(`PLAY RTSP/1.0
|
||||
CSeq: %d
|
||||
Range: npt=%d-
|
||||
`, d.sn, second)
|
||||
return p.info(body)
|
||||
}
|
||||
|
||||
// 快进/快退播放
|
||||
// speed 取值: 0.25 0.5 1 2 4 或者其对应的负数表示倒放
|
||||
func (p *PullStream) PlayForward(speed float32) int {
|
||||
d := p.channel.device
|
||||
body := fmt.Sprintf(`PLAY RTSP/1.0
|
||||
CSeq: %d
|
||||
Scale: %0.6f
|
||||
`, d.sn, speed)
|
||||
return p.info(body)
|
||||
}
|
||||
|
||||
type Channel struct {
|
||||
device *Device // 所属设备
|
||||
status atomic.Int32 // 通道状态,0:空闲,1:正在invite,2:正在播放
|
||||
LiveSubSP string // 实时子码流,通过rtsp
|
||||
GpsTime time.Time //gps时间
|
||||
Longitude string //经度
|
||||
Latitude string //纬度
|
||||
*log.Logger `json:"-" yaml:"-"`
|
||||
ChannelInfo
|
||||
}
|
||||
|
||||
// Channel 通道
|
||||
type Channel struct {
|
||||
DeviceID string
|
||||
type ChannelInfo struct {
|
||||
DeviceID string // 通道ID
|
||||
ParentID string
|
||||
Name string
|
||||
Manufacturer string
|
||||
@@ -40,75 +129,138 @@ type Channel struct {
|
||||
Owner string
|
||||
CivilCode string
|
||||
Address string
|
||||
Port int
|
||||
Parental int
|
||||
SafetyWay int
|
||||
RegisterWay int
|
||||
Secrecy int
|
||||
Status string
|
||||
Children []*Channel
|
||||
*ChannelEx //自定义属性
|
||||
Status ChannelStatus
|
||||
}
|
||||
|
||||
func (c *Channel) CreateRequst(Method Method) (request *Request) {
|
||||
request = &Request{}
|
||||
request.Message = c.device.CreateMessage(Method)
|
||||
request.Message.StartLine.Uri = NewURI(c.DeviceID + "@" + c.device.to.Uri.Domain())
|
||||
request.Message.To = &Contact{
|
||||
Uri: request.Message.StartLine.Uri,
|
||||
}
|
||||
request.Message.From = &Contact{
|
||||
Uri: NewURI(config.Serial + "@" + config.Realm),
|
||||
Params: map[string]string{"tag": utils.RandNumString(9)},
|
||||
}
|
||||
return
|
||||
}
|
||||
func (channel *Channel) QueryRecord(startTime, endTime string) int {
|
||||
type ChannelStatus string
|
||||
|
||||
const (
|
||||
ChannelOnStatus = "ON"
|
||||
ChannelOffStatus = "OFF"
|
||||
)
|
||||
|
||||
func (channel *Channel) CreateRequst(Method sip.RequestMethod) (req sip.Request) {
|
||||
d := channel.device
|
||||
channel.RecordStartTime = startTime
|
||||
channel.RecordEndTime = endTime
|
||||
channel.recordStartTime, _ = time.Parse(TIME_LAYOUT, startTime)
|
||||
channel.recordEndTime, _ = time.Parse(TIME_LAYOUT, endTime)
|
||||
channel.Records = nil
|
||||
requestMsg := channel.CreateRequst(MESSAGE)
|
||||
requestMsg.ContentType = "Application/MANSCDP+xml"
|
||||
requestMsg.Body = fmt.Sprintf(`<?xml version="1.0"?>
|
||||
<Query>
|
||||
<CmdType>RecordInfo</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
<StartTime>%s</StartTime>
|
||||
<EndTime>%s</EndTime>
|
||||
<Secrecy>0</Secrecy>
|
||||
<Type>time</Type>
|
||||
</Query>`, d.sn, requestMsg.To.Uri.UserInfo(), startTime, endTime)
|
||||
requestMsg.ContentLength = len(requestMsg.Body)
|
||||
resp, err := d.SipRequestForResponse(requestMsg)
|
||||
if err != nil {
|
||||
return http.StatusRequestTimeout
|
||||
}
|
||||
return resp.GetStatusCode()
|
||||
d.sn++
|
||||
|
||||
callId := sip.CallID(utils.RandNumString(10))
|
||||
userAgent := sip.UserAgentHeader("Monibuca")
|
||||
maxForwards := sip.MaxForwards(70) //增加max-forwards为默认值 70
|
||||
cseq := sip.CSeq{
|
||||
SeqNo: uint32(d.sn),
|
||||
MethodName: Method,
|
||||
}
|
||||
port := sip.Port(conf.SipPort)
|
||||
serverAddr := sip.Address{
|
||||
//DisplayName: sip.String{Str: d.serverConfig.Serial},
|
||||
Uri: &sip.SipUri{
|
||||
FUser: sip.String{Str: conf.Serial},
|
||||
FHost: d.sipIP,
|
||||
FPort: &port,
|
||||
},
|
||||
Params: sip.NewParams().Add("tag", sip.String{Str: utils.RandNumString(9)}),
|
||||
}
|
||||
//非同一域的目标地址需要使用@host
|
||||
host := conf.Realm
|
||||
if channel.DeviceID[0:9] != host {
|
||||
if channel.Port != 0 {
|
||||
deviceIp := d.NetAddr
|
||||
deviceIp = deviceIp[0:strings.LastIndex(deviceIp, ":")]
|
||||
host = fmt.Sprintf("%s:%d", deviceIp, channel.Port)
|
||||
} else {
|
||||
host = d.NetAddr
|
||||
}
|
||||
}
|
||||
|
||||
channelAddr := sip.Address{
|
||||
//DisplayName: sip.String{Str: d.serverConfig.Serial},
|
||||
Uri: &sip.SipUri{FUser: sip.String{Str: channel.DeviceID}, FHost: host},
|
||||
}
|
||||
req = sip.NewRequest(
|
||||
"",
|
||||
Method,
|
||||
channelAddr.Uri,
|
||||
"SIP/2.0",
|
||||
[]sip.Header{
|
||||
serverAddr.AsFromHeader(),
|
||||
channelAddr.AsToHeader(),
|
||||
&callId,
|
||||
&userAgent,
|
||||
&cseq,
|
||||
&maxForwards,
|
||||
serverAddr.AsContactHeader(),
|
||||
},
|
||||
"",
|
||||
nil,
|
||||
)
|
||||
|
||||
req.SetTransport(conf.SipNetwork)
|
||||
req.SetDestination(d.NetAddr)
|
||||
return req
|
||||
}
|
||||
|
||||
func (channel *Channel) QueryRecord(startTime, endTime string) ([]*Record, error) {
|
||||
d := channel.device
|
||||
request := d.CreateRequest(sip.MESSAGE)
|
||||
contentType := sip.ContentType("Application/MANSCDP+xml")
|
||||
request.AppendHeader(&contentType)
|
||||
// body := fmt.Sprintf(`<?xml version="1.0"?>
|
||||
// <Query>
|
||||
// <CmdType>RecordInfo</CmdType>
|
||||
// <SN>%d</SN>
|
||||
// <DeviceID>%s</DeviceID>
|
||||
// <StartTime>%s</StartTime>
|
||||
// <EndTime>%s</EndTime>
|
||||
// <Secrecy>0</Secrecy>
|
||||
// <Type>all</Type>
|
||||
// </Query>`, d.sn, channel.DeviceID, startTime, endTime)
|
||||
start, _ := strconv.ParseInt(startTime, 10, 0)
|
||||
end, _ := strconv.ParseInt(endTime, 10, 0)
|
||||
body := BuildRecordInfoXML(d.sn, channel.DeviceID, start, end)
|
||||
request.SetBody(body, true)
|
||||
|
||||
resultCh := RecordQueryLink.WaitResult(d.ID, channel.DeviceID, d.sn, QUERY_RECORD_TIMEOUT)
|
||||
resp, err := d.SipRequestForResponse(request)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("query error: %s", err)
|
||||
}
|
||||
if resp.StatusCode() != http.StatusOK {
|
||||
return nil, fmt.Errorf("query error, status=%d", resp.StatusCode())
|
||||
}
|
||||
// RecordQueryLink 中加了超时机制,该结果一定会返回
|
||||
// 所以此处不用再增加超时等保护机制
|
||||
r := <-resultCh
|
||||
return r.list, r.err
|
||||
}
|
||||
|
||||
func (channel *Channel) Control(PTZCmd string) int {
|
||||
d := channel.device
|
||||
requestMsg := channel.CreateRequst(MESSAGE)
|
||||
requestMsg.ContentType = "Application/MANSCDP+xml"
|
||||
requestMsg.Body = fmt.Sprintf(`<?xml version="1.0"?>
|
||||
<Control>
|
||||
<CmdType>DeviceControl</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
<PTZCmd>%s</PTZCmd>
|
||||
</Control>`, d.sn, requestMsg.To.Uri.UserInfo(), PTZCmd)
|
||||
requestMsg.ContentLength = len(requestMsg.Body)
|
||||
resp, err := d.SipRequestForResponse(requestMsg)
|
||||
request := d.CreateRequest(sip.MESSAGE)
|
||||
contentType := sip.ContentType("Application/MANSCDP+xml")
|
||||
request.AppendHeader(&contentType)
|
||||
body := fmt.Sprintf(`<?xml version="1.0"?>
|
||||
<Control>
|
||||
<CmdType>DeviceControl</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
<PTZCmd>%s</PTZCmd>
|
||||
</Control>`, d.sn, channel.DeviceID, PTZCmd)
|
||||
request.SetBody(body, true)
|
||||
resp, err := d.SipRequestForResponse(request)
|
||||
if err != nil {
|
||||
return http.StatusRequestTimeout
|
||||
}
|
||||
return resp.GetStatusCode()
|
||||
return int(resp.StatusCode())
|
||||
}
|
||||
|
||||
/*
|
||||
// Invite 发送Invite报文 invites a channel to play
|
||||
// 注意里面的锁保证不同时发送invite报文,该锁由channel持有
|
||||
/***
|
||||
f字段: f = v/编码格式/分辨率/帧率/码率类型/码率大小a/编码格式/码率大小/采样率
|
||||
各项具体含义:
|
||||
v:后续参数为视频的参数;各参数间以 “/”分割;
|
||||
@@ -152,190 +304,234 @@ f = v/a/编码格式/码率大小/采样率
|
||||
f字段中视、音频参数段之间不需空格分割。
|
||||
可使用f字段中的分辨率参数标识同一设备不同分辨率的码流。
|
||||
*/
|
||||
func (channel *Channel) Invite(start, end string) (code int) {
|
||||
if start == "" {
|
||||
if !atomic.CompareAndSwapInt32(&channel.state, 0, 1) {
|
||||
return 304
|
||||
|
||||
func (channel *Channel) Invite(opt *InviteOptions) (code int, err error) {
|
||||
if opt.IsLive() {
|
||||
if !channel.status.CompareAndSwap(0, 1) {
|
||||
return 304, nil
|
||||
}
|
||||
defer func() {
|
||||
if code != 200 {
|
||||
atomic.StoreInt32(&channel.state, 0)
|
||||
if err != nil {
|
||||
GB28181Plugin.Error("Invite", zap.Error(err))
|
||||
channel.status.Store(0)
|
||||
if conf.InviteMode == 1 {
|
||||
// 5秒后重试
|
||||
time.AfterFunc(time.Second*5, func() {
|
||||
channel.Invite(opt)
|
||||
})
|
||||
}
|
||||
} else {
|
||||
channel.status.Store(2)
|
||||
}
|
||||
}()
|
||||
channel.Bye(true)
|
||||
} else {
|
||||
channel.Bye(false)
|
||||
}
|
||||
sint, err1 := strconv.ParseInt(start, 10, 0)
|
||||
eint, err2 := strconv.ParseInt(end, 10, 0)
|
||||
d := channel.device
|
||||
streamPath := fmt.Sprintf("%s/%s", d.ID, channel.DeviceID)
|
||||
s := "Play"
|
||||
ssrc := make([]byte, 10)
|
||||
if start != "" {
|
||||
if err1 != nil || err2 != nil {
|
||||
return 400
|
||||
}
|
||||
opt.CreateSSRC()
|
||||
if opt.Record() {
|
||||
s = "Playback"
|
||||
ssrc[0] = '1'
|
||||
streamPath = fmt.Sprintf("%s/%s/%s-%s", d.ID, channel.DeviceID, start, end)
|
||||
streamPath = fmt.Sprintf("%s/%s/%d-%d", d.ID, channel.DeviceID, opt.Start, opt.End)
|
||||
}
|
||||
if opt.StreamPath != "" {
|
||||
streamPath = opt.StreamPath
|
||||
} else {
|
||||
ssrc[0] = '0'
|
||||
opt.StreamPath = streamPath
|
||||
}
|
||||
if opt.dump == "" {
|
||||
opt.dump = conf.DumpPath
|
||||
}
|
||||
protocol := ""
|
||||
networkType := "udp"
|
||||
reusePort := true
|
||||
if conf.IsMediaNetworkTCP() {
|
||||
networkType = "tcp"
|
||||
protocol = "TCP/"
|
||||
if conf.tcpPorts.Valid {
|
||||
opt.MediaPort, err = conf.tcpPorts.GetPort()
|
||||
opt.recyclePort = conf.tcpPorts.Recycle
|
||||
reusePort = false
|
||||
}
|
||||
} else {
|
||||
if conf.udpPorts.Valid {
|
||||
opt.MediaPort, err = conf.udpPorts.GetPort()
|
||||
opt.recyclePort = conf.udpPorts.Recycle
|
||||
reusePort = false
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
if opt.MediaPort == 0 {
|
||||
opt.MediaPort = conf.MediaPort
|
||||
}
|
||||
|
||||
// size := 1
|
||||
// fps := 15
|
||||
// bitrate := 200
|
||||
// fmt.Sprintf("f=v/2/%d/%d/1/%da///", size, fps, bitrate)
|
||||
copy(ssrc[1:6], []byte(config.Serial[3:8]))
|
||||
randNum := rand.Intn(10000)
|
||||
copy(ssrc[6:], []byte(strconv.Itoa(randNum)))
|
||||
protocol := ""
|
||||
port := config.MediaPort
|
||||
if config.TCP {
|
||||
protocol = "TCP/"
|
||||
port = config.MediaPort + channel.tcpPortIndex
|
||||
if channel.tcpPortIndex++; channel.tcpPortIndex >= config.TCPMediaPortNum {
|
||||
channel.tcpPortIndex = 0
|
||||
}
|
||||
}
|
||||
sdpInfo := []string{
|
||||
"v=0",
|
||||
fmt.Sprintf("o=%s 0 0 IN IP4 %s", d.Serial, d.SipIP),
|
||||
fmt.Sprintf("o=%s 0 0 IN IP4 %s", channel.DeviceID, d.mediaIP),
|
||||
"s=" + s,
|
||||
"u=" + channel.DeviceID + ":0",
|
||||
"c=IN IP4 " + d.SipIP,
|
||||
fmt.Sprintf("t=%d %d", sint, eint),
|
||||
fmt.Sprintf("m=video %d %sRTP/AVP 96", port, protocol),
|
||||
"c=IN IP4 " + d.mediaIP,
|
||||
opt.String(),
|
||||
fmt.Sprintf("m=video %d %sRTP/AVP 96", opt.MediaPort, protocol),
|
||||
"a=recvonly",
|
||||
"a=rtpmap:96 PS/90000",
|
||||
"y=" + opt.ssrc,
|
||||
}
|
||||
if config.TCP {
|
||||
if conf.IsMediaNetworkTCP() {
|
||||
sdpInfo = append(sdpInfo, "a=setup:passive", "a=connection:new")
|
||||
}
|
||||
invite := channel.CreateRequst(INVITE)
|
||||
invite.ContentType = "application/sdp"
|
||||
invite.Contact = &Contact{
|
||||
Uri: NewURI(fmt.Sprintf("%s@%s:%d", d.Serial, d.SipIP, d.SipPort)),
|
||||
}
|
||||
invite.Body = strings.Join(sdpInfo, "\r\n") + "\r\ny=" + string(ssrc) + "\r\n"
|
||||
invite.ContentLength = len(invite.Body)
|
||||
invite.Subject = fmt.Sprintf("%s:%s,%s:0", channel.DeviceID, ssrc, config.Serial)
|
||||
response, _ := d.Core.SipRequestForResponse(invite)
|
||||
if response == nil {
|
||||
return http.StatusRequestTimeout
|
||||
}
|
||||
fmt.Printf("invite response statuscode: %d\n", response.GetStatusCode())
|
||||
invite := channel.CreateRequst(sip.INVITE)
|
||||
contentType := sip.ContentType("application/sdp")
|
||||
invite.AppendHeader(&contentType)
|
||||
|
||||
if response.GetStatusCode() == 200 {
|
||||
ds := strings.Split(response.Body, "\r\n")
|
||||
_SSRC, _ := strconv.ParseInt(string(ssrc), 10, 0)
|
||||
SSRC := uint32(_SSRC)
|
||||
invite.SetBody(strings.Join(sdpInfo, "\r\n")+"\r\n", true)
|
||||
|
||||
subject := sip.GenericHeader{
|
||||
HeaderName: "Subject", Contents: fmt.Sprintf("%s:%s,%s:0", channel.DeviceID, opt.ssrc, conf.Serial),
|
||||
}
|
||||
invite.AppendHeader(&subject)
|
||||
inviteRes, err := d.SipRequestForResponse(invite)
|
||||
if err != nil {
|
||||
channel.Error("invite", zap.Error(err), zap.String("msg", invite.String()))
|
||||
return http.StatusInternalServerError, err
|
||||
}
|
||||
code = int(inviteRes.StatusCode())
|
||||
channel.Info("invite response", zap.Int("status code", code))
|
||||
|
||||
if code == http.StatusOK {
|
||||
ds := strings.Split(inviteRes.Body(), "\r\n")
|
||||
for _, l := range ds {
|
||||
if ls := strings.Split(l, "="); len(ls) > 1 {
|
||||
if ls[0] == "y" && len(ls[1]) > 0 {
|
||||
_SSRC, _ = strconv.ParseInt(ls[1], 10, 0)
|
||||
SSRC = uint32(_SSRC)
|
||||
break
|
||||
if _ssrc, err := strconv.ParseInt(ls[1], 10, 0); err == nil {
|
||||
opt.SSRC = uint32(_ssrc)
|
||||
} else {
|
||||
channel.Error("read invite response y ", zap.Error(err))
|
||||
}
|
||||
// break
|
||||
}
|
||||
if ls[0] == "m" && len(ls[1]) > 0 {
|
||||
netinfo := strings.Split(ls[1], " ")
|
||||
if strings.ToUpper(netinfo[2]) == "TCP/RTP/AVP" {
|
||||
channel.Debug("Device support tcp")
|
||||
} else {
|
||||
channel.Debug("Device not support tcp")
|
||||
networkType = "udp"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
publisher := &Publisher{
|
||||
Stream: &engine.Stream{
|
||||
StreamPath: streamPath,
|
||||
AutoCloseAfter: &config.AutoCloseAfter,
|
||||
},
|
||||
err = ps.Receive(streamPath, opt.dump, fmt.Sprintf("%s:%d", networkType, opt.MediaPort), opt.SSRC, reusePort)
|
||||
if err == nil {
|
||||
PullStreams.Store(streamPath, &PullStream{
|
||||
opt: opt,
|
||||
channel: channel,
|
||||
inviteRes: inviteRes,
|
||||
})
|
||||
err = srv.Send(sip.NewAckRequest("", invite, inviteRes, "", nil))
|
||||
}
|
||||
if config.UdpCacheSize > 0 && !config.TCP {
|
||||
publisher.udpCache = utils.NewPqRtp()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (channel *Channel) Bye(streamPath string) int {
|
||||
d := channel.device
|
||||
if streamPath == "" {
|
||||
streamPath = fmt.Sprintf("%s/%s", d.ID, channel.DeviceID)
|
||||
}
|
||||
if s, loaded := PullStreams.LoadAndDelete(streamPath); loaded {
|
||||
s.(*PullStream).Bye()
|
||||
if s := Streams.Get(streamPath); s != nil {
|
||||
s.Close()
|
||||
}
|
||||
if start == "" {
|
||||
publisher.Type = "GB28181 Live"
|
||||
publisher.OnClose = func() {
|
||||
publishers.Remove(SSRC)
|
||||
channel.LivePublisher = nil
|
||||
channel.ByeBye((*Request)(channel.inviteRes))
|
||||
channel.inviteRes = nil
|
||||
atomic.StoreInt32(&channel.state, 0)
|
||||
if config.AutoInvite {
|
||||
go channel.Invite("", "")
|
||||
}
|
||||
return http.StatusOK
|
||||
}
|
||||
return http.StatusNotFound
|
||||
}
|
||||
|
||||
func (channel *Channel) Pause(streamPath string) int {
|
||||
if s, loaded := PullStreams.Load(streamPath); loaded {
|
||||
r := s.(*PullStream).Pause()
|
||||
if s := Streams.Get(streamPath); s != nil {
|
||||
s.Pause()
|
||||
}
|
||||
return r
|
||||
}
|
||||
return http.StatusNotFound
|
||||
}
|
||||
|
||||
func (channel *Channel) Resume(streamPath string) int {
|
||||
if s, loaded := PullStreams.Load(streamPath); loaded {
|
||||
r := s.(*PullStream).Resume()
|
||||
if s := Streams.Get(streamPath); s != nil {
|
||||
s.Resume()
|
||||
}
|
||||
return r
|
||||
}
|
||||
return http.StatusNotFound
|
||||
}
|
||||
|
||||
func (channel *Channel) PlayAt(streamPath string, second uint) int {
|
||||
if s, loaded := PullStreams.Load(streamPath); loaded {
|
||||
r := s.(*PullStream).PlayAt(second)
|
||||
if s := Streams.Get(streamPath); s != nil {
|
||||
s.Resume()
|
||||
}
|
||||
return r
|
||||
}
|
||||
return http.StatusNotFound
|
||||
}
|
||||
|
||||
func (channel *Channel) PlayForward(streamPath string, speed float32) int {
|
||||
if s, loaded := PullStreams.Load(streamPath); loaded {
|
||||
return s.(*PullStream).PlayForward(speed)
|
||||
}
|
||||
if s := Streams.Get(streamPath); s != nil {
|
||||
s.Resume()
|
||||
}
|
||||
return http.StatusNotFound
|
||||
}
|
||||
|
||||
func (channel *Channel) TryAutoInvite(opt *InviteOptions) {
|
||||
if channel.CanInvite() {
|
||||
go channel.Invite(opt)
|
||||
}
|
||||
}
|
||||
|
||||
func (channel *Channel) CanInvite() bool {
|
||||
if channel.status.Load() != 0 || len(channel.DeviceID) != 20 || channel.Status == ChannelOffStatus {
|
||||
return false
|
||||
}
|
||||
|
||||
if conf.InviteIDs == "" {
|
||||
return true
|
||||
}
|
||||
|
||||
// 11~13位是设备类型编码
|
||||
typeID := channel.DeviceID[10:13]
|
||||
|
||||
// format: start-end,type1,type2
|
||||
tokens := strings.Split(conf.InviteIDs, ",")
|
||||
for _, tok := range tokens {
|
||||
if first, second, ok := strings.Cut(tok, "-"); ok {
|
||||
if typeID >= first && typeID <= second {
|
||||
return true
|
||||
}
|
||||
} else {
|
||||
publisher.Type = "GB28181 Record"
|
||||
publisher.OnClose = func() {
|
||||
publishers.Remove(SSRC)
|
||||
channel.RecordPublisher = nil
|
||||
channel.ByeBye((*Request)(channel.recordInviteRes))
|
||||
channel.recordInviteRes = nil
|
||||
if typeID == first {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if !publisher.Publish() {
|
||||
return 403
|
||||
}
|
||||
publishers.Add(SSRC, publisher)
|
||||
if start == "" {
|
||||
channel.inviteRes = response
|
||||
channel.LivePublisher = publisher
|
||||
} else {
|
||||
channel.RecordPublisher = publisher
|
||||
channel.recordInviteRes = response
|
||||
}
|
||||
ack := d.CreateMessage(ACK)
|
||||
ack.StartLine = &StartLine{
|
||||
Uri: NewURI(channel.DeviceID + "@" + d.to.Uri.Domain()),
|
||||
Method: ACK,
|
||||
}
|
||||
ack.From = response.From
|
||||
ack.To = response.To
|
||||
ack.CallID = response.CallID
|
||||
ack.CSeq.ID = invite.CSeq.ID
|
||||
d.Respond(&Response{Message: ack})
|
||||
} else if start == "" && config.AutoInvite {
|
||||
time.AfterFunc(time.Second*5, func() {
|
||||
channel.Invite("", "")
|
||||
})
|
||||
}
|
||||
return response.GetStatusCode()
|
||||
}
|
||||
func (channel *Channel) Bye(live bool) int {
|
||||
if live && channel.inviteRes != nil {
|
||||
defer func() {
|
||||
channel.inviteRes = nil
|
||||
if channel.LivePublisher != nil {
|
||||
channel.LivePublisher.Close()
|
||||
}
|
||||
}()
|
||||
return channel.ByeBye((*Request)(channel.inviteRes)).GetStatusCode()
|
||||
}
|
||||
if !live && channel.recordInviteRes != nil {
|
||||
defer func() {
|
||||
channel.recordInviteRes = nil
|
||||
if channel.RecordPublisher != nil {
|
||||
channel.RecordPublisher.Close()
|
||||
}
|
||||
}()
|
||||
return channel.ByeBye((*Request)(channel.recordInviteRes)).GetStatusCode()
|
||||
}
|
||||
return 404
|
||||
}
|
||||
func (c *Channel) ByeBye(res *Request) *Response {
|
||||
if res == nil {
|
||||
return nil
|
||||
}
|
||||
d := c.device
|
||||
bye := c.device.CreateMessage(BYE)
|
||||
bye.StartLine = &StartLine{
|
||||
Uri: NewURI(c.DeviceID + "@" + c.device.to.Uri.Domain()),
|
||||
Method: BYE,
|
||||
}
|
||||
bye.From = res.From
|
||||
bye.To = res.To
|
||||
bye.CallID = res.CallID
|
||||
req := &Request{}
|
||||
req.Message = bye
|
||||
|
||||
resp, _ := d.SipRequestForResponse(req)
|
||||
return resp
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func getSipRespErrorCode(err error) int {
|
||||
if re, ok := err.(*sip.RequestError); ok {
|
||||
return int(re.Code)
|
||||
} else {
|
||||
return http.StatusInternalServerError
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,18 @@
|
||||
package sip
|
||||
package gb28181
|
||||
|
||||
import "fmt"
|
||||
|
||||
//transaction sip error
|
||||
var errorMap = map[int]string{
|
||||
//1xx
|
||||
var reasons = map[int]string{
|
||||
100: "Trying",
|
||||
180: "Ringing",
|
||||
181: "Call Is Being Forwarded",
|
||||
182: "Queued",
|
||||
183: "Session Progress",
|
||||
199: "Early Dialog Terminated",
|
||||
//2xx
|
||||
200: "OK",
|
||||
202: "Accepted",
|
||||
204: "No Notification",
|
||||
//3xx
|
||||
300: "Multiple Choices",
|
||||
301: "Moved Permanently",
|
||||
302: "Moved Temporarily",
|
||||
305: "Use Proxy",
|
||||
380: "Alternative Service",
|
||||
//4xx
|
||||
400: "Bad Request",
|
||||
401: "Unauthorized",
|
||||
402: "Payment Required",
|
||||
@@ -31,33 +22,16 @@ var errorMap = map[int]string{
|
||||
406: "Not Acceptable",
|
||||
407: "Proxy Authentication Required",
|
||||
408: "Request Timeout",
|
||||
409: "Conflict",
|
||||
410: "Gone",
|
||||
411: "Length Required",
|
||||
412: "Conditional Request Failed",
|
||||
413: "Request Entity Too Large",
|
||||
414: "Request-URI Too Long",
|
||||
415: "Unsupported Media Type",
|
||||
416: "Unsupported URI Scheme",
|
||||
417: "Unknown Resource-Priority",
|
||||
420: "Bad Extension",
|
||||
421: "Extension Required",
|
||||
422: "Session Interval Too Small",
|
||||
423: "Interval Too Brief",
|
||||
424: "Bad Location Information",
|
||||
428: "Use Identity Header",
|
||||
429: "Provide Referrer Identity",
|
||||
430: "Flow Failed",
|
||||
433: "Anonymity Disallowed",
|
||||
436: "Bad Identity Info",
|
||||
437: "Unsupported Credential",
|
||||
438: "Invalid Identity Header",
|
||||
439: "First Hop Lacks Outbound Support",
|
||||
440: "Max-Breadth Exceeded",
|
||||
469: "Bad Info Package",
|
||||
470: "Consent Needed",
|
||||
480: "Temporarily Unavailable",
|
||||
481: "Call/Transaction Does Not Exist",
|
||||
481: "Call transaction Does Not Exist",
|
||||
482: "Loop Detected",
|
||||
483: "Too Many Hops",
|
||||
484: "Address Incomplete",
|
||||
@@ -68,28 +42,25 @@ var errorMap = map[int]string{
|
||||
489: "Bad Event",
|
||||
491: "Request Pending",
|
||||
493: "Undecipherable",
|
||||
494: "Security Agreement Required",
|
||||
//5xx
|
||||
500: "Server Internal Error",
|
||||
501: "Not Implemented",
|
||||
502: "Bad Gateway",
|
||||
503: "Service Unavailable",
|
||||
504: "Server Time-out",
|
||||
504: "Server Tim",
|
||||
505: "Version Not Supported",
|
||||
513: "Message Too Large",
|
||||
580: "Precondition Failure",
|
||||
//6xx
|
||||
513: "message Too Large",
|
||||
600: "Busy Everywhere",
|
||||
603: "Decline",
|
||||
604: "Does Not Exist Anywhere",
|
||||
606: "Not Acceptable",
|
||||
607: "Unwanted",
|
||||
687: "Dialog Terminated",
|
||||
606: "SESSION NOT ACCEPTABLE",
|
||||
}
|
||||
|
||||
func DumpError(code int) string {
|
||||
if code == 0 {
|
||||
return "invalid status reason for request"
|
||||
}
|
||||
return fmt.Sprintf("%d %s", code, errorMap[code])
|
||||
func Explain(statusCode int) string {
|
||||
return reasons[statusCode]
|
||||
}
|
||||
|
||||
const (
|
||||
INVIDE_MODE_MANUAL = iota
|
||||
INVIDE_MODE_AUTO
|
||||
INVIDE_MODE_ONSUBSCRIBE
|
||||
)
|
||||
636
device.go
636
device.go
@@ -1,27 +1,29 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/logrusorgru/aurora"
|
||||
"net"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/engine/v3"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transaction"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
// . "github.com/Monibuca/utils/v3"
|
||||
"go.uber.org/zap"
|
||||
"m7s.live/engine/v4"
|
||||
"m7s.live/engine/v4/log"
|
||||
"m7s.live/plugin/gb28181/v4/utils"
|
||||
|
||||
// . "github.com/logrusorgru/aurora"
|
||||
"github.com/ghettovoice/gosip/sip"
|
||||
myip "github.com/husanpao/ip"
|
||||
)
|
||||
|
||||
const TIME_LAYOUT = "2006-01-02T15:04:05"
|
||||
|
||||
// Record 录像
|
||||
type Record struct {
|
||||
//channel *Channel
|
||||
DeviceID string
|
||||
Name string
|
||||
FilePath string
|
||||
@@ -42,190 +44,500 @@ var (
|
||||
DeviceRegisterCount sync.Map //设备注册次数
|
||||
)
|
||||
|
||||
type DeviceStatus string
|
||||
|
||||
const (
|
||||
DeviceRegisterStatus = "REGISTER"
|
||||
DeviceRecoverStatus = "RECOVER"
|
||||
DeviceOnlineStatus = "ONLINE"
|
||||
DeviceOfflineStatus = "OFFLINE"
|
||||
DeviceAlarmedStatus = "ALARMED"
|
||||
)
|
||||
|
||||
type Device struct {
|
||||
*transaction.Core `json:"-"`
|
||||
ID string
|
||||
Name string
|
||||
Manufacturer string
|
||||
Model string
|
||||
Owner string
|
||||
RegisterTime time.Time
|
||||
UpdateTime time.Time
|
||||
LastKeepaliveAt time.Time
|
||||
Status string
|
||||
Channels []*Channel
|
||||
sn int
|
||||
from *sip.Contact
|
||||
to *sip.Contact
|
||||
Addr string
|
||||
SipIP string //暴露的IP
|
||||
channelMap map[string]*Channel
|
||||
channelMutex sync.RWMutex
|
||||
subscriber struct {
|
||||
//*transaction.Core `json:"-" yaml:"-"`
|
||||
ID string
|
||||
Name string
|
||||
Manufacturer string
|
||||
Model string
|
||||
Owner string
|
||||
RegisterTime time.Time
|
||||
UpdateTime time.Time
|
||||
LastKeepaliveAt time.Time
|
||||
Status DeviceStatus
|
||||
sn int
|
||||
addr sip.Address
|
||||
sipIP string //设备对应网卡的服务器ip
|
||||
mediaIP string //设备对应网卡的服务器ip
|
||||
NetAddr string
|
||||
channelMap sync.Map
|
||||
subscriber struct {
|
||||
CallID string
|
||||
Timeout time.Time
|
||||
}
|
||||
lastSyncTime time.Time
|
||||
GpsTime time.Time //gps时间
|
||||
Longitude string //经度
|
||||
Latitude string //纬度
|
||||
*log.Logger `json:"-" yaml:"-"`
|
||||
}
|
||||
|
||||
func (d *Device) addChannel(channel *Channel) {
|
||||
for _, c := range d.Channels {
|
||||
if c.DeviceID == channel.DeviceID {
|
||||
return
|
||||
func (d *Device) MarshalJSON() ([]byte, error) {
|
||||
type Alias Device
|
||||
data := &struct {
|
||||
Channels []*ChannelInfo
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(d),
|
||||
}
|
||||
d.channelMap.Range(func(key, value interface{}) bool {
|
||||
c := value.(*Channel)
|
||||
data.Channels = append(data.Channels, &c.ChannelInfo)
|
||||
return true
|
||||
})
|
||||
return json.Marshal(data)
|
||||
}
|
||||
func (c *GB28181Config) RecoverDevice(d *Device, req sip.Request) {
|
||||
from, _ := req.From()
|
||||
d.addr = sip.Address{
|
||||
DisplayName: from.DisplayName,
|
||||
Uri: from.Address,
|
||||
}
|
||||
deviceIp := req.Source()
|
||||
servIp := req.Recipient().Host()
|
||||
//根据网卡ip获取对应的公网ip
|
||||
sipIP := c.routes[servIp]
|
||||
//如果相等,则服务器是内网通道.海康摄像头不支持...自动获取
|
||||
if strings.LastIndex(deviceIp, ".") != -1 && strings.LastIndex(servIp, ".") != -1 {
|
||||
if servIp[0:strings.LastIndex(servIp, ".")] == deviceIp[0:strings.LastIndex(deviceIp, ".")] || sipIP == "" {
|
||||
sipIP = servIp
|
||||
}
|
||||
}
|
||||
d.Channels = append(d.Channels, channel)
|
||||
//如果用户配置过则使用配置的
|
||||
if c.SipIP != "" {
|
||||
sipIP = c.SipIP
|
||||
} else if sipIP == "" {
|
||||
sipIP = myip.InternalIPv4()
|
||||
}
|
||||
mediaIp := sipIP
|
||||
if c.MediaIP != "" {
|
||||
mediaIp = c.MediaIP
|
||||
}
|
||||
d.Info("RecoverDevice", zap.String("deviceIp", deviceIp), zap.String("servIp", servIp), zap.String("sipIP", sipIP), zap.String("mediaIp", mediaIp))
|
||||
d.Status = DeviceRegisterStatus
|
||||
d.sipIP = sipIP
|
||||
d.mediaIP = mediaIp
|
||||
d.NetAddr = deviceIp
|
||||
d.UpdateTime = time.Now()
|
||||
}
|
||||
|
||||
func (d *Device) CheckSubStream() {
|
||||
d.channelMutex.Lock()
|
||||
defer d.channelMutex.Unlock()
|
||||
for _, c := range d.Channels {
|
||||
if s := engine.FindStream("sub/" + c.DeviceID); s != nil {
|
||||
c.LiveSubSP = s.StreamPath
|
||||
} else {
|
||||
c.LiveSubSP = ""
|
||||
}
|
||||
func (c *GB28181Config) StoreDevice(id string, req sip.Request) (d *Device) {
|
||||
from, _ := req.From()
|
||||
deviceAddr := sip.Address{
|
||||
DisplayName: from.DisplayName,
|
||||
Uri: from.Address,
|
||||
}
|
||||
}
|
||||
func (d *Device) UpdateChannels(list []*Channel) {
|
||||
d.channelMutex.Lock()
|
||||
defer d.channelMutex.Unlock()
|
||||
for _, c := range list {
|
||||
if _, ok := Ignores[c.DeviceID]; ok {
|
||||
continue
|
||||
}
|
||||
if c.ParentID != "" {
|
||||
path := strings.Split(c.ParentID, "/")
|
||||
parentId := path[len(path)-1]
|
||||
if parent, ok := d.channelMap[parentId]; ok {
|
||||
if c.DeviceID != parentId {
|
||||
parent.Children = append(parent.Children, c)
|
||||
}
|
||||
} else {
|
||||
d.addChannel(c)
|
||||
}
|
||||
} else {
|
||||
d.addChannel(c)
|
||||
}
|
||||
if old, ok := d.channelMap[c.DeviceID]; ok {
|
||||
c.ChannelEx = old.ChannelEx
|
||||
if len(old.Children) == 0 {
|
||||
if config.PreFetchRecord {
|
||||
n := time.Now()
|
||||
n = time.Date(n.Year(), n.Month(), n.Day(), 0, 0, 0, 0, time.Local)
|
||||
if len(c.Records) == 0 || (n.Format(TIME_LAYOUT) == c.RecordStartTime &&
|
||||
n.Add(time.Hour*24-time.Second).Format(TIME_LAYOUT) == c.RecordEndTime) {
|
||||
go c.QueryRecord(n.Format(TIME_LAYOUT), n.Add(time.Hour*24-time.Second).Format(TIME_LAYOUT))
|
||||
}
|
||||
}
|
||||
if config.AutoInvite && c.LivePublisher == nil {
|
||||
go c.Invite("", "")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
c.ChannelEx = &ChannelEx{
|
||||
device: d,
|
||||
}
|
||||
if config.AutoInvite {
|
||||
go c.Invite("", "")
|
||||
deviceIp := req.Source()
|
||||
if _d, loaded := Devices.Load(id); loaded {
|
||||
d = _d.(*Device)
|
||||
d.UpdateTime = time.Now()
|
||||
d.NetAddr = deviceIp
|
||||
d.addr = deviceAddr
|
||||
d.Debug("UpdateDevice", zap.String("netaddr", d.NetAddr))
|
||||
} else {
|
||||
servIp := req.Recipient().Host()
|
||||
//根据网卡ip获取对应的公网ip
|
||||
sipIP := c.routes[servIp]
|
||||
//如果相等,则服务器是内网通道.海康摄像头不支持...自动获取
|
||||
if strings.LastIndex(deviceIp, ".") != -1 && strings.LastIndex(servIp, ".") != -1 {
|
||||
if servIp[0:strings.LastIndex(servIp, ".")] == deviceIp[0:strings.LastIndex(deviceIp, ".")] || sipIP == "" {
|
||||
sipIP = servIp
|
||||
}
|
||||
}
|
||||
if s := engine.FindStream("sub/" + c.DeviceID); s != nil {
|
||||
c.LiveSubSP = s.StreamPath
|
||||
} else {
|
||||
c.LiveSubSP = ""
|
||||
//如果用户配置过则使用配置的
|
||||
if c.SipIP != "" {
|
||||
sipIP = c.SipIP
|
||||
} else if sipIP == "" {
|
||||
sipIP = myip.InternalIPv4()
|
||||
}
|
||||
d.channelMap[c.DeviceID] = c
|
||||
}
|
||||
}
|
||||
func (d *Device) UpdateRecord(channelId string, list []*Record) {
|
||||
d.channelMutex.RLock()
|
||||
if c, ok := d.channelMap[channelId]; ok {
|
||||
c.Records = append(c.Records, list...)
|
||||
}
|
||||
d.channelMutex.RUnlock()
|
||||
}
|
||||
|
||||
func (d *Device) CreateMessage(Method sip.Method) (requestMsg *sip.Message) {
|
||||
d.sn++
|
||||
//if msg.Via.Transport == "UDP" {
|
||||
deviceAddr, err2 := net.ResolveUDPAddr(strings.ToLower(d.SipNetwork), d.Addr)
|
||||
//} else {
|
||||
// pkt.Addr, err2 = net.ResolveTCPAddr("tcp", addr)
|
||||
//}
|
||||
if err2 != nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
requestMsg = &sip.Message{
|
||||
Mode: sip.SIP_MESSAGE_REQUEST,
|
||||
MaxForwards: 70,
|
||||
UserAgent: "Monibuca",
|
||||
StartLine: &sip.StartLine{
|
||||
Method: Method,
|
||||
Uri: d.to.Uri,
|
||||
}, Via: &sip.Via{
|
||||
Transport: "UDP",
|
||||
Host: d.Core.SipIP,
|
||||
Port: fmt.Sprintf("%d", d.SipPort),
|
||||
Params: map[string]string{
|
||||
"branch": fmt.Sprintf("z9hG4bK%s", utils.RandNumString(8)),
|
||||
"rport": "-1", //only key,no-value
|
||||
},
|
||||
}, From: &sip.Contact{Uri: d.from.Uri, Params: map[string]string{"tag": utils.RandNumString(9)}},
|
||||
To: d.to, CSeq: &sip.CSeq{
|
||||
ID: uint32(d.sn),
|
||||
Method: Method,
|
||||
}, CallID: utils.RandNumString(10),
|
||||
Addr: d.Addr,
|
||||
DestAdd: deviceAddr,
|
||||
mediaIp := sipIP
|
||||
if c.MediaIP != "" {
|
||||
mediaIp = c.MediaIP
|
||||
}
|
||||
d = &Device{
|
||||
ID: id,
|
||||
RegisterTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
Status: DeviceRegisterStatus,
|
||||
addr: deviceAddr,
|
||||
sipIP: sipIP,
|
||||
mediaIP: mediaIp,
|
||||
NetAddr: deviceIp,
|
||||
Logger: GB28181Plugin.With(zap.String("id", id)),
|
||||
}
|
||||
d.Info("StoreDevice", zap.String("deviceIp", deviceIp), zap.String("servIp", servIp), zap.String("sipIP", sipIP), zap.String("mediaIp", mediaIp))
|
||||
Devices.Store(id, d)
|
||||
c.SaveDevices()
|
||||
}
|
||||
return
|
||||
}
|
||||
func (d *Device) Subscribe(req *sip.Request) int {
|
||||
requestMsg := d.CreateMessage(sip.SUBSCRIBE)
|
||||
if d.subscriber.CallID != "" {
|
||||
requestMsg.CallID = d.subscriber.CallID
|
||||
func (c *GB28181Config) ReadDevices() {
|
||||
if f, err := os.OpenFile("devices.json", os.O_RDONLY, 0644); err == nil {
|
||||
defer f.Close()
|
||||
var items []*Device
|
||||
if err = json.NewDecoder(f).Decode(&items); err == nil {
|
||||
for _, item := range items {
|
||||
if time.Since(item.UpdateTime) < conf.RegisterValidity {
|
||||
item.Status = "RECOVER"
|
||||
item.Logger = GB28181Plugin.With(zap.String("id", item.ID))
|
||||
Devices.Store(item.ID, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
requestMsg.Expires = 3600
|
||||
requestMsg.Event = "Catalog"
|
||||
d.subscriber.Timeout = time.Now().Add(time.Second * time.Duration(requestMsg.Expires))
|
||||
requestMsg.ContentType = "Application/MANSCDP+xml"
|
||||
requestMsg.Body = sip.BuildCatalogXML(d.sn, requestMsg.To.Uri.UserInfo())
|
||||
requestMsg.ContentLength = len(requestMsg.Body)
|
||||
}
|
||||
func (c *GB28181Config) SaveDevices() {
|
||||
var item []any
|
||||
Devices.Range(func(key, value any) bool {
|
||||
item = append(item, value)
|
||||
return true
|
||||
})
|
||||
if f, err := os.OpenFile("devices.json", os.O_WRONLY|os.O_CREATE, 0644); err == nil {
|
||||
defer f.Close()
|
||||
encoder := json.NewEncoder(f)
|
||||
encoder.SetIndent("", " ")
|
||||
encoder.Encode(item)
|
||||
}
|
||||
}
|
||||
|
||||
request := &sip.Request{Message: requestMsg}
|
||||
response, err := d.Core.SipRequestForResponse(request)
|
||||
func (d *Device) addOrUpdateChannel(info ChannelInfo) (c *Channel) {
|
||||
if old, ok := d.channelMap.Load(info.DeviceID); ok {
|
||||
c = old.(*Channel)
|
||||
c.ChannelInfo = info
|
||||
} else {
|
||||
c = &Channel{
|
||||
device: d,
|
||||
ChannelInfo: info,
|
||||
Logger: d.Logger.With(zap.String("channel", info.DeviceID)),
|
||||
}
|
||||
if s := engine.Streams.Get(fmt.Sprintf("%s/%s/rtsp", c.device.ID, c.DeviceID)); s != nil {
|
||||
c.LiveSubSP = s.Path
|
||||
} else {
|
||||
c.LiveSubSP = ""
|
||||
}
|
||||
d.channelMap.Store(info.DeviceID, c)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Device) deleteChannel(DeviceID string) {
|
||||
d.channelMap.Delete(DeviceID)
|
||||
}
|
||||
|
||||
func (d *Device) UpdateChannels(list ...ChannelInfo) {
|
||||
for _, c := range list {
|
||||
if _, ok := conf.Ignores[c.DeviceID]; ok {
|
||||
continue
|
||||
}
|
||||
//当父设备非空且存在时、父设备节点增加通道
|
||||
if c.ParentID != "" {
|
||||
path := strings.Split(c.ParentID, "/")
|
||||
parentId := path[len(path)-1]
|
||||
//如果父ID并非本身所属设备,一般情况下这是因为下级设备上传了目录信息,该信息通常不需要处理。
|
||||
// 暂时不考虑级联目录的实现
|
||||
if d.ID != parentId {
|
||||
if v, ok := Devices.Load(parentId); ok {
|
||||
parent := v.(*Device)
|
||||
parent.addOrUpdateChannel(c)
|
||||
continue
|
||||
} else {
|
||||
c.Model = "Directory " + c.Model
|
||||
c.Status = "NoParent"
|
||||
}
|
||||
}
|
||||
}
|
||||
//本设备增加通道
|
||||
channel := d.addOrUpdateChannel(c)
|
||||
|
||||
if conf.InviteMode == INVIDE_MODE_AUTO {
|
||||
channel.TryAutoInvite(&InviteOptions{})
|
||||
}
|
||||
if s := engine.Streams.Get("sub/" + c.DeviceID); s != nil {
|
||||
channel.LiveSubSP = s.Path
|
||||
} else {
|
||||
channel.LiveSubSP = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Device) CreateRequest(Method sip.RequestMethod) (req sip.Request) {
|
||||
d.sn++
|
||||
|
||||
callId := sip.CallID(utils.RandNumString(10))
|
||||
userAgent := sip.UserAgentHeader("Monibuca")
|
||||
maxForwards := sip.MaxForwards(70) //增加max-forwards为默认值 70
|
||||
cseq := sip.CSeq{
|
||||
SeqNo: uint32(d.sn),
|
||||
MethodName: Method,
|
||||
}
|
||||
port := sip.Port(conf.SipPort)
|
||||
serverAddr := sip.Address{
|
||||
//DisplayName: sip.String{Str: d.config.Serial},
|
||||
Uri: &sip.SipUri{
|
||||
FUser: sip.String{Str: conf.Serial},
|
||||
FHost: d.sipIP,
|
||||
FPort: &port,
|
||||
},
|
||||
Params: sip.NewParams().Add("tag", sip.String{Str: utils.RandNumString(9)}),
|
||||
}
|
||||
req = sip.NewRequest(
|
||||
"",
|
||||
Method,
|
||||
d.addr.Uri,
|
||||
"SIP/2.0",
|
||||
[]sip.Header{
|
||||
serverAddr.AsFromHeader(),
|
||||
d.addr.AsToHeader(),
|
||||
&callId,
|
||||
&userAgent,
|
||||
&cseq,
|
||||
&maxForwards,
|
||||
serverAddr.AsContactHeader(),
|
||||
},
|
||||
"",
|
||||
nil,
|
||||
)
|
||||
|
||||
req.SetTransport(conf.SipNetwork)
|
||||
req.SetDestination(d.NetAddr)
|
||||
//fmt.Printf("构建请求参数:%s", *&req)
|
||||
// requestMsg.DestAdd, err2 = d.ResolveAddress(requestMsg)
|
||||
// if err2 != nil {
|
||||
// return nil
|
||||
// }
|
||||
//intranet ip , let's resolve it with public ip
|
||||
// var deviceIp, deviceSourceIP net.IP
|
||||
// switch addr := requestMsg.DestAdd.(type) {
|
||||
// case *net.UDPAddr:
|
||||
// deviceIp = addr.IP
|
||||
// case *net.TCPAddr:
|
||||
// deviceIp = addr.IP
|
||||
// }
|
||||
|
||||
// switch addr2 := d.SourceAddr.(type) {
|
||||
// case *net.UDPAddr:
|
||||
// deviceSourceIP = addr2.IP
|
||||
// case *net.TCPAddr:
|
||||
// deviceSourceIP = addr2.IP
|
||||
// }
|
||||
// if deviceIp.IsPrivate() && !deviceSourceIP.IsPrivate() {
|
||||
// requestMsg.DestAdd = d.SourceAddr
|
||||
// }
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Device) Subscribe() int {
|
||||
request := d.CreateRequest(sip.SUBSCRIBE)
|
||||
if d.subscriber.CallID != "" {
|
||||
callId := sip.CallID(utils.RandNumString(10))
|
||||
request.AppendHeader(&callId)
|
||||
}
|
||||
expires := sip.Expires(3600)
|
||||
d.subscriber.Timeout = time.Now().Add(time.Second * time.Duration(expires))
|
||||
contentType := sip.ContentType("Application/MANSCDP+xml")
|
||||
request.AppendHeader(&contentType)
|
||||
request.AppendHeader(&expires)
|
||||
|
||||
request.SetBody(BuildCatalogXML(d.sn, d.ID), true)
|
||||
|
||||
response, err := d.SipRequestForResponse(request)
|
||||
if err == nil && response != nil {
|
||||
if response.GetStatusCode() == 200 {
|
||||
d.subscriber.CallID = requestMsg.CallID
|
||||
if response.StatusCode() == http.StatusOK {
|
||||
callId, _ := request.CallID()
|
||||
d.subscriber.CallID = string(*callId)
|
||||
} else {
|
||||
d.subscriber.CallID = ""
|
||||
}
|
||||
return response.GetStatusCode()
|
||||
return int(response.StatusCode())
|
||||
}
|
||||
return http.StatusRequestTimeout
|
||||
}
|
||||
func (d *Device) Query(req *sip.Request) {
|
||||
|
||||
func (d *Device) Catalog() int {
|
||||
//os.Stdout.Write(debug.Stack())
|
||||
request := d.CreateRequest(sip.MESSAGE)
|
||||
expires := sip.Expires(3600)
|
||||
d.subscriber.Timeout = time.Now().Add(time.Second * time.Duration(expires))
|
||||
contentType := sip.ContentType("Application/MANSCDP+xml")
|
||||
|
||||
request.AppendHeader(&contentType)
|
||||
request.AppendHeader(&expires)
|
||||
request.SetBody(BuildCatalogXML(d.sn, d.ID), true)
|
||||
// 输出Sip请求设备通道信息信令
|
||||
GB28181Plugin.Sugar().Debugf("SIP->Catalog:%s", request)
|
||||
resp, err := d.SipRequestForResponse(request)
|
||||
if err == nil && resp != nil {
|
||||
GB28181Plugin.Sugar().Debugf("SIP<-Catalog Response: %s", resp.String())
|
||||
return int(resp.StatusCode())
|
||||
} else if err != nil {
|
||||
GB28181Plugin.Error("SIP<-Catalog error:", zap.Error(err))
|
||||
}
|
||||
return http.StatusRequestTimeout
|
||||
}
|
||||
|
||||
func (d *Device) QueryDeviceInfo() {
|
||||
for i := time.Duration(5); i < 100; i++ {
|
||||
|
||||
fmt.Println(aurora.Red("device.Query"))
|
||||
time.Sleep(time.Second * i)
|
||||
requestMsg := d.CreateMessage(sip.MESSAGE)
|
||||
requestMsg.ContentType = "Application/MANSCDP+xml"
|
||||
requestMsg.Body = sip.BuildDeviceInfoXML(d.sn, requestMsg.To.Uri.UserInfo())
|
||||
requestMsg.ContentLength = len(requestMsg.Body)
|
||||
request := &sip.Request{Message: requestMsg}
|
||||
request := d.CreateRequest(sip.MESSAGE)
|
||||
contentType := sip.ContentType("Application/MANSCDP+xml")
|
||||
request.AppendHeader(&contentType)
|
||||
request.SetBody(BuildDeviceInfoXML(d.sn, d.ID), true)
|
||||
|
||||
response, _ := d.Core.SipRequestForResponse(request)
|
||||
if response != nil && response.Via != nil && response.Via.Params["received"] != "" {
|
||||
d.SipIP = response.Via.Params["received"]
|
||||
}
|
||||
if response != nil && response.GetStatusCode() != 200 {
|
||||
fmt.Printf("device %s send Catalog : %d\n", d.ID, response.GetStatusCode())
|
||||
} else {
|
||||
d.Subscribe(req)
|
||||
break
|
||||
response, _ := d.SipRequestForResponse(request)
|
||||
if response != nil {
|
||||
// via, _ := response.ViaHop()
|
||||
|
||||
// if via != nil && via.Params.Has("received") {
|
||||
// received, _ := via.Params.Get("received")
|
||||
// d.SipIP = received.String()
|
||||
// }
|
||||
d.Info("QueryDeviceInfo", zap.Uint16("status code", uint16(response.StatusCode())))
|
||||
if response.StatusCode() == http.StatusOK {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Device) SipRequestForResponse(request sip.Request) (sip.Response, error) {
|
||||
return srv.RequestWithContext(context.Background(), request)
|
||||
}
|
||||
|
||||
// MobilePositionSubscribe 移动位置订阅
|
||||
func (d *Device) MobilePositionSubscribe(id string, expires time.Duration, interval time.Duration) (code int) {
|
||||
mobilePosition := d.CreateRequest(sip.SUBSCRIBE)
|
||||
if d.subscriber.CallID != "" {
|
||||
callId := sip.CallID(utils.RandNumString(10))
|
||||
mobilePosition.ReplaceHeaders(callId.Name(), []sip.Header{&callId})
|
||||
}
|
||||
expiresHeader := sip.Expires(expires / time.Second)
|
||||
d.subscriber.Timeout = time.Now().Add(expires)
|
||||
contentType := sip.ContentType("Application/MANSCDP+xml")
|
||||
mobilePosition.AppendHeader(&contentType)
|
||||
mobilePosition.AppendHeader(&expiresHeader)
|
||||
|
||||
mobilePosition.SetBody(BuildDevicePositionXML(d.sn, id, int(interval/time.Second)), true)
|
||||
|
||||
response, err := d.SipRequestForResponse(mobilePosition)
|
||||
if err == nil && response != nil {
|
||||
if response.StatusCode() == http.StatusOK {
|
||||
callId, _ := mobilePosition.CallID()
|
||||
d.subscriber.CallID = callId.String()
|
||||
} else {
|
||||
d.subscriber.CallID = ""
|
||||
}
|
||||
return int(response.StatusCode())
|
||||
}
|
||||
return http.StatusRequestTimeout
|
||||
}
|
||||
|
||||
// UpdateChannelPosition 更新通道GPS坐标
|
||||
func (d *Device) UpdateChannelPosition(channelId string, gpsTime string, lng string, lat string) {
|
||||
if v, ok := d.channelMap.Load(channelId); ok {
|
||||
c := v.(*Channel)
|
||||
c.GpsTime = time.Now() //时间取系统收到的时间,避免设备时间和格式问题
|
||||
c.Longitude = lng
|
||||
c.Latitude = lat
|
||||
c.Debug("update channel position success")
|
||||
} else {
|
||||
//如果未找到通道,则更新到设备上
|
||||
d.GpsTime = time.Now() //时间取系统收到的时间,避免设备时间和格式问题
|
||||
d.Longitude = lng
|
||||
d.Latitude = lat
|
||||
d.Debug("update device position success", zap.String("channelId", channelId))
|
||||
}
|
||||
}
|
||||
|
||||
// UpdateChannelStatus 目录订阅消息处理:新增/移除/更新通道或者更改通道状态
|
||||
func (d *Device) UpdateChannelStatus(deviceList []*notifyMessage) {
|
||||
for _, v := range deviceList {
|
||||
switch v.Event {
|
||||
case "ON":
|
||||
d.Debug("receive channel online notify")
|
||||
d.channelOnline(v.DeviceID)
|
||||
case "OFF":
|
||||
d.Debug("receive channel offline notify")
|
||||
d.channelOffline(v.DeviceID)
|
||||
case "VLOST":
|
||||
d.Debug("receive channel video lost notify")
|
||||
d.channelOffline(v.DeviceID)
|
||||
case "DEFECT":
|
||||
d.Debug("receive channel video defect notify")
|
||||
d.channelOffline(v.DeviceID)
|
||||
case "ADD":
|
||||
d.Debug("receive channel add notify")
|
||||
channel := ChannelInfo{
|
||||
DeviceID: v.DeviceID,
|
||||
ParentID: v.ParentID,
|
||||
Name: v.Name,
|
||||
Manufacturer: v.Manufacturer,
|
||||
Model: v.Model,
|
||||
Owner: v.Owner,
|
||||
CivilCode: v.CivilCode,
|
||||
Address: v.Address,
|
||||
Port: v.Port,
|
||||
Parental: v.Parental,
|
||||
SafetyWay: v.SafetyWay,
|
||||
RegisterWay: v.RegisterWay,
|
||||
Secrecy: v.Secrecy,
|
||||
Status: ChannelStatus(v.Status),
|
||||
}
|
||||
d.addOrUpdateChannel(channel)
|
||||
case "DEL":
|
||||
//删除
|
||||
d.Debug("receive channel delete notify")
|
||||
d.deleteChannel(v.DeviceID)
|
||||
case "UPDATE":
|
||||
d.Debug("receive channel update notify")
|
||||
// 更新通道
|
||||
channel := ChannelInfo{
|
||||
DeviceID: v.DeviceID,
|
||||
ParentID: v.ParentID,
|
||||
Name: v.Name,
|
||||
Manufacturer: v.Manufacturer,
|
||||
Model: v.Model,
|
||||
Owner: v.Owner,
|
||||
CivilCode: v.CivilCode,
|
||||
Address: v.Address,
|
||||
Port: v.Port,
|
||||
Parental: v.Parental,
|
||||
SafetyWay: v.SafetyWay,
|
||||
RegisterWay: v.RegisterWay,
|
||||
Secrecy: v.Secrecy,
|
||||
Status: ChannelStatus(v.Status),
|
||||
}
|
||||
d.UpdateChannels(channel)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Device) channelOnline(DeviceID string) {
|
||||
if v, ok := d.channelMap.Load(DeviceID); ok {
|
||||
c := v.(*Channel)
|
||||
c.Status = ChannelOnStatus
|
||||
c.Debug("channel online", zap.String("channelId", DeviceID))
|
||||
} else {
|
||||
d.Debug("update channel status failed, not found", zap.String("channelId", DeviceID))
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Device) channelOffline(DeviceID string) {
|
||||
if v, ok := d.channelMap.Load(DeviceID); ok {
|
||||
c := v.(*Channel)
|
||||
c.Status = ChannelOffStatus
|
||||
c.Debug("channel offline", zap.String("channelId", DeviceID))
|
||||
} else {
|
||||
d.Debug("update channel status failed, not found", zap.String("channelId", DeviceID))
|
||||
}
|
||||
}
|
||||
|
||||
67
go.mod
67
go.mod
@@ -1,15 +1,64 @@
|
||||
module github.com/Monibuca/plugin-gb28181/v3
|
||||
module m7s.live/plugin/gb28181/v4
|
||||
|
||||
go 1.13
|
||||
go 1.19
|
||||
|
||||
require (
|
||||
github.com/Monibuca/engine/v3 v3.5.0
|
||||
github.com/Monibuca/utils/v3 v3.0.5
|
||||
github.com/agiledragon/gomonkey/v2 v2.2.0
|
||||
github.com/ghettovoice/gosip v0.0.0-20230802091127-d58873a3fe44
|
||||
github.com/husanpao/ip v0.0.0-20220711082147-73160bb611a8
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||
github.com/pion/rtp v1.7.4
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2
|
||||
golang.org/x/text v0.3.7
|
||||
github.com/pion/rtp v1.8.0
|
||||
go.uber.org/zap v1.24.0
|
||||
golang.org/x/net v0.12.0
|
||||
golang.org/x/text v0.11.0
|
||||
m7s.live/engine/v4 v4.13.8
|
||||
m7s.live/plugin/ps/v4 v4.0.9
|
||||
)
|
||||
|
||||
|
||||
require (
|
||||
github.com/bluenviron/mediacommon v0.7.0 // indirect
|
||||
github.com/cnotch/ipchub v1.1.0 // indirect
|
||||
github.com/denisbrodbeck/machineid v1.0.1 // indirect
|
||||
github.com/discoviking/fsm v0.0.0-20150126104936-f4a273feecca // indirect
|
||||
github.com/fsnotify/fsnotify v1.6.0 // indirect
|
||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
|
||||
github.com/gobwas/httphead v0.1.0 // indirect
|
||||
github.com/gobwas/pool v0.2.1 // indirect
|
||||
github.com/gobwas/ws v1.2.1 // indirect
|
||||
github.com/golang/mock v1.6.0 // indirect
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
|
||||
github.com/google/uuid v1.3.0 // indirect
|
||||
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||
github.com/mcuadros/go-defaults v1.2.0 // indirect
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
|
||||
github.com/onsi/ginkgo/v2 v2.2.0 // indirect
|
||||
github.com/pion/randutil v0.1.0 // indirect
|
||||
github.com/pion/webrtc/v3 v3.1.56 // indirect
|
||||
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c // indirect
|
||||
github.com/q191201771/naza v0.30.8 // indirect
|
||||
github.com/quic-go/qtls-go1-18 v0.2.0 // indirect
|
||||
github.com/quic-go/qtls-go1-19 v0.2.0 // indirect
|
||||
github.com/quic-go/qtls-go1-20 v0.1.0 // indirect
|
||||
github.com/quic-go/quic-go v0.32.0 // indirect
|
||||
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b // indirect
|
||||
github.com/shirou/gopsutil/v3 v3.22.11 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
github.com/tevino/abool v1.2.0 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.11 // indirect
|
||||
github.com/tklauser/numcpus v0.6.0 // indirect
|
||||
github.com/x-cray/logrus-prefixed-formatter v0.5.2 // indirect
|
||||
github.com/yapingcat/gomedia v0.0.0-20230727105416-c491e66c9d2a // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.2 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
golang.org/x/crypto v0.11.0 // indirect
|
||||
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db // indirect
|
||||
golang.org/x/mod v0.8.0 // indirect
|
||||
golang.org/x/sync v0.1.0 // indirect
|
||||
golang.org/x/sys v0.10.0 // indirect
|
||||
golang.org/x/term v0.10.0 // indirect
|
||||
golang.org/x/tools v0.6.0 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
)
|
||||
|
||||
601
go.sum
601
go.sum
@@ -1,35 +1,10 @@
|
||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
|
||||
cloud.google.com/go v0.44.2/go.mod h1:60680Gw3Yr4ikxnPRS/oxxkBccT6SA1yMk63TGekxKY=
|
||||
cloud.google.com/go v0.45.1/go.mod h1:RpBamKRgapWJb87xiFSdk4g1CME7QZg3uwTez+TSTjc=
|
||||
cloud.google.com/go v0.46.3/go.mod h1:a6bKKbmY7er1mI7TEI4lsAkts/mkhTSZK8w33B4RAg0=
|
||||
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
|
||||
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
|
||||
cloud.google.com/go/firestore v1.1.0/go.mod h1:ulACoGHTpvq5r8rxGJ4ddJZBZqakUQqClKRT5SZwBmk=
|
||||
cloud.google.com/go/pubsub v1.0.1/go.mod h1:R0Gpsv3s54REJCy4fxDixWD93lHJMoZTyQ2kNxGRt3I=
|
||||
cloud.google.com/go/storage v1.0.0/go.mod h1:IhtSnM/ZTZV8YYJWCY8RULGVqBDmpoyjwiyrjsg+URw=
|
||||
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
|
||||
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/agiledragon/gomonkey/v2 v2.2.0 h1:QJWqpdEhGV/JJy70sZ/LDnhbSlMrqHAWHcNOjz1kyuI=
|
||||
github.com/agiledragon/gomonkey/v2 v2.2.0/go.mod h1:ap1AmDzcVOAz1YpeJ3TCzIgstoaWLA6jbbgxfB4w2iY=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||
github.com/aws/aws-sdk-go v1.34.28/go.mod h1:H7NKnBqNVzoTJpGfLrQkkD+ytBA93eiDYi/+8rV9s48=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
|
||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/benbjohnson/clock v1.1.0 h1:Q92kusRqC1XV2MjkWETPvjJVqKetz1OzxZB7mHJLju8=
|
||||
github.com/bluenviron/mediacommon v0.7.0 h1:dJWLLL9oDbAqfK8KuNfnDUQwNbeMAtGeRjZc9Vo95js=
|
||||
github.com/bluenviron/mediacommon v0.7.0/go.mod h1:wuLJdxcITiSPgY1MvQqrX+qPlKmNfeV9wNvXth5M98I=
|
||||
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
|
||||
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
|
||||
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
|
||||
github.com/cnotch/apirouter v0.0.0-20200731232942-89e243a791f3/go.mod h1:5deJPLON/x/s2dLOQfuKS0lenhOIT4xX0pvtN/OEIuY=
|
||||
github.com/cnotch/ipchub v1.1.0 h1:hH0lh2mU3AZXPiqMwA0pdtqrwo7PFIMRGush9OobMUs=
|
||||
github.com/cnotch/ipchub v1.1.0/go.mod h1:2PbeBs2q2VxxTVCn1eYCDwpAWuVXbq1+N0FU7GimOH4=
|
||||
@@ -38,394 +13,322 @@ github.com/cnotch/queue v0.0.0-20200326024423-6e88bdbf2ad4/go.mod h1:zOssjAlNusO
|
||||
github.com/cnotch/queue v0.0.0-20201224060551-4191569ce8f6/go.mod h1:zOssjAlNusOxvtaqT+EMA+Iyi8rrtKr4/XfzN1Fgoeg=
|
||||
github.com/cnotch/scheduler v0.0.0-20200522024700-1d2da93eefc5/go.mod h1:F4GE3SZkJZ8an1Y0ZCqvSM3jeozNuKzoC67erG1PhIo=
|
||||
github.com/cnotch/xlog v0.0.0-20201208005456-cfda439cd3a0/go.mod h1:RW9oHsR79ffl3sR3yMGgxYupMn2btzdtJUwoxFPUE5E=
|
||||
github.com/coreos/bbolt v1.3.2/go.mod h1:iRUV2dpdMOn7Bo10OQBFzIJO9kkE559Wcmn+qkEiiKk=
|
||||
github.com/coreos/etcd v3.3.13+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||
github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
|
||||
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
github.com/denisbrodbeck/machineid v1.0.1 h1:geKr9qtkB876mXguW2X6TU4ZynleN6ezuMSRhl4D7AQ=
|
||||
github.com/denisbrodbeck/machineid v1.0.1/go.mod h1:dJUwb7PTidGDeYyUBmXZ2GphQBbjJCrnectwCyxcUSI=
|
||||
github.com/discoviking/fsm v0.0.0-20150126104936-f4a273feecca h1:cTTdXpkQ1aVbOOmHwdwtYuwUZcQtcMrleD1UXLWhAq8=
|
||||
github.com/discoviking/fsm v0.0.0-20150126104936-f4a273feecca/go.mod h1:W+3LQaEkN8qAwwcw0KC546sUEnX86GIT8CcMLZC4mG0=
|
||||
github.com/emitter-io/address v1.0.0/go.mod h1:GfZb5+S/o8694B1GMGK2imUYQyn2skszMvGNA5D84Ug=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478 h1:Db9StoJ6RZN3YttC0Pm0I4Y5izITRYch3RMbT59BYN0=
|
||||
github.com/funny/slab v0.0.0-20180511031532-b1fad5e5d478/go.mod h1:0j1+svBH8ABEIPdUP0AIg4qedsybnXGJBakCEw8cfoo=
|
||||
github.com/funny/utest v0.0.0-20161029064919-43870a374500 h1:Z0r1CZnoIWFB/Uiwh1BU5FYmuFe6L5NPi6XWQEmsTRg=
|
||||
github.com/funny/utest v0.0.0-20161029064919-43870a374500/go.mod h1:mUn39tBov9jKnTWV1RlOYoNzxdBFHiSzXWdY1FoNGGg=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
|
||||
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/gobuffalo/attrs v0.0.0-20190224210810-a9411de4debd/go.mod h1:4duuawTqi2wkkpB4ePgWMaai6/Kc6WEz83bhFwpHzj0=
|
||||
github.com/gobuffalo/depgen v0.0.0-20190329151759-d478694a28d3/go.mod h1:3STtPUQYuzV0gBVOY3vy6CfMm/ljR4pABfrTeHNLHUY=
|
||||
github.com/gobuffalo/depgen v0.1.0/go.mod h1:+ifsuy7fhi15RWncXQQKjWS9JPkdah5sZvtHc2RXGlg=
|
||||
github.com/gobuffalo/envy v1.6.15/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
|
||||
github.com/gobuffalo/envy v1.7.0/go.mod h1:n7DRkBerg/aorDM8kbduw5dN3oXGswK5liaSCx4T5NI=
|
||||
github.com/gobuffalo/flect v0.1.0/go.mod h1:d2ehjJqGOH/Kjqcoz+F7jHTBbmDb38yXA598Hb50EGs=
|
||||
github.com/gobuffalo/flect v0.1.1/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
|
||||
github.com/gobuffalo/flect v0.1.3/go.mod h1:8JCgGVbRjJhVgD6399mQr4fx5rRfGKVzFjbj6RE/9UI=
|
||||
github.com/gobuffalo/genny v0.0.0-20190329151137-27723ad26ef9/go.mod h1:rWs4Z12d1Zbf19rlsn0nurr75KqhYp52EAGGxTbBhNk=
|
||||
github.com/gobuffalo/genny v0.0.0-20190403191548-3ca520ef0d9e/go.mod h1:80lIj3kVJWwOrXWWMRzzdhW3DsrdjILVil/SFKBzF28=
|
||||
github.com/gobuffalo/genny v0.1.0/go.mod h1:XidbUqzak3lHdS//TPu2OgiFB+51Ur5f7CSnXZ/JDvo=
|
||||
github.com/gobuffalo/genny v0.1.1/go.mod h1:5TExbEyY48pfunL4QSXxlDOmdsD44RRq4mVZ0Ex28Xk=
|
||||
github.com/gobuffalo/gitgen v0.0.0-20190315122116-cc086187d211/go.mod h1:vEHJk/E9DmhejeLeNt7UVvlSGv3ziL+djtTr3yyzcOw=
|
||||
github.com/gobuffalo/gogen v0.0.0-20190315121717-8f38393713f5/go.mod h1:V9QVDIxsgKNZs6L2IYiGR8datgMhB577vzTDqypH360=
|
||||
github.com/gobuffalo/gogen v0.1.0/go.mod h1:8NTelM5qd8RZ15VjQTFkAW6qOMx5wBbW4dSCS3BY8gg=
|
||||
github.com/gobuffalo/gogen v0.1.1/go.mod h1:y8iBtmHmGc4qa3urIyo1shvOD8JftTtfcKi+71xfDNE=
|
||||
github.com/gobuffalo/logger v0.0.0-20190315122211-86e12af44bc2/go.mod h1:QdxcLw541hSGtBnhUc4gaNIXRjiDppFGaDqzbrBd3v8=
|
||||
github.com/gobuffalo/mapi v1.0.1/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
|
||||
github.com/gobuffalo/mapi v1.0.2/go.mod h1:4VAGh89y6rVOvm5A8fKFxYG+wIW6LO1FMTG9hnKStFc=
|
||||
github.com/gobuffalo/packd v0.0.0-20190315124812-a385830c7fc0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
|
||||
github.com/gobuffalo/packd v0.1.0/go.mod h1:M2Juc+hhDXf/PnmBANFCqx4DM3wRbgDvnVWeG2RIxq4=
|
||||
github.com/gobuffalo/packr/v2 v2.0.9/go.mod h1:emmyGweYTm6Kdper+iywB6YK5YzuKchGtJQZ0Odn4pQ=
|
||||
github.com/gobuffalo/packr/v2 v2.2.0/go.mod h1:CaAwI0GPIAv+5wKLtv8Afwl+Cm78K/I/VCm/3ptBN+0=
|
||||
github.com/gobuffalo/syncx v0.0.0-20190224160051-33c29581e754/go.mod h1:HhnNqWY95UYwwW3uSASeV7vtgYkT2t16hJgV3AEPUpw=
|
||||
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/gofrs/uuid v4.2.0+incompatible h1:yyYWMnhkhrKwwr8gAOcOCYxOOscHgDS9yZgBrnJfGa0=
|
||||
github.com/gofrs/uuid v4.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.3.1/go.mod h1:sBzyDLLjw3U8JLTeZvSv8jJB+tU5PVekmnlKIyFUx0Y=
|
||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||
github.com/fsnotify/fsnotify v1.6.0 h1:n+5WquG0fcWoWp6xPWfHdbskMCQaFnG6PfBrh1Ky4HY=
|
||||
github.com/fsnotify/fsnotify v1.6.0/go.mod h1:sl3t1tCWJFWoRz9R8WJCbQihKKwmorjAbSClcnxKAGw=
|
||||
github.com/ghettovoice/gosip v0.0.0-20230802091127-d58873a3fe44 h1:m4/46V6uAJ95CLimMRHJjiH5psW1JuL+iLeUBzF2r70=
|
||||
github.com/ghettovoice/gosip v0.0.0-20230802091127-d58873a3fe44/go.mod h1:rlD1yLOErWYohWTryG/2bTTpmzB79p52ntLA/uIFXeI=
|
||||
github.com/go-ole/go-ole v1.2.6 h1:/Fpf6oFPoeFik9ty7siob0G6Ke8QvQEuVcuChpwXzpY=
|
||||
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 h1:p104kn46Q8WdvHunIJ9dAyjPVtrBPhSr3KT2yUst43I=
|
||||
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
|
||||
github.com/gobwas/httphead v0.1.0 h1:exrUm0f4YX0L7EBwZHuCF4GDp8aJfVeBrlLQrs6NqWU=
|
||||
github.com/gobwas/httphead v0.1.0/go.mod h1:O/RXo79gxV8G+RqlR/otEwx4Q36zl9rqC5u12GKvMCM=
|
||||
github.com/gobwas/pool v0.2.1 h1:xfeeEhW7pwmX8nuLVlqbzVc7udMDrwetjEv+TZIz1og=
|
||||
github.com/gobwas/pool v0.2.1/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
|
||||
github.com/gobwas/ws v1.1.0-rc.1/go.mod h1:nzvNcVha5eUziGrbxFCo6qFIojQHjJV5cLYIbezhfL0=
|
||||
github.com/gobwas/ws v1.2.1 h1:F2aeBZrm2NDsc7vbovKrWSogd4wvfAxg0FQ89/iqOTk=
|
||||
github.com/gobwas/ws v1.2.1/go.mod h1:hRKAFb8wOxFROYNsT1bqfWnhX+b5MFeJM9r2ZSwg/KY=
|
||||
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
|
||||
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/snappy v0.0.1/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
|
||||
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
|
||||
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
|
||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
|
||||
github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw=
|
||||
github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/pprof v0.0.0-20190515194954-54271f7e092f/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
|
||||
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 h1:yAJXTCF9TqKcTiHJAE8dj7HMvPfh66eeA2JYW7eFpSE=
|
||||
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
|
||||
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
|
||||
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gax-go/v2 v2.0.5/go.mod h1:DWXyrwAJ9X0FpwwEdw+IPEYBICEFu5mhpdKc/us6bOk=
|
||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/hashicorp/consul/api v1.1.0/go.mod h1:VmuI/Lkw1nC05EYQWNKwWGbkg+FbDBtguAZLlVdkD9Q=
|
||||
github.com/hashicorp/consul/sdk v0.1.1/go.mod h1:VKf9jXwCTEY1QZP2MOLRhb5i/I/ssyNV1vwHyQBF0x8=
|
||||
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
|
||||
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
|
||||
github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60=
|
||||
github.com/hashicorp/go-msgpack v0.5.3/go.mod h1:ahLV/dePpqEmjfWmKiqvPkv/twdG7iPBM1vqhUKIvfM=
|
||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||
github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU=
|
||||
github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU=
|
||||
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
|
||||
github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go-uuid v1.0.1/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro=
|
||||
github.com/hashicorp/go.net v0.0.1/go.mod h1:hjKkEWcCURg++eb33jQU7oqQcI9XDCnUzHA0oac0k90=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO+LraFDTW64=
|
||||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
|
||||
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
|
||||
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
|
||||
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
|
||||
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/jtolds/gls v4.20.0+incompatible/go.mod h1:QJZ7F/aHp+rZTRtaJ1ow/lLfFfVYBRgL+9YlvaHOwJU=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||
github.com/karrick/godirwalk v1.8.0/go.mod h1:H5KPZjojv4lE+QYImBI8xVtrBRgYrIVsaRPx4tDPEn4=
|
||||
github.com/karrick/godirwalk v1.10.3/go.mod h1:RoGL9dQei4vP9ilrpETWE8CLOZ1kiN0LhBygSwrAsHA=
|
||||
github.com/husanpao/ip v0.0.0-20220711082147-73160bb611a8 h1:4Jk58quTZmzJcTrLlbB5L1Q6qXu49EIjCReWxcBFWKo=
|
||||
github.com/husanpao/ip v0.0.0-20220711082147-73160bb611a8/go.mod h1:medl9/CfYoQlqAXtAARmMW5dAX2UOdwwkhaszYPk0AM=
|
||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||
github.com/kelindar/process v0.0.0-20170730150328-69a29e249ec3/go.mod h1:+lTCLnZFXOkqwD8sLPl6u4erAc0cP8wFegQHfipz7KE=
|
||||
github.com/kelindar/rate v1.0.0/go.mod h1:AjT4G+hTItNwt30lucEGZIz8y7Uk5zPho6vurIZ+1Es=
|
||||
github.com/kelindar/tcp v1.0.0/go.mod h1:JB5hj1cshLU60XrLij2BBxW3JQ4hOye8vqbyvuKb52k=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/klauspost/compress v1.9.5/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.2/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible h1:tOpm7WcpBTn4fjmVfgpQq0EfczGlG91VSDkswnjF5A8=
|
||||
github.com/logrusorgru/aurora v2.0.3+incompatible/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4=
|
||||
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/markbates/oncer v0.0.0-20181203154359-bf2de49a0be2/go.mod h1:Ld9puTsIW75CHf65OeIOkyKbteujpZVXDpWK6YGZbxE=
|
||||
github.com/markbates/safe v1.0.1/go.mod h1:nAqgmRi7cY2nqMc92/bSEeQA+R4OheNU2T1kNSCBdG0=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
|
||||
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
|
||||
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
|
||||
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/go-testing-interface v1.0.0/go.mod h1:kRemZodwjscx+RGhAo8eIhFbs2+BFgRtFPeD/KE+zxI=
|
||||
github.com/mitchellh/gox v0.4.0/go.mod h1:Sd9lOJ0+aimLBi73mGofS1ycjY8lL3uZM3JPS42BGNg=
|
||||
github.com/mitchellh/iochan v1.0.0/go.mod h1:JwYml1nuB7xOzsp52dPpHFffvOCDupsG0QubkSMEySY=
|
||||
github.com/mitchellh/mapstructure v0.0.0-20160808181253-ca63d7c062ee/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/montanaflynn/stats v0.0.0-20171201202039-1bf9dbcd8cbe/go.mod h1:wL8QJuTMNUDYhXwkmfOly8iTdp5TEcJFWZD2D7SIkUc=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
|
||||
github.com/lufia/plan9stats v0.0.0-20211012122336-39d0f177ccd0/go.mod h1:zJYVVT2jmtg6P3p1VtQj7WsuWi/y4VnjVBn7F8KPB3I=
|
||||
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c h1:VtwQ41oftZwlMnOEbMWQtSEUgU64U4s+GHk7hZK+jtY=
|
||||
github.com/lufia/plan9stats v0.0.0-20220913051719-115f729f3c8c/go.mod h1:JKx41uQRwqlTZabZc+kILPrO/3jlKnQ2Z8b7YiVw5cE=
|
||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
|
||||
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
|
||||
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
|
||||
github.com/mcuadros/go-defaults v1.2.0 h1:FODb8WSf0uGaY8elWJAkoLL0Ri6AlZ1bFlenk56oZtc=
|
||||
github.com/mcuadros/go-defaults v1.2.0/go.mod h1:WEZtHEVIGYVDqkKSWBdWKUVdRyKlMfulPaGDWIVeCWY=
|
||||
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d h1:5PJl274Y63IEHC+7izoQE9x6ikvDFZS2mDVS3drnohI=
|
||||
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d/go.mod h1:01TrycV0kFyexm33Z7vhZRXopbI8J3TDReVlkTgMUxE=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
|
||||
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
|
||||
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.5/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
|
||||
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
|
||||
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
|
||||
github.com/onsi/ginkgo v1.14.2/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
|
||||
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
|
||||
github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
|
||||
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
|
||||
github.com/onsi/ginkgo/v2 v2.2.0 h1:3ZNA3L1c5FYDFTTxbFeVGGD8jYvjYauHD30YgLxVsNI=
|
||||
github.com/onsi/ginkgo/v2 v2.2.0/go.mod h1:MEH45j8TBi6u9BMogfbp0stKC5cdGjumZj5Y7AG4VIk=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/panjjo/gosdp v0.0.0-20201029020038-56e3a0ec56ef/go.mod h1:VyTSJoai1m6iMalmg8kEMuaKk2amkc6JS0K7H0xfcmQ=
|
||||
github.com/panjjo/gosip v0.0.0-20210428012454-2314e85e3fd8 h1:Hy4HOOn7M9Bf5EBwl9sYbvWDJGBYIfg+SDwbuNhjVAU=
|
||||
github.com/panjjo/gosip v0.0.0-20210428012454-2314e85e3fd8/go.mod h1:wB/uSqjtaky3fLAePmqXyOatDzLvOmSG7dlgSscIIXc=
|
||||
github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
github.com/pelletier/go-toml v1.7.0/go.mod h1:vwGMzjaWMwyfHwgIBhI2YUM4fB6nL6lVAvS1LBMMhTE=
|
||||
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
|
||||
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||
github.com/onsi/gomega v1.10.4/go.mod h1:g/HbgYopi++010VEqkFgJHKC09uJiW9UkXvMUuKHUCQ=
|
||||
github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
|
||||
github.com/onsi/gomega v1.20.1 h1:PA/3qinGoukvymdIDV8pii6tiZgC8kbmJO6Z5+b002Q=
|
||||
github.com/pion/datachannel v1.5.5/go.mod h1:iMz+lECmfdCMqFRhXhcA/219B0SQlbpoR2V118yimL0=
|
||||
github.com/pion/dtls/v2 v2.2.6/go.mod h1:t8fWJCIquY5rlQZwA2yWxUS1+OCrAdXrhVKXB5oD/wY=
|
||||
github.com/pion/ice/v2 v2.3.1/go.mod h1:aq2kc6MtYNcn4XmMhobAv6hTNJiHzvD0yXRz80+bnP8=
|
||||
github.com/pion/interceptor v0.1.12/go.mod h1:bDtgAD9dRkBZpWHGKaoKb42FhDHTG2rX8Ii9LRALLVA=
|
||||
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
|
||||
github.com/pion/mdns v0.0.7/go.mod h1:4iP2UbeFhLI/vWju/bw6ZfwjJzk0z8DNValjGxR/dD8=
|
||||
github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA=
|
||||
github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8=
|
||||
github.com/pion/rtcp v1.2.10/go.mod h1:ztfEwXZNLGyF1oQDttz/ZKIBaeeg/oWbRYqzBM9TL1I=
|
||||
github.com/pion/rtp v1.6.2/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
||||
github.com/pion/rtp v1.7.4 h1:4dMbjb1SuynU5OpA3kz1zHK+u+eOCQjW3MAeVHf1ODA=
|
||||
github.com/pion/rtp v1.7.4/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
||||
github.com/pion/rtp v1.7.13/go.mod h1:bDb5n+BFZxXx0Ea7E5qe+klMuqiBrP+w8XSjiWtCUko=
|
||||
github.com/pion/rtp v1.8.0 h1:SYD7040IR+NqrGBOc2GDU5iDjAR+0m5rnX/EWCUMNhw=
|
||||
github.com/pion/rtp v1.8.0/go.mod h1:pBGHaFt/yW7bf1jjWAoUjpSNoDnw98KTMg+jWWvziqU=
|
||||
github.com/pion/sctp v1.8.5/go.mod h1:SUFFfDpViyKejTAdwD1d/HQsCu+V/40cCs2nZIvC3s0=
|
||||
github.com/pion/sctp v1.8.6/go.mod h1:SUFFfDpViyKejTAdwD1d/HQsCu+V/40cCs2nZIvC3s0=
|
||||
github.com/pion/sdp/v3 v3.0.6/go.mod h1:iiFWFpQO8Fy3S5ldclBkpXqmWy02ns78NOKoLLL0YQw=
|
||||
github.com/pion/srtp/v2 v2.0.12/go.mod h1:C3Ep44hlOo2qEYaq4ddsmK5dL63eLehXFbHaZ9F5V9Y=
|
||||
github.com/pion/stun v0.4.0/go.mod h1:QPsh1/SbXASntw3zkkrIk3ZJVKz4saBY2G7S10P3wCw=
|
||||
github.com/pion/transport v0.14.1/go.mod h1:4tGmbk00NeYA3rUa9+n+dzCCoKkcy3YlYb99Jn2fNnI=
|
||||
github.com/pion/transport/v2 v2.0.0/go.mod h1:HS2MEBJTwD+1ZI2eSXSvHJx/HnzQqRy2/LXxt6eVMHc=
|
||||
github.com/pion/transport/v2 v2.0.2/go.mod h1:vrz6bUbFr/cjdwbnxq8OdDDzHf7JJfGsIRkxfpZoTA0=
|
||||
github.com/pion/turn/v2 v2.1.0/go.mod h1:yrT5XbXSGX1VFSF31A3c1kCNB5bBZgk/uu5LET162qs=
|
||||
github.com/pion/udp/v2 v2.0.1/go.mod h1:B7uvTMP00lzWdyMr/1PVZXtV3wpPIxBRd4Wl6AksXn8=
|
||||
github.com/pion/webrtc/v3 v3.1.56 h1:ScaiqKQN3liQwT+kJwOBaYP6TwSfixzdUnZmzHAo0a0=
|
||||
github.com/pion/webrtc/v3 v3.1.56/go.mod h1:7VhbA6ihqJlz6R/INHjyh1b8HpiV9Ct4UQvE1OB/xoM=
|
||||
github.com/pixelbender/go-sdp v1.1.0/go.mod h1:6IBlz9+BrUHoFTea7gcp4S54khtOhjCW/nVDLhmZBAs=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.3/go.mod h1:/TN21ttK/J9q6uSwhBd54HahCDft0ttaMvbicHlPoso=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||
github.com/prometheus/common v0.0.0-20181113130724-41aa239b4cce/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||
github.com/prometheus/common v0.4.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/q191201771/naza v0.19.1 h1:4KLcxT2CHztO+7miPRtBG3FFgadSQYQw1gPPPKN7rnY=
|
||||
github.com/q191201771/naza v0.19.1/go.mod h1:5LeGupZZFtYP1g/S203n9vXoUNVdlRnPIfM6rExjqt0=
|
||||
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.2.2/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
|
||||
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
|
||||
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c h1:NRoLoZvkBTKvR5gQLgA3e0hqjkY9u1wm+iOL45VN/qI=
|
||||
github.com/power-devops/perfstat v0.0.0-20220216144756-c35f1ee13d7c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
|
||||
github.com/q191201771/naza v0.30.8 h1:Lhh29o65C4PmTDj2l+eKfsw9dddpgWZk4bFICtcnSaA=
|
||||
github.com/q191201771/naza v0.30.8/go.mod h1:n+dpJjQSh90PxBwxBNuifOwQttywvSIN5TkWSSYCeBk=
|
||||
github.com/quic-go/qtls-go1-18 v0.2.0 h1:5ViXqBZ90wpUcZS0ge79rf029yx0dYB0McyPJwqqj7U=
|
||||
github.com/quic-go/qtls-go1-18 v0.2.0/go.mod h1:moGulGHK7o6O8lSPSZNoOwcLvJKJ85vVNc7oJFD65bc=
|
||||
github.com/quic-go/qtls-go1-19 v0.2.0 h1:Cvn2WdhyViFUHoOqK52i51k4nDX8EwIh5VJiVM4nttk=
|
||||
github.com/quic-go/qtls-go1-19 v0.2.0/go.mod h1:ySOI96ew8lnoKPtSqx2BlI5wCpUVPT05RMAlajtnyOI=
|
||||
github.com/quic-go/qtls-go1-20 v0.1.0 h1:d1PK3ErFy9t7zxKsG3NXBJXZjp/kMLoIb3y/kV54oAI=
|
||||
github.com/quic-go/qtls-go1-20 v0.1.0/go.mod h1:JKtK6mjbAVcUTN/9jZpvLbGxvdWIKS8uT7EiStoU1SM=
|
||||
github.com/quic-go/quic-go v0.32.0 h1:lY02md31s1JgPiiyfqJijpu/UX/Iun304FI3yUqX7tA=
|
||||
github.com/quic-go/quic-go v0.32.0/go.mod h1:/fCsKANhQIeD5l76c2JFU+07gVE3KaA0FP+0zMWwfwo=
|
||||
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b h1:gQZ0qzfKHQIybLANtM3mBXNUtOfsCFXeTsnBqCsx1KM=
|
||||
github.com/satori/go.uuid v1.2.1-0.20181028125025-b2ce2384e17b/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
|
||||
github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw=
|
||||
github.com/shirou/gopsutil/v3 v3.22.11 h1:kxsPKS+Eeo+VnEQ2XCaGJepeP6KY53QoRTETx3+1ndM=
|
||||
github.com/shirou/gopsutil/v3 v3.22.11/go.mod h1:xl0EeL4vXJ+hQMAGN8B9VFpxukEMA0XdevQOe5MZ1oY=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
|
||||
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
|
||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/viper v1.7.1/go.mod h1:8WkrPz2fc9jxqZNCJI/76HCieCp4Q8HaLFoCha5qpdg=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/sqs/goreturns v0.0.0-20181028201513-538ac6014518/go.mod h1:CKI4AZ4XmGV240rTHfO0hfE83S6/a3/Q1siZJ/vXf7A=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
|
||||
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
|
||||
github.com/tidwall/pretty v1.0.0/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/xdg/scram v0.0.0-20180814205039-7eeb5667e42c/go.mod h1:lB8K/P019DLNhemzwFU4jHLhdvlE6uDZjXFejJXr49I=
|
||||
github.com/xdg/stringprep v0.0.0-20180714160509-73f8eece6fdc/go.mod h1:Jhud4/sHMO4oL310DaZAKk9ZaJ08SJfe+sJh0HrGL1Y=
|
||||
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
|
||||
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||
go.mongodb.org/mongo-driver v1.4.3/go.mod h1:WcMNYLx/IlOxLe6JRJiv2uXuCz6zBLndR4SoGjYphSc=
|
||||
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
|
||||
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
|
||||
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
|
||||
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
|
||||
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
|
||||
github.com/tevino/abool v0.0.0-20170917061928-9b9efcf221b5/go.mod h1:f1SCnEOt6sc3fOJfPQDRDzHOtSXuTtnz0ImG9kPRDV0=
|
||||
github.com/tevino/abool v1.2.0 h1:heAkClL8H6w+mK5md9dzsuohKeXHUpY7Vw0ZCKW+huA=
|
||||
github.com/tevino/abool v1.2.0/go.mod h1:qc66Pna1RiIsPa7O4Egxxs9OqkuxDX55zznh9K07Tzg=
|
||||
github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM=
|
||||
github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI=
|
||||
github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms=
|
||||
github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4=
|
||||
github.com/x-cray/logrus-prefixed-formatter v0.5.2 h1:00txxvfBM9muc0jiLIEAkAcIMJzfthRT6usrui8uGmg=
|
||||
github.com/x-cray/logrus-prefixed-formatter v0.5.2/go.mod h1:2duySbKsL6M18s5GU7VPsoEPHyzalCE06qoARUCeBBE=
|
||||
github.com/yapingcat/gomedia v0.0.0-20230727105416-c491e66c9d2a h1:x60q0A7QmoUTzixNz7zVTdEA9JC0oYqm8S51PdbTWgs=
|
||||
github.com/yapingcat/gomedia v0.0.0-20230727105416-c491e66c9d2a/go.mod h1:WSZ59bidJOO40JSJmLqlkBJrjZCtjbKKkygEMfzY/kc=
|
||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
|
||||
github.com/yusufpapurcu/wmi v1.2.2/go.mod h1:SBZ9tNy3G9/m5Oi98Zks0QjeHVDvuK0qfxQmPyzfmi0=
|
||||
go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc=
|
||||
go.uber.org/atomic v1.10.0 h1:9qC72Qh0+3MqyJbAn8YU5xVq1frD8bn3JtD2oXtafVQ=
|
||||
go.uber.org/atomic v1.10.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0=
|
||||
go.uber.org/goleak v1.1.11 h1:wy28qYRKZgnJTxGxvye5/wgWr1EKjmUDGYox5mGlRlI=
|
||||
go.uber.org/multierr v1.8.0 h1:dg6GjLku4EH+249NNmoIciG9N/jURbDG+pFlTkhzIC8=
|
||||
go.uber.org/multierr v1.8.0/go.mod h1:7EAYxJLBy9rStEaz58O2t4Uvip6FSURkq8/ppBp95ak=
|
||||
go.uber.org/zap v1.24.0 h1:FiJd5l1UOLj0wCgbSE0rwwXHzEdAZS6hiiSnxJN/D60=
|
||||
go.uber.org/zap v1.24.0/go.mod h1:2kMP+WWQ8aoFoedH3T2sq6iJ2yDWpHbP0f6MQbS9Gkg=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190422162423-af44ce270edf/go.mod h1:WFFai1msRO1wXaEeE5yQxYXgSfI8pQAWXbQop6sCtWE=
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190530122614-20be4c3c3ed5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
golang.org/x/exp v0.0.0-20190829153037-c13cbed26979/go.mod h1:86+5VVa7VpoJ4kLfm080zCjGlMRFzhUhsZKEZO7MGek=
|
||||
golang.org/x/exp v0.0.0-20191030013958-a1ab85dbe136/go.mod h1:JXzH8nQsPlswgeRAPE3MuO9GYsAcnJvJ4vnMwN/5qkY=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||
golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||
golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc=
|
||||
golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
|
||||
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU=
|
||||
golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58=
|
||||
golang.org/x/crypto v0.11.0 h1:6Ewdq3tDic1mg5xRO4milcWCfMVQhI4NkqWWvqejpuA=
|
||||
golang.org/x/crypto v0.11.0/go.mod h1:xgJhtzW8F9jGdVFWZESrid1U1bjeNy4zgy5cRr/CIio=
|
||||
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db h1:D/cFflL63o2KSLJIwjlcIt8PR064j/xsmdEJL/YvY/o=
|
||||
golang.org/x/exp v0.0.0-20221205204356-47842c84f3db/go.mod h1:CxIveKay+FTh1D0yPZemJVgC/95VzuuOLq5Qi4xnoYc=
|
||||
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
|
||||
golang.org/x/mod v0.8.0 h1:LUYupSeNrTNCGzR/hVBk2NHZO4hXcVaW1k4Qx7rjPx8=
|
||||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181023162649-9b4f9f5ad519/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181201002055-351d144fa1fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE=
|
||||
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20201202161906-c7110b5ffcbb/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
|
||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
|
||||
golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
|
||||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
|
||||
golang.org/x/net v0.1.0/go.mod h1:Cx3nUiGt4eDBEyega/BKRp+/AlGL8hYe7U9odMt2Cco=
|
||||
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws=
|
||||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.7.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
|
||||
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
|
||||
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190412183630-56d357773e84/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a h1:DcqTD9SDLc+1P/r1EmRBwnVsrOwW+kk2vWf9n+1sGhs=
|
||||
golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
|
||||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181026203630-95b1ffbd15a5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181107165924-66b7b1311ac8/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190403152447-81d4e9dc473e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190419153524-e8e3143a4f4a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190502145724-3ef323f4f1fd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190507160741-ecd444e8653b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190531175056-4c3a928424d2/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190606165138-5da285871e9c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190624142023-c5567b49c5d0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190916202348-b4ddaad3f8a3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da h1:b3NXsE2LusjYGGjL5bxEVZZORm/YEFFrWFjR8eFrw/c=
|
||||
golang.org/x/sys v0.0.0-20201204225414-ed752295db88/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20201207223542-d4d67f95c62d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210510120138-977fb7262007/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
|
||||
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.1.0/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ=
|
||||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
|
||||
golang.org/x/term v0.10.0 h1:3R7pNqamzBraeqj/Tj8qt1aQ2HpmlC+Cx/qL/7hn4/c=
|
||||
golang.org/x/term v0.10.0/go.mod h1:lpqdcUyK/oCiQxvxVrppt5ggO2KCZ5QblwqPnfZ6d5o=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/text v0.3.7 h1:olpwvP2KacW1ZWvsR7uQhoyTYvKAupfQrRGBFM352Gk=
|
||||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.6.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
|
||||
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
|
||||
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190329151228-23e29df326fe/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190416151739-9c9e1878f421/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190420181800-aa740d480789/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190506145303-2d16b83fe98c/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190531172133-b3315ee88b7d/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190606124116-d0a3d012864b/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190628153133-6cdbf07be9d0/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190816200558-6889da9d5479/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20190911174233-4f2ddba30aff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191012152004-8de300cfc20a/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191112195655-aa38f8e97acc/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
|
||||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
|
||||
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
|
||||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/api v0.4.0/go.mod h1:8k5glujaEP+g9n7WNsDg8QP6cUVNI86fCNMcbazEtwE=
|
||||
google.golang.org/api v0.7.0/go.mod h1:WtwebWUNSVBH/HAw79HIFXZNqEvBhG+Ra+ax0hx3E3M=
|
||||
google.golang.org/api v0.8.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||
google.golang.org/api v0.9.0/go.mod h1:o4eAsZoiT+ibD93RtjEohWalFOjRDx6CVaqeizhEnKg=
|
||||
google.golang.org/api v0.13.0/go.mod h1:iLdEw5Ide6rF15KTC1Kkl0iskquN2gFfn9o9XIsbkAI=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190425155659-357c62f0e4bb/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190801165951-fa694d86fc64/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
|
||||
google.golang.org/genproto v0.0.0-20190911173649-1774047e7e51/go.mod h1:IbNlFCBrqXvoKpeg0TB2l7cyZUmoaFKYIwrEpbDKLA8=
|
||||
google.golang.org/genproto v0.0.0-20191108220845-16a3f7862a1a/go.mod h1:n3cpQtvxv34hfy77yVDNjmbRyujviMdxYliBSkLhpCc=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
|
||||
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
|
||||
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
|
||||
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
|
||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
|
||||
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
|
||||
google.golang.org/protobuf v1.28.0 h1:w43yiav+6bVFTBQFZX0r7ipe9JQ1QsbMgHwbBziscLw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU=
|
||||
gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
|
||||
gopkg.in/natefinch/lumberjack.v2 v2.0.0/go.mod h1:l0ndWWf7gzL7RNwBG7wST/UCcT4T24xpD6X8LsfU/+k=
|
||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190418001031-e561f6794a2a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
rsc.io/binaryregexp v0.2.0/go.mod h1:qTv7/COck+e2FymRvadv62gMdZztPaShugOCi3I+8D8=
|
||||
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
m7s.live/engine/v4 v4.13.8 h1:pDl8YWxip5aTidw2Q4NuU+8A6irBraLRfoeBi42S6iQ=
|
||||
m7s.live/engine/v4 v4.13.8/go.mod h1:k/6iFSuJxmhJL8VO45NAga8BbgZHLLfRXOwCcCzk2s8=
|
||||
m7s.live/plugin/ps/v4 v4.0.9 h1:79iHz546EdjhH2Op5IMXsjO0SK9tUk9AFSWKo0VON3w=
|
||||
m7s.live/plugin/ps/v4 v4.0.9/go.mod h1:v59bPt1T+IxuRLRchQ+PwKkLxTRuEY4tbo13lNX6JPc=
|
||||
|
||||
316
handle.go
316
handle.go
@@ -2,129 +2,347 @@ package gb28181
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/xml"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transaction"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
"github.com/logrusorgru/aurora"
|
||||
"fmt"
|
||||
"strconv"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"m7s.live/plugin/gb28181/v4/utils"
|
||||
|
||||
"github.com/ghettovoice/gosip/sip"
|
||||
|
||||
. "github.com/Monibuca/utils/v3"
|
||||
"golang.org/x/net/html/charset"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"golang.org/x/net/html/charset"
|
||||
)
|
||||
|
||||
func OnRegister(req *sip.Request, tx *transaction.GBTx) {
|
||||
id := req.From.Uri.UserInfo()
|
||||
type Authorization struct {
|
||||
*sip.Authorization
|
||||
}
|
||||
|
||||
func (a *Authorization) Verify(username, passwd, realm, nonce string) bool {
|
||||
|
||||
//1、将 username,realm,password 依次组合获取 1 个字符串,并用算法加密的到密文 r1
|
||||
s1 := fmt.Sprintf("%s:%s:%s", username, realm, passwd)
|
||||
r1 := a.getDigest(s1)
|
||||
//2、将 method,即REGISTER ,uri 依次组合获取 1 个字符串,并对这个字符串使用算法 加密得到密文 r2
|
||||
s2 := fmt.Sprintf("REGISTER:%s", a.Uri())
|
||||
r2 := a.getDigest(s2)
|
||||
|
||||
if r1 == "" || r2 == "" {
|
||||
GB28181Plugin.Error("Authorization algorithm wrong")
|
||||
return false
|
||||
}
|
||||
//3、将密文 1,nonce 和密文 2 依次组合获取 1 个字符串,并对这个字符串使用算法加密,获得密文 r3,即Response
|
||||
s3 := fmt.Sprintf("%s:%s:%s", r1, nonce, r2)
|
||||
r3 := a.getDigest(s3)
|
||||
|
||||
//4、计算服务端和客户端上报的是否相等
|
||||
return r3 == a.Response()
|
||||
}
|
||||
|
||||
func (a *Authorization) getDigest(raw string) string {
|
||||
switch a.Algorithm() {
|
||||
case "MD5":
|
||||
return fmt.Sprintf("%x", md5.Sum([]byte(raw)))
|
||||
default: //如果没有算法,默认使用MD5
|
||||
return fmt.Sprintf("%x", md5.Sum([]byte(raw)))
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) OnRegister(req sip.Request, tx sip.ServerTransaction) {
|
||||
from, ok := req.From()
|
||||
if !ok || from.Address == nil {
|
||||
GB28181Plugin.Error("OnRegister", zap.String("error", "no from"))
|
||||
return
|
||||
}
|
||||
id := from.Address.User().String()
|
||||
|
||||
GB28181Plugin.Debug("SIP<-OnMessage", zap.String("id", id), zap.String("source", req.Source()), zap.String("req", req.String()))
|
||||
|
||||
isUnregister := false
|
||||
if exps := req.GetHeaders("Expires"); len(exps) > 0 {
|
||||
exp := exps[0]
|
||||
expSec, err := strconv.ParseInt(exp.Value(), 10, 32)
|
||||
if err != nil {
|
||||
GB28181Plugin.Info("OnRegister",
|
||||
zap.String("error", fmt.Sprintf("wrong expire header value %q", exp)),
|
||||
zap.String("id", id),
|
||||
zap.String("source", req.Source()),
|
||||
zap.String("destination", req.Destination()))
|
||||
return
|
||||
}
|
||||
if expSec == 0 {
|
||||
isUnregister = true
|
||||
}
|
||||
} else {
|
||||
GB28181Plugin.Info("OnRegister",
|
||||
zap.String("error", "has no expire header"),
|
||||
zap.String("id", id),
|
||||
zap.String("source", req.Source()),
|
||||
zap.String("destination", req.Destination()))
|
||||
return
|
||||
}
|
||||
|
||||
GB28181Plugin.Info("OnRegister",
|
||||
zap.Bool("isUnregister", isUnregister),
|
||||
zap.String("id", id),
|
||||
zap.String("source", req.Source()),
|
||||
zap.String("destination", req.Destination()))
|
||||
|
||||
if len(id) != 20 {
|
||||
GB28181Plugin.Info("Wrong GB-28181", zap.String("id", id))
|
||||
return
|
||||
}
|
||||
passAuth := false
|
||||
// 不需要密码情况
|
||||
if config.Username == "" && config.Password == "" {
|
||||
if c.Username == "" && c.Password == "" {
|
||||
passAuth = true
|
||||
} else {
|
||||
// 需要密码情况 设备第一次上报,返回401和加密算法
|
||||
if req.Authorization != nil && req.Authorization.GetUsername() != "" {
|
||||
if hdrs := req.GetHeaders("Authorization"); len(hdrs) > 0 {
|
||||
authenticateHeader := hdrs[0].(*sip.GenericHeader)
|
||||
auth := &Authorization{sip.AuthFromValue(authenticateHeader.Contents)}
|
||||
|
||||
// 有些摄像头没有配置用户名的地方,用户名就是摄像头自己的国标id
|
||||
var username string
|
||||
if req.Authorization.GetUsername() == id {
|
||||
if auth.Username() == id {
|
||||
username = id
|
||||
} else {
|
||||
username = config.Username
|
||||
username = c.Username
|
||||
}
|
||||
|
||||
if dc, ok := DeviceRegisterCount.LoadOrStore(id, 1); ok && dc.(int) > MaxRegisterCount {
|
||||
var response sip.Response
|
||||
response.Message = req.BuildResponse(http.StatusForbidden)
|
||||
_ = tx.Respond(&response)
|
||||
response := sip.NewResponseFromRequest("", req, http.StatusForbidden, "Forbidden", "")
|
||||
tx.Respond(response)
|
||||
return
|
||||
} else {
|
||||
// 设备第二次上报,校验
|
||||
_nonce, loaded := DeviceNonce.Load(id)
|
||||
if loaded && req.Authorization.Verify(username, config.Password, config.Realm, _nonce.(string)) {
|
||||
if loaded && auth.Verify(username, c.Password, c.Realm, _nonce.(string)) {
|
||||
passAuth = true
|
||||
} else {
|
||||
DeviceRegisterCount.Store(id, dc.(int)+1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if passAuth {
|
||||
storeDevice(id, tx.Core, req.Message)
|
||||
var d *Device
|
||||
if isUnregister {
|
||||
tmpd, ok := Devices.LoadAndDelete(id)
|
||||
if ok {
|
||||
GB28181Plugin.Info("Unregister Device", zap.String("id", id))
|
||||
d = tmpd.(*Device)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if v, ok := Devices.Load(id); ok {
|
||||
d = v.(*Device)
|
||||
c.RecoverDevice(d, req)
|
||||
} else {
|
||||
d = c.StoreDevice(id, req)
|
||||
}
|
||||
}
|
||||
DeviceNonce.Delete(id)
|
||||
DeviceRegisterCount.Delete(id)
|
||||
m := req.BuildOK()
|
||||
resp := &sip.Response{Message: m}
|
||||
resp := sip.NewResponseFromRequest("", req, http.StatusOK, "OK", "")
|
||||
to, _ := resp.To()
|
||||
resp.ReplaceHeaders("To", []sip.Header{&sip.ToHeader{Address: to.Address, Params: sip.NewParams().Add("tag", sip.String{Str: utils.RandNumString(9)})}})
|
||||
resp.RemoveHeader("Allow")
|
||||
expires := sip.Expires(3600)
|
||||
resp.AppendHeader(&expires)
|
||||
resp.AppendHeader(&sip.GenericHeader{
|
||||
HeaderName: "Date",
|
||||
Contents: time.Now().Format(TIME_LAYOUT),
|
||||
})
|
||||
_ = tx.Respond(resp)
|
||||
|
||||
if !isUnregister {
|
||||
//订阅设备更新
|
||||
go d.syncChannels()
|
||||
}
|
||||
} else {
|
||||
var response sip.Response
|
||||
response.Message = req.BuildResponseWithPhrase(401, "Unauthorized")
|
||||
GB28181Plugin.Info("OnRegister unauthorized", zap.String("id", id), zap.String("source", req.Source()),
|
||||
zap.String("destination", req.Destination()))
|
||||
response := sip.NewResponseFromRequest("", req, http.StatusUnauthorized, "Unauthorized", "")
|
||||
_nonce, _ := DeviceNonce.LoadOrStore(id, utils.RandNumString(32))
|
||||
response.WwwAuthenticate = sip.NewWwwAuthenticate(config.Realm, _nonce.(string), sip.DIGEST_ALGO_MD5)
|
||||
response.SourceAdd = req.DestAdd
|
||||
response.DestAdd = req.SourceAdd
|
||||
_ = tx.Respond(&response)
|
||||
auth := fmt.Sprintf(
|
||||
`Digest realm="%s",algorithm=%s,nonce="%s"`,
|
||||
c.Realm,
|
||||
"MD5",
|
||||
_nonce.(string),
|
||||
)
|
||||
response.AppendHeader(&sip.GenericHeader{
|
||||
HeaderName: "WWW-Authenticate",
|
||||
Contents: auth,
|
||||
})
|
||||
_ = tx.Respond(response)
|
||||
}
|
||||
}
|
||||
func OnMessage(req *sip.Request, tx *transaction.GBTx) {
|
||||
|
||||
if v, ok := Devices.Load(req.From.Uri.UserInfo()); ok {
|
||||
// syncChannels
|
||||
// 同步设备信息、下属通道信息,包括主动查询通道信息,订阅通道变化情况
|
||||
func (d *Device) syncChannels() {
|
||||
if time.Since(d.lastSyncTime) > 2*conf.HeartbeatInterval {
|
||||
d.lastSyncTime = time.Now()
|
||||
d.Catalog()
|
||||
d.Subscribe()
|
||||
d.QueryDeviceInfo()
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) OnMessage(req sip.Request, tx sip.ServerTransaction) {
|
||||
from, _ := req.From()
|
||||
id := from.Address.User().String()
|
||||
GB28181Plugin.Debug("SIP<-OnMessage", zap.String("id", id), zap.String("source", req.Source()), zap.String("req", req.String()))
|
||||
if v, ok := Devices.Load(id); ok {
|
||||
d := v.(*Device)
|
||||
if d.Status == string(sip.REGISTER) {
|
||||
d.Status = "ONLINE"
|
||||
go d.Query(req)
|
||||
switch d.Status {
|
||||
case DeviceOfflineStatus, DeviceRecoverStatus:
|
||||
c.RecoverDevice(d, req)
|
||||
go d.syncChannels()
|
||||
case DeviceRegisterStatus:
|
||||
d.Status = DeviceOnlineStatus
|
||||
}
|
||||
d.UpdateTime = time.Now()
|
||||
temp := &struct {
|
||||
XMLName xml.Name
|
||||
CmdType string
|
||||
SN int // 请求序列号,一般用于对应 request 和 response
|
||||
DeviceID string
|
||||
DeviceName string
|
||||
Manufacturer string
|
||||
Model string
|
||||
Channel string
|
||||
DeviceList []*Channel `xml:"DeviceList>Item"`
|
||||
RecordList []*Record `xml:"RecordList>Item"`
|
||||
DeviceList []ChannelInfo `xml:"DeviceList>Item"`
|
||||
RecordList []*Record `xml:"RecordList>Item"`
|
||||
SumNum int // 录像结果的总数 SumNum,录像结果会按照多条消息返回,可用于判断是否全部返回
|
||||
}{}
|
||||
decoder := xml.NewDecoder(bytes.NewReader([]byte(req.Body)))
|
||||
decoder := xml.NewDecoder(bytes.NewReader([]byte(req.Body())))
|
||||
decoder.CharsetReader = charset.NewReaderLabel
|
||||
err := decoder.Decode(temp)
|
||||
if err != nil {
|
||||
err = utils.DecodeGbk(temp, []byte(req.Body))
|
||||
err = utils.DecodeGbk(temp, []byte(req.Body()))
|
||||
if err != nil {
|
||||
Printf("decode catelog err: %s", err)
|
||||
GB28181Plugin.Error("decode catelog err", zap.Error(err))
|
||||
}
|
||||
}
|
||||
var body string
|
||||
switch temp.CmdType {
|
||||
case "Keepalive":
|
||||
if d.subscriber.CallID != "" && time.Now().After(d.subscriber.Timeout) {
|
||||
go d.Subscribe(req)
|
||||
d.LastKeepaliveAt = time.Now()
|
||||
//callID !="" 说明是订阅的事件类型信息
|
||||
if d.lastSyncTime.IsZero() {
|
||||
go d.syncChannels()
|
||||
} else {
|
||||
d.channelMap.Range(func(key, value interface{}) bool {
|
||||
if conf.InviteMode == INVIDE_MODE_AUTO {
|
||||
value.(*Channel).TryAutoInvite(&InviteOptions{})
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
//在KeepLive 进行位置订阅的处理,如果开启了自动订阅位置,则去订阅位置
|
||||
if c.Position.AutosubPosition && time.Since(d.GpsTime) > c.Position.Interval*2 {
|
||||
d.MobilePositionSubscribe(d.ID, c.Position.Expires, c.Position.Interval)
|
||||
GB28181Plugin.Debug("Mobile Position Subscribe", zap.String("deviceID", d.ID))
|
||||
}
|
||||
d.CheckSubStream()
|
||||
case "Catalog":
|
||||
d.UpdateChannels(temp.DeviceList)
|
||||
d.UpdateChannels(temp.DeviceList...)
|
||||
case "RecordInfo":
|
||||
d.UpdateRecord(temp.DeviceID, temp.RecordList)
|
||||
RecordQueryLink.Put(d.ID, temp.DeviceID, temp.SN, temp.SumNum, temp.RecordList)
|
||||
case "DeviceInfo":
|
||||
// 主设备信息
|
||||
d.Name = temp.DeviceName
|
||||
d.Manufacturer = temp.Manufacturer
|
||||
d.Model = temp.Model
|
||||
case "Alarm":
|
||||
d.Status = "Alarmed"
|
||||
body = sip.BuildAlarmResponseXML(d.ID)
|
||||
d.Status = DeviceAlarmedStatus
|
||||
body = BuildAlarmResponseXML(d.ID)
|
||||
default:
|
||||
Println("DeviceID:", aurora.Red(d.ID), " Not supported CmdType : "+temp.CmdType+" body:\n", req.Body)
|
||||
response := &sip.Response{req.BuildResponse(http.StatusBadRequest)}
|
||||
d.Warn("Not supported CmdType", zap.String("CmdType", temp.CmdType), zap.String("body", req.Body()))
|
||||
response := sip.NewResponseFromRequest("", req, http.StatusBadRequest, "", "")
|
||||
tx.Respond(response)
|
||||
return
|
||||
}
|
||||
|
||||
buildOK := req.BuildOK()
|
||||
buildOK.Body = body
|
||||
response := &sip.Response{buildOK}
|
||||
tx.Respond(response)
|
||||
tx.Respond(sip.NewResponseFromRequest("", req, http.StatusOK, "OK", body))
|
||||
} else {
|
||||
GB28181Plugin.Debug("Unauthorized message, device not found", zap.String("id", id))
|
||||
}
|
||||
}
|
||||
func (c *GB28181Config) OnBye(req sip.Request, tx sip.ServerTransaction) {
|
||||
tx.Respond(sip.NewResponseFromRequest("", req, http.StatusOK, "OK", ""))
|
||||
}
|
||||
|
||||
// OnNotify 订阅通知处理
|
||||
func (c *GB28181Config) OnNotify(req sip.Request, tx sip.ServerTransaction) {
|
||||
from, _ := req.From()
|
||||
id := from.Address.User().String()
|
||||
if v, ok := Devices.Load(id); ok {
|
||||
d := v.(*Device)
|
||||
d.UpdateTime = time.Now()
|
||||
temp := &struct {
|
||||
XMLName xml.Name
|
||||
CmdType string
|
||||
DeviceID string
|
||||
Time string //位置订阅-GPS时间
|
||||
Longitude string //位置订阅-经度
|
||||
Latitude string //位置订阅-维度
|
||||
// Speed string //位置订阅-速度(km/h)(可选)
|
||||
// Direction string //位置订阅-方向(取值为当前摄像头方向与正北方的顺时针夹角,取值范围0°~360°,单位:°)(可选)
|
||||
// Altitude string //位置订阅-海拔高度,单位:m(可选)
|
||||
DeviceList []*notifyMessage `xml:"DeviceList>Item"` //目录订阅
|
||||
}{}
|
||||
decoder := xml.NewDecoder(bytes.NewReader([]byte(req.Body())))
|
||||
decoder.CharsetReader = charset.NewReaderLabel
|
||||
err := decoder.Decode(temp)
|
||||
if err != nil {
|
||||
err = utils.DecodeGbk(temp, []byte(req.Body()))
|
||||
if err != nil {
|
||||
GB28181Plugin.Error("decode catelog err", zap.Error(err))
|
||||
}
|
||||
}
|
||||
var body string
|
||||
switch temp.CmdType {
|
||||
case "Catalog":
|
||||
//目录状态
|
||||
d.UpdateChannelStatus(temp.DeviceList)
|
||||
case "MobilePosition":
|
||||
//更新channel的坐标
|
||||
d.UpdateChannelPosition(temp.DeviceID, temp.Time, temp.Longitude, temp.Latitude)
|
||||
// case "Alarm":
|
||||
// //报警事件通知 TODO
|
||||
default:
|
||||
d.Warn("Not supported CmdType", zap.String("CmdType", temp.CmdType), zap.String("body", req.Body()))
|
||||
response := sip.NewResponseFromRequest("", req, http.StatusBadRequest, "", "")
|
||||
tx.Respond(response)
|
||||
return
|
||||
}
|
||||
|
||||
tx.Respond(sip.NewResponseFromRequest("", req, http.StatusOK, "OK", body))
|
||||
}
|
||||
}
|
||||
|
||||
type notifyMessage struct {
|
||||
DeviceID string
|
||||
ParentID string
|
||||
Name string
|
||||
Manufacturer string
|
||||
Model string
|
||||
Owner string
|
||||
CivilCode string
|
||||
Address string
|
||||
Port int
|
||||
Parental int
|
||||
SafetyWay int
|
||||
RegisterWay int
|
||||
Secrecy int
|
||||
Status string
|
||||
//状态改变事件 ON:上线,OFF:离线,VLOST:视频丢失,DEFECT:故障,ADD:增加,DEL:删除,UPDATE:更新(必选)
|
||||
Event string
|
||||
}
|
||||
|
||||
67
inviteoption.go
Normal file
67
inviteoption.go
Normal file
@@ -0,0 +1,67 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type InviteOptions struct {
|
||||
Start int
|
||||
End int
|
||||
dump string
|
||||
ssrc string
|
||||
SSRC uint32
|
||||
MediaPort uint16
|
||||
StreamPath string
|
||||
recyclePort func(p uint16) (err error)
|
||||
}
|
||||
|
||||
func (o InviteOptions) IsLive() bool {
|
||||
return o.Start == 0 || o.End == 0
|
||||
}
|
||||
|
||||
func (o InviteOptions) Record() bool {
|
||||
return !o.IsLive()
|
||||
}
|
||||
|
||||
func (o *InviteOptions) Validate(start, end string) error {
|
||||
if start != "" {
|
||||
sint, err1 := strconv.ParseInt(start, 10, 0)
|
||||
if err1 != nil {
|
||||
return err1
|
||||
}
|
||||
o.Start = int(sint)
|
||||
}
|
||||
if end != "" {
|
||||
eint, err2 := strconv.ParseInt(end, 10, 0)
|
||||
if err2 != nil {
|
||||
return err2
|
||||
}
|
||||
o.End = int(eint)
|
||||
}
|
||||
if o.Start >= o.End {
|
||||
return errors.New("start < end")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o InviteOptions) String() string {
|
||||
return fmt.Sprintf("t=%d %d", o.Start, o.End)
|
||||
}
|
||||
|
||||
func (o *InviteOptions) CreateSSRC() {
|
||||
ssrc := make([]byte, 10)
|
||||
if o.IsLive() {
|
||||
ssrc[0] = '0'
|
||||
} else {
|
||||
ssrc[0] = '1'
|
||||
}
|
||||
copy(ssrc[1:6], conf.Serial[3:8])
|
||||
randNum := 1000 + rand.Intn(8999)
|
||||
copy(ssrc[6:], strconv.Itoa(randNum))
|
||||
o.ssrc = string(ssrc)
|
||||
_ssrc, _ := strconv.ParseInt(o.ssrc, 10, 0)
|
||||
o.SSRC = uint32(_ssrc)
|
||||
}
|
||||
119
link.go
Normal file
119
link.go
Normal file
@@ -0,0 +1,119 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// 对于录像查询,通过 queryKey (即 deviceId + channelId + sn) 唯一区分一次请求和响应
|
||||
// 并将其关联起来,以实现异步响应的目的
|
||||
// 提供单例实例供调用
|
||||
var RecordQueryLink = NewRecordQueryLink(time.Second * 60)
|
||||
|
||||
type recordQueryLink struct {
|
||||
pendingResult map[string]recordQueryResult // queryKey 查询结果缓存
|
||||
pendingResp map[string]recordQueryResp // queryKey 待回复的查询请求
|
||||
timeout time.Duration // 查询结果的过期时间
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
type recordQueryResult struct {
|
||||
time time.Time
|
||||
err error
|
||||
sum int
|
||||
finished bool
|
||||
list []*Record
|
||||
}
|
||||
type recordQueryResp struct {
|
||||
respChan chan<- recordQueryResult
|
||||
timeout time.Duration
|
||||
startTime time.Time
|
||||
}
|
||||
|
||||
func NewRecordQueryLink(resultTimeout time.Duration) *recordQueryLink {
|
||||
c := &recordQueryLink{
|
||||
timeout: resultTimeout,
|
||||
pendingResult: make(map[string]recordQueryResult),
|
||||
pendingResp: make(map[string]recordQueryResp),
|
||||
}
|
||||
return c
|
||||
}
|
||||
|
||||
// 唯一区分一次录像查询
|
||||
func recordQueryKey(deviceId, channelId string, sn int) string {
|
||||
return fmt.Sprintf("%s-%s-%d", deviceId, channelId, sn)
|
||||
}
|
||||
|
||||
// 定期清理过期的查询结果和请求
|
||||
func (c *recordQueryLink) cleanTimeout() {
|
||||
for k, s := range c.pendingResp {
|
||||
if time.Since(s.startTime) > s.timeout {
|
||||
if r, ok := c.pendingResult[k]; ok {
|
||||
c.notify(k, r)
|
||||
} else {
|
||||
c.notify(k, recordQueryResult{err: fmt.Errorf("query time out")})
|
||||
}
|
||||
}
|
||||
}
|
||||
for k, r := range c.pendingResult {
|
||||
if time.Since(r.time) > c.timeout {
|
||||
delete(c.pendingResult, k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *recordQueryLink) Put(deviceId, channelId string, sn int, sum int, record []*Record) {
|
||||
key, r := c.doPut(deviceId, channelId, sn, sum, record)
|
||||
if r.finished {
|
||||
c.notify(key, r)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *recordQueryLink) doPut(deviceId, channelId string, sn, sum int, record []*Record) (key string, r recordQueryResult) {
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
key = recordQueryKey(deviceId, channelId, sn)
|
||||
if v, ok := c.pendingResult[key]; ok {
|
||||
r = v
|
||||
} else {
|
||||
r = recordQueryResult{time: time.Now(), sum: sum, list: make([]*Record, 0)}
|
||||
}
|
||||
|
||||
r.list = append(r.list, record...)
|
||||
if len(r.list) == sum {
|
||||
r.finished = true
|
||||
}
|
||||
c.pendingResult[key] = r
|
||||
GB28181Plugin.Logger.Debug("put record",
|
||||
zap.String("key", key),
|
||||
zap.Int("sum", sum),
|
||||
zap.Int("count", len(r.list)))
|
||||
return
|
||||
}
|
||||
|
||||
func (c *recordQueryLink) WaitResult(
|
||||
deviceId, channelId string, sn int,
|
||||
timeout time.Duration) (resultCh <-chan recordQueryResult) {
|
||||
|
||||
key := recordQueryKey(deviceId, channelId, sn)
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
respCh := make(chan recordQueryResult, 1)
|
||||
resultCh = respCh
|
||||
c.pendingResp[key] = recordQueryResp{startTime: time.Now(), timeout: timeout, respChan: respCh}
|
||||
return
|
||||
}
|
||||
|
||||
func (c *recordQueryLink) notify(key string, r recordQueryResult) {
|
||||
if s, ok := c.pendingResp[key]; ok {
|
||||
s.respChan <- r
|
||||
}
|
||||
c.Lock()
|
||||
defer c.Unlock()
|
||||
delete(c.pendingResp, key)
|
||||
delete(c.pendingResult, key)
|
||||
GB28181Plugin.Logger.Debug("record notify", zap.String("key", key))
|
||||
}
|
||||
421
main.go
421
main.go
@@ -1,330 +1,141 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/engine/v3"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transaction"
|
||||
. "github.com/Monibuca/utils/v3"
|
||||
. "github.com/logrusorgru/aurora"
|
||||
"github.com/pion/rtp"
|
||||
myip "github.com/husanpao/ip"
|
||||
"go.uber.org/zap"
|
||||
. "m7s.live/engine/v4"
|
||||
"m7s.live/engine/v4/util"
|
||||
)
|
||||
|
||||
var (
|
||||
Ignores = make(map[string]struct{})
|
||||
publishers Publishers
|
||||
serverConfig *transaction.Config
|
||||
)
|
||||
|
||||
const MaxRegisterCount = 3
|
||||
|
||||
func FindChannel(deviceId string, channelId string) (c *Channel) {
|
||||
if v, ok := Devices.Load(deviceId); ok {
|
||||
d := v.(*Device)
|
||||
d.channelMutex.RLock()
|
||||
c = d.channelMap[channelId]
|
||||
d.channelMutex.RUnlock()
|
||||
}
|
||||
return
|
||||
type GB28181PositionConfig struct {
|
||||
AutosubPosition bool //是否自动订阅定位
|
||||
Expires time.Duration `default:"3600s"` //订阅周期(单位:秒)
|
||||
Interval time.Duration `default:"6s"` //订阅间隔(单位:秒)
|
||||
}
|
||||
|
||||
type Publishers struct {
|
||||
data map[uint32]*Publisher
|
||||
sync.RWMutex
|
||||
type GB28181Config struct {
|
||||
InviteMode int `default:"1"` //邀请模式,0:手动拉流,1:预拉流,2:按需拉流
|
||||
InviteIDs string //按照国标gb28181协议允许邀请的设备类型:132 摄像机 NVR
|
||||
ListenAddr string `default:"0.0.0.0"`
|
||||
//sip服务器的配置
|
||||
SipNetwork string `default:"udp"` //传输协议,默认UDP,可选TCP
|
||||
SipIP string //sip 服务器公网IP
|
||||
SipPort uint16 `default:"5060"` //sip 服务器端口,默认 5060
|
||||
Serial string `default:"34020000002000000001"` //sip 服务器 id, 默认 34020000002000000001
|
||||
Realm string `default:"3402000000"` //sip 服务器域,默认 3402000000
|
||||
Username string //sip 服务器账号
|
||||
Password string //sip 服务器密码
|
||||
Port struct { // 新配置方式
|
||||
Sip string `default:"udp:5060"`
|
||||
Media string `default:"tcp:58200-59200"`
|
||||
}
|
||||
// AckTimeout uint16 //sip 服务应答超时,单位秒
|
||||
RegisterValidity time.Duration `default:"3600s"` //注册有效期,单位秒,默认 3600
|
||||
// RegisterInterval int //注册间隔,单位秒,默认 60
|
||||
HeartbeatInterval time.Duration `default:"60s"` //心跳间隔,单位秒,默认 60
|
||||
// HeartbeatRetry int //心跳超时次数,默认 3
|
||||
|
||||
//媒体服务器配置
|
||||
MediaIP string //媒体服务器地址
|
||||
MediaPort uint16 `default:"58200"` //媒体服务器端口
|
||||
MediaNetwork string `default:"tcp"` //媒体传输协议,默认UDP,可选TCP
|
||||
MediaPortMin uint16 `default:"58200"`
|
||||
MediaPortMax uint16 `default:"59200"`
|
||||
// MediaIdleTimeout uint16 //推流超时时间,超过则断开链接,让设备重连
|
||||
|
||||
// WaitKeyFrame bool //是否等待关键帧,如果等待,则在收到第一个关键帧之前,忽略所有媒体流
|
||||
RemoveBanInterval time.Duration `default:"600s"` //移除禁止设备间隔
|
||||
// UdpCacheSize int //udp缓存大小
|
||||
LogLevel string `default:"info"` //trace, debug, info, warn, error, fatal, panic
|
||||
routes map[string]string
|
||||
DumpPath string //dump PS流本地文件路径
|
||||
Ignores map[string]struct{}
|
||||
tcpPorts PortManager
|
||||
udpPorts PortManager
|
||||
|
||||
Position GB28181PositionConfig //关于定位的配置参数
|
||||
|
||||
}
|
||||
|
||||
func (p *Publishers) Add(key uint32, pp *Publisher) {
|
||||
p.Lock()
|
||||
p.data[key] = pp
|
||||
p.Unlock()
|
||||
}
|
||||
func (p *Publishers) Remove(key uint32) {
|
||||
p.Lock()
|
||||
delete(p.data, key)
|
||||
p.Unlock()
|
||||
}
|
||||
func (p *Publishers) Get(key uint32) *Publisher {
|
||||
p.RLock()
|
||||
defer p.RUnlock()
|
||||
return p.data[key]
|
||||
}
|
||||
|
||||
var config = struct {
|
||||
Serial string
|
||||
Realm string
|
||||
ListenAddr string
|
||||
Expires int
|
||||
MediaPort uint16
|
||||
AutoInvite bool
|
||||
AutoCloseAfter int
|
||||
Ignore []string
|
||||
TCP bool
|
||||
TCPMediaPortNum uint16
|
||||
RemoveBanInterval int
|
||||
PreFetchRecord bool
|
||||
Username string
|
||||
Password string
|
||||
UdpCacheSize int //udp排序缓存
|
||||
}{"34020000002000000001", "3402000000", "127.0.0.1:5060", 3600, 58200, false, -1, nil, false, 1, 600, false, "", "", 0}
|
||||
|
||||
func init() {
|
||||
pc := engine.PluginConfig{
|
||||
Name: "GB28181",
|
||||
Config: &config,
|
||||
}
|
||||
pc.Install(run)
|
||||
publishers.data = make(map[uint32]*Publisher)
|
||||
}
|
||||
func onBye(req *sip.Request, tx *transaction.GBTx) {
|
||||
response := &sip.Response{req.BuildOK()}
|
||||
_ = tx.Respond(response)
|
||||
}
|
||||
func storeDevice(id string, s *transaction.Core, req *sip.Message) {
|
||||
var d *Device
|
||||
|
||||
if _d, loaded := Devices.LoadOrStore(id, &Device{
|
||||
ID: id,
|
||||
RegisterTime: time.Now(),
|
||||
UpdateTime: time.Now(),
|
||||
Status: string(sip.REGISTER),
|
||||
Core: s,
|
||||
from: &sip.Contact{Uri: req.StartLine.Uri, Params: make(map[string]string)},
|
||||
to: req.To,
|
||||
Addr: req.Via.GetSendBy(),
|
||||
SipIP: serverConfig.MediaIP,
|
||||
channelMap: make(map[string]*Channel),
|
||||
}); loaded {
|
||||
d = _d.(*Device)
|
||||
d.UpdateTime = time.Now()
|
||||
d.from = &sip.Contact{Uri: req.StartLine.Uri, Params: make(map[string]string)}
|
||||
d.to = req.To
|
||||
d.Addr = req.Via.GetSendBy()
|
||||
|
||||
//TODO: Should we send GetDeviceInf request?
|
||||
//message := d.CreateMessage(sip.MESSAGE)
|
||||
//message.Body = sip.GetDeviceInfoXML(d.ID)
|
||||
|
||||
//request := &sip.Request{Message: message}
|
||||
//if newTx, err := s.Request(request); err == nil {
|
||||
// if _, err = newTx.SipResponse(); err != nil {
|
||||
// Println("notify device after register,", err)
|
||||
// return
|
||||
// }
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
func run() {
|
||||
ipAddr, err := net.ResolveUDPAddr("", config.ListenAddr)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
Print(Green("server gb28181 start at"), BrightBlue(config.ListenAddr))
|
||||
for _, id := range config.Ignore {
|
||||
Ignores[id] = struct{}{}
|
||||
}
|
||||
useTCP := config.TCP
|
||||
serverConfig = &transaction.Config{
|
||||
SipIP: ipAddr.IP.String(),
|
||||
SipPort: uint16(ipAddr.Port),
|
||||
SipNetwork: "UDP",
|
||||
Serial: config.Serial,
|
||||
Realm: config.Realm,
|
||||
Username: config.Username,
|
||||
Password: config.Password,
|
||||
AckTimeout: 10,
|
||||
MediaIP: ipAddr.IP.String(),
|
||||
RegisterValidity: config.Expires,
|
||||
RegisterInterval: 60,
|
||||
HeartbeatInterval: 60,
|
||||
HeartbeatRetry: 3,
|
||||
AudioEnable: true,
|
||||
WaitKeyFrame: true,
|
||||
MediaIdleTimeout: 30,
|
||||
RemoveBanInterval: config.RemoveBanInterval,
|
||||
UdpCacheSize: config.UdpCacheSize,
|
||||
}
|
||||
|
||||
s := transaction.NewCore(serverConfig)
|
||||
s.RegistHandler(sip.REGISTER, OnRegister)
|
||||
s.RegistHandler(sip.MESSAGE, OnMessage)
|
||||
s.RegistHandler(sip.BYE, onBye)
|
||||
|
||||
//OnStreamClosedHooks.AddHook(func(stream *Stream) {
|
||||
// Devices.Range(func(key, value interface{}) bool {
|
||||
// device:=value.(*Device)
|
||||
// for _,channel := range device.Channels {
|
||||
// if stream.StreamPath == channel.RecordSP {
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// })
|
||||
//})
|
||||
if useTCP {
|
||||
listenMediaTCP()
|
||||
} else {
|
||||
go listenMediaUDP()
|
||||
}
|
||||
// go queryCatalog(serverConfig)
|
||||
if serverConfig.Username != "" || serverConfig.Password != "" {
|
||||
go removeBanDevice(serverConfig)
|
||||
}
|
||||
|
||||
http.HandleFunc("/api/gb28181/query/records", func(w http.ResponseWriter, r *http.Request) {
|
||||
CORS(w, r)
|
||||
id := r.URL.Query().Get("id")
|
||||
channel := r.URL.Query().Get("channel")
|
||||
startTime := r.URL.Query().Get("startTime")
|
||||
endTime := r.URL.Query().Get("endTime")
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.QueryRecord(startTime, endTime))
|
||||
} else {
|
||||
w.WriteHeader(404)
|
||||
func (c *GB28181Config) initRoutes() {
|
||||
c.routes = make(map[string]string)
|
||||
tempIps := myip.LocalAndInternalIPs()
|
||||
for k, v := range tempIps {
|
||||
c.routes[k] = v
|
||||
if lastdot := strings.LastIndex(k, "."); lastdot >= 0 {
|
||||
c.routes[k[0:lastdot]] = k
|
||||
}
|
||||
})
|
||||
http.HandleFunc("/api/gb28181/list", func(w http.ResponseWriter, r *http.Request) {
|
||||
CORS(w, r)
|
||||
sse := NewSSE(w, r.Context())
|
||||
for {
|
||||
var list []*Device
|
||||
Devices.Range(func(key, value interface{}) bool {
|
||||
device := value.(*Device)
|
||||
if time.Since(device.UpdateTime) > time.Duration(serverConfig.RegisterValidity)*time.Second {
|
||||
Devices.Delete(key)
|
||||
} else {
|
||||
list = append(list, device)
|
||||
}
|
||||
return true
|
||||
})
|
||||
sse.WriteJSON(list)
|
||||
select {
|
||||
case <-time.After(time.Second * 5):
|
||||
case <-sse.Done():
|
||||
return
|
||||
}
|
||||
}
|
||||
GB28181Plugin.Info("LocalAndInternalIPs", zap.Any("routes", c.routes))
|
||||
}
|
||||
|
||||
func (c *GB28181Config) OnEvent(event any) {
|
||||
switch e := event.(type) {
|
||||
case FirstConfig:
|
||||
if c.Port.Sip != "udp:5060" {
|
||||
protocol, ports := util.Conf2Listener(c.Port.Sip)
|
||||
c.SipNetwork = protocol
|
||||
c.SipPort = ports[0]
|
||||
}
|
||||
})
|
||||
http.HandleFunc("/api/gb28181/control", func(w http.ResponseWriter, r *http.Request) {
|
||||
CORS(w, r)
|
||||
id := r.URL.Query().Get("id")
|
||||
channel := r.URL.Query().Get("channel")
|
||||
ptzcmd := r.URL.Query().Get("ptzcmd")
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.Control(ptzcmd))
|
||||
} else {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
})
|
||||
http.HandleFunc("/api/gb28181/invite", func(w http.ResponseWriter, r *http.Request) {
|
||||
CORS(w, r)
|
||||
query := r.URL.Query()
|
||||
id := query.Get("id")
|
||||
channel := r.URL.Query().Get("channel")
|
||||
startTime := query.Get("startTime")
|
||||
endTime := query.Get("endTime")
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
if startTime == "" && c.LivePublisher != nil {
|
||||
w.WriteHeader(304) //直播流已存在
|
||||
if c.Port.Media != "tcp:58200-59200" {
|
||||
protocol, ports := util.Conf2Listener(c.Port.Media)
|
||||
c.MediaNetwork = protocol
|
||||
if len(ports) > 1 {
|
||||
c.MediaPortMin = ports[0]
|
||||
c.MediaPortMax = ports[1]
|
||||
} else {
|
||||
w.WriteHeader(c.Invite(startTime, endTime))
|
||||
c.MediaPortMin = 0
|
||||
c.MediaPortMax = 0
|
||||
c.MediaPort = ports[0]
|
||||
}
|
||||
} else {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
})
|
||||
http.HandleFunc("/api/gb28181/bye", func(w http.ResponseWriter, r *http.Request) {
|
||||
CORS(w, r)
|
||||
id := r.URL.Query().Get("id")
|
||||
channel := r.URL.Query().Get("channel")
|
||||
live := r.URL.Query().Get("live")
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.Bye(live != "false"))
|
||||
} else {
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
})
|
||||
|
||||
s.StartAndWait()
|
||||
}
|
||||
func listenMediaTCP() {
|
||||
for i := uint16(0); i < config.TCPMediaPortNum; i++ {
|
||||
addr := ":" + strconv.Itoa(int(config.MediaPort+i))
|
||||
go ListenTCP(addr, func(conn net.Conn) {
|
||||
var rtpPacket rtp.Packet
|
||||
reader := bufio.NewReader(conn)
|
||||
lenBuf := make([]byte, 2)
|
||||
defer conn.Close()
|
||||
var err error
|
||||
for err == nil {
|
||||
if _, err = io.ReadFull(reader, lenBuf); err != nil {
|
||||
return
|
||||
}
|
||||
ps := make([]byte, BigEndian.Uint16(lenBuf))
|
||||
if _, err = io.ReadFull(reader, ps); err != nil {
|
||||
return
|
||||
}
|
||||
if err := rtpPacket.Unmarshal(ps); err != nil {
|
||||
Println("gb28181 decode rtp error:", err)
|
||||
} else if publisher := publishers.Get(rtpPacket.SSRC); publisher != nil && publisher.Err() == nil {
|
||||
publisher.PushPS(&rtpPacket)
|
||||
os.MkdirAll(c.DumpPath, 0766)
|
||||
c.ReadDevices()
|
||||
go c.initRoutes()
|
||||
c.startServer()
|
||||
case *Stream:
|
||||
if c.InviteMode == INVIDE_MODE_ONSUBSCRIBE {
|
||||
//流可能是回放流,stream path是device/channel/start-end形式
|
||||
streamNames := strings.Split(e.StreamName, "/")
|
||||
if channel := FindChannel(e.AppName, streamNames[0]); channel != nil {
|
||||
opt := InviteOptions{}
|
||||
if len(streamNames) > 1 {
|
||||
last := len(streamNames) - 1
|
||||
timestr := streamNames[last]
|
||||
trange := strings.Split(timestr, "-")
|
||||
if len(trange) == 2 {
|
||||
startTime := trange[0]
|
||||
endTime := trange[1]
|
||||
opt.Validate(startTime, endTime)
|
||||
}
|
||||
}
|
||||
channel.TryAutoInvite(&opt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
func listenMediaUDP() {
|
||||
var rtpPacket rtp.Packet
|
||||
networkBuffer := 1048576
|
||||
addr := ":" + strconv.Itoa(int(config.MediaPort))
|
||||
conn, err := ListenUDP(addr, networkBuffer)
|
||||
if err != nil {
|
||||
Printf("listen udp %s err: %v", addr, err)
|
||||
return
|
||||
}
|
||||
bufUDP := make([]byte, networkBuffer)
|
||||
Printf("udp server start listen video port[%d]", config.MediaPort)
|
||||
defer Printf("udp server stop listen video port[%d]", config.MediaPort)
|
||||
for n, _, err := conn.ReadFromUDP(bufUDP); err == nil; n, _, err = conn.ReadFromUDP(bufUDP) {
|
||||
ps := bufUDP[:n]
|
||||
if err := rtpPacket.Unmarshal(ps); err != nil {
|
||||
Println("gb28181 decode rtp error:", err)
|
||||
}
|
||||
if publisher := publishers.Get(rtpPacket.SSRC); publisher != nil && publisher.Err() == nil {
|
||||
publisher.PushPS(&rtpPacket)
|
||||
case SEpublish:
|
||||
if channel := FindChannel(e.Target.AppName, strings.TrimSuffix(e.Target.StreamName, "/rtsp")); channel != nil {
|
||||
channel.LiveSubSP = e.Target.Path
|
||||
}
|
||||
case SEclose:
|
||||
if channel := FindChannel(e.Target.AppName, strings.TrimSuffix(e.Target.StreamName, "/rtsp")); channel != nil {
|
||||
channel.LiveSubSP = ""
|
||||
}
|
||||
if v, ok := PullStreams.LoadAndDelete(e.Target.Path); ok {
|
||||
go v.(*PullStream).Bye()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// func queryCatalog(config *transaction.Config) {
|
||||
// t := time.NewTicker(time.Duration(config.CatalogInterval) * time.Second)
|
||||
// for range t.C {
|
||||
// Devices.Range(func(key, value interface{}) bool {
|
||||
// device := value.(*Device)
|
||||
// if time.Since(device.UpdateTime) > time.Duration(config.RegisterValidity)*time.Second {
|
||||
// Devices.Delete(key)
|
||||
// } else if device.Channels != nil {
|
||||
// go device.Subscribe()
|
||||
// }
|
||||
// return true
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
func removeBanDevice(config *transaction.Config) {
|
||||
t := time.NewTicker(time.Duration(config.RemoveBanInterval) * time.Second)
|
||||
for range t.C {
|
||||
DeviceRegisterCount.Range(func(key, value interface{}) bool {
|
||||
if value.(int)>MaxRegisterCount {DeviceRegisterCount.Delete(key)}
|
||||
return true
|
||||
})
|
||||
}
|
||||
func (c *GB28181Config) IsMediaNetworkTCP() bool {
|
||||
return strings.ToLower(c.MediaNetwork) == "tcp"
|
||||
}
|
||||
|
||||
var conf GB28181Config
|
||||
|
||||
var GB28181Plugin = InstallPlugin(&conf)
|
||||
var PullStreams sync.Map //拉流
|
||||
|
||||
92
manscdp.go
Normal file
92
manscdp.go
Normal file
@@ -0,0 +1,92 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var (
|
||||
// CatalogXML 获取设备列表xml样式
|
||||
CatalogXML = `<?xml version="1.0"?><Query>
|
||||
<CmdType>Catalog</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
</Query>
|
||||
`
|
||||
// RecordInfoXML 获取录像文件列表xml样式
|
||||
RecordInfoXML = `<?xml version="1.0"?>
|
||||
<Query>
|
||||
<CmdType>RecordInfo</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
<StartTime>%s</StartTime>
|
||||
<EndTime>%s</EndTime>
|
||||
<Secrecy>0</Secrecy>
|
||||
<Type>all</Type>
|
||||
</Query>
|
||||
`
|
||||
// DeviceInfoXML 查询设备详情xml样式
|
||||
DeviceInfoXML = `<?xml version="1.0"?>
|
||||
<Query>
|
||||
<CmdType>DeviceInfo</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
</Query>
|
||||
`
|
||||
// DevicePositionXML 订阅设备位置
|
||||
DevicePositionXML = `<?xml version="1.0"?>
|
||||
<Query>
|
||||
<CmdType>MobilePosition</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
<Interval>%d</Interval>
|
||||
</Query>`
|
||||
)
|
||||
|
||||
func intTotime(t int64) time.Time {
|
||||
tstr := strconv.FormatInt(t, 10)
|
||||
if len(tstr) == 10 {
|
||||
return time.Unix(t, 0)
|
||||
}
|
||||
if len(tstr) == 13 {
|
||||
return time.UnixMilli(t)
|
||||
}
|
||||
return time.Now()
|
||||
}
|
||||
|
||||
// BuildDeviceInfoXML 获取设备详情指令
|
||||
func BuildDeviceInfoXML(sn int, id string) string {
|
||||
return fmt.Sprintf(DeviceInfoXML, sn, id)
|
||||
}
|
||||
|
||||
// BuildCatalogXML 获取NVR下设备列表指令
|
||||
func BuildCatalogXML(sn int, id string) string {
|
||||
return fmt.Sprintf(CatalogXML, sn, id)
|
||||
}
|
||||
|
||||
// BuildRecordInfoXML 获取录像文件列表指令
|
||||
func BuildRecordInfoXML(sn int, id string, start, end int64) string {
|
||||
return fmt.Sprintf(RecordInfoXML, sn, id, intTotime(start).Format("2006-01-02T15:04:05"), intTotime(end).Format("2006-01-02T15:04:05"))
|
||||
}
|
||||
|
||||
// BuildDevicePositionXML 订阅设备位置
|
||||
func BuildDevicePositionXML(sn int, id string, interval int) string {
|
||||
return fmt.Sprintf(DevicePositionXML, sn, id, interval)
|
||||
}
|
||||
|
||||
// AlarmResponseXML alarm response xml样式
|
||||
var (
|
||||
AlarmResponseXML = `<?xml version="1.0"?>
|
||||
<Response>
|
||||
<CmdType>Alarm</CmdType>
|
||||
<SN>17430</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
</Response>
|
||||
`
|
||||
)
|
||||
|
||||
// BuildRecordInfoXML 获取录像文件列表指令
|
||||
func BuildAlarmResponseXML(id string) string {
|
||||
return fmt.Sprintf(AlarmResponseXML, id)
|
||||
}
|
||||
47
portmanager.go
Normal file
47
portmanager.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package gb28181
|
||||
|
||||
import "io"
|
||||
|
||||
type PortManager struct {
|
||||
recycle chan uint16
|
||||
max uint16
|
||||
pos uint16
|
||||
Valid bool
|
||||
}
|
||||
|
||||
func (pm *PortManager) Init(start, end uint16) {
|
||||
pm.pos = start - 1
|
||||
pm.max = end
|
||||
if pm.pos > 0 && pm.max > pm.pos {
|
||||
pm.Valid = true
|
||||
pm.recycle = make(chan uint16, pm.Range())
|
||||
}
|
||||
}
|
||||
|
||||
func (pm *PortManager) Range() uint16 {
|
||||
return pm.max - pm.pos
|
||||
}
|
||||
|
||||
func (pm *PortManager) Recycle(p uint16) (err error) {
|
||||
select {
|
||||
case pm.recycle <- p:
|
||||
return nil
|
||||
default:
|
||||
return io.EOF //TODO: 换一个Error
|
||||
}
|
||||
}
|
||||
|
||||
func (pm *PortManager) GetPort() (p uint16, err error) {
|
||||
select {
|
||||
case p = <-pm.recycle:
|
||||
return
|
||||
default:
|
||||
if pm.Range() > 0 {
|
||||
pm.pos++
|
||||
p = pm.pos
|
||||
return
|
||||
} else {
|
||||
return 0, io.EOF //TODO: 换一个Error
|
||||
}
|
||||
}
|
||||
}
|
||||
47
ptz.go
Normal file
47
ptz.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package gb28181
|
||||
|
||||
import "fmt"
|
||||
|
||||
var (
|
||||
name2code = map[string]uint8{
|
||||
"stop": 0,
|
||||
"right": 1,
|
||||
"left": 2,
|
||||
"down": 4,
|
||||
"downright": 5,
|
||||
"downleft": 6,
|
||||
"up": 8,
|
||||
"upright": 9,
|
||||
"upleft": 10,
|
||||
"zoomin": 16,
|
||||
"zoomout": 32,
|
||||
}
|
||||
)
|
||||
|
||||
func toPtzStrByCmdName(cmdName string, horizontalSpeed, verticalSpeed, zoomSpeed uint8) (string, error) {
|
||||
c, err := toPtzCode(cmdName)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
return toPtzStr(c, horizontalSpeed, verticalSpeed, zoomSpeed), nil
|
||||
}
|
||||
|
||||
func toPtzStr(cmdCode, horizontalSpeed, verticalSpeed, zoomSpeed uint8) string {
|
||||
checkCode := uint16(0xA5+0x0F+0x01+cmdCode+horizontalSpeed+verticalSpeed+(zoomSpeed&0xF0)) % 0x100
|
||||
|
||||
return fmt.Sprintf("A50F01%02X%02X%02X%01X0%02X",
|
||||
cmdCode,
|
||||
horizontalSpeed,
|
||||
verticalSpeed,
|
||||
zoomSpeed>>4, // 根据 GB28181 协议,zoom 只取 4 bit
|
||||
checkCode,
|
||||
)
|
||||
}
|
||||
|
||||
func toPtzCode(cmd string) (uint8, error) {
|
||||
if code, ok := name2code[cmd]; ok {
|
||||
return code, nil
|
||||
} else {
|
||||
return 0, fmt.Errorf("invalid ptz cmd %q", cmd)
|
||||
}
|
||||
}
|
||||
106
publisher.go
106
publisher.go
@@ -1,106 +0,0 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"github.com/Monibuca/engine/v3"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
. "github.com/Monibuca/utils/v3"
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
type Publisher struct {
|
||||
*engine.Stream
|
||||
parser *utils.DecPSPackage
|
||||
pushVideo func(uint32, uint32, []byte)
|
||||
pushAudio func(uint32, []byte)
|
||||
lastSeq uint16
|
||||
udpCache *utils.PriorityQueueRtp
|
||||
}
|
||||
|
||||
func (p *Publisher) PushVideo(ts uint32, cts uint32, payload []byte) {
|
||||
p.pushVideo(ts, cts, payload)
|
||||
}
|
||||
func (p *Publisher) PushAudio(ts uint32, payload []byte) {
|
||||
p.pushAudio(ts, payload)
|
||||
}
|
||||
func (p *Publisher) Publish() (result bool) {
|
||||
if result = p.Stream.Publish(); result {
|
||||
p.pushVideo = func(ts uint32, cts uint32, payload []byte) {
|
||||
var vt *engine.VideoTrack
|
||||
switch p.parser.VideoStreamType {
|
||||
case utils.StreamTypeH264:
|
||||
vt = p.Stream.NewVideoTrack(7)
|
||||
case utils.StreamTypeH265:
|
||||
vt = p.Stream.NewVideoTrack(12)
|
||||
default:
|
||||
return
|
||||
}
|
||||
vt.PushAnnexB(ts, cts, payload)
|
||||
p.pushVideo = vt.PushAnnexB
|
||||
}
|
||||
p.pushAudio = func(ts uint32, payload []byte) {
|
||||
switch p.parser.AudioStreamType {
|
||||
case utils.G711A:
|
||||
at := p.Stream.NewAudioTrack(7)
|
||||
at.SoundRate = 8000
|
||||
at.SoundSize = 16
|
||||
at.Channels = 1
|
||||
at.ExtraData = []byte{(at.CodecID << 4) | (1 << 1)}
|
||||
at.PushRaw(ts, payload)
|
||||
p.pushAudio = at.PushRaw
|
||||
// case utils.G711U:
|
||||
// at := p.Stream.NewAudioTrack(8)
|
||||
// at.SoundRate = 8000
|
||||
// at.SoundSize = 16
|
||||
// asc := at.CodecID << 4
|
||||
// asc = asc + 1<<1
|
||||
// at.ExtraData = []byte{asc}
|
||||
// at.PushRaw(pack)
|
||||
// p.pushAudio = at.PushRaw
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
func (p *Publisher) PushPS(rtp *rtp.Packet) {
|
||||
originRtp := *rtp
|
||||
if config.UdpCacheSize > 0 && config.TCP == false {
|
||||
//序号小于第一个包的丢弃,rtp包序号达到65535后会从0开始,所以这里需要判断一下
|
||||
if rtp.SequenceNumber < p.lastSeq && p.lastSeq-rtp.SequenceNumber < utils.MaxRtpDiff {
|
||||
return
|
||||
}
|
||||
p.udpCache.Push(*rtp)
|
||||
rtpTmp, _ := p.udpCache.Pop()
|
||||
rtp = &rtpTmp
|
||||
}
|
||||
ps := rtp.Payload
|
||||
if p.lastSeq != 0 {
|
||||
// rtp序号不连续,丢弃PS
|
||||
if p.lastSeq+1 != rtp.SequenceNumber {
|
||||
if config.UdpCacheSize > 0 && config.TCP == false {
|
||||
if p.udpCache.Len() < config.UdpCacheSize {
|
||||
p.udpCache.Push(*rtp)
|
||||
return
|
||||
} else {
|
||||
p.udpCache.Empty()
|
||||
rtp = &originRtp // 还原rtp包,而不是使用缓存中,避免rtp序号断裂
|
||||
}
|
||||
}
|
||||
p.parser.Reset()
|
||||
}
|
||||
}
|
||||
p.lastSeq = rtp.SequenceNumber
|
||||
p.Update()
|
||||
if p.parser == nil {
|
||||
p.parser = new(utils.DecPSPackage)
|
||||
}
|
||||
if len(ps) >= 4 && BigEndian.Uint32(ps) == utils.StartCodePS {
|
||||
if p.parser.Len() > 0 {
|
||||
p.parser.Skip(4)
|
||||
p.parser.Read(rtp.Timestamp, p)
|
||||
p.parser.Reset()
|
||||
}
|
||||
p.parser.Write(ps)
|
||||
} else if p.parser.Len() > 0 {
|
||||
p.parser.Write(ps)
|
||||
}
|
||||
}
|
||||
263
restful.go
Normal file
263
restful.go
Normal file
@@ -0,0 +1,263 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"m7s.live/engine/v4/util"
|
||||
)
|
||||
|
||||
var (
|
||||
playScaleValues = map[float32]bool{0.25: true, 0.5: true, 1: true, 2: true, 4: true}
|
||||
)
|
||||
|
||||
func (c *GB28181Config) API_list(w http.ResponseWriter, r *http.Request) {
|
||||
util.ReturnJson(func() (list []*Device) {
|
||||
list = make([]*Device, 0)
|
||||
Devices.Range(func(key, value interface{}) bool {
|
||||
list = append(list, value.(*Device))
|
||||
return true
|
||||
})
|
||||
return
|
||||
}, time.Second*5, w, r)
|
||||
}
|
||||
|
||||
func (c *GB28181Config) API_records(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
id := query.Get("id")
|
||||
channel := query.Get("channel")
|
||||
startTime := query.Get("startTime")
|
||||
endTime := query.Get("endTime")
|
||||
trange := strings.Split(query.Get("range"), "-")
|
||||
if len(trange) == 2 {
|
||||
startTime = trange[0]
|
||||
endTime = trange[1]
|
||||
}
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
res, err := c.QueryRecord(startTime, endTime)
|
||||
if err == nil {
|
||||
WriteJSONOk(w, res)
|
||||
} else {
|
||||
WriteJSON(w, err.Error(), http.StatusInternalServerError)
|
||||
}
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) API_control(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.URL.Query().Get("id")
|
||||
channel := r.URL.Query().Get("channel")
|
||||
ptzcmd := r.URL.Query().Get("ptzcmd")
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.Control(ptzcmd))
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) API_ptz(w http.ResponseWriter, r *http.Request) {
|
||||
q := r.URL.Query()
|
||||
id := q.Get("id")
|
||||
channel := q.Get("channel")
|
||||
cmd := q.Get("cmd") // 命令名称,见 ptz.go name2code 定义
|
||||
hs := q.Get("hSpeed") // 水平速度
|
||||
vs := q.Get("vSpeed") // 垂直速度
|
||||
zs := q.Get("zSpeed") // 缩放速度
|
||||
|
||||
hsN, err := strconv.ParseUint(hs, 10, 8)
|
||||
if err != nil {
|
||||
WriteJSON(w, "hSpeed parameter is invalid", 400)
|
||||
return
|
||||
}
|
||||
vsN, err := strconv.ParseUint(vs, 10, 8)
|
||||
if err != nil {
|
||||
WriteJSON(w, "vSpeed parameter is invalid", 400)
|
||||
return
|
||||
}
|
||||
zsN, err := strconv.ParseUint(zs, 10, 8)
|
||||
if err != nil {
|
||||
WriteJSON(w, "zSpeed parameter is invalid", 400)
|
||||
return
|
||||
}
|
||||
|
||||
ptzcmd, err := toPtzStrByCmdName(cmd, uint8(hsN), uint8(vsN), uint8(zsN))
|
||||
if err != nil {
|
||||
WriteJSON(w, err.Error(), 400)
|
||||
return
|
||||
}
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
code := c.Control(ptzcmd)
|
||||
WriteJSON(w, "device received", code)
|
||||
} else {
|
||||
WriteJSON(w, fmt.Sprintf("device %q channel %q not found", id, channel), 404)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) API_invite(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
id := query.Get("id")
|
||||
channel := query.Get("channel")
|
||||
streamPath := query.Get("streamPath")
|
||||
port, _ := strconv.Atoi(query.Get("mediaPort"))
|
||||
opt := InviteOptions{
|
||||
dump: query.Get("dump"),
|
||||
MediaPort: uint16(port),
|
||||
StreamPath: streamPath,
|
||||
}
|
||||
startTime := query.Get("startTime")
|
||||
endTime := query.Get("endTime")
|
||||
trange := strings.Split(query.Get("range"), "-")
|
||||
if len(trange) == 2 {
|
||||
startTime = trange[0]
|
||||
endTime = trange[1]
|
||||
}
|
||||
opt.Validate(startTime, endTime)
|
||||
if c := FindChannel(id, channel); c == nil {
|
||||
http.NotFound(w, r)
|
||||
} else if opt.IsLive() && c.status.Load() > 0 {
|
||||
http.Error(w, "live stream already exists", http.StatusNotModified)
|
||||
} else if code, err := c.Invite(&opt); err == nil {
|
||||
w.WriteHeader(code)
|
||||
} else {
|
||||
http.Error(w, err.Error(), code)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) API_bye(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.URL.Query().Get("id")
|
||||
channel := r.URL.Query().Get("channel")
|
||||
streamPath := r.URL.Query().Get("streamPath")
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.Bye(streamPath))
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) API_play_pause(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.URL.Query().Get("id")
|
||||
channel := r.URL.Query().Get("channel")
|
||||
streamPath := r.URL.Query().Get("streamPath")
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.Pause(streamPath))
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) API_play_resume(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.URL.Query().Get("id")
|
||||
channel := r.URL.Query().Get("channel")
|
||||
streamPath := r.URL.Query().Get("streamPath")
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.Resume(streamPath))
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) API_play_seek(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.URL.Query().Get("id")
|
||||
channel := r.URL.Query().Get("channel")
|
||||
streamPath := r.URL.Query().Get("streamPath")
|
||||
secStr := r.URL.Query().Get("second")
|
||||
sec, err := strconv.ParseUint(secStr, 10, 32)
|
||||
if err != nil {
|
||||
WriteJSON(w, "second parameter is invalid: "+err.Error(), 400)
|
||||
return
|
||||
}
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.PlayAt(streamPath, uint(sec)))
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) API_play_forward(w http.ResponseWriter, r *http.Request) {
|
||||
id := r.URL.Query().Get("id")
|
||||
channel := r.URL.Query().Get("channel")
|
||||
streamPath := r.URL.Query().Get("streamPath")
|
||||
speedStr := r.URL.Query().Get("speed")
|
||||
speed, err := strconv.ParseFloat(speedStr, 32)
|
||||
secondErrMsg := "speed parameter is invalid, should be one of 0.25,0.5,1,2,4"
|
||||
if err != nil || !playScaleValues[float32(speed)] {
|
||||
WriteJSON(w, secondErrMsg, 400)
|
||||
return
|
||||
}
|
||||
if c := FindChannel(id, channel); c != nil {
|
||||
w.WriteHeader(c.PlayForward(streamPath, float32(speed)))
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) API_position(w http.ResponseWriter, r *http.Request) {
|
||||
//CORS(w, r)
|
||||
query := r.URL.Query()
|
||||
//设备id
|
||||
id := query.Get("id")
|
||||
//订阅周期(单位:秒)
|
||||
expires := query.Get("expires")
|
||||
//订阅间隔(单位:秒)
|
||||
interval := query.Get("interval")
|
||||
|
||||
expiresInt, err := time.ParseDuration(expires)
|
||||
if expires == "" || err != nil {
|
||||
expiresInt = c.Position.Expires
|
||||
}
|
||||
intervalInt, err := time.ParseDuration(interval)
|
||||
if interval == "" || err != nil {
|
||||
intervalInt = c.Position.Interval
|
||||
}
|
||||
|
||||
if v, ok := Devices.Load(id); ok {
|
||||
d := v.(*Device)
|
||||
w.WriteHeader(d.MobilePositionSubscribe(id, expiresInt, intervalInt))
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
}
|
||||
}
|
||||
|
||||
type DevicePosition struct {
|
||||
ID string
|
||||
GpsTime time.Time //gps时间
|
||||
Longitude string //经度
|
||||
Latitude string //纬度
|
||||
}
|
||||
|
||||
func (c *GB28181Config) API_get_position(w http.ResponseWriter, r *http.Request) {
|
||||
query := r.URL.Query()
|
||||
//设备id
|
||||
id := query.Get("id")
|
||||
|
||||
util.ReturnJson(func() (list []*DevicePosition) {
|
||||
if id == "" {
|
||||
Devices.Range(func(key, value interface{}) bool {
|
||||
d := value.(*Device)
|
||||
if time.Since(d.GpsTime) <= c.Position.Interval {
|
||||
list = append(list, &DevicePosition{ID: d.ID, GpsTime: d.GpsTime, Longitude: d.Longitude, Latitude: d.Latitude})
|
||||
}
|
||||
return true
|
||||
})
|
||||
} else if v, ok := Devices.Load(id); ok {
|
||||
d := v.(*Device)
|
||||
list = append(list, &DevicePosition{ID: d.ID, GpsTime: d.GpsTime, Longitude: d.Longitude, Latitude: d.Latitude})
|
||||
}
|
||||
return
|
||||
}, c.Position.Interval, w, r)
|
||||
}
|
||||
|
||||
func WriteJSONOk(w http.ResponseWriter, data interface{}) {
|
||||
WriteJSON(w, data, 200)
|
||||
}
|
||||
|
||||
func WriteJSON(w http.ResponseWriter, data interface{}, status int) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(status)
|
||||
json.NewEncoder(w).Encode(data)
|
||||
}
|
||||
114
rtpsort_test.go
114
rtpsort_test.go
@@ -1,114 +0,0 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Monibuca/engine/v3"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
"github.com/agiledragon/gomonkey/v2"
|
||||
"github.com/pion/rtp"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// 测试rtp序号数据
|
||||
var items = []uint16{
|
||||
65526, 65530, 65524, 65525, 65527, 65528, 65529,
|
||||
0, 65533, 65531, 65532, 65534, 65535, 1,
|
||||
3, 6, 5, 4, 2, 8, 7,
|
||||
}
|
||||
|
||||
var items2 = []uint16{
|
||||
11672, 11673, 11674, 11675, 11676, 11677, 11678,
|
||||
11679, 11680, 11681, 11682, 11683, 11684, 11685,
|
||||
11686, 11687, 11688, 11689, 11690, 11691, 11692,
|
||||
11693, 11694, 11695, 11696, 11697, 11698, 11699,
|
||||
11700, 11701, 11702, 11703, 11704, 11705, 11706,
|
||||
11707, 11708, 11709, 11710, 11711, 11712,
|
||||
}
|
||||
|
||||
func _pushPsWithCache(p *Publisher, rtp *rtp.Packet) {
|
||||
originRtp := *rtp
|
||||
if config.UdpCacheSize > 0 && !config.TCP {
|
||||
//序号小于第一个包的丢弃,rtp包序号达到65535后会从0开始,所以这里需要判断一下
|
||||
if rtp.SequenceNumber < p.lastSeq && p.lastSeq-rtp.SequenceNumber < utils.MaxRtpDiff {
|
||||
return
|
||||
}
|
||||
p.udpCache.Push(*rtp)
|
||||
rtpTmp, _ := p.udpCache.Pop()
|
||||
rtp = &rtpTmp
|
||||
}
|
||||
|
||||
if p.lastSeq != 0 {
|
||||
// rtp序号不连续,丢弃PS
|
||||
if p.lastSeq+1 != rtp.SequenceNumber {
|
||||
if config.UdpCacheSize > 0 && !config.TCP {
|
||||
if p.udpCache.Len() < config.UdpCacheSize {
|
||||
p.udpCache.Push(*rtp)
|
||||
return
|
||||
} else {
|
||||
p.udpCache.Empty()
|
||||
rtp = &originRtp
|
||||
}
|
||||
}
|
||||
p.parser.Reset()
|
||||
}
|
||||
}
|
||||
|
||||
p.lastSeq = rtp.SequenceNumber
|
||||
fmt.Println("rtp.SequenceNumber:", rtp.SequenceNumber)
|
||||
|
||||
}
|
||||
|
||||
// 如果运行失败可以关闭gc,go test -gcflags=all=-l -v
|
||||
func TestRtpSort(t *testing.T) {
|
||||
publisher := Publisher{
|
||||
Stream: &engine.Stream{
|
||||
StreamPath: "live/test",
|
||||
},
|
||||
udpCache: utils.NewPqRtp(),
|
||||
}
|
||||
config.UdpCacheSize = 7
|
||||
|
||||
patches := gomonkey.ApplyMethod(reflect.TypeOf(&publisher), "PushPS", _pushPsWithCache)
|
||||
defer patches.Reset()
|
||||
|
||||
for i := 0; i < len(items); i++ {
|
||||
rtpPacket := &rtp.Packet{Header: rtp.Header{SequenceNumber: items[i]}}
|
||||
publisher.PushPS(rtpPacket)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 如果运行失败可以关闭gc,go test -gcflags=all=-l -v
|
||||
// 测试有empty的情况
|
||||
func TestRtpSortWithEmpty(t *testing.T) {
|
||||
publisher := Publisher{
|
||||
Stream: &engine.Stream{
|
||||
StreamPath: "live/test",
|
||||
},
|
||||
udpCache: utils.NewPqRtp(),
|
||||
}
|
||||
config.UdpCacheSize = 7
|
||||
publisher.udpCache.Push(rtp.Packet{Header: rtp.Header{SequenceNumber: 11665}})
|
||||
patches := gomonkey.ApplyMethod(reflect.TypeOf(&publisher), "PushPS", _pushPsWithCache)
|
||||
defer patches.Reset()
|
||||
|
||||
for i := 0; i < len(items2); i++ {
|
||||
rtpPacket := &rtp.Packet{Header: rtp.Header{SequenceNumber: items2[i]}}
|
||||
publisher.PushPS(rtpPacket)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestPqSort(t *testing.T) {
|
||||
pq := utils.NewPqRtp()
|
||||
for i := 0; i < len(items); i++ {
|
||||
rtpPacket := rtp.Packet{Header: rtp.Header{SequenceNumber: items[i]}}
|
||||
pq.Push(rtpPacket)
|
||||
}
|
||||
|
||||
for pq.Len() > 0 {
|
||||
rtpPacket, _ := pq.Pop()
|
||||
fmt.Println("packet seq:", rtpPacket.SequenceNumber)
|
||||
}
|
||||
}
|
||||
217
server.go
Executable file
217
server.go
Executable file
@@ -0,0 +1,217 @@
|
||||
package gb28181
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/logrusorgru/aurora"
|
||||
"go.uber.org/zap"
|
||||
"m7s.live/plugin/gb28181/v4/utils"
|
||||
|
||||
"github.com/ghettovoice/gosip"
|
||||
"github.com/ghettovoice/gosip/log"
|
||||
"github.com/ghettovoice/gosip/sip"
|
||||
)
|
||||
|
||||
var srv gosip.Server
|
||||
|
||||
const MaxRegisterCount = 3
|
||||
|
||||
func FindChannel(deviceId string, channelId string) (c *Channel) {
|
||||
if v, ok := Devices.Load(deviceId); ok {
|
||||
d := v.(*Device)
|
||||
if v, ok := d.channelMap.Load(channelId); ok {
|
||||
return v.(*Channel)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var levelMap = map[string]log.Level{
|
||||
"trace": log.TraceLevel,
|
||||
"debug": log.DebugLevel,
|
||||
"info": log.InfoLevel,
|
||||
"warn": log.WarnLevel,
|
||||
"error": log.ErrorLevel,
|
||||
"fatal": log.FatalLevel,
|
||||
"panic": log.PanicLevel,
|
||||
}
|
||||
|
||||
func GetSipServer(transport string) gosip.Server {
|
||||
return srv
|
||||
}
|
||||
|
||||
var sn = 0
|
||||
|
||||
func CreateRequest(exposedId string, Method sip.RequestMethod, recipient *sip.Address, netAddr string) (req sip.Request) {
|
||||
|
||||
sn++
|
||||
|
||||
callId := sip.CallID(utils.RandNumString(10))
|
||||
userAgent := sip.UserAgentHeader("Monibuca")
|
||||
cseq := sip.CSeq{
|
||||
SeqNo: uint32(sn),
|
||||
MethodName: Method,
|
||||
}
|
||||
port := sip.Port(conf.SipPort)
|
||||
serverAddr := sip.Address{
|
||||
//DisplayName: sip.String{Str: d.config.Serial},
|
||||
Uri: &sip.SipUri{
|
||||
FUser: sip.String{Str: exposedId},
|
||||
FHost: conf.SipIP,
|
||||
FPort: &port,
|
||||
},
|
||||
Params: sip.NewParams().Add("tag", sip.String{Str: utils.RandNumString(9)}),
|
||||
}
|
||||
req = sip.NewRequest(
|
||||
"",
|
||||
Method,
|
||||
recipient.Uri,
|
||||
"SIP/2.0",
|
||||
[]sip.Header{
|
||||
serverAddr.AsFromHeader(),
|
||||
recipient.AsToHeader(),
|
||||
&callId,
|
||||
&userAgent,
|
||||
&cseq,
|
||||
serverAddr.AsContactHeader(),
|
||||
},
|
||||
"",
|
||||
nil,
|
||||
)
|
||||
|
||||
req.SetTransport(conf.SipNetwork)
|
||||
req.SetDestination(netAddr)
|
||||
//fmt.Printf("构建请求参数:%s", *&req)
|
||||
// requestMsg.DestAdd, err2 = d.ResolveAddress(requestMsg)
|
||||
// if err2 != nil {
|
||||
// return nil
|
||||
// }
|
||||
//intranet ip , let's resolve it with public ip
|
||||
// var deviceIp, deviceSourceIP net.IP
|
||||
// switch addr := requestMsg.DestAdd.(type) {
|
||||
// case *net.UDPAddr:
|
||||
// deviceIp = addr.IP
|
||||
// case *net.TCPAddr:
|
||||
// deviceIp = addr.IP
|
||||
// }
|
||||
|
||||
// switch addr2 := d.SourceAddr.(type) {
|
||||
// case *net.UDPAddr:
|
||||
// deviceSourceIP = addr2.IP
|
||||
// case *net.TCPAddr:
|
||||
// deviceSourceIP = addr2.IP
|
||||
// }
|
||||
// if deviceIp.IsPrivate() && !deviceSourceIP.IsPrivate() {
|
||||
// requestMsg.DestAdd = d.SourceAddr
|
||||
// }
|
||||
return
|
||||
}
|
||||
func RequestForResponse(transport string, request sip.Request,
|
||||
options ...gosip.RequestWithContextOption) (sip.Response, error) {
|
||||
return (GetSipServer(transport)).RequestWithContext(context.Background(), request, options...)
|
||||
}
|
||||
|
||||
func (c *GB28181Config) startServer() {
|
||||
addr := c.ListenAddr + ":" + strconv.Itoa(int(c.SipPort))
|
||||
|
||||
logger := utils.NewZapLogger(GB28181Plugin.Logger, "GB SIP Server", nil)
|
||||
logger.SetLevel(levelMap[c.LogLevel])
|
||||
// logger := log.NewDefaultLogrusLogger().WithPrefix("GB SIP Server")
|
||||
srvConf := gosip.ServerConfig{}
|
||||
if c.SipIP != "" {
|
||||
srvConf.Host = c.SipIP
|
||||
}
|
||||
srv = gosip.NewServer(srvConf, nil, nil, logger)
|
||||
srv.OnRequest(sip.REGISTER, c.OnRegister)
|
||||
srv.OnRequest(sip.MESSAGE, c.OnMessage)
|
||||
srv.OnRequest(sip.NOTIFY, c.OnNotify)
|
||||
srv.OnRequest(sip.BYE, c.OnBye)
|
||||
err := srv.Listen(strings.ToLower(c.SipNetwork), addr)
|
||||
if err != nil {
|
||||
GB28181Plugin.Logger.Error("gb28181 server listen", zap.Error(err))
|
||||
} else {
|
||||
GB28181Plugin.Info(fmt.Sprint(aurora.Green("Server gb28181 start at"), aurora.BrightBlue(addr)))
|
||||
}
|
||||
|
||||
if c.MediaNetwork == "tcp" {
|
||||
c.tcpPorts.Init(c.MediaPortMin, c.MediaPortMax)
|
||||
} else {
|
||||
c.udpPorts.Init(c.MediaPortMin, c.MediaPortMax)
|
||||
}
|
||||
go c.startJob()
|
||||
}
|
||||
|
||||
// func queryCatalog(config *transaction.Config) {
|
||||
// t := time.NewTicker(time.Duration(config.CatalogInterval) * time.Second)
|
||||
// for range t.C {
|
||||
// Devices.Range(func(key, value interface{}) bool {
|
||||
// device := value.(*Device)
|
||||
// if time.Since(device.UpdateTime) > time.Duration(config.RegisterValidity)*time.Second {
|
||||
// Devices.Delete(key)
|
||||
// } else if device.Channels != nil {
|
||||
// go device.Catalog()
|
||||
// }
|
||||
// return true
|
||||
// })
|
||||
// }
|
||||
// }
|
||||
|
||||
// 定时任务
|
||||
func (c *GB28181Config) startJob() {
|
||||
statusTick := time.NewTicker(c.HeartbeatInterval / 2)
|
||||
banTick := time.NewTicker(c.RemoveBanInterval)
|
||||
linkTick := time.NewTicker(time.Millisecond * 100)
|
||||
GB28181Plugin.Debug("start job")
|
||||
for {
|
||||
select {
|
||||
case <-banTick.C:
|
||||
if c.Username != "" || c.Password != "" {
|
||||
c.removeBanDevice()
|
||||
}
|
||||
case <-statusTick.C:
|
||||
c.statusCheck()
|
||||
case <-linkTick.C:
|
||||
RecordQueryLink.cleanTimeout()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *GB28181Config) removeBanDevice() {
|
||||
DeviceRegisterCount.Range(func(key, value interface{}) bool {
|
||||
if value.(int) > MaxRegisterCount {
|
||||
DeviceRegisterCount.Delete(key)
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
// statusCheck
|
||||
// - 当设备超过 3 倍心跳时间未发送过心跳(通过 UpdateTime 判断), 视为离线
|
||||
// - 当设备超过注册有效期内为发送过消息,则从设备列表中删除
|
||||
// UpdateTime 在设备发送心跳之外的消息也会被更新,相对于 LastKeepaliveAt 更能体现出设备最会一次活跃的时间
|
||||
func (c *GB28181Config) statusCheck() {
|
||||
Devices.Range(func(key, value any) bool {
|
||||
d := value.(*Device)
|
||||
if time.Since(d.UpdateTime) > c.RegisterValidity {
|
||||
Devices.Delete(key)
|
||||
GB28181Plugin.Info("Device register timeout",
|
||||
zap.String("id", d.ID),
|
||||
zap.Time("registerTime", d.RegisterTime),
|
||||
zap.Time("updateTime", d.UpdateTime),
|
||||
)
|
||||
} else if time.Since(d.UpdateTime) > c.HeartbeatInterval*3 {
|
||||
d.Status = DeviceOfflineStatus
|
||||
d.channelMap.Range(func(key, value any) bool {
|
||||
ch := value.(*Channel)
|
||||
ch.Status = ChannelOffStatus
|
||||
return true
|
||||
})
|
||||
GB28181Plugin.Info("Device offline", zap.String("id", d.ID), zap.Time("updateTime", d.UpdateTime))
|
||||
}
|
||||
return true
|
||||
})
|
||||
}
|
||||
120
sip/README.md
120
sip/README.md
@@ -1,120 +0,0 @@
|
||||
|
||||
#### SIP消息
|
||||
|
||||
```
|
||||
SIP-message = Request / Response
|
||||
Request = Request-Line
|
||||
*( message-header )
|
||||
CRLF
|
||||
[ message-body ]
|
||||
```
|
||||
|
||||
#### SIP消息头域
|
||||
|
||||
```
|
||||
message-header = (Accept
|
||||
/ Accept-Encoding
|
||||
/ Accept-Language
|
||||
/ Alert-Info
|
||||
/ Allow
|
||||
/ Authentication-Info
|
||||
/ Authorization
|
||||
/ Call-ID
|
||||
/ Call-Info
|
||||
/ Contact
|
||||
/ Content-Disposition
|
||||
/ Content-Encoding
|
||||
/ Content-Language
|
||||
/ Content-Length
|
||||
/ Content-Type
|
||||
/ CSeq
|
||||
/ Date
|
||||
/ Error-Info
|
||||
/ Expires
|
||||
/ From
|
||||
/ In-Reply-To
|
||||
/ Max-Forwards
|
||||
/ MIME-Version
|
||||
/ Min-Expires
|
||||
/ Organization
|
||||
/ Priority
|
||||
/ Proxy-Authenticate
|
||||
/ Proxy-Authorization
|
||||
/ Proxy-Require
|
||||
/ Record-Route
|
||||
/ Reply-To
|
||||
/ Require
|
||||
/ Retry-After
|
||||
/ Route
|
||||
/ Server
|
||||
/ Subject
|
||||
/ Supported
|
||||
/ Timestamp
|
||||
/ To
|
||||
/ Unsupported
|
||||
/ User-Agent
|
||||
/ Via
|
||||
/ Warning
|
||||
/ WWW-Authenticate
|
||||
/ extension-header) CRLF
|
||||
```
|
||||
|
||||
|
||||
#### SIP 响应状态码
|
||||
|
||||
```
|
||||
Informational = "100" ; Trying
|
||||
/ "180" ; Ringing
|
||||
/ "181" ; Call Is Being Forwarded
|
||||
/ "182" ; Queued
|
||||
/ "183" ; Session Progress
|
||||
Success = "200" ; OK
|
||||
|
||||
Redirection = "300" ; Multiple Choices
|
||||
/ "301" ; Moved Permanently
|
||||
/ "302" ; Moved Temporarily
|
||||
/ "305" ; Use Proxy
|
||||
/ "380" ; Alternative Service
|
||||
|
||||
Client-Error = "400" ; Bad Request
|
||||
/ "401" ; Unauthorized
|
||||
/ "402" ; Payment Required
|
||||
/ "403" ; Forbidden
|
||||
/ "404" ; Not Found
|
||||
/ "405" ; Method Not Allowed
|
||||
/ "406" ; Not Acceptable
|
||||
/ "407" ; Proxy Authentication Required
|
||||
/ "408" ; Request Timeout
|
||||
/ "410" ; Gone
|
||||
/ "413" ; Request Entity Too Large
|
||||
/ "414" ; Request-URI Too Large
|
||||
/ "415" ; Unsupported Media Type
|
||||
/ "416" ; Unsupported URI Scheme
|
||||
/ "420" ; Bad Extension
|
||||
/ "421" ; Extension Required
|
||||
/ "423" ; Interval Too Brief
|
||||
/ "480" ; Temporarily not available
|
||||
/ "481" ; Call Leg/Transaction Does Not Exist
|
||||
/ "482" ; Loop Detected
|
||||
/ "483" ; Too Many Hops
|
||||
/ "484" ; Address Incomplete
|
||||
/ "485" ; Ambiguous
|
||||
/ "486" ; Busy Here
|
||||
/ "487" ; Request Terminated
|
||||
/ "488" ; Not Acceptable Here
|
||||
/ "491" ; Request Pending
|
||||
/ "493" ; Undecipherable
|
||||
|
||||
Server-Error = "500" ; Internal Server Error
|
||||
/ "501" ; Not Implemented
|
||||
/ "502" ; Bad Gateway
|
||||
/ "503" ; Service Unavailable
|
||||
/ "504" ; Server Time-out
|
||||
/ "505" ; SIP Version not supported
|
||||
/ "513" ; Message Too Large
|
||||
Global-Failure = "600" ; Busy Everywhere
|
||||
/ "603" ; Decline
|
||||
/ "604" ; Does not exist anywhere
|
||||
/ "606" ; Not Acceptable
|
||||
|
||||
```
|
||||
18
sip/body.go
18
sip/body.go
@@ -1,18 +0,0 @@
|
||||
package sip
|
||||
|
||||
//sip message body
|
||||
//xml解析的字段
|
||||
const (
|
||||
MESSAGE_CATALOG = "Catalog"
|
||||
MESSAGE_DEVICE_INFO = "DeviceInfo"
|
||||
MESSAGE_BROADCAST = "Broadcast"
|
||||
MESSAGE_DEVICE_STATUS = "DeviceStatus"
|
||||
MESSAGE_KEEP_ALIVE = "Keepalive"
|
||||
MESSAGE_MOBILE_POSITION = "MobilePosition"
|
||||
MESSAGE_MOBILE_POSITION_INTERVAL = "Interval"
|
||||
|
||||
ELEMENT_DEVICE_ID = "DeviceID"
|
||||
ELEMENT_DEVICE_LIST = "DeviceList"
|
||||
ELEMENT_NAME = "Name"
|
||||
ELEMENT_STATUS = "Status"
|
||||
)
|
||||
56
sip/demo.go
56
sip/demo.go
@@ -1,56 +0,0 @@
|
||||
package sip
|
||||
|
||||
import "fmt"
|
||||
|
||||
func DemoMessage() {
|
||||
registerStr := `REGISTER sip:34020000002000000001@3402000000 SIP/2.0
|
||||
Via: SIP/2.0/UDP 192.168.1.64:5060;rport;branch=z9hG4bK385701375
|
||||
From: <sip:34020000001320000001@3402000000>;tag=1840661473
|
||||
To: <sip:34020000001320000001@3402000000>
|
||||
Call-ID: 418133739
|
||||
CSeq: 1 REGISTER
|
||||
Contact: <sip:34020000001320000001@192.168.1.64:5060>
|
||||
Max-Forwards: 70
|
||||
User-Agent: IP Camera
|
||||
Expires: 3600
|
||||
Content-Length: 0`
|
||||
|
||||
fmt.Println("input:")
|
||||
fmt.Println(registerStr)
|
||||
msg, err := Decode([]byte(registerStr))
|
||||
if err != nil {
|
||||
fmt.Println("decode message failed:", err.Error())
|
||||
return
|
||||
}
|
||||
out, err := Encode(msg)
|
||||
if err != nil {
|
||||
fmt.Println("encode message failed:", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println("=====================================")
|
||||
fmt.Println("output:")
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
|
||||
func DemoVIA() {
|
||||
str1 := "SIP / 2.0 / UDP first.example.com: 4000;ttl=16 ;maddr=224.2.0.1 ;branch=z9hG4bKa7c6a8dlze.1"
|
||||
str2 := "SIP/2.0/UDP 192.168.1.64:5060;rport;received=192.168.1.64;branch=z9hG4bK1000615294"
|
||||
|
||||
var err error
|
||||
v1 := &Via{}
|
||||
err = v1.Parse(str1)
|
||||
if err != nil {
|
||||
fmt.Println("error:", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("result:%v\n", v1.String())
|
||||
|
||||
v2 := &Via{}
|
||||
err = v2.Parse(str2)
|
||||
if err != nil {
|
||||
fmt.Println("error:", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("result:%v\n", v2.String())
|
||||
|
||||
}
|
||||
704
sip/head.go
704
sip/head.go
@@ -1,704 +0,0 @@
|
||||
package sip
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"errors"
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//换行符号:
|
||||
//linux,unix : \r\n
|
||||
//windows : \n
|
||||
//Mac OS : \r
|
||||
const (
|
||||
VERSION = "SIP/2.0" // sip version
|
||||
CRLF = "\r\n" // 0x0D0A
|
||||
CRLFCRLF = "\r\n\r\n" // 0x0D0A0D0A
|
||||
DIGEST_ALGO_MD5 = "MD5"
|
||||
//CRLF = "\n" // 0x0D
|
||||
//CRLFCRLF = "\n\n" // 0x0D0D
|
||||
)
|
||||
|
||||
//SIP消息类型:请求or响应
|
||||
type Mode int
|
||||
|
||||
const (
|
||||
SIP_MESSAGE_REQUEST Mode = 0
|
||||
SIP_MESSAGE_RESPONSE Mode = 1
|
||||
)
|
||||
|
||||
//sip request method
|
||||
type Method string
|
||||
|
||||
const (
|
||||
ACK Method = "ACK"
|
||||
BYE Method = "BYE"
|
||||
CANCEL Method = "CANCEL"
|
||||
INVITE Method = "INVITE"
|
||||
OPTIONS Method = "OPTIONS"
|
||||
REGISTER Method = "REGISTER"
|
||||
NOTIFY Method = "NOTIFY"
|
||||
SUBSCRIBE Method = "SUBSCRIBE"
|
||||
MESSAGE Method = "MESSAGE"
|
||||
REFER Method = "REFER"
|
||||
INFO Method = "INFO"
|
||||
PRACK Method = "PRACK"
|
||||
UPDATE Method = "UPDATE"
|
||||
PUBLISH Method = "PUBLISH"
|
||||
)
|
||||
|
||||
//startline
|
||||
//MESSAGE sip:34020000001320000001@3402000000 SIP/2.0
|
||||
//SIP/2.0 200 OK
|
||||
type StartLine struct {
|
||||
raw string //原始内容
|
||||
|
||||
//request line: method uri version
|
||||
Method Method
|
||||
Uri URI //Request-URI:请求的服务地址,不能包含空白字符或者控制字符,并且禁止用”<>”括上。
|
||||
Version string
|
||||
|
||||
//status line: version code phrase
|
||||
Code int //status code
|
||||
phrase string
|
||||
}
|
||||
|
||||
func (l *StartLine) String() string {
|
||||
if l.Version == "" {
|
||||
l.Version = "SIP/2.0"
|
||||
}
|
||||
var result string
|
||||
if l.Method == "" {
|
||||
result = fmt.Sprintf("%s %d %s", l.Version, l.Code, l.phrase)
|
||||
} else {
|
||||
result = fmt.Sprintf("%s %s %s", l.Method, l.Uri.String(), l.Version)
|
||||
}
|
||||
l.raw = result
|
||||
return l.raw
|
||||
}
|
||||
|
||||
//To From Referto Contact
|
||||
//From: <sip:34020000001320000001@3402000000>;tag=575945878
|
||||
//To: <sip:34020000002000000001@3402000000>
|
||||
//Contact: <sip:34020000001320000001@27.38.49.149:49243>
|
||||
//Contact: <sip:34020000001320000001@192.168.1.64:5060>;expires=0
|
||||
type Contact struct {
|
||||
raw string //原始内容
|
||||
|
||||
Nickname string //可以没有
|
||||
Uri URI //
|
||||
|
||||
//header params
|
||||
Params map[string]string // include tag/q/expires
|
||||
}
|
||||
|
||||
func (c *Contact) String() string {
|
||||
sb := strings.Builder{}
|
||||
|
||||
if c.Nickname != "" {
|
||||
sb.WriteByte('"')
|
||||
sb.WriteString(c.Nickname)
|
||||
sb.WriteByte('"')
|
||||
sb.WriteByte(' ')
|
||||
}
|
||||
urlStr := c.Uri.String()
|
||||
if strings.ContainsAny(urlStr, ",?:") {
|
||||
urlStr = fmt.Sprintf("<%s>", urlStr)
|
||||
}
|
||||
sb.WriteString(urlStr)
|
||||
|
||||
if c.Params != nil {
|
||||
for k, v := range c.Params {
|
||||
sb.WriteString(";")
|
||||
sb.WriteString(k)
|
||||
sb.WriteString("=")
|
||||
sb.WriteString(v)
|
||||
}
|
||||
}
|
||||
|
||||
c.raw = sb.String()
|
||||
return c.raw
|
||||
}
|
||||
|
||||
func (c *Contact) Parse(str string) (err error) {
|
||||
c.raw = str
|
||||
|
||||
if str == "*" {
|
||||
c.Uri.host = "*"
|
||||
return
|
||||
}
|
||||
|
||||
n0 := strings.IndexByte(str, '"')
|
||||
if n0 != -1 {
|
||||
str = str[n0+1:]
|
||||
n1 := strings.IndexByte(str, '"')
|
||||
if n1 == -1 {
|
||||
return errors.New("parse nickname failed")
|
||||
}
|
||||
c.Nickname = str[:n1]
|
||||
str = strings.TrimSpace(str[n1+1:])
|
||||
}
|
||||
|
||||
if len(str) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
var uriDone = false
|
||||
if strings.ContainsAny(str, "<>") {
|
||||
n2 := strings.IndexByte(str, '<')
|
||||
n3 := strings.IndexByte(str, '>')
|
||||
if n2 == -1 || n3 == -1 {
|
||||
err = errors.New("parse contact-uri failed")
|
||||
return
|
||||
}
|
||||
c.Uri, err = parseURI(str[n2+1 : n3])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
uriDone = true
|
||||
str = strings.TrimSpace(str[n3+1:])
|
||||
}
|
||||
|
||||
if len(str) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
str = strings.Trim(str, ";")
|
||||
arr1 := strings.Split(str, ";")
|
||||
for idx, one := range arr1 {
|
||||
//如果上面没有通过<>解析出来uri,则用分号split的第一个元素,就是uri字符串
|
||||
if !uriDone && idx == 0 {
|
||||
c.Uri, err = parseURI(one)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
if c.Params == nil {
|
||||
c.Params = make(map[string]string)
|
||||
}
|
||||
arr2 := strings.Split(one, "=")
|
||||
k, v := arr2[0], arr2[1]
|
||||
c.Params[k] = v
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//Via: SIP/2.0/UDP 192.168.1.64:5060;rport=49243;received=27.38.49.149;branch=z9hG4bK879576192
|
||||
//Params:
|
||||
//Received : IPv4address / IPv6address
|
||||
//RPort : 0-not found, -1-no-value, other-value
|
||||
//Branch : branch参数的值必须用magic cookie "z9hG4bK" 作为开头
|
||||
|
||||
/*
|
||||
Via = ( "Via" / "v" ) HCOLON via-parm *(COMMA via-parm)
|
||||
via-parm = sent-protocol LWS sent-by *( SEMI via-params )
|
||||
via-params = via-ttl / via-maddr
|
||||
/ via-received / via-branch
|
||||
/ via-extension
|
||||
via-ttl = "ttl" EQUAL ttl
|
||||
via-maddr = "maddr" EQUAL host
|
||||
via-received = "received" EQUAL (IPv4address / IPv6address)
|
||||
via-branch = "branch" EQUAL token
|
||||
via-extension = generic-param
|
||||
sent-protocol = protocol-name SLASH protocol-version
|
||||
SLASH transport
|
||||
protocol-name = "SIP" / token
|
||||
protocol-version = token
|
||||
transport = "UDP" / "TCP" / "TLS" / "SCTP"
|
||||
/ other-transport
|
||||
sent-by = host [ COLON port ]
|
||||
ttl = 1*3DIGIT ; 0 to 255
|
||||
*/
|
||||
type Via struct {
|
||||
raw string // 原始内容
|
||||
Version string // sip version: default to SIP/2.0
|
||||
Transport string // UDP,TCP ,TLS , SCTP
|
||||
Host string // sent-by : host:port
|
||||
Port string //
|
||||
//header params
|
||||
Params map[string]string // include branch/rport/received/ttl/maddr
|
||||
}
|
||||
|
||||
func (v *Via) GetBranch() string {
|
||||
return v.Params["branch"]
|
||||
}
|
||||
|
||||
func (v *Via) GetSendBy() string {
|
||||
var host, port string
|
||||
|
||||
sb := strings.Builder{}
|
||||
received := v.Params["received"]
|
||||
rport := v.Params["rport"]
|
||||
|
||||
if received != "" {
|
||||
host = received
|
||||
} else {
|
||||
host = v.Host
|
||||
}
|
||||
|
||||
if rport != "" && rport != "0" && rport != "-1" {
|
||||
port = rport
|
||||
} else if v.Port != "" {
|
||||
port = v.Port
|
||||
} else {
|
||||
if strings.ToUpper(v.Transport) == "UDP" {
|
||||
port = "5060"
|
||||
} else {
|
||||
port = "5061"
|
||||
}
|
||||
}
|
||||
|
||||
sb.WriteString(host)
|
||||
sb.WriteString(":")
|
||||
sb.WriteString(port)
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
func (v *Via) String() string {
|
||||
sb := strings.Builder{}
|
||||
if v.Version == "" {
|
||||
v.Version = "SIP/2.0"
|
||||
}
|
||||
|
||||
if v.Transport == "" {
|
||||
v.Transport = "UDP"
|
||||
}
|
||||
|
||||
sb.WriteString(v.Version)
|
||||
sb.WriteString("/")
|
||||
sb.WriteString(v.Transport)
|
||||
sb.WriteString(" ")
|
||||
sb.WriteString(v.Host)
|
||||
if v.Port != "" {
|
||||
sb.WriteString(":")
|
||||
sb.WriteString(v.Port)
|
||||
}
|
||||
|
||||
if v.Params != nil {
|
||||
for k, v := range v.Params {
|
||||
sb.WriteString(";")
|
||||
sb.WriteString(k)
|
||||
if v == "-1" {
|
||||
//rport 值为-1的时候,没有值
|
||||
continue
|
||||
}
|
||||
sb.WriteString("=")
|
||||
sb.WriteString(v)
|
||||
}
|
||||
}
|
||||
|
||||
v.raw = sb.String()
|
||||
return v.raw
|
||||
}
|
||||
|
||||
//注意via允许以下这种添加空白
|
||||
//Via: SIP / 2.0 / UDP first.example.com: 4000;ttl=16 ;maddr=224.2.0.1 ;branch=z9hG4bKa7c6a8dlze.1
|
||||
//Via: SIP/2.0/UDP 192.168.1.64:5060;rport=5060;received=192.168.1.64;branch=z9hG4bK1000615294
|
||||
func (v *Via) Parse(str string) (err error) {
|
||||
v.raw = str
|
||||
|
||||
str = strings.Trim(str, ";")
|
||||
arr1 := strings.Split(str, ";")
|
||||
part1 := strings.TrimSpace(arr1[0]) //SIP / 2.0 / UDP first.example.com: 4000
|
||||
|
||||
v.Host, v.Port = "", ""
|
||||
if n1 := strings.IndexByte(part1, ':'); n1 != -1 {
|
||||
v.Port = strings.TrimSpace(part1[n1+1:])
|
||||
part1 = strings.TrimSpace(part1[:n1])
|
||||
}
|
||||
|
||||
n2 := strings.LastIndexByte(part1, ' ')
|
||||
if n2 == -1 {
|
||||
v.Host = part1 //error?
|
||||
} else {
|
||||
v.Host = strings.TrimSpace(part1[n2+1:])
|
||||
|
||||
//解析protocol、version和transport,SIP / 2.0 / UDP
|
||||
part2 := part1[:n2]
|
||||
arr2 := strings.Split(part2, "/")
|
||||
if len(arr2) != 3 {
|
||||
err = errors.New("parse contait part1.1 failed:" + part2)
|
||||
return
|
||||
}
|
||||
v.Version = fmt.Sprintf("%s/%s", strings.TrimSpace(arr2[0]), strings.TrimSpace(arr2[1]))
|
||||
v.Transport = strings.TrimSpace(arr2[2])
|
||||
}
|
||||
|
||||
//必须有参数
|
||||
v.Params = make(map[string]string)
|
||||
for i, one := range arr1 {
|
||||
if i == 0 {
|
||||
//arr[0]已经处理
|
||||
continue
|
||||
}
|
||||
one = strings.TrimSpace(one)
|
||||
arr2 := strings.Split(one, "=")
|
||||
//rport 这个参数可能没有 value。 -1:no-value, other-value
|
||||
if len(arr2) == 1 {
|
||||
if arr2[0] == "rport" {
|
||||
v.Params["rport"] = "-1"
|
||||
continue
|
||||
} else {
|
||||
fmt.Println("invalid param:", one)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
||||
k, val := arr2[0], arr2[1]
|
||||
v.Params[k] = val
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
//CSeq: 101 INVITE
|
||||
//CSeq: 2 REGISTER
|
||||
type CSeq struct {
|
||||
raw string //原始内容
|
||||
ID uint32
|
||||
Method Method
|
||||
}
|
||||
|
||||
func (c *CSeq) String() string {
|
||||
c.raw = fmt.Sprintf("%d %s", c.ID, c.Method)
|
||||
return c.raw
|
||||
}
|
||||
|
||||
func (c *CSeq) Parse(str string) error {
|
||||
c.raw = str
|
||||
arr1 := strings.Split(str, " ")
|
||||
n, err := strconv.ParseInt(arr1[0], 10, 64)
|
||||
if err != nil {
|
||||
fmt.Println("parse cseq faield:", str)
|
||||
return err
|
||||
}
|
||||
c.ID = uint32(n)
|
||||
if len(arr1) < 2 {
|
||||
return errors.New("no method: " + str)
|
||||
}
|
||||
c.Method = Method(arr1[1])
|
||||
return nil
|
||||
}
|
||||
|
||||
//sip:user:password@domain;uri-parameters?headers
|
||||
/*
|
||||
RFC3261
|
||||
SIP-URI = "sip:" [ userinfo ] hostport
|
||||
uri-parameters [ headers ]
|
||||
SIPS-URI = "sips:" [ userinfo ] hostport
|
||||
uri-parameters [ headers ]
|
||||
userinfo = ( user / telephone-subscriber ) [ ":" password ] "@"
|
||||
user = 1*( unreserved / escaped / user-unreserved )
|
||||
user-unreserved = "&" / "=" / "+" / "$" / "," / ";" / "?" / "/"
|
||||
password = *( unreserved / escaped /
|
||||
"&" / "=" / "+" / "$" / "," )
|
||||
hostport = host [ ":" port ]
|
||||
host = hostname / IPv4address / IPv6reference
|
||||
hostname = *( domainlabel "." ) toplabel [ "." ]
|
||||
domainlabel = alphanum
|
||||
/ alphanum *( alphanum / "-" ) alphanum
|
||||
toplabel = ALPHA / ALPHA *( alphanum / "-" ) alphanum
|
||||
|
||||
IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
|
||||
IPv6reference = "[" IPv6address "]"
|
||||
IPv6address = hexpart [ ":" IPv4address ]
|
||||
hexpart = hexseq / hexseq "::" [ hexseq ] / "::" [ hexseq ]
|
||||
hexseq = hex4 *( ":" hex4)
|
||||
hex4 = 1*4HEXDIG
|
||||
port = 1*DIGIT
|
||||
|
||||
uri-parameters = *( ";" uri-parameter)
|
||||
uri-parameter = transport-param / user-param / method-param
|
||||
/ ttl-param / maddr-param / lr-param / other-param
|
||||
transport-param = "transport="
|
||||
( "udp" / "tcp" / "sctp" / "tls"
|
||||
/ other-transport)
|
||||
other-transport = token
|
||||
user-param = "user=" ( "phone" / "ip" / other-user)
|
||||
other-user = token
|
||||
method-param = "method=" Method
|
||||
ttl-param = "ttl=" ttl
|
||||
maddr-param = "maddr=" host
|
||||
lr-param = "lr"
|
||||
other-param = pname [ "=" pvalue ]
|
||||
pname = 1*paramchar
|
||||
pvalue = 1*paramchar
|
||||
paramchar = param-unreserved / unreserved / escaped
|
||||
param-unreserved = "[" / "]" / "/" / ":" / "&" / "+" / "$"
|
||||
|
||||
headers = "?" header *( "&" header )
|
||||
header = hname "=" hvalue
|
||||
hname = 1*( hnv-unreserved / unreserved / escaped )
|
||||
hvalue = *( hnv-unreserved / unreserved / escaped )
|
||||
hnv-unreserved = "[" / "]" / "/" / "?" / ":" / "+" / "$"
|
||||
*/
|
||||
type URI struct {
|
||||
scheme string // sip sips
|
||||
host string // userinfo@domain or userinfo@ip:port
|
||||
method string // uri和method有关?
|
||||
params map[string]string // include branch/maddr/received/ttl/rport
|
||||
headers map[string]string // include branch/maddr/received/ttl/rport
|
||||
}
|
||||
|
||||
func (u *URI) Host() string {
|
||||
return u.host
|
||||
}
|
||||
func (u *URI) UserInfo() string {
|
||||
return strings.Split(u.host, "@")[0]
|
||||
}
|
||||
func (u *URI) Domain() string {
|
||||
return strings.Split(u.host, "@")[1]
|
||||
}
|
||||
func (u *URI) IP() string {
|
||||
t := strings.Split(u.host, "@")
|
||||
if len(t) == 1 {
|
||||
return strings.Split(t[0], ":")[0]
|
||||
}
|
||||
return strings.Split(t[1], ":")[0]
|
||||
}
|
||||
func (u *URI) Port() string {
|
||||
t := strings.Split(u.host, "@")
|
||||
if len(t) == 1 {
|
||||
return strings.Split(t[0], ":")[1]
|
||||
}
|
||||
return strings.Split(t[1], ":")[1]
|
||||
}
|
||||
func (u *URI) String() string {
|
||||
if u.scheme == "" {
|
||||
u.scheme = "sip"
|
||||
}
|
||||
sb := strings.Builder{}
|
||||
sb.WriteString(u.scheme)
|
||||
sb.WriteString(":")
|
||||
sb.WriteString(u.host)
|
||||
if u.params != nil {
|
||||
for k, v := range u.params {
|
||||
sb.WriteString(";")
|
||||
sb.WriteString(k)
|
||||
sb.WriteString("=")
|
||||
sb.WriteString(v)
|
||||
}
|
||||
}
|
||||
|
||||
if u.headers != nil {
|
||||
sb.WriteString("?")
|
||||
for k, v := range u.headers {
|
||||
sb.WriteString("&")
|
||||
sb.WriteString(k)
|
||||
sb.WriteString("=")
|
||||
sb.WriteString(v)
|
||||
}
|
||||
}
|
||||
|
||||
return sb.String()
|
||||
}
|
||||
|
||||
//对于gb28181,request-uri 不带参数
|
||||
func NewURI(host string) URI {
|
||||
return URI{
|
||||
scheme: "sip",
|
||||
host: host,
|
||||
}
|
||||
}
|
||||
func parseURI(str string) (ret URI, err error) {
|
||||
ret = URI{}
|
||||
|
||||
//解析scheme
|
||||
str = strings.TrimSpace(str)
|
||||
n1 := strings.IndexByte(str, ':')
|
||||
if n1 == -1 {
|
||||
err = errors.New("invalid sheme")
|
||||
return
|
||||
}
|
||||
ret.scheme = str[:n1]
|
||||
str = str[n1+1:]
|
||||
if len(str) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
//解析host
|
||||
n2 := strings.IndexByte(str, ';')
|
||||
if n2 == -1 {
|
||||
ret.host = str
|
||||
return
|
||||
}
|
||||
ret.host = str[:n2]
|
||||
|
||||
str = str[n2+1:]
|
||||
if len(str) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
//解析params and headers
|
||||
var paramStr, headerStr = "", ""
|
||||
n3 := strings.IndexByte(str, '?')
|
||||
if n3 == -1 {
|
||||
paramStr = str
|
||||
} else {
|
||||
paramStr = str[:n3]
|
||||
headerStr = str[n3+1:]
|
||||
}
|
||||
|
||||
//k1=v1;k2=v2
|
||||
if paramStr != "" {
|
||||
ret.params = make(map[string]string)
|
||||
paramStr = strings.Trim(paramStr, ";")
|
||||
arr1 := strings.Split(paramStr, ";")
|
||||
for _, one := range arr1 {
|
||||
tmp := strings.Split(one, "=")
|
||||
if len(tmp) == 2 {
|
||||
k, v := tmp[0], tmp[1]
|
||||
ret.params[k] = v
|
||||
} else {
|
||||
ret.params[tmp[0]] = ""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//k1=v1&k2=v2
|
||||
if headerStr != "" {
|
||||
ret.headers = make(map[string]string)
|
||||
arr2 := strings.Split(paramStr, "&")
|
||||
for _, one := range arr2 {
|
||||
tmp := strings.Split(one, "=")
|
||||
var k, v string
|
||||
if len(tmp) == 2 {
|
||||
k, v = tmp[0], tmp[1]
|
||||
} else {
|
||||
k = tmp[0]
|
||||
}
|
||||
ret.headers[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
type WwwAuthenticate struct {
|
||||
realm string
|
||||
nonce string
|
||||
algorithm string
|
||||
//opaque string // gb28181不需要这字段,海康有
|
||||
}
|
||||
|
||||
func NewWwwAuthenticate(realm, nonce, algorithm string) *WwwAuthenticate {
|
||||
return &WwwAuthenticate{
|
||||
realm: realm,
|
||||
nonce: nonce,
|
||||
algorithm: algorithm,
|
||||
}
|
||||
}
|
||||
|
||||
// WWW-Authenticate: Digest realm="hik", nonce="a8afe6fcbee6331d89d3eb0d3d19ce39", opaque="a853e4f25298413f9bf3a9aa6767857d", algorithm=MD5
|
||||
func (w *WwwAuthenticate) String() string {
|
||||
return fmt.Sprintf(`Digest realm="%s", nonce="%s", algorithm=%s`, w.realm, w.nonce, w.algorithm)
|
||||
}
|
||||
|
||||
func (w *WwwAuthenticate) Parse(str string) error {
|
||||
arr := strings.Split(str, ",")
|
||||
for _, s := range arr {
|
||||
tmp := strings.Split(s, "=")
|
||||
if len(tmp) != 2 {
|
||||
continue
|
||||
}
|
||||
v := strings.ReplaceAll(tmp[1], "\"", "")
|
||||
if strings.Contains(tmp[0], "realm") {
|
||||
w.realm = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "nonce") {
|
||||
w.nonce = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "algorithm") {
|
||||
w.algorithm = v
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type Authorization struct {
|
||||
username string
|
||||
realm string
|
||||
nonce string
|
||||
uri string
|
||||
response string
|
||||
algorithm string
|
||||
//opaque string // gb28181不需要这字段,海康有
|
||||
}
|
||||
|
||||
// Authorization: Digest username="admin", realm="hik", nonce="a8afe6fcbee6331d89d3eb0d3d19ce39", uri="sip:130909115229300920@10.64.49.44:7100", response="907ddb1bcc25174d7de4a96c947fb066", algorithm=MD5, opaque="a853e4f25298413f"
|
||||
func (a *Authorization) String() string {
|
||||
return fmt.Sprintf(`Digest username="%s", realm="%s", nonce="%s", uri="%s", response="%s", algorithm=%s`,
|
||||
a.username, a.realm, a.nonce, a.uri, a.response, a.algorithm)
|
||||
}
|
||||
|
||||
func (a *Authorization) GetUsername() string {
|
||||
return a.username
|
||||
}
|
||||
|
||||
func (a *Authorization) Parse(str string) error {
|
||||
arr := strings.Split(str, ",")
|
||||
for _, s := range arr {
|
||||
tmp := strings.Split(s, "=")
|
||||
if len(tmp) != 2 {
|
||||
continue
|
||||
}
|
||||
v := strings.ReplaceAll(tmp[1], "\"", "")
|
||||
if strings.Contains(tmp[0], "username") {
|
||||
a.username = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "realm") {
|
||||
a.realm = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "nonce") {
|
||||
a.nonce = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "uri") {
|
||||
a.uri = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "response") {
|
||||
a.response = v
|
||||
}
|
||||
if strings.Contains(tmp[0], "algorithm") {
|
||||
a.algorithm = strings.Trim(v,"H:")
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Authorization) Verify(username, passwd, realm, nonce string) bool {
|
||||
|
||||
//1、将 username,realm,password 依次组合获取 1 个字符串,并用算法加密的到密文 r1
|
||||
s1 := fmt.Sprintf("%s:%s:%s", username, realm, passwd)
|
||||
r1 := a.getDigest(s1)
|
||||
//2、将 method,即REGISTER ,uri 依次组合获取 1 个字符串,并对这个字符串使用算法 加密得到密文 r2
|
||||
s2 := fmt.Sprintf("REGISTER:%s", a.uri)
|
||||
r2 := a.getDigest(s2)
|
||||
|
||||
if r1 == "" || r2 == "" {
|
||||
fmt.Println("Authorization algorithm wrong")
|
||||
return false
|
||||
}
|
||||
//3、将密文 1,nonce 和密文 2 依次组合获取 1 个字符串,并对这个字符串使用算法加密,获得密文 r3,即Response
|
||||
s3 := fmt.Sprintf("%s:%s:%s", r1, nonce, r2)
|
||||
r3 := a.getDigest(s3)
|
||||
|
||||
//4、计算服务端和客户端上报的是否相等
|
||||
if r3 == a.response {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (a *Authorization) getDigest(raw string) string {
|
||||
switch a.algorithm {
|
||||
case DIGEST_ALGO_MD5:
|
||||
return fmt.Sprintf("%x", md5.Sum([]byte(raw)))
|
||||
default: //如果没有算法,默认使用MD5
|
||||
return fmt.Sprintf("%x", md5.Sum([]byte(raw)))
|
||||
}
|
||||
}
|
||||
171
sip/head_test.go
171
sip/head_test.go
@@ -1,171 +0,0 @@
|
||||
package sip
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestContact(t *testing.T) {
|
||||
str1 := "\"Mr.Watson\" <sip:watson@worcester.bell-telephone.com>;q=0.7; expires=3600,\"Mr.Watson\" <mailto:watson@bell-telephone.com>"
|
||||
//str1 := `"Mr.Watson" <sip:watson@worcester.bell-telephone.com>;q=0.7;`
|
||||
c := &Contact{}
|
||||
err := c.Parse(str1)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
return
|
||||
}
|
||||
fmt.Println("source:", str1)
|
||||
fmt.Println("result:", c.String())
|
||||
}
|
||||
|
||||
func TestVia(t *testing.T) {
|
||||
str1 := "SIP / 2.0 / UDP first.example.com: 4000;ttl=16 ;maddr=224.2.0.1 ;branch=z9hG4bKa7c6a8dlze.1"
|
||||
str2 := "SIP/2.0/UDP 192.168.1.64:5060;rport;received=192.168.1.64;branch=z9hG4bK1000615294"
|
||||
|
||||
var err error
|
||||
v1 := &Via{}
|
||||
err = v1.Parse(str1)
|
||||
if err != nil {
|
||||
fmt.Println("error:", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("source:%v\n", str1)
|
||||
fmt.Printf("result:%v\n", v1.String())
|
||||
|
||||
v2 := &Via{}
|
||||
err = v2.Parse(str2)
|
||||
if err != nil {
|
||||
fmt.Println("error:", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Printf("source:%v\n", str2)
|
||||
fmt.Printf("result:%v\n", v2.String())
|
||||
|
||||
}
|
||||
|
||||
func TestMessage1(t *testing.T) {
|
||||
str1 := `REGISTER sip:34020000002000000001@3402000000 SIP/2.0
|
||||
Via: SIP/2.0/UDP 192.168.1.64:5060;rport;branch=z9hG4bK385701375
|
||||
From: <sip:34020000001320000001@3402000000>;tag=1840661473
|
||||
To: <sip:34020000001320000001@3402000000>
|
||||
Call-ID: 418133739
|
||||
CSeq: 1 REGISTER
|
||||
Contact: <sip:34020000001320000001@192.168.1.64:5060>
|
||||
Max-Forwards: 70
|
||||
User-Agent: IP Camera
|
||||
Expires: 3600
|
||||
Content-Length: 0`
|
||||
|
||||
fmt.Println("input:")
|
||||
fmt.Println(str1)
|
||||
msg, err := Decode([]byte(str1))
|
||||
if err != nil {
|
||||
fmt.Println("decode message failed:", err.Error())
|
||||
return
|
||||
}
|
||||
out, err := Encode(msg)
|
||||
if err != nil {
|
||||
fmt.Println("encode message failed:", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println("=====================================")
|
||||
fmt.Println("output:")
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
|
||||
func TestMessage2(t *testing.T) {
|
||||
str1 := `SIP/2.0 200 OK
|
||||
Via: SIP/2.0/UDP 192.168.1.151:5060;rport=5060;branch=SrsGbB56116414
|
||||
From: <sip:34020000002000000001@3402000000>;tag=SrsGbF72006729
|
||||
To: <sip:34020000001320000001@3402000000>;tag=416442565
|
||||
Call-ID: 202093500940
|
||||
CSeq: 101 INVITE
|
||||
Contact: <sip:34020000001320000001@192.168.1.64:5060>
|
||||
Content-Type: application/sdp
|
||||
User-Agent: IP Camera
|
||||
Content-Length: 185
|
||||
|
||||
v=0
|
||||
o=34020000001320000001 1835 1835 IN IP4 192.168.1.64
|
||||
s=Play
|
||||
c=IN IP4 192.168.1.64
|
||||
t=0 0
|
||||
m=video 15060 RTP/AVP 96
|
||||
a=sendonly
|
||||
a=rtpmap:96 PS/90000
|
||||
a=filesize:0
|
||||
y=0009093131`
|
||||
|
||||
fmt.Println("input:")
|
||||
fmt.Println(str1)
|
||||
msg, err := Decode([]byte(str1))
|
||||
if err != nil {
|
||||
fmt.Println("decode message failed:", err.Error())
|
||||
return
|
||||
}
|
||||
out, err := Encode(msg)
|
||||
if err != nil {
|
||||
fmt.Println("encode message failed:", err.Error())
|
||||
return
|
||||
}
|
||||
fmt.Println("=====================================")
|
||||
fmt.Println("output:")
|
||||
fmt.Println(string(out))
|
||||
}
|
||||
|
||||
func TestAuthorization_Verify(t *testing.T) {
|
||||
type fields struct {
|
||||
username string
|
||||
realm string
|
||||
nonce string
|
||||
uri string
|
||||
response string
|
||||
algorithm string
|
||||
}
|
||||
type args struct {
|
||||
username string
|
||||
passwd string
|
||||
realm string
|
||||
nonce string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
fields: fields{
|
||||
username: "34020000001320000001",
|
||||
realm: "3402000000",
|
||||
nonce: "1628819207",
|
||||
uri: "sip:34020000002000000001@172.165.0.10:15060",
|
||||
response: "fa2b30e05ea42dd0ab69ef05d3a06096",
|
||||
algorithm: "MD5",
|
||||
},
|
||||
args: args{
|
||||
username: "34020000001320000001",
|
||||
passwd: "12345678",
|
||||
realm: "3402000000",
|
||||
nonce: "1628819207",
|
||||
},
|
||||
want: true,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
a := &Authorization{
|
||||
username: tt.fields.username,
|
||||
realm: tt.fields.realm,
|
||||
nonce: tt.fields.nonce,
|
||||
uri: tt.fields.uri,
|
||||
response: tt.fields.response,
|
||||
algorithm: tt.fields.algorithm,
|
||||
}
|
||||
if got := a.Verify(tt.args.username, tt.args.passwd, tt.args.realm, tt.args.nonce); got != tt.want {
|
||||
t.Errorf("Verify() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
499
sip/message.go
499
sip/message.go
@@ -1,499 +0,0 @@
|
||||
package sip
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
)
|
||||
|
||||
//Content-Type: Application/MANSCDP+xml
|
||||
//Content-Type: Application/SDP
|
||||
//Call-ID: 202081530679
|
||||
//Max-Forwards: 70
|
||||
//User-Agent: SRS/4.0.32(Leo)
|
||||
//Subject: 34020000001320000001:0009093128,34020000002000000001:0
|
||||
//Content-Length: 164
|
||||
|
||||
type Message struct {
|
||||
Mode Mode //0:REQUEST, 1:RESPONSE
|
||||
|
||||
StartLine *StartLine
|
||||
Via *Via //Via
|
||||
From *Contact //From
|
||||
To *Contact //To
|
||||
CallID string //Call-ID
|
||||
CSeq *CSeq //CSeq
|
||||
Contact *Contact //Contact
|
||||
Authorization *Authorization //Authorization
|
||||
MaxForwards int //Max-Forwards
|
||||
UserAgent string //User-Agent
|
||||
Subject string //Subject
|
||||
ContentType string //Content-Type
|
||||
Expires int //Expires
|
||||
ContentLength int //Content-Length
|
||||
Route *Contact
|
||||
Body string
|
||||
Addr string
|
||||
Event string
|
||||
Date time.Time
|
||||
WwwAuthenticate *WwwAuthenticate //gb28181 密码验证 上级发给下级是WwwAuthenticate;下级发给上级是Authorization
|
||||
SourceAdd net.Addr
|
||||
DestAdd net.Addr
|
||||
}
|
||||
|
||||
func (m *Message) BuildResponse(code int) *Message {
|
||||
return m.BuildResponseWithPhrase(code, "")
|
||||
}
|
||||
func (m *Message) BuildOK() *Message {
|
||||
return m.BuildResponseWithPhrase(200, "OK")
|
||||
}
|
||||
func (m *Message) BuildResponseWithPhrase(code int, phrase string) *Message {
|
||||
response := Message{
|
||||
Mode: SIP_MESSAGE_RESPONSE,
|
||||
From: m.From,
|
||||
To: m.To,
|
||||
CallID: m.CallID,
|
||||
CSeq: m.CSeq,
|
||||
Via: m.Via,
|
||||
MaxForwards: m.MaxForwards,
|
||||
UserAgent: "Monibuca",
|
||||
StartLine: &StartLine{
|
||||
Code: code,
|
||||
phrase: phrase,
|
||||
},
|
||||
Date: time.Now(),
|
||||
DestAdd: m.SourceAdd,
|
||||
}
|
||||
return &response
|
||||
}
|
||||
|
||||
//z9hG4bK + 10个随机数字
|
||||
func RandBranch() string {
|
||||
return fmt.Sprintf("z9hG4bK%s", utils.RandNumString(8))
|
||||
}
|
||||
|
||||
func BuildMessageRequest(method Method, transport, sipSerial, sipRealm, username, srcIP string, srcPort uint16, expires, cseq int, body string) *Message {
|
||||
server := fmt.Sprintf("%s@%s", sipSerial, sipRealm)
|
||||
client := fmt.Sprintf("%s@%s", username, sipRealm)
|
||||
|
||||
msg := &Message{
|
||||
Mode: SIP_MESSAGE_REQUEST,
|
||||
MaxForwards: 70,
|
||||
UserAgent: "IPC",
|
||||
Expires: expires,
|
||||
ContentLength: 0,
|
||||
}
|
||||
msg.StartLine = &StartLine{
|
||||
Method: method,
|
||||
Uri: NewURI(server),
|
||||
}
|
||||
msg.Via = &Via{
|
||||
Transport: transport,
|
||||
Host: client,
|
||||
}
|
||||
msg.Via.Params = map[string]string{
|
||||
"branch": RandBranch(),
|
||||
"rport": "-1", //only key,no-value
|
||||
}
|
||||
msg.From = &Contact{
|
||||
Uri: NewURI(client),
|
||||
Params: nil,
|
||||
}
|
||||
msg.From.Params = map[string]string{
|
||||
"tag": utils.RandNumString(10),
|
||||
}
|
||||
msg.To = &Contact{
|
||||
Uri: NewURI(client),
|
||||
}
|
||||
msg.CallID = utils.RandNumString(8)
|
||||
msg.CSeq = &CSeq{
|
||||
ID: uint32(cseq),
|
||||
Method: method,
|
||||
}
|
||||
|
||||
msg.Contact = &Contact{
|
||||
Uri: NewURI(fmt.Sprintf("%s@%s:%d", username, srcIP, srcPort)),
|
||||
}
|
||||
if len(body) > 0 {
|
||||
msg.ContentLength = len(body)
|
||||
msg.Body = body
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
func (m *Message) GetMode() Mode {
|
||||
return m.Mode
|
||||
}
|
||||
|
||||
func (m *Message) IsRequest() bool {
|
||||
return m.Mode == SIP_MESSAGE_REQUEST
|
||||
}
|
||||
|
||||
func (m *Message) IsResponse() bool {
|
||||
return m.Mode == SIP_MESSAGE_RESPONSE
|
||||
}
|
||||
|
||||
func (m *Message) GetMethod() Method {
|
||||
if m.CSeq == nil {
|
||||
return MESSAGE
|
||||
}
|
||||
return m.CSeq.Method
|
||||
}
|
||||
|
||||
//此消息是否使用可靠传输
|
||||
func (m *Message) IsReliable() bool {
|
||||
protocol := strings.ToUpper(m.Via.Transport)
|
||||
return "TCP" == protocol || "TLS" == protocol || "SCTP" == protocol
|
||||
}
|
||||
|
||||
//response code
|
||||
func (m *Message) GetStatusCode() int {
|
||||
return m.StartLine.Code
|
||||
}
|
||||
|
||||
//response code and reason
|
||||
func (m *Message) GetReason() string {
|
||||
return DumpError(m.StartLine.Code)
|
||||
}
|
||||
|
||||
func (m *Message) GetBranch() string {
|
||||
if m.Via == nil {
|
||||
panic("invalid via")
|
||||
}
|
||||
if m.Via.Params == nil {
|
||||
panic("invalid via params")
|
||||
}
|
||||
|
||||
b, ok := m.Via.Params["branch"]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
|
||||
return b
|
||||
}
|
||||
|
||||
//构建响应消息的时候,会使用请求消息的 source 和 destination
|
||||
//请求消息的source,格式: host:port
|
||||
func (m *Message) Source() string {
|
||||
if m.Mode == SIP_MESSAGE_RESPONSE {
|
||||
//fmt.Println("only for request message")
|
||||
return ""
|
||||
}
|
||||
|
||||
if m.Via == nil {
|
||||
//fmt.Println("invalid request message")
|
||||
return ""
|
||||
}
|
||||
|
||||
var (
|
||||
host, port string
|
||||
via = m.Via
|
||||
)
|
||||
|
||||
if received, ok := via.Params["received"]; ok && received != "" {
|
||||
host = received
|
||||
} else {
|
||||
host = via.Host
|
||||
}
|
||||
|
||||
if rport, ok := via.Params["rport"]; ok && rport != "-1" && rport != "0" && rport != "" {
|
||||
port = rport
|
||||
} else if via.Port != "" {
|
||||
port = via.Port
|
||||
} else {
|
||||
//如果port为空,则上层构建消息的时候,根据sip服务的默认端口来选择
|
||||
}
|
||||
return fmt.Sprintf("%v:%v", host, port)
|
||||
}
|
||||
|
||||
//目标地址:这个应该是用于通过route头域实现proxy这样的功能,暂时不支持
|
||||
func (m *Message) Destination() string {
|
||||
//TODO:
|
||||
return ""
|
||||
}
|
||||
|
||||
//=======================================================================================================
|
||||
|
||||
func Decode(data []byte) (msg *Message, err error) {
|
||||
msg = &Message{}
|
||||
|
||||
content := string(data)
|
||||
content = strings.Trim(content, CRLFCRLF)
|
||||
msgArr := strings.Split(content, CRLFCRLF)
|
||||
//第一部分:header
|
||||
//第二部分:body
|
||||
if len(msgArr) == 0 {
|
||||
fmt.Println("invalid sip message:", data)
|
||||
err = errors.New("invalid sip message")
|
||||
return
|
||||
}
|
||||
|
||||
headStr := strings.TrimSpace(msgArr[0])
|
||||
if msgArrLen := len(msgArr); msgArrLen > 1 {
|
||||
for i := 1; i < msgArrLen; i++ {
|
||||
msg.Body += strings.TrimSpace(msgArr[i])
|
||||
}
|
||||
}
|
||||
|
||||
headStr = strings.Trim(headStr, CRLF)
|
||||
headArr := strings.Split(headStr, CRLF)
|
||||
for i, line := range headArr {
|
||||
//fmt.Printf("%02d --- %s ---- %d\n", i, line, len(line))
|
||||
if i == 0 {
|
||||
firstline := strings.Trim(line, " ")
|
||||
tmp := strings.Split(firstline, " ")
|
||||
//if len(tmp) != 3 {
|
||||
// fmt.Println("parse first line failed:", firstline)
|
||||
// err = errors.New("invalid first line")
|
||||
// return
|
||||
//}
|
||||
|
||||
if strings.HasPrefix(firstline, VERSION) {
|
||||
//status line
|
||||
//SIP/2.0 200 OK
|
||||
var num int64
|
||||
num, err = strconv.ParseInt(tmp[1], 10, 64)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
msg.Mode = SIP_MESSAGE_RESPONSE
|
||||
msg.StartLine = &StartLine{
|
||||
raw: firstline,
|
||||
Version: VERSION,
|
||||
Code: int(num),
|
||||
phrase: strings.Join(tmp[2:], " "),
|
||||
}
|
||||
} else {
|
||||
//request line
|
||||
//REGISTER sip:34020000002000000001@3402000000 SIP/2.0
|
||||
//MESSAGE sip:34020000002000000001@3402000000 SIP/2.0
|
||||
msg.Mode = SIP_MESSAGE_REQUEST
|
||||
msg.StartLine = &StartLine{
|
||||
raw: firstline,
|
||||
Method: Method(tmp[0]),
|
||||
Version: VERSION,
|
||||
}
|
||||
if len(tmp) > 1 {
|
||||
msg.StartLine.Uri, err = parseURI(tmp[1])
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
//fmt.Println(firstline)
|
||||
}
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
pos := strings.IndexByte(line, ':')
|
||||
if pos == -1 {
|
||||
continue
|
||||
}
|
||||
k := strings.ToLower(strings.TrimSpace(line[:pos]))
|
||||
v := strings.TrimSpace(line[pos+1:])
|
||||
//fmt.Printf("%02d ---k = %s , v = %s\n", i, k, v)
|
||||
|
||||
if len(v) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
switch k {
|
||||
case "via":
|
||||
//Via: SIP/2.0/UDP 192.168.1.64:5060;rport;branch=z9hG4bK385701375
|
||||
msg.Via = &Via{}
|
||||
err = msg.Via.Parse(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
case "from":
|
||||
msg.From = &Contact{}
|
||||
err = msg.From.Parse(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
case "to":
|
||||
msg.To = &Contact{}
|
||||
err = msg.To.Parse(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
case "call-id":
|
||||
msg.CallID = v
|
||||
|
||||
case "cseq":
|
||||
//CSeq: 2 REGISTER
|
||||
msg.CSeq = &CSeq{}
|
||||
err = msg.CSeq.Parse(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
case "contact":
|
||||
msg.Contact = &Contact{}
|
||||
err = msg.Contact.Parse(v)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
case "max-forwards":
|
||||
n, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Printf("parse head faield: %s,%s\n", k, v)
|
||||
return nil, err
|
||||
}
|
||||
msg.MaxForwards = int(n)
|
||||
|
||||
case "user-agent":
|
||||
msg.UserAgent = v
|
||||
|
||||
case "expires":
|
||||
n, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Printf("parse head faield: %s,%s\n", k, v)
|
||||
return nil, err
|
||||
}
|
||||
msg.Expires = int(n)
|
||||
|
||||
case "content-length":
|
||||
n, err := strconv.ParseInt(v, 10, 64)
|
||||
if err != nil {
|
||||
fmt.Printf("parse head faield: %s,%s\n", k, v)
|
||||
return nil, err
|
||||
}
|
||||
msg.ContentLength = int(n)
|
||||
|
||||
case "authorization":
|
||||
msg.Authorization = &Authorization{}
|
||||
msg.Authorization.Parse(v)
|
||||
|
||||
case "content-type":
|
||||
msg.ContentType = v
|
||||
case "route":
|
||||
//msg.Route = new(Contact)
|
||||
//msg.Route.Parse(v)
|
||||
case "www-authenticate":
|
||||
msg.WwwAuthenticate = &WwwAuthenticate{}
|
||||
msg.WwwAuthenticate.Parse(v)
|
||||
case "event":
|
||||
msg.Event = v
|
||||
default:
|
||||
fmt.Printf("invalid sip head: %s,%s\n", k, v)
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func Encode(msg *Message) ([]byte, error) {
|
||||
sb := strings.Builder{}
|
||||
sb.WriteString(msg.StartLine.String())
|
||||
sb.WriteString(CRLF)
|
||||
|
||||
if msg.Via != nil {
|
||||
sb.WriteString("Via: ")
|
||||
sb.WriteString(msg.Via.String())
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
|
||||
if msg.From != nil {
|
||||
sb.WriteString("From: ")
|
||||
sb.WriteString(msg.From.String())
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
|
||||
if msg.To != nil {
|
||||
sb.WriteString("To: ")
|
||||
sb.WriteString(msg.To.String())
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
|
||||
if msg.CallID != "" {
|
||||
sb.WriteString("Call-ID: ")
|
||||
sb.WriteString(msg.CallID)
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
if msg.CSeq != nil {
|
||||
sb.WriteString("CSeq: ")
|
||||
sb.WriteString(msg.CSeq.String())
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
|
||||
if msg.Contact != nil {
|
||||
sb.WriteString("Contact: ")
|
||||
sb.WriteString(msg.Contact.String())
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
|
||||
if msg.UserAgent != "" {
|
||||
sb.WriteString("User-Agent: ")
|
||||
sb.WriteString(msg.UserAgent)
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
|
||||
if msg.ContentType != "" {
|
||||
sb.WriteString("Content-Type: ")
|
||||
sb.WriteString(msg.ContentType)
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
|
||||
if msg.Expires != 0 {
|
||||
sb.WriteString("Expires: ")
|
||||
sb.WriteString(strconv.Itoa(msg.Expires))
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
|
||||
if msg.Subject != "" {
|
||||
sb.WriteString("Subject: ")
|
||||
sb.WriteString(msg.Subject)
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
|
||||
if msg.WwwAuthenticate != nil {
|
||||
sb.WriteString("WWW-Authenticate: ")
|
||||
sb.WriteString(msg.WwwAuthenticate.String())
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
if !msg.Date.IsZero() {
|
||||
sb.WriteString("Date: ")
|
||||
sb.WriteString(msg.Date.Format("2006-01-02T15:04:05.999"))
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
if msg.Event != "" {
|
||||
sb.WriteString("Event: ")
|
||||
sb.WriteString(msg.Event)
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
if msg.IsRequest() {
|
||||
//request only
|
||||
|
||||
sb.WriteString("Max-Forwards: ")
|
||||
sb.WriteString(strconv.Itoa(msg.MaxForwards))
|
||||
sb.WriteString(CRLF)
|
||||
|
||||
if msg.Authorization != nil {
|
||||
sb.WriteString("Authorization: ")
|
||||
sb.WriteString(msg.Authorization.String())
|
||||
sb.WriteString(CRLF)
|
||||
}
|
||||
} else {
|
||||
//response only
|
||||
}
|
||||
|
||||
sb.WriteString("Content-Length: ")
|
||||
sb.WriteString(strconv.Itoa(len(msg.Body)))
|
||||
|
||||
sb.WriteString(CRLFCRLF)
|
||||
|
||||
if msg.Body != "" {
|
||||
sb.WriteString(msg.Body)
|
||||
}
|
||||
|
||||
return []byte(sb.String()), nil
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
package sip
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Request Request
|
||||
type Request struct {
|
||||
*Message
|
||||
}
|
||||
|
||||
var (
|
||||
// CatalogXML 获取设备列表xml样式
|
||||
CatalogXML = `<?xml version="1.0"?><Query>
|
||||
<CmdType>Catalog</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
</Query>
|
||||
`
|
||||
// RecordInfoXML 获取录像文件列表xml样式
|
||||
RecordInfoXML = `<?xml version="1.0"?>
|
||||
<Query>
|
||||
<CmdType>RecordInfo</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
<StartTime>%s</StartTime>
|
||||
<EndTime>%s</EndTime>
|
||||
<Secrecy>0</Secrecy>
|
||||
<Type>time</Type>
|
||||
</Query>
|
||||
`
|
||||
// DeviceInfoXML 查询设备详情xml样式
|
||||
DeviceInfoXML = `<?xml version="1.0"?>
|
||||
<Query>
|
||||
<CmdType>DeviceInfo</CmdType>
|
||||
<SN>%d</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
</Query>
|
||||
`
|
||||
)
|
||||
|
||||
// BuildDeviceInfoXML 获取设备详情指令
|
||||
func BuildDeviceInfoXML(sn int,id string) string {
|
||||
return fmt.Sprintf(DeviceInfoXML,sn, id)
|
||||
}
|
||||
|
||||
// BuildCatalogXML 获取NVR下设备列表指令
|
||||
func BuildCatalogXML(sn int, id string) string {
|
||||
return fmt.Sprintf(CatalogXML,sn, id)
|
||||
}
|
||||
|
||||
// BuildRecordInfoXML 获取录像文件列表指令
|
||||
func BuildRecordInfoXML(sn int,id string, start, end int64) string {
|
||||
return fmt.Sprintf(RecordInfoXML, sn,id, time.Unix(start, 0).Format("2006-01-02T15:04:05"), time.Unix(end, 0).Format("2006-01-02T15:04:05"))
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
package sip
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Response Response
|
||||
type Response struct {
|
||||
*Message
|
||||
}
|
||||
// AlarmResponseXML alarm response xml样式
|
||||
var (AlarmResponseXML = `<?xml version="1.0"?>
|
||||
<Response>
|
||||
<CmdType>Alarm</CmdType>
|
||||
<SN>17430</SN>
|
||||
<DeviceID>%s</DeviceID>
|
||||
</Response>
|
||||
`
|
||||
)
|
||||
|
||||
// BuildRecordInfoXML 获取录像文件列表指令
|
||||
func BuildAlarmResponseXML(id string) string {
|
||||
return fmt.Sprintf(AlarmResponseXML, id)
|
||||
}
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
#### 事务
|
||||
transaction事务是SIP的基本组成部分。
|
||||
一个事务是客户发送的一个请求事务(通过通讯层)发送到一个服务器事务,连同服务器事务的所有的该请求的应答发送回客户端事务。
|
||||
事务层处理应用服务层的重发,匹配请求的应答,以及应用服务层的超时。
|
||||
任何一个用户代理客户端(user agent client UAC)完成的事情都是由一组事务构成的。
|
||||
用户代理包含一个事务层,来实现有状态的代理服务器。
|
||||
事务层包含一个客户元素(可以认为是一个客户事务)和一个服务器元素(可以认为是一个服务器事务),他们都可以用一个有限状态机来处理特定的请求。
|
||||
|
||||
在状态机层面,事务分为ict、ist、nict、nist四种。
|
||||
但底层事务方面,仅根据 method 等信息,分支处理。
|
||||
|
||||
#### 关于事务管理
|
||||
|
||||
事务在map里面管理,事务ID的选择是要和事务匹配相关。
|
||||
|
||||
```
|
||||
客户端事件的匹配
|
||||
|
||||
当客户端中的传输层收到响应时,它必须确定哪个客户端事务将处理该响应,以便可以进行17.1.1和17.1.2节的处理。头域 Via 字段中的branch参数用于匹配规则。 一个匹配的响应应该满足下面两个条件:
|
||||
1.如果响应的头域 Via头字段中的branch参数值与创建事务的请求的头域 Via头字段中的branch参数值相同。
|
||||
2.如果CSeq标头字段中的method参数与创建事务的请求的方法匹配。(由于CANCEL请求会创建新的事务,但共享相同的branch参数值。所以仅用branch参数是不够的)
|
||||
|
||||
|
||||
服务端事务匹配
|
||||
|
||||
首先要检查请求中的Via头域的branch参数。如果他以”z9hG4bk”开头,那么这个请求一定是由客户端事务根据本规范产生的。因此,branch参数在该客户端发出的所有的事务中都是唯一的。根据下列规则我们可以判定请求是否和事务匹配:
|
||||
|
||||
1、 请求的Via头域的branch参数和创建本事务的请求的Via头域的branch参数一样,并且:
|
||||
2、 请求的Via头域的send-by参数和创建本事务的请求的Via头域的send-by参数一样(可能存在来自不同客户端的branch参数的意外或恶意重复,所以将 send-by 值用作匹配的一部分),并且:
|
||||
3、 请求的方法与创建事务的方法匹配,但ACK除外,在ACK中,创建事务的请求的方法为INVITE。
|
||||
```
|
||||
|
||||
所以,根据匹配规则,事务的ID 使用 branch,然后在匹配逻辑里面,再做条件判断。而因为branch可能会重复,所以如果使用map来简化transaction的管理,key的取值应该:
|
||||
|type| key|
|
||||
|----|----|
|
||||
|客户端事务:| branch+method|
|
||||
|服务端事务:| branch + sendby + method,method中ack还要除外。所以只能用branch + sendby|
|
||||
@@ -1,64 +0,0 @@
|
||||
package transaction
|
||||
|
||||
//SIP服务器静态配置信息
|
||||
|
||||
/*
|
||||
# sip监听udp端口
|
||||
listen 5060;
|
||||
|
||||
# SIP server ID(SIP服务器ID).
|
||||
# 设备端配置编号需要与该值一致,否则无法注册
|
||||
serial 34020000002000000001;
|
||||
|
||||
# SIP server domain(SIP服务器域)
|
||||
realm 3402000000;
|
||||
|
||||
# 服务端发送ack后,接收回应的超时时间,单位为秒
|
||||
# 如果指定时间没有回应,认为失败
|
||||
ack_timeout 30;
|
||||
|
||||
# 设备心跳维持时间,如果指定时间内(秒)没有接收一个心跳
|
||||
# 认为设备离线
|
||||
keepalive_timeout 120;
|
||||
|
||||
# 注册之后是否自动给设备端发送invite
|
||||
# on: 是 off 不是,需要通过api控制
|
||||
auto_play on;
|
||||
# 设备将流发送的端口,是否固定
|
||||
# on 发送流到多路复用端口 如9000
|
||||
# off 自动从rtp_mix_port - rtp_max_port 之间的值中
|
||||
# 选一个可以用的端口
|
||||
invite_port_fixed on;
|
||||
|
||||
# 向设备或下级域查询设备列表的间隔,单位(秒)
|
||||
# 默认60秒
|
||||
query_catalog_interval 60;
|
||||
*/
|
||||
|
||||
type Config struct {
|
||||
//sip服务器的配置
|
||||
SipNetwork string //传输协议,默认UDP,可选TCP
|
||||
SipIP string //sip 服务器公网IP
|
||||
SipPort uint16 //sip 服务器端口,默认 5060
|
||||
Serial string //sip 服务器 id, 默认 34020000002000000001
|
||||
Realm string //sip 服务器域,默认 3402000000
|
||||
Username string //sip 服务器账号
|
||||
Password string //sip 服务器密码
|
||||
|
||||
AckTimeout uint16 //sip 服务应答超时,单位秒
|
||||
RegisterValidity int //注册有效期,单位秒,默认 3600
|
||||
RegisterInterval int //注册间隔,单位秒,默认 60
|
||||
HeartbeatInterval int //心跳间隔,单位秒,默认 60
|
||||
HeartbeatRetry int //心跳超时次数,默认 3
|
||||
|
||||
//媒体服务器配置
|
||||
MediaIP string //媒体服务器地址
|
||||
MediaPort uint16 //媒体服务器端口
|
||||
MediaPortMin uint16
|
||||
MediaPortMax uint16
|
||||
MediaIdleTimeout uint16 //推流超时时间,超过则断开链接,让设备重连
|
||||
AudioEnable bool //是否开启音频
|
||||
WaitKeyFrame bool //是否等待关键帧,如果等待,则在收到第一个关键帧之前,忽略所有媒体流
|
||||
RemoveBanInterval int //移除禁止设备间隔
|
||||
UdpCacheSize int //udp缓存大小
|
||||
}
|
||||
@@ -1,203 +0,0 @@
|
||||
package transaction
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
. "github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transport"
|
||||
. "github.com/Monibuca/utils/v3"
|
||||
"net"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
)
|
||||
|
||||
type RequestHandler func(req *Request, tx *GBTx)
|
||||
|
||||
//Core: transactions manager
|
||||
//管理所有 transactions,以及相关全局参数、运行状态机
|
||||
type Core struct {
|
||||
ctx context.Context //上下文
|
||||
hmu *sync.RWMutex
|
||||
requestHandlers map[Method]RequestHandler
|
||||
txs *GBTxs
|
||||
tp transport.ITransport //transport
|
||||
*Config //sip server配置信息
|
||||
OnRegister func(msg *Request, tx *GBTx)
|
||||
OnMessage func(msg *Request, tx *GBTx)
|
||||
udpaddr net.Addr
|
||||
}
|
||||
|
||||
//初始化一个 Core,需要能响应请求,也要能发起请求
|
||||
//client 发起请求
|
||||
//server 响应请求
|
||||
//TODO:根据角色,增加相关配置信息
|
||||
//TODO:通过context管理子线程
|
||||
//TODO:单元测试
|
||||
func NewCore(config *Config) *Core {
|
||||
ActiveTX = &GBTxs{
|
||||
Txs: map[string]*GBTx{},
|
||||
RWM: &sync.RWMutex{},
|
||||
}
|
||||
|
||||
core := &Core{
|
||||
requestHandlers: map[Method]RequestHandler{},
|
||||
txs: ActiveTX,
|
||||
Config: config,
|
||||
ctx: context.Background(),
|
||||
hmu: &sync.RWMutex{},
|
||||
}
|
||||
|
||||
if config.SipNetwork == "TCP" {
|
||||
core.tp = transport.NewTCPServer(config.SipPort, true)
|
||||
} else {
|
||||
core.tp = transport.NewUDPServer(config.SipPort)
|
||||
}
|
||||
|
||||
return core
|
||||
}
|
||||
|
||||
func (c *Core) StartAndWait() {
|
||||
go c.handlerListen()
|
||||
|
||||
_ = c.tp.StartAndWait()
|
||||
}
|
||||
|
||||
func (c *Core) handlerListen() {
|
||||
//阻塞读取消息
|
||||
for p := range c.tp.ReadPacketChan() {
|
||||
if len(p.Data) < 5 {
|
||||
continue
|
||||
}
|
||||
if err := c.HandleReceiveMessage(p); err != nil {
|
||||
fmt.Println("handler sip response message failed:", err.Error())
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//接收到的消息处理
|
||||
//收到消息有两种:1、请求消息 2、响应消息
|
||||
//请求消息则直接响应处理。
|
||||
//响应消息则需要匹配到请求,让请求的transaction来处理。
|
||||
//TODO:参考srs和osip的流程,以及文档,做最终处理。需要将逻辑分成两层:TU 层和 transaction 层
|
||||
func (c *Core) HandleReceiveMessage(p *transport.Packet) (err error) {
|
||||
// fmt.Println("packet content:", string(p.Data))
|
||||
//var msg *Message
|
||||
msg, err := Decode(p.Data)
|
||||
if err != nil {
|
||||
fmt.Println("parse sip message failed:", err.Error())
|
||||
return ErrorParse
|
||||
}
|
||||
if msg.Via == nil || msg.From == nil {
|
||||
return ErrorParse
|
||||
}
|
||||
//这里不处理超过MTU的包,不处理半包
|
||||
err = checkMessage(msg)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if msg.IsRequest() {
|
||||
req := &Request{Message: msg}
|
||||
req.SourceAdd = p.Addr
|
||||
req.DestAdd = c.udpaddr
|
||||
c.handlerRequest(req)
|
||||
} else {
|
||||
//TODO:对于uac,收到response消息,是否要检查 rport 和 received 呢?因为uas可能对此做了修改
|
||||
resp := &Response{Message: msg}
|
||||
resp.SourceAdd = p.Addr
|
||||
resp.DestAdd = c.udpaddr
|
||||
c.handlerResponse(resp)
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (c *Core) NewTX(key string) *GBTx {
|
||||
tx := c.txs.NewTX(key, *c.tp.Conn())
|
||||
tx.Core = c
|
||||
return tx
|
||||
}
|
||||
func (c *Core) GetTX(key string) *GBTx {
|
||||
return c.txs.GetTX(key)
|
||||
}
|
||||
func (c *Core) MustTX(key string) *GBTx {
|
||||
tx := c.txs.GetTX(key)
|
||||
if tx == nil {
|
||||
tx = c.NewTX(key)
|
||||
}
|
||||
return tx
|
||||
}
|
||||
|
||||
func (c *Core) handlerRequest(msg *Request) {
|
||||
tx := c.MustTX(GetTXKey(msg.Message))
|
||||
|
||||
//Println("receive request from:", msg.Source(), ",method:", msg.GetMethod(), "txKey:", tx.Key(), "message: \n", string(encode))
|
||||
c.hmu.RLock()
|
||||
handler, ok := c.requestHandlers[msg.GetMethod()]
|
||||
c.hmu.RUnlock()
|
||||
if !ok {
|
||||
encode, _ := Encode(msg.Message)
|
||||
Println("not found handler func,requestMethod:", msg.GetMethod(), msg.Event, encode)
|
||||
go handlerMethodNotAllowed(msg, tx)
|
||||
return
|
||||
}
|
||||
|
||||
go handler(msg, tx)
|
||||
}
|
||||
|
||||
func (c *Core) handlerResponse(msg *Response) {
|
||||
tx := c.GetTX(GetTXKey(msg.Message))
|
||||
|
||||
if tx == nil {
|
||||
str, _ := Encode(msg.Message)
|
||||
Println("not found tx. receive response from:", msg.Source(), "message: \n", string(str))
|
||||
} else {
|
||||
tx.ReceiveResponse(msg)
|
||||
}
|
||||
}
|
||||
func handlerMethodNotAllowed(req *Request, tx *GBTx) {
|
||||
var resp Response
|
||||
resp.Message = req.BuildResponse(http.StatusMethodNotAllowed)
|
||||
resp.DestAdd = req.SourceAdd
|
||||
resp.SourceAdd = req.DestAdd
|
||||
_ = tx.Respond(&resp)
|
||||
}
|
||||
func (c *Core) SipRequestForResponse(req *Request) (response *Response, err error) {
|
||||
var tx *GBTx
|
||||
tx, err = c.Request(req)
|
||||
if err == nil {
|
||||
return tx.SipResponse()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Request Request
|
||||
func (c *Core) Request(req *Request) (*GBTx, error) {
|
||||
if req.Via == nil {
|
||||
var viaHop Via
|
||||
viaHop.Host = c.SipIP
|
||||
viaHop.Port = strconv.Itoa(int(c.SipPort))
|
||||
viaHop.Params = make(map[string]string)
|
||||
viaHop.Params["branch"] = RandBranch()
|
||||
viaHop.Params["rport"] = ""
|
||||
req.Via = &viaHop
|
||||
}
|
||||
tx := c.MustTX(GetTXKey(req.Message))
|
||||
return tx, tx.Request(req)
|
||||
}
|
||||
|
||||
// Request Request
|
||||
func (c *Core) Respond(resp *Response) (*GBTx, error) {
|
||||
|
||||
tx := c.MustTX(GetTXKey(resp.Message))
|
||||
return tx, tx.Respond(resp)
|
||||
}
|
||||
|
||||
// RegistHandler RegistHandler
|
||||
func (c *Core) RegistHandler(method Method, handler RequestHandler) {
|
||||
c.hmu.Lock()
|
||||
c.requestHandlers[method] = handler
|
||||
c.hmu.Unlock()
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
package transaction
|
||||
|
||||
import (
|
||||
"errors"
|
||||
)
|
||||
|
||||
//transaction 的错误定义
|
||||
var (
|
||||
ErrorSyntax = errors.New("message syntax error")
|
||||
ErrorCheck = errors.New("message check failed")
|
||||
ErrorParse = errors.New("message parse failed")
|
||||
ErrorUnknown = errors.New("message unknown")
|
||||
)
|
||||
@@ -1,27 +0,0 @@
|
||||
package transaction
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTimeout(t *testing.T) {
|
||||
// Pass a context with a timeout to tell a blocking function that it
|
||||
// should abandon its work after the timeout elapses.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond)
|
||||
defer cancel()
|
||||
go func() {
|
||||
select {
|
||||
case <-time.After(1 * time.Second):
|
||||
fmt.Println("overslept")
|
||||
case <-ctx.Done():
|
||||
fmt.Println(ctx.Err()) // prints "context deadline exceeded"
|
||||
default:
|
||||
time.Sleep(1000 * time.Millisecond)
|
||||
fmt.Println("fuck gc.")
|
||||
}
|
||||
}()
|
||||
|
||||
}
|
||||
@@ -1,157 +0,0 @@
|
||||
package transaction
|
||||
|
||||
import (
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
. "github.com/Monibuca/plugin-gb28181/v3/transport"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
var ActiveTX *GBTxs
|
||||
|
||||
// GBTxs a GBTxs stands for a Gb28181 Transaction collection
|
||||
type GBTxs struct {
|
||||
Txs map[string]*GBTx
|
||||
RWM *sync.RWMutex
|
||||
}
|
||||
|
||||
func (txs *GBTxs) NewTX(key string, conn Connection) *GBTx {
|
||||
tx := NewTransaction(key, conn)
|
||||
txs.RWM.Lock()
|
||||
txs.Txs[key] = tx
|
||||
txs.RWM.Unlock()
|
||||
return tx
|
||||
}
|
||||
|
||||
func (txs *GBTxs) GetTX(key string) *GBTx {
|
||||
txs.RWM.RLock()
|
||||
tx, ok := txs.Txs[key]
|
||||
if !ok {
|
||||
tx = nil
|
||||
}
|
||||
txs.RWM.RUnlock()
|
||||
return tx
|
||||
}
|
||||
|
||||
func (txs *GBTxs) rmTX(tx *GBTx) {
|
||||
txs.RWM.Lock()
|
||||
delete(txs.Txs, tx.key)
|
||||
txs.RWM.Unlock()
|
||||
}
|
||||
|
||||
// GBTx Gb28181 Transaction
|
||||
type GBTx struct {
|
||||
conn Connection
|
||||
key string
|
||||
resp chan *sip.Response
|
||||
active chan int
|
||||
*Core
|
||||
}
|
||||
|
||||
// NewTransaction create a new GBtx
|
||||
func NewTransaction(key string, conn Connection) *GBTx {
|
||||
tx := &GBTx{conn: conn, key: key, resp: make(chan *sip.Response, 10), active: make(chan int, 1)}
|
||||
go tx.watch()
|
||||
return tx
|
||||
}
|
||||
|
||||
// Key returns the GBTx Key
|
||||
func (tx *GBTx) Key() string {
|
||||
return tx.key
|
||||
}
|
||||
|
||||
func (tx *GBTx) watch() {
|
||||
for {
|
||||
select {
|
||||
case <-tx.active:
|
||||
//Println("active tx", tx.Key(), time.Now().Format("2006-01-02 15:04:05"))
|
||||
case <-time.After(20 * time.Second):
|
||||
tx.Close()
|
||||
//Println("watch closed tx", tx.key, time.Now().Format("2006-01-02 15:04:05"))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// GetResponse GetResponse
|
||||
func (tx *GBTx) GetResponse() *sip.Response {
|
||||
for {
|
||||
res := <-tx.resp
|
||||
if res == nil {
|
||||
return res
|
||||
}
|
||||
tx.active <- 2
|
||||
//Println("response tx", tx.key, time.Now().Format("2006-01-02 15:04:05"))
|
||||
if res.GetStatusCode() == http.StatusContinue || res.GetStatusCode() == http.StatusSwitchingProtocols {
|
||||
// Trying and Dialog Establishement 等待下一个返回
|
||||
continue
|
||||
}
|
||||
return res
|
||||
}
|
||||
}
|
||||
|
||||
// Close the Close function closes the GBTx
|
||||
func (tx *GBTx) Close() {
|
||||
//Printf("closed tx: %s %s TXs: %d", tx.key, time.Now().Format("2006-01-02 15:04:05"), len(ActiveTX.Txs))
|
||||
ActiveTX.rmTX(tx)
|
||||
close(tx.resp)
|
||||
close(tx.active)
|
||||
}
|
||||
|
||||
// ReceiveResponse receive a Response
|
||||
func (tx *GBTx) ReceiveResponse(msg *sip.Response) {
|
||||
defer func() {
|
||||
if r := recover(); r != nil {
|
||||
//Println("send to closed channel, txkey:", tx.key, "message: \n", msg)
|
||||
}
|
||||
}()
|
||||
//Println("receiveResponse tx", tx.Key(), time.Now().Format("2006-01-02 15:04:05"))
|
||||
tx.resp <- msg
|
||||
tx.active <- 1
|
||||
}
|
||||
|
||||
// Respond Respond
|
||||
func (tx *GBTx) Respond(res *sip.Response) error {
|
||||
str, _ := sip.Encode(res.Message)
|
||||
//Println("send response,to:", (res.DestAdd).String(), "txkey:", tx.key, "message: \n", string(str))
|
||||
_, err := tx.conn.WriteTo(str, res.DestAdd)
|
||||
return err
|
||||
}
|
||||
|
||||
// Request Request
|
||||
func (tx *GBTx) Request(req *sip.Request) error {
|
||||
str, _ := sip.Encode(req.Message)
|
||||
//Println("send Request,to:", (req.DestAdd).String(), "txkey:", tx.key, "message: \n", string(str))
|
||||
_, err := tx.conn.WriteTo(str, req.DestAdd)
|
||||
return err
|
||||
}
|
||||
|
||||
func GetTXKey(msg *sip.Message) (key string) {
|
||||
if len(msg.CallID) > 0 {
|
||||
key = msg.CallID
|
||||
} else {
|
||||
key = utils.RandString(10)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (tx *GBTx) SipResponse() (*sip.Response, error) {
|
||||
response := tx.GetResponse()
|
||||
if response == nil {
|
||||
return nil, utils.NewError(nil, "response timeout", "tx key:", tx.Key())
|
||||
}
|
||||
if response.GetStatusCode() != http.StatusOK {
|
||||
return response, utils.NewError(nil, "response fail", response.GetStatusCode(), response.GetReason(), "tx key:", tx.Key())
|
||||
}
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (tx *GBTx) SipRequestForResponse(req *sip.Request) (response *sip.Response, err error) {
|
||||
err = tx.Request(req)
|
||||
if err == nil {
|
||||
return tx.SipResponse()
|
||||
}
|
||||
return
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
package transaction
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"net"
|
||||
"strings"
|
||||
)
|
||||
|
||||
//=====================================================sip message utils
|
||||
//The branch ID parameter in the Via header field values serves as a transaction identifier,
|
||||
//and is used by proxies to detect loops.
|
||||
//The branch parameter in the topmost Via header field of the request
|
||||
// is examined. If it is present and begins with the magic cookie
|
||||
// "z9hG4bK", the request was generated by a client transaction
|
||||
// compliant to this specification.
|
||||
//参考RFC3261
|
||||
func getMessageTransactionID(m *sip.Message) string {
|
||||
if m.GetMethod() == sip.ACK {
|
||||
//TODO:在匹配服务端事务的ACK中,创建事务的请求的方法为INVITE。所以ACK消息匹配事务的时候需要注意????
|
||||
}
|
||||
return string(m.GetMethod()) + "_" + m.GetBranch()
|
||||
}
|
||||
|
||||
func checkMessage(msg *sip.Message) error {
|
||||
//TODO:sip消息解析成功之后,检查必要元素,如果失败,则返回 ErrorCheckMessage
|
||||
|
||||
//检查头域字段:callID via startline 等
|
||||
//检查seq、method等
|
||||
//不可以有router?
|
||||
//是否根据消息是接收还是发送检查?
|
||||
if msg == nil {
|
||||
return ErrorCheck
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
//fix via header,add send-by info,
|
||||
func fixReceiveMessageViaParams(msg *sip.Message, addr net.Addr) {
|
||||
rport := msg.Via.Params["rport"]
|
||||
if rport == "" || rport == "0" || rport == "-1" {
|
||||
arr := strings.Split(addr.String(), ":")
|
||||
if len(arr) == 2 {
|
||||
msg.Via.Params["rport"] = arr[1]
|
||||
if msg.Via.Host != arr[0] {
|
||||
msg.Via.Params["received"] = arr[0]
|
||||
}
|
||||
} else {
|
||||
//TODO:数据报的地址错误??
|
||||
fmt.Println("packet handle > invalid addr :", addr.String())
|
||||
}
|
||||
} else {
|
||||
fmt.Println("sip message has have send-by info:", msg.Via.GetSendBy())
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
|
||||
#### 介绍
|
||||
|
||||
transport 包括客户端和服务器端,仅实现tcp和udp的传输层,不负责具体消息的解析和处理。不负责粘包、半包、消息解析、心跳处理、状态管理等工作。
|
||||
|
||||
比如设备关闭或者离线,要修改缓存状态、数据库状态、发送离线通知、执行离线回调等等,都在上层处理。tcp server 和 udp server、tcp client 和 udp client , 消息的接收和发送都在外面处理。
|
||||
|
||||
tcp是流传输,需要注意粘包和半包的处理。在上层处理tcp包的时候,可以尝试使用 ring buffer
|
||||
|
||||
|
||||
#### usage
|
||||
|
||||
参考 example.go
|
||||
|
||||
#### TODO
|
||||
|
||||
- sip协议的传输层,TCP和UDP有所不同,比如重传以及超时的错误信息等。所以需要在 transaction上面,处理消息重传、错误上报等。具体参考RFC3261。
|
||||
|
||||
@@ -1,115 +0,0 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
. "github.com/Monibuca/utils/v3"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Connection Wrapper around net.Conn.
|
||||
type Connection interface {
|
||||
net.Conn
|
||||
Network() string
|
||||
// String() string
|
||||
ReadFrom(buf []byte) (num int, raddr net.Addr, err error)
|
||||
WriteTo(buf []byte, raddr net.Addr) (num int, err error)
|
||||
}
|
||||
|
||||
// Connection implementation.
|
||||
type connection struct {
|
||||
baseConn net.Conn
|
||||
laddr net.Addr
|
||||
raddr net.Addr
|
||||
mu sync.RWMutex
|
||||
logKey string
|
||||
Online bool
|
||||
ReconnectCount int64 //重连次数
|
||||
}
|
||||
|
||||
func newUDPConnection(baseConn net.Conn) Connection {
|
||||
conn := &connection{
|
||||
baseConn: baseConn,
|
||||
laddr: baseConn.LocalAddr(),
|
||||
raddr: baseConn.RemoteAddr(),
|
||||
logKey: "udpConnection",
|
||||
}
|
||||
return conn
|
||||
}
|
||||
func newTCPConnection(baseConn net.Conn) Connection {
|
||||
conn := &connection{
|
||||
baseConn: baseConn,
|
||||
laddr: baseConn.LocalAddr(),
|
||||
raddr: baseConn.RemoteAddr(),
|
||||
logKey: "udpConnection",
|
||||
}
|
||||
return conn
|
||||
}
|
||||
|
||||
func (conn *connection) Read(buf []byte) (int, error) {
|
||||
var (
|
||||
num int
|
||||
err error
|
||||
)
|
||||
|
||||
num, err = conn.baseConn.Read(buf)
|
||||
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (conn *connection) ReadFrom(buf []byte) (num int, raddr net.Addr, err error) {
|
||||
num, raddr, err = conn.baseConn.(net.PacketConn).ReadFrom(buf)
|
||||
if err != nil {
|
||||
return num, raddr, err
|
||||
}
|
||||
Printf("readFrom %d , %s -> %s \n %s", num, raddr, conn.LocalAddr(), string(buf[:num]))
|
||||
return num, raddr, err
|
||||
}
|
||||
|
||||
func (conn *connection) Write(buf []byte) (int, error) {
|
||||
var (
|
||||
num int
|
||||
err error
|
||||
)
|
||||
num, err = conn.baseConn.Write(buf)
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (conn *connection) WriteTo(buf []byte, raddr net.Addr) (num int, err error) {
|
||||
num, err = conn.baseConn.(net.PacketConn).WriteTo(buf, raddr)
|
||||
if err != nil {
|
||||
return num, err
|
||||
}
|
||||
//Printf("writeTo %d , %s -> %s \n %s", num, conn.baseConn.LocalAddr(), raddr.String(), string(buf[:num]))
|
||||
return num, err
|
||||
}
|
||||
|
||||
func (conn *connection) LocalAddr() net.Addr {
|
||||
return conn.baseConn.LocalAddr()
|
||||
}
|
||||
|
||||
func (conn *connection) RemoteAddr() net.Addr {
|
||||
return conn.baseConn.RemoteAddr()
|
||||
}
|
||||
|
||||
func (conn *connection) Close() error {
|
||||
err := conn.baseConn.Close()
|
||||
return err
|
||||
}
|
||||
|
||||
func (conn *connection) Network() string {
|
||||
return strings.ToUpper(conn.baseConn.LocalAddr().Network())
|
||||
}
|
||||
|
||||
func (conn *connection) SetDeadline(t time.Time) error {
|
||||
return conn.baseConn.SetDeadline(t)
|
||||
}
|
||||
|
||||
func (conn *connection) SetReadDeadline(t time.Time) error {
|
||||
return conn.baseConn.SetReadDeadline(t)
|
||||
}
|
||||
|
||||
func (conn *connection) SetWriteDeadline(t time.Time) error {
|
||||
return conn.baseConn.SetWriteDeadline(t)
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
//默认端口:TCP/UDP是5060,5061是在TCP上的TLS
|
||||
//对于服务器监听UDP的任何端口和界面,都必须在TCP上也进行同样的监听。这是因为可能消息还需要通过TCP进行传输,比如消息过大的情况。
|
||||
const SipHost string = "127.0.0.1"
|
||||
const SipPort uint16 = 5060
|
||||
|
||||
func RunServerTCP() {
|
||||
tcp := NewTCPServer(SipPort, true)
|
||||
go PacketHandler(tcp)
|
||||
go func() {
|
||||
_ = tcp.StartAndWait()
|
||||
}()
|
||||
|
||||
select {}
|
||||
}
|
||||
|
||||
//测试通讯,客户端先发一条消息
|
||||
func RunClientTCP() {
|
||||
c := NewTCPClient(SipHost, SipPort)
|
||||
go PacketHandler(c)
|
||||
go func() {
|
||||
_ = c.StartAndWait()
|
||||
}()
|
||||
|
||||
//发送测试数据
|
||||
fmt.Println("send test data")
|
||||
go func() {
|
||||
for {
|
||||
c.WritePacket(&Packet{Data: []byte("from client : " + time.Now().String())})
|
||||
time.Sleep(2 * time.Second)
|
||||
}
|
||||
}()
|
||||
select {}
|
||||
}
|
||||
func PacketHandler(s ITransport) {
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Println("packet handler panic: ", err)
|
||||
utils.PrintStack()
|
||||
os.Exit(1)
|
||||
}
|
||||
}()
|
||||
|
||||
fmt.Println("PacketHandler ========== ", s.Name())
|
||||
|
||||
ch := s.ReadPacketChan()
|
||||
//阻塞读取消息
|
||||
for {
|
||||
select {
|
||||
case p := <-ch:
|
||||
fmt.Println("packet content:", string(p.Data))
|
||||
//TODO:message parse
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//======================================================================
|
||||
|
||||
func RunServerUDP() {
|
||||
udp := NewUDPServer(SipPort)
|
||||
|
||||
go PacketHandler(udp)
|
||||
go func() {
|
||||
_ = udp.StartAndWait()
|
||||
}()
|
||||
|
||||
select {}
|
||||
}
|
||||
|
||||
func RunClientUDP() {
|
||||
c := NewUDPClient(SipHost, SipPort)
|
||||
go PacketHandler(c)
|
||||
go func() {
|
||||
_ = c.StartAndWait()
|
||||
}()
|
||||
//发送测试数据
|
||||
go func() {
|
||||
for {
|
||||
time.Sleep(1 * time.Second)
|
||||
c.WritePacket(&Packet{
|
||||
Data: []byte("hello " + time.Now().String())})
|
||||
}
|
||||
}()
|
||||
|
||||
select {}
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
)
|
||||
|
||||
type TCPClient struct {
|
||||
Statistic
|
||||
host string
|
||||
port uint16
|
||||
conn Connection
|
||||
readChan chan *Packet
|
||||
writeChan chan *Packet
|
||||
remoteAddr net.Addr
|
||||
localAddr net.Addr
|
||||
done chan struct{}
|
||||
}
|
||||
|
||||
func NewTCPClient(host string, port uint16) IClient {
|
||||
return &TCPClient{
|
||||
host: host,
|
||||
port: port,
|
||||
readChan: make(chan *Packet, 10),
|
||||
writeChan: make(chan *Packet, 10),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *TCPClient) IsReliable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *TCPClient) Name() string {
|
||||
return fmt.Sprintf("tcp client to:%s", fmt.Sprintf("%s:%d", c.host, c.port))
|
||||
}
|
||||
|
||||
func (c *TCPClient) LocalAddr() net.Addr {
|
||||
return c.localAddr
|
||||
}
|
||||
|
||||
func (c *TCPClient) RemoteAddr() net.Addr {
|
||||
return c.remoteAddr
|
||||
}
|
||||
|
||||
func (c *TCPClient) StartAndWait() error {
|
||||
conn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", c.host, c.port))
|
||||
if err != nil {
|
||||
fmt.Println("dial tcp server failed :", err.Error())
|
||||
return err
|
||||
} else {
|
||||
fmt.Println("start tcp client")
|
||||
}
|
||||
|
||||
c.conn = newTCPConnection(conn)
|
||||
c.remoteAddr = conn.RemoteAddr()
|
||||
c.localAddr = conn.LocalAddr()
|
||||
|
||||
//开启写线程
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case p := <-c.writeChan:
|
||||
_, err := c.conn.Write(p.Data)
|
||||
if err != nil {
|
||||
fmt.Println("client write failed:", err.Error())
|
||||
_ = c.Close()
|
||||
return
|
||||
}
|
||||
case <-c.done:
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
fmt.Println("start tcp client")
|
||||
fmt.Printf("remote addr: %s, local addr: %s\n", conn.RemoteAddr().String(), conn.LocalAddr().String())
|
||||
|
||||
//读线程,阻塞
|
||||
for {
|
||||
buf := make([]byte, 2048)
|
||||
n, err := conn.Read(buf)
|
||||
if err != nil {
|
||||
fmt.Println("tcp client read error:", err.Error())
|
||||
return err
|
||||
}
|
||||
c.readChan <- &Packet{
|
||||
Addr: c.remoteAddr,
|
||||
Data: buf[:n],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *TCPClient) ReadPacketChan() <-chan *Packet {
|
||||
return c.readChan
|
||||
}
|
||||
|
||||
func (c *TCPClient) WritePacket(packet *Packet) {
|
||||
c.writeChan <- packet
|
||||
}
|
||||
|
||||
func (c *TCPClient) Close() error {
|
||||
close(c.done)
|
||||
return c.conn.Close()
|
||||
}
|
||||
|
||||
//外部定期调用此接口,实现心跳
|
||||
func (c *TCPClient) Heartbeat(p *Packet) {
|
||||
if p == nil {
|
||||
p = &Packet{
|
||||
Data: []byte("ping"),
|
||||
}
|
||||
}
|
||||
c.WritePacket(p)
|
||||
}
|
||||
|
||||
func (s *TCPClient) Conn() *Connection {
|
||||
return &s.conn
|
||||
}
|
||||
@@ -1,179 +0,0 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
type TCPServer struct {
|
||||
Statistic
|
||||
addr string
|
||||
listener net.Listener
|
||||
readChan chan *Packet
|
||||
writeChan chan *Packet
|
||||
done chan struct{}
|
||||
Keepalive bool
|
||||
sessions sync.Map //key 是 remote-addr , value:*Connection。
|
||||
}
|
||||
|
||||
func NewTCPServer(port uint16, keepalive bool) IServer {
|
||||
tcpAddr := fmt.Sprintf(":%d", port)
|
||||
|
||||
return &TCPServer{
|
||||
addr: tcpAddr,
|
||||
Keepalive: keepalive,
|
||||
readChan: make(chan *Packet, 10),
|
||||
writeChan: make(chan *Packet, 10),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TCPServer) IsReliable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *TCPServer) Name() string {
|
||||
return fmt.Sprintf("tcp server at:%s", s.addr)
|
||||
}
|
||||
func (s *TCPServer) IsKeepalive() bool {
|
||||
return s.Keepalive
|
||||
}
|
||||
|
||||
func (s *TCPServer) StartAndWait() error {
|
||||
//监听端口
|
||||
//开启tcp连接线程
|
||||
var err error
|
||||
s.listener, err = net.Listen("tcp", s.addr)
|
||||
//s.listener, err = tls.Listen("tcp", s.tcpAddr, tlsConfig)
|
||||
if err != nil {
|
||||
fmt.Println("TCP Listen failed:", err)
|
||||
return err
|
||||
}
|
||||
defer s.listener.Close()
|
||||
|
||||
fmt.Println("start tcp server at: ", s.addr)
|
||||
|
||||
//心跳线程
|
||||
if s.Keepalive {
|
||||
//TODO:start heartbeat thread
|
||||
}
|
||||
//写线程
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case p := <-s.writeChan:
|
||||
val, ok := s.sessions.Load(p.Addr.String())
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
c := *val.(*Connection)
|
||||
_, _ = c.Write(p.Data)
|
||||
case <-s.done:
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
}()
|
||||
|
||||
//读线程
|
||||
for {
|
||||
conn, err := s.listener.Accept()
|
||||
if err != nil {
|
||||
var tempDelay time.Duration // how long to sleep on accept failure
|
||||
fmt.Println("accept err :", err.Error())
|
||||
// 重连。参考http server
|
||||
if ne, ok := err.(net.Error); ok && ne.Temporary() {
|
||||
if tempDelay == 0 {
|
||||
tempDelay = 5 * time.Millisecond
|
||||
} else {
|
||||
tempDelay *= 2
|
||||
}
|
||||
|
||||
if max := 1 * time.Second; tempDelay > max {
|
||||
tempDelay = max
|
||||
}
|
||||
|
||||
time.Sleep(tempDelay)
|
||||
continue
|
||||
}
|
||||
fmt.Println("accept error, retry failed & exit.")
|
||||
return err
|
||||
}
|
||||
|
||||
// conn.SetReadDeadline(time.Now().Add(600 * time.Second))
|
||||
session := newTCPConnection(conn)
|
||||
address := session.RemoteAddr().String()
|
||||
s.sessions.Store(address, session)
|
||||
|
||||
fmt.Println(fmt.Sprintf("new tcp client remoteAddr: %v", address))
|
||||
go s.handlerSession(&session)
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TCPServer) handlerSession(c *Connection) {
|
||||
conn := *c
|
||||
addrStr := conn.RemoteAddr().String()
|
||||
|
||||
//recovery from panic
|
||||
defer func() {
|
||||
s.CloseOne(addrStr)
|
||||
if err := recover(); err != nil {
|
||||
fmt.Println("client receiver handler panic: ", err)
|
||||
}
|
||||
}()
|
||||
|
||||
buf := make([]byte, 2048)
|
||||
for {
|
||||
n, err := conn.Read(buf)
|
||||
switch {
|
||||
case err == nil:
|
||||
p := &Packet{
|
||||
Addr: conn.RemoteAddr(),
|
||||
Data: buf[:n],
|
||||
}
|
||||
s.readChan <- p
|
||||
case err == io.EOF:
|
||||
fmt.Println(fmt.Sprintf("io.EOF,client close --- remoteAddr: %v", conn.RemoteAddr()))
|
||||
return
|
||||
case err != nil:
|
||||
fmt.Println("client other err: ", err)
|
||||
fmt.Println(fmt.Sprintf("client other err --- remoteAddr: %v", addrStr))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *TCPServer) CloseOne(addr string) {
|
||||
val, ok := s.sessions.Load(addr)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
c := *val.(*Connection)
|
||||
_ = c.Close()
|
||||
s.sessions.Delete(addr)
|
||||
}
|
||||
|
||||
func (s *TCPServer) ReadPacketChan() <-chan *Packet {
|
||||
return s.readChan
|
||||
}
|
||||
func (s *TCPServer) WritePacket(packet *Packet) {
|
||||
s.writeChan <- packet
|
||||
}
|
||||
|
||||
func (s *TCPServer) Close() error {
|
||||
//TODO:TCP服务退出之前,需要先close掉所有客户端的连接
|
||||
s.sessions.Range(func(key, value interface{}) bool {
|
||||
c := *value.(*Connection)
|
||||
_ = c.Close()
|
||||
s.sessions.Delete(key)
|
||||
return true
|
||||
})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *TCPServer) Conn() *Connection {
|
||||
return nil
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"net"
|
||||
"time"
|
||||
)
|
||||
|
||||
/*
|
||||
transport层仅实现数据的读写,连接的关闭
|
||||
|
||||
TCP和UDP的区别
|
||||
|
||||
- TCP面向链接,在服务关闭的时候,要先close掉所有客户端连接。所以使用一个map简单做session管理,key 是 remote address。
|
||||
- udp不需要管理session。
|
||||
*/
|
||||
|
||||
//transport server and client interface
|
||||
//对于面向连接的服务,需要有两个关闭接口:Close and CloseOne
|
||||
//非面向连接的服务,不必实现
|
||||
//TODO:心跳管理,使用timewheel
|
||||
|
||||
type ITransport interface {
|
||||
Name() string
|
||||
ReadPacketChan() <-chan *Packet //读消息,消息处理器需在循环中阻塞读取
|
||||
WritePacket(packet *Packet) //写消息
|
||||
StartAndWait() error //开启连接,阻塞接收消息
|
||||
Close() error //关闭连接
|
||||
IsReliable() bool //是否可靠传输
|
||||
Conn() *Connection
|
||||
}
|
||||
|
||||
type IServer interface {
|
||||
ITransport
|
||||
CloseOne(addr string) //对于关闭某个客户端连接,比如没有鉴权的非法链接,心跳超时等
|
||||
IsKeepalive() bool //persistent connection or not
|
||||
}
|
||||
|
||||
//transport 需要实现的接口如下
|
||||
type IClient interface {
|
||||
ITransport
|
||||
LocalAddr() net.Addr //本地地址
|
||||
RemoteAddr() net.Addr //远程地址
|
||||
Heartbeat(packet *Packet) //客户端需要定期发送心跳包到服务器端
|
||||
}
|
||||
|
||||
type Packet struct {
|
||||
Type string //消息类型,预留字段,对于客户端主动关闭等消息的上报、心跳超时等。如果为空,则仅透传消息。
|
||||
Addr net.Addr
|
||||
Data []byte
|
||||
}
|
||||
|
||||
//通讯统计
|
||||
type Statistic struct {
|
||||
startTime time.Time
|
||||
stopTime time.Time
|
||||
recvCount int64
|
||||
sendCount int64
|
||||
errCount int64
|
||||
}
|
||||
@@ -1,123 +0,0 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
)
|
||||
|
||||
type UDPClient struct {
|
||||
Statistic
|
||||
host string
|
||||
port uint16
|
||||
conn Connection
|
||||
readChan chan *Packet
|
||||
writeChan chan *Packet
|
||||
done chan struct{}
|
||||
remoteAddr net.Addr
|
||||
localAddr net.Addr
|
||||
}
|
||||
|
||||
func NewUDPClient(host string, port uint16) IClient {
|
||||
return &UDPClient{
|
||||
host: host,
|
||||
port: port,
|
||||
readChan: make(chan *Packet, 10),
|
||||
writeChan: make(chan *Packet, 10),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (c *UDPClient) IsReliable() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *UDPClient) Name() string {
|
||||
return fmt.Sprintf("udp client to:%s", fmt.Sprintf("%s:%d", c.host, c.port))
|
||||
}
|
||||
func (c *UDPClient) LocalAddr() net.Addr {
|
||||
return c.localAddr
|
||||
}
|
||||
|
||||
func (c *UDPClient) RemoteAddr() net.Addr {
|
||||
return c.remoteAddr
|
||||
}
|
||||
|
||||
func (c *UDPClient) StartAndWait() error {
|
||||
addrStr := fmt.Sprintf("%s:%d", c.host, c.port)
|
||||
addr, err := net.ResolveUDPAddr("udp", addrStr)
|
||||
if err != nil {
|
||||
fmt.Println("Can't resolve address: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
conn, err := net.DialUDP("udp", nil, addr)
|
||||
if err != nil {
|
||||
fmt.Println("Can't dial: ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
c.remoteAddr = conn.RemoteAddr()
|
||||
c.localAddr = conn.LocalAddr()
|
||||
|
||||
fmt.Println("udp client remote addr:", conn.RemoteAddr().String())
|
||||
fmt.Println("udp client local addr:", conn.LocalAddr().String())
|
||||
|
||||
//写线程
|
||||
go func() {
|
||||
for {
|
||||
select {
|
||||
case p := <-c.writeChan:
|
||||
_, err = conn.Write(p.Data)
|
||||
if err != nil {
|
||||
fmt.Println("udp client write failed:", err.Error())
|
||||
continue
|
||||
}
|
||||
case <-c.done:
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
for {
|
||||
buf := make([]byte, 4096)
|
||||
n, err := conn.Read(buf)
|
||||
if err != nil {
|
||||
fmt.Println("failed to read UDP msg because of ", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
c.readChan <- &Packet{
|
||||
Addr: c.remoteAddr,
|
||||
Data: buf[:n],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *UDPClient) ReadPacketChan() <-chan *Packet {
|
||||
return c.readChan
|
||||
}
|
||||
|
||||
func (c *UDPClient) WritePacket(packet *Packet) {
|
||||
c.writeChan <- packet
|
||||
}
|
||||
|
||||
func (c *UDPClient) Close() error {
|
||||
close(c.done)
|
||||
return c.conn.Close()
|
||||
}
|
||||
|
||||
//外部定期调用此接口,实现心跳
|
||||
func (c *UDPClient) Heartbeat(p *Packet) {
|
||||
if p == nil {
|
||||
p = &Packet{
|
||||
Data: []byte("ping"),
|
||||
}
|
||||
}
|
||||
c.WritePacket(p)
|
||||
}
|
||||
|
||||
func (c *UDPClient) Conn() *Connection {
|
||||
return &c.conn
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
package transport
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"os"
|
||||
)
|
||||
|
||||
type UDPServer struct {
|
||||
Statistic
|
||||
addr string
|
||||
conn *Connection
|
||||
readChan chan *Packet
|
||||
writeChan chan *Packet
|
||||
done chan struct{}
|
||||
Keepalive bool
|
||||
//Sessions sync.Map // key is remote-addr的string , value:*Connection。UDP不需要
|
||||
}
|
||||
|
||||
func NewUDPServer(port uint16) IServer {
|
||||
addrStr := fmt.Sprintf(":%d", port)
|
||||
|
||||
return &UDPServer{
|
||||
addr: addrStr,
|
||||
readChan: make(chan *Packet, 1024),
|
||||
writeChan: make(chan *Packet, 1024),
|
||||
done: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *UDPServer) IsReliable() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (s *UDPServer) Name() string {
|
||||
return fmt.Sprintf("udp client to:%s", s.addr)
|
||||
}
|
||||
|
||||
func (s *UDPServer) IsKeepalive() bool {
|
||||
return s.Keepalive
|
||||
}
|
||||
|
||||
func (s *UDPServer) StartAndWait() error {
|
||||
addr, err := net.ResolveUDPAddr("udp", s.addr)
|
||||
if err != nil {
|
||||
fmt.Println("Can't resolve address: ", err)
|
||||
return err
|
||||
}
|
||||
|
||||
conn, err := net.ListenUDP("udp", addr)
|
||||
if err != nil {
|
||||
fmt.Println("Error listenUDP :", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
defer func() {
|
||||
_ = conn.Close()
|
||||
}()
|
||||
udpConnection := newUDPConnection(conn)
|
||||
s.conn = &udpConnection
|
||||
fmt.Println("start udp server at: ", s.addr)
|
||||
|
||||
//心跳线程
|
||||
if s.Keepalive {
|
||||
//TODO:start heartbeat thread
|
||||
}
|
||||
|
||||
//读线程
|
||||
for {
|
||||
data := make([]byte, 4096)
|
||||
n, remoteAddr, err := conn.ReadFromUDP(data)
|
||||
if err != nil {
|
||||
fmt.Println("failed to read UDP msg because of ", err.Error())
|
||||
continue
|
||||
}
|
||||
s.readChan <- &Packet{
|
||||
Addr: remoteAddr,
|
||||
Data: data[:n],
|
||||
}
|
||||
}
|
||||
}
|
||||
func (s *UDPServer) ReadPacketChan() <-chan *Packet {
|
||||
return s.readChan
|
||||
}
|
||||
func (s *UDPServer) WritePacket(packet *Packet) {
|
||||
s.writeChan <- packet
|
||||
}
|
||||
|
||||
func (s *UDPServer) Close() error {
|
||||
//所有session离线和关闭处理
|
||||
return nil
|
||||
}
|
||||
func (s *UDPServer) CloseOne(addr string) {
|
||||
//处理某设备离线
|
||||
}
|
||||
|
||||
func (s *UDPServer) Conn() *Connection {
|
||||
return s.conn
|
||||
}
|
||||
24
tu/README.md
24
tu/README.md
@@ -1,24 +0,0 @@
|
||||
|
||||
Transaction User(TU)事务用户:在transaction 层之上的协议层。TU包括了UAC core、UAS core,和proxy core。
|
||||
tu处理业务逻辑,并对事务层进行操作。
|
||||
|
||||
#### 类型
|
||||
|
||||
SIP服务器典型有以下几类:
|
||||
|
||||
a. 注册服务器 -即只管Register消息,这里相当于location也在这里了
|
||||
|
||||
b. 重定向服务器 -给ua回一条302后,转给其它的服务器,这样保证全系统统一接入
|
||||
|
||||
c. 代理服务器 -只做proxy,即对SIP消息转发
|
||||
|
||||
d. 媒体服务器-只做rtp包相关处理,即media server
|
||||
|
||||
e. B2BUA - 这个里包实际一般是可以含以上几种服务器类型
|
||||
|
||||
暂时仅处理gb28181 相关
|
||||
|
||||
#### TU
|
||||
|
||||
tu负责根据应用层需求,发起操作。
|
||||
比如注册到sip服务器、发起会话、取消会话等。
|
||||
95
tu/client.go
95
tu/client.go
@@ -1,95 +0,0 @@
|
||||
package tu
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transaction"
|
||||
)
|
||||
|
||||
//sip server和client的配置,可以得到sip URI:sip
|
||||
//格式:user:password@host:port;uri-parameters?headers
|
||||
//在这些URI里边包含了足够的信息来发起和维持到这个资源的一个通讯会话。
|
||||
//client静态配置
|
||||
type ClientStatic struct {
|
||||
LocalIP string //设备本地IP
|
||||
LocalPort uint16 //客户端SIP端口
|
||||
Username string //SIP用户名,一般是取通道ID,默认 34020000001320000001
|
||||
AuthID string //SIP用户认证ID,一般是通道ID, 默认 34020000001320000001
|
||||
Password string //密码
|
||||
}
|
||||
|
||||
//client运行时信息
|
||||
type ClientRuntime struct {
|
||||
RemoteAddress string //设备的公网的IP和端口,格式x.x.x.x:x
|
||||
Online bool //在线状态
|
||||
Branch string //branch
|
||||
Cseq int //消息序列号,发送消息递增, uint32
|
||||
FromTag string //from tag
|
||||
ToTag string //to tag
|
||||
Received string //remote ip
|
||||
Rport string //remote port
|
||||
}
|
||||
|
||||
type Client struct {
|
||||
*transaction.Core //transaction manager
|
||||
static *ClientStatic //静态配置
|
||||
runtime *ClientRuntime //运行时信息
|
||||
}
|
||||
|
||||
//config:sip信令服务器配置
|
||||
//static:sip客户端配置
|
||||
func NewClient(config *transaction.Config, static *ClientStatic) *Client {
|
||||
return &Client{
|
||||
Core: transaction.NewCore(config),
|
||||
static: static,
|
||||
runtime: &ClientRuntime{},
|
||||
}
|
||||
}
|
||||
|
||||
//TODO:对于一个TU,开启之后
|
||||
//运行一个sip client
|
||||
func RunClient() {
|
||||
config := &transaction.Config{
|
||||
SipIP: "192.168.1.102",
|
||||
SipPort: 5060,
|
||||
SipNetwork: "UDP",
|
||||
Serial: "34020000002000000001",
|
||||
Realm: "3402000000",
|
||||
AckTimeout: 10,
|
||||
|
||||
RegisterValidity: 3600,
|
||||
RegisterInterval: 60,
|
||||
HeartbeatInterval: 60,
|
||||
HeartbeatRetry: 3,
|
||||
|
||||
AudioEnable: true,
|
||||
WaitKeyFrame: true,
|
||||
MediaPortMin: 58200,
|
||||
MediaPortMax: 58300,
|
||||
MediaIdleTimeout: 30,
|
||||
}
|
||||
static := &ClientStatic{
|
||||
LocalIP: "192.168.1.65",
|
||||
LocalPort: 5060,
|
||||
Username: "34020000001320000001",
|
||||
AuthID: "34020000001320000001",
|
||||
Password: "123456",
|
||||
}
|
||||
c := NewClient(config, static)
|
||||
|
||||
go c.StartAndWait()
|
||||
|
||||
//TODO:先发起注册
|
||||
//TODO:build sip message
|
||||
msg := BuildMessageRequest("", "", "", "", "", "",
|
||||
0, 0, 0, "")
|
||||
tx := c.MustTX(transaction.GetTXKey(msg))
|
||||
|
||||
resp, err := tx.SipRequestForResponse(&sip.Request{Message: msg})
|
||||
if err != nil {
|
||||
fmt.Println("request failed, ", err)
|
||||
}
|
||||
fmt.Println("response: ", resp.Body)
|
||||
|
||||
select {}
|
||||
}
|
||||
75
tu/common.go
75
tu/common.go
@@ -1,75 +0,0 @@
|
||||
package tu
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/sip"
|
||||
"github.com/Monibuca/plugin-gb28181/v3/utils"
|
||||
)
|
||||
|
||||
//根据参数构建各种消息
|
||||
//参数来自于session/transaction等会话管理器
|
||||
/*
|
||||
method:请求方法
|
||||
transport:UDP/TCP
|
||||
sipSerial: sip server ID
|
||||
sipRealm: sip domain
|
||||
username: 用户名/设备序列号
|
||||
srcIP: 源IP
|
||||
srcPort:源端口
|
||||
expires: 过期时间
|
||||
cseq:消息序列号,当前对话递增
|
||||
*/
|
||||
//构建消息:以客户端(可能是IPC,也可能是SIP Server)的角度
|
||||
func BuildMessageRequest(method sip.Method, transport, sipSerial, sipRealm, username, srcIP string, srcPort uint16, expires, cseq int, body string) *sip.Message {
|
||||
server := fmt.Sprintf("%s@%s", sipSerial, sipRealm)
|
||||
client := fmt.Sprintf("%s@%s", username, sipRealm)
|
||||
|
||||
msg := &sip.Message{
|
||||
Mode: sip.SIP_MESSAGE_REQUEST,
|
||||
MaxForwards: 70,
|
||||
UserAgent: "IPC",
|
||||
Expires: expires,
|
||||
ContentLength: 0,
|
||||
}
|
||||
msg.StartLine = &sip.StartLine{
|
||||
Method: method,
|
||||
Uri: sip.NewURI(server),
|
||||
}
|
||||
msg.Via = &sip.Via{
|
||||
Transport: transport,
|
||||
Host: client,
|
||||
}
|
||||
msg.Via.Params = map[string]string{
|
||||
"branch": randBranch(),
|
||||
"rport": "-1", //only key,no-value
|
||||
}
|
||||
msg.From = &sip.Contact{
|
||||
Uri: sip.NewURI(client),
|
||||
Params: nil,
|
||||
}
|
||||
msg.From.Params = map[string]string{
|
||||
"tag": utils.RandNumString(10),
|
||||
}
|
||||
msg.To = &sip.Contact{
|
||||
Uri: sip.NewURI(client),
|
||||
}
|
||||
msg.CallID = utils.RandNumString(8)
|
||||
msg.CSeq = &sip.CSeq{
|
||||
ID: uint32(cseq),
|
||||
Method: method,
|
||||
}
|
||||
|
||||
msg.Contact = &sip.Contact{
|
||||
Uri: sip.NewURI(fmt.Sprintf("%s@%s:%d", username, srcIP, srcPort)),
|
||||
}
|
||||
if len(body) > 0 {
|
||||
msg.ContentLength = len(body)
|
||||
msg.Body = body
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
//z9hG4bK + 10个随机数字
|
||||
func randBranch() string {
|
||||
return fmt.Sprintf("z9hG4bK%s", utils.RandNumString(8))
|
||||
}
|
||||
49
tu/server.go
49
tu/server.go
@@ -1,49 +0,0 @@
|
||||
package tu
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/Monibuca/plugin-gb28181/v3/transaction"
|
||||
)
|
||||
|
||||
//TODO:参考http服务,使用者仅需要根据需要实现某些handler,替换某些header fileds or body信息。其他的处理都由库来实现。
|
||||
type Server struct {
|
||||
*transaction.Core //SIP transaction manager
|
||||
registers sync.Map //管理所有已经注册的设备端
|
||||
//routers:TODO:消息路由,应用层可以处理消息体,或者针对某些消息的callback
|
||||
}
|
||||
|
||||
//提供config参数
|
||||
func NewServer(config *transaction.Config) *Server {
|
||||
return &Server{
|
||||
Core: transaction.NewCore(config),
|
||||
}
|
||||
}
|
||||
|
||||
//运行一个sip server
|
||||
func RunServer() {
|
||||
config := &transaction.Config{
|
||||
SipIP: "192.168.1.102",
|
||||
SipPort: 5060,
|
||||
SipNetwork: "UDP",
|
||||
Serial: "34020000002000000001",
|
||||
Realm: "3402000000",
|
||||
AckTimeout: 10,
|
||||
|
||||
RegisterValidity: 3600,
|
||||
RegisterInterval: 60,
|
||||
HeartbeatInterval: 60,
|
||||
HeartbeatRetry: 3,
|
||||
|
||||
AudioEnable: true,
|
||||
WaitKeyFrame: true,
|
||||
MediaPortMin: 58200,
|
||||
MediaPortMax: 58300,
|
||||
MediaIdleTimeout: 30,
|
||||
}
|
||||
s := NewServer(config)
|
||||
|
||||
s.StartAndWait()
|
||||
|
||||
select {}
|
||||
}
|
||||
@@ -47,6 +47,13 @@ func (b *IOBuffer) ReadN(length int) ([]byte, error) {
|
||||
return nil, io.EOF
|
||||
}
|
||||
|
||||
//func (b *IOBuffer) Read(buf []byte) (n int, err error) {
|
||||
// var ret []byte
|
||||
// ret, err = b.ReadN(len(buf))
|
||||
// copy(buf, ret)
|
||||
// return len(ret), err
|
||||
//}
|
||||
|
||||
// empty reports whether the unread portion of the buffer is empty.
|
||||
func (b *IOBuffer) empty() bool { return b.Len() <= b.off }
|
||||
|
||||
@@ -60,6 +67,7 @@ func (b *IOBuffer) ReadByte() (byte, error) {
|
||||
b.off++
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (b *IOBuffer) Reset() {
|
||||
b.buf = b.buf[:0]
|
||||
b.off = 0
|
||||
@@ -81,20 +89,24 @@ func (b *IOBuffer) tryGrowByReslice(n int) (int, bool) {
|
||||
var ErrTooLarge = errors.New("IOBuffer: too large")
|
||||
|
||||
func (b *IOBuffer) Write(p []byte) (n int, err error) {
|
||||
defer func() {
|
||||
if recover() != nil {
|
||||
panic(ErrTooLarge)
|
||||
}
|
||||
}()
|
||||
l := len(p)
|
||||
oldLen := len(b.buf)
|
||||
m, ok := b.tryGrowByReslice(l)
|
||||
if !ok {
|
||||
buf := make([]byte, oldLen+l)
|
||||
copy(buf, b.buf[b.off:])
|
||||
m = oldLen - b.off
|
||||
b.off = 0
|
||||
b.buf = buf
|
||||
}
|
||||
return copy(b.buf[m:], p), nil
|
||||
l := copy(b.buf, b.buf[b.off:])
|
||||
b.buf = append(b.buf[:l], p...)
|
||||
b.off = 0
|
||||
// println(b.buf, b.off, b.buf[b.off], b.buf[b.off+1], b.buf[b.off+2], b.buf[b.off+3])
|
||||
return len(p), nil
|
||||
// defer func() {
|
||||
// if recover() != nil {
|
||||
// panic(ErrTooLarge)
|
||||
// }
|
||||
// }()
|
||||
// l := len(p)
|
||||
// oldLen := len(b.buf)
|
||||
// m, ok := b.tryGrowByReslice(l)
|
||||
// if !ok {
|
||||
// m = oldLen - b.off
|
||||
// buf := append(append(([]byte)(nil), b.buf[b.off:]...), p...)
|
||||
// b.off = 0
|
||||
// b.buf = buf
|
||||
// }
|
||||
// return copy(b.buf[m:], p), nil
|
||||
}
|
||||
|
||||
159
utils/log.go
Executable file
159
utils/log.go
Executable file
@@ -0,0 +1,159 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/ghettovoice/gosip/log"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
m7slog "m7s.live/engine/v4/log"
|
||||
)
|
||||
|
||||
type ZapLogger struct {
|
||||
log *m7slog.Logger
|
||||
prefix string
|
||||
fields log.Fields
|
||||
sugared *zap.SugaredLogger
|
||||
level log.Level
|
||||
}
|
||||
|
||||
func NewZapLogger(log *m7slog.Logger, prefix string, fields log.Fields) (z *ZapLogger) {
|
||||
z = &ZapLogger{
|
||||
log: log,
|
||||
prefix: prefix,
|
||||
fields: fields,
|
||||
}
|
||||
z.sugared = z.prepareEntry()
|
||||
return
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Print(args ...interface{}) {
|
||||
if l.level >= log.InfoLevel {
|
||||
l.sugared.Info(args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Printf(format string, args ...interface{}) {
|
||||
if l.level >= log.InfoLevel {
|
||||
l.sugared.Infof(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Trace(args ...interface{}) {
|
||||
if l.level >= log.TraceLevel {
|
||||
l.sugared.Debug(args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Tracef(format string, args ...interface{}) {
|
||||
if l.level >= log.TraceLevel {
|
||||
l.sugared.Debugf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Debug(args ...interface{}) {
|
||||
if l.level >= log.DebugLevel {
|
||||
l.sugared.Debug(args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Debugf(format string, args ...interface{}) {
|
||||
if l.level >= log.DebugLevel {
|
||||
l.sugared.Debugf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Info(args ...interface{}) {
|
||||
if l.level >= log.InfoLevel {
|
||||
l.sugared.Info(args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Infof(format string, args ...interface{}) {
|
||||
if l.level >= log.InfoLevel {
|
||||
l.sugared.Infof(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Warn(args ...interface{}) {
|
||||
if l.level >= log.WarnLevel {
|
||||
l.sugared.Warn(args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Warnf(format string, args ...interface{}) {
|
||||
if l.level >= log.WarnLevel {
|
||||
l.sugared.Warnf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Error(args ...interface{}) {
|
||||
if l.level >= log.ErrorLevel {
|
||||
l.sugared.Error(args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Errorf(format string, args ...interface{}) {
|
||||
if l.level >= log.ErrorLevel {
|
||||
l.sugared.Errorf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Fatal(args ...interface{}) {
|
||||
if l.level >= log.FatalLevel {
|
||||
l.sugared.Fatal(args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Fatalf(format string, args ...interface{}) {
|
||||
if l.level >= log.FatalLevel {
|
||||
l.sugared.Fatalf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Panic(args ...interface{}) {
|
||||
if l.level >= log.PanicLevel {
|
||||
l.sugared.Panic(args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Panicf(format string, args ...interface{}) {
|
||||
if l.level >= log.PanicLevel {
|
||||
l.sugared.Panicf(format, args...)
|
||||
}
|
||||
}
|
||||
|
||||
func (l *ZapLogger) WithPrefix(prefix string) log.Logger {
|
||||
return NewZapLogger(l.log, prefix, l.Fields())
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Prefix() string {
|
||||
return l.prefix
|
||||
}
|
||||
|
||||
func (l *ZapLogger) WithFields(fields log.Fields) log.Logger {
|
||||
return NewZapLogger(l.log, l.Prefix(), l.Fields().WithFields(fields))
|
||||
}
|
||||
|
||||
func (l *ZapLogger) Fields() log.Fields {
|
||||
return l.fields
|
||||
}
|
||||
|
||||
func (l *ZapLogger) prepareEntry() *zap.SugaredLogger {
|
||||
newlog := l.log.With(zap.String("prefix", l.Prefix()))
|
||||
if l.fields != nil {
|
||||
fields := make([]zapcore.Field, len(l.fields))
|
||||
idx := 0
|
||||
for k, v := range l.fields {
|
||||
s, _ := json.Marshal(v)
|
||||
fields[idx] = zap.String(k, string(s))
|
||||
idx++
|
||||
}
|
||||
newlog = newlog.With(fields...)
|
||||
}
|
||||
return newlog.Sugar()
|
||||
}
|
||||
|
||||
func (l *ZapLogger) SetLevel(level log.Level) {
|
||||
l.level = level
|
||||
}
|
||||
317
utils/ps.go
317
utils/ps.go
@@ -1,317 +0,0 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/Monibuca/utils/v3"
|
||||
"github.com/logrusorgru/aurora"
|
||||
)
|
||||
|
||||
//
|
||||
const (
|
||||
UDPTransfer int = 0
|
||||
TCPTransferActive int = 1
|
||||
TCPTransferPassive int = 2
|
||||
LocalCache int = 3
|
||||
|
||||
StreamTypeH264 = 0x1b
|
||||
StreamTypeH265 = 0x24
|
||||
G711A = 0x90 //PCMA
|
||||
G7221AUDIOTYPE = 0x92
|
||||
G7231AUDIOTYPE = 0x93
|
||||
G729AUDIOTYPE = 0x99
|
||||
|
||||
StreamIDVideo = 0xe0
|
||||
StreamIDAudio = 0xc0
|
||||
|
||||
StartCodePS = 0x000001ba
|
||||
StartCodeSYS = 0x000001bb
|
||||
StartCodeMAP = 0x000001bc
|
||||
StartCodeVideo = 0x000001e0
|
||||
StartCodeAudio = 0x000001c0
|
||||
HaiKangCode = 0x000001bd
|
||||
MEPGProgramEndCode = 0x000001b9
|
||||
|
||||
RTPHeaderLength int = 12
|
||||
PSHeaderLength int = 14
|
||||
SystemHeaderLength int = 18
|
||||
MAPHeaderLength int = 24
|
||||
PESHeaderLength int = 19
|
||||
RtpLoadLength int = 1460
|
||||
PESLoadLength int = 0xFFFF
|
||||
MAXFrameLen int = 1024 * 1024 * 2
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotFoundStartCode = errors.New("not found the need start code flag")
|
||||
ErrMarkerBit = errors.New("marker bit value error")
|
||||
ErrFormatPack = errors.New("not package standard")
|
||||
ErrParsePakcet = errors.New("parse ps packet error")
|
||||
)
|
||||
|
||||
type Pusher interface {
|
||||
PushVideo(uint32, uint32, []byte)
|
||||
PushAudio(uint32, []byte)
|
||||
}
|
||||
|
||||
/*
|
||||
This implement from VLC source code
|
||||
notes: https://github.com/videolan/vlc/blob/master/modules/mux/mpeg/bits.h
|
||||
*/
|
||||
|
||||
//bitsBuffer bits buffer
|
||||
// type bitsBuffer struct {
|
||||
// iSize int
|
||||
// iData int
|
||||
// iMask uint8
|
||||
// pData []byte
|
||||
// }
|
||||
|
||||
// func bitsInit(isize int, buffer []byte) *bitsBuffer {
|
||||
|
||||
// bits := &bitsBuffer{
|
||||
// iSize: isize,
|
||||
// iData: 0,
|
||||
// iMask: 0x80,
|
||||
// pData: buffer,
|
||||
// }
|
||||
// if bits.pData == nil {
|
||||
// bits.pData = make([]byte, isize)
|
||||
// }
|
||||
// return bits
|
||||
// }
|
||||
|
||||
// func bitsAlign(bits *bitsBuffer) {
|
||||
|
||||
// if bits.iMask != 0x80 && bits.iData < bits.iSize {
|
||||
// bits.iMask = 0x80
|
||||
// bits.iData++
|
||||
// bits.pData[bits.iData] = 0x00
|
||||
// }
|
||||
// }
|
||||
// func bitsWrite(bits *bitsBuffer, count int, src uint64) *bitsBuffer {
|
||||
|
||||
// for count > 0 {
|
||||
// count--
|
||||
// if ((src >> uint(count)) & 0x01) != 0 {
|
||||
// bits.pData[bits.iData] |= bits.iMask
|
||||
// } else {
|
||||
// bits.pData[bits.iData] &= ^bits.iMask
|
||||
// }
|
||||
// bits.iMask >>= 1
|
||||
// if bits.iMask == 0 {
|
||||
// bits.iData++
|
||||
// bits.iMask = 0x80
|
||||
// }
|
||||
// }
|
||||
|
||||
// return bits
|
||||
// }
|
||||
|
||||
/*
|
||||
https://github.com/videolan/vlc/blob/master/modules/demux/mpeg
|
||||
*/
|
||||
type DecPSPackage struct {
|
||||
systemClockReferenceBase uint64
|
||||
systemClockReferenceExtension uint64
|
||||
programMuxRate uint32
|
||||
|
||||
VideoStreamType uint32
|
||||
AudioStreamType uint32
|
||||
IOBuffer
|
||||
Payload []byte
|
||||
PTS uint32
|
||||
DTS uint32
|
||||
}
|
||||
|
||||
func (dec *DecPSPackage) clean() {
|
||||
dec.systemClockReferenceBase = 0
|
||||
dec.systemClockReferenceExtension = 0
|
||||
dec.programMuxRate = 0
|
||||
dec.Payload = nil
|
||||
dec.PTS = 0
|
||||
dec.DTS = 0
|
||||
}
|
||||
|
||||
func (dec *DecPSPackage) ReadPayload() (payload []byte, err error) {
|
||||
payloadlen, err := dec.Uint16()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return dec.ReadN(int(payloadlen))
|
||||
}
|
||||
|
||||
//read the buffer and push video or audio
|
||||
func (dec *DecPSPackage) Read(ts uint32, pusher Pusher) error {
|
||||
again:
|
||||
dec.clean()
|
||||
if err := dec.Skip(9); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
psl, err := dec.ReadByte()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
psl &= 0x07
|
||||
if err = dec.Skip(int(psl)); err != nil {
|
||||
return err
|
||||
}
|
||||
var video []byte
|
||||
var nextStartCode, videoTs, videoCts uint32
|
||||
loop:
|
||||
for err == nil {
|
||||
if nextStartCode, err = dec.Uint32(); err != nil {
|
||||
break
|
||||
}
|
||||
switch nextStartCode {
|
||||
case StartCodeSYS:
|
||||
dec.ReadPayload()
|
||||
//err = dec.decSystemHeader()
|
||||
case StartCodeMAP:
|
||||
err = dec.decProgramStreamMap()
|
||||
case StartCodeVideo:
|
||||
var cts uint32
|
||||
if err = dec.decPESPacket(); err == nil {
|
||||
if len(video) == 0 {
|
||||
if dec.PTS == 0 {
|
||||
dec.PTS = ts
|
||||
}
|
||||
if dec.DTS != 0 {
|
||||
cts = dec.PTS - dec.DTS
|
||||
} else {
|
||||
dec.DTS = dec.PTS
|
||||
}
|
||||
videoTs = dec.DTS / 90
|
||||
videoCts = cts / 90
|
||||
}
|
||||
video = append (video,dec.Payload...)
|
||||
} else {
|
||||
utils.Println("video", err)
|
||||
}
|
||||
case StartCodeAudio:
|
||||
if err = dec.decPESPacket(); err == nil {
|
||||
ts := ts / 90
|
||||
if dec.PTS != 0 {
|
||||
ts = dec.PTS / 90
|
||||
}
|
||||
pusher.PushAudio(ts, dec.Payload)
|
||||
} else {
|
||||
utils.Println("audio", err)
|
||||
}
|
||||
case StartCodePS:
|
||||
break loop
|
||||
default:
|
||||
dec.ReadPayload()
|
||||
}
|
||||
}
|
||||
if len(video) > 0 {
|
||||
pusher.PushVideo(videoTs, videoCts, video)
|
||||
}
|
||||
if nextStartCode == StartCodePS {
|
||||
utils.Println(aurora.Red("StartCodePS recursion..."), err)
|
||||
goto again
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
/*
|
||||
func (dec *DecPSPackage) decSystemHeader() error {
|
||||
syslens, err := dec.Uint16()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// drop rate video audio bound and lock flag
|
||||
syslens -= 6
|
||||
if err = dec.Skip(6); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// ONE WAY: do not to parse the stream and skip the buffer
|
||||
//br.Skip(syslen * 8)
|
||||
|
||||
// TWO WAY: parse every stream info
|
||||
for syslens > 0 {
|
||||
if nextbits, err := dec.Uint8(); err != nil {
|
||||
return err
|
||||
} else if (nextbits&0x80)>>7 != 1 {
|
||||
break
|
||||
}
|
||||
if err = dec.Skip(2); err != nil {
|
||||
return err
|
||||
}
|
||||
syslens -= 3
|
||||
}
|
||||
return nil
|
||||
}
|
||||
*/
|
||||
func (dec *DecPSPackage) decProgramStreamMap() error {
|
||||
psm, err := dec.ReadPayload()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
l := len(psm)
|
||||
index := 2
|
||||
programStreamInfoLen := utils.BigEndian.Uint16(psm[index:])
|
||||
index += 2
|
||||
index += int(programStreamInfoLen)
|
||||
programStreamMapLen := utils.BigEndian.Uint16(psm[index:])
|
||||
index += 2
|
||||
for programStreamMapLen > 0 {
|
||||
if l <= index+1 {
|
||||
break
|
||||
}
|
||||
streamType := psm[index]
|
||||
index++
|
||||
elementaryStreamID := psm[index]
|
||||
index++
|
||||
if elementaryStreamID >= 0xe0 && elementaryStreamID <= 0xef {
|
||||
dec.VideoStreamType = uint32(streamType)
|
||||
} else if elementaryStreamID >= 0xc0 && elementaryStreamID <= 0xdf {
|
||||
dec.AudioStreamType = uint32(streamType)
|
||||
}
|
||||
if l <= index+1 {
|
||||
break
|
||||
}
|
||||
elementaryStreamInfoLength := utils.BigEndian.Uint16(psm[index:])
|
||||
index += 2
|
||||
index += int(elementaryStreamInfoLength)
|
||||
programStreamMapLen -= 4 + elementaryStreamInfoLength
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (dec *DecPSPackage) decPESPacket() error {
|
||||
payload, err := dec.ReadPayload()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(payload) < 4 {
|
||||
return errors.New("not enough data")
|
||||
}
|
||||
//data_alignment_indicator := (payload[0]&0b0001_0000)>>4 == 1
|
||||
flag := payload[1]
|
||||
ptsFlag := flag>>7 == 1
|
||||
dtsFlag := (flag&0b0100_0000)>>6 == 1
|
||||
var pts, dts uint32
|
||||
pesHeaderDataLen := payload[2]
|
||||
payload = payload[3:]
|
||||
extraData := payload[:pesHeaderDataLen]
|
||||
if ptsFlag && len(extraData) > 4 {
|
||||
pts = uint32(extraData[0]&0b0000_1110) << 29
|
||||
pts += uint32(extraData[1]) << 22
|
||||
pts += uint32(extraData[2]&0b1111_1110) << 14
|
||||
pts += uint32(extraData[3]) << 7
|
||||
pts += uint32(extraData[4]) >> 1
|
||||
if dtsFlag && len(extraData) > 9 {
|
||||
dts = uint32(extraData[5]&0b0000_1110) << 29
|
||||
dts += uint32(extraData[6]) << 22
|
||||
dts += uint32(extraData[7]&0b1111_1110) << 14
|
||||
dts += uint32(extraData[8]) << 7
|
||||
dts += uint32(extraData[9]) >> 1
|
||||
}
|
||||
}
|
||||
dec.PTS = pts
|
||||
dec.DTS = dts
|
||||
dec.Payload = payload[pesHeaderDataLen:]
|
||||
return err
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package utils
|
||||
import (
|
||||
"container/heap"
|
||||
"errors"
|
||||
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user