Ai
10 Star 41 Fork 20

Gitee 极速下载/Pion-WebRTC

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/pion/webrtc
克隆/下载
chunk_heartbeat.go 2.26 KB
一键复制 编辑 原始数据 按行查看 历史
Sean DuBois 提交于 2018-07-25 16:00 +08:00 . Switch from individual linters to golangci-lint
package sctp
import (
"encoding/binary"
"github.com/pkg/errors"
)
/*
chunkHeartbeat represents an SCTP Chunk of type HEARTBEAT
An endpoint should send this chunk to its peer endpoint to probe the
reachability of a particular destination transport address defined in
the present association.
The parameter field contains the Heartbeat Information, which is a
variable-length opaque data structure understood only by the sender.
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Type = 4 | Chunk Flags | Heartbeat Length |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
| Heartbeat Information TLV (Variable-Length) |
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Defined as a variable-length parameter using the format described
in Section 3.2.1, i.e.:
Variable Parameters Status Type Value
-------------------------------------------------------------
heartbeat Info Mandatory 1
*/
type chunkHeartbeat struct {
chunkHeader
params []param
}
func (h *chunkHeartbeat) unmarshal(raw []byte) error {
if err := h.chunkHeader.unmarshal(raw); err != nil {
return err
} else if h.typ != HEARTBEAT {
return errors.Errorf("ChunkType is not of type HEARTBEAT, actually is %s", h.typ.String())
}
if len(raw) <= chunkHeaderSize {
return errors.Errorf("Heartbeat is not long enough to contain Heartbeat Info %d", len(raw))
}
pType := paramType(binary.BigEndian.Uint16(raw[chunkHeaderSize:]))
if pType != heartbeatInfo {
return errors.Errorf("Heartbeat should only have HEARTBEAT param, instead have %s", pType.String())
}
p, err := buildParam(pType, raw[chunkHeaderSize:])
if err != nil {
return errors.Wrap(err, "Failed unmarshalling param in Heartbeat Chunk")
}
h.params = append(h.params, p)
return nil
}
func (h *chunkHeartbeat) Marshal() ([]byte, error) {
return nil, errors.Errorf("Unimplemented")
}
func (h *chunkHeartbeat) check() (abort bool, err error) {
return false, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/Pion-WebRTC.git
git@gitee.com:mirrors/Pion-WebRTC.git
mirrors
Pion-WebRTC
Pion-WebRTC
v1.1.1

搜索帮助