This repository has been archived by the owner on Sep 18, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chunk_shutdown.go
72 lines (57 loc) · 1.73 KB
/
chunk_shutdown.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package sctp
import (
"encoding/binary"
"errors"
"fmt"
)
/*
chunkShutdown represents an SCTP Chunk of type chunkShutdown
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 = 7 | Chunk Flags | Length = 8 |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Cumulative TSN Ack |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*/
type chunkShutdown struct {
chunkHeader
cumulativeTSNAck uint32
}
const (
cumulativeTSNAckLength = 4
)
// Shutdown chunk errors
var (
ErrInvalidChunkSize = errors.New("invalid chunk size")
ErrChunkTypeNotShutdown = errors.New("ChunkType is not of type SHUTDOWN")
)
func (c *chunkShutdown) unmarshal(raw []byte) error {
if err := c.chunkHeader.unmarshal(raw); err != nil {
return err
}
if c.typ != ctShutdown {
return fmt.Errorf("%w: actually is %s", ErrChunkTypeNotShutdown, c.typ.String())
}
if len(c.raw) != cumulativeTSNAckLength {
return ErrInvalidChunkSize
}
c.cumulativeTSNAck = binary.BigEndian.Uint32(c.raw[0:])
return nil
}
func (c *chunkShutdown) marshal() ([]byte, error) {
out := make([]byte, cumulativeTSNAckLength)
binary.BigEndian.PutUint32(out[0:], c.cumulativeTSNAck)
c.typ = ctShutdown
c.raw = out
return c.chunkHeader.marshal()
}
func (c *chunkShutdown) check() (abort bool, err error) {
return false, nil
}
// String makes chunkShutdown printable
func (c *chunkShutdown) String() string {
return c.chunkHeader.String()
}