Newer
Older
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
package packet
import (
"bytes"
"github.com/bio-routing/bio-rd/util/decoder"
)
// PeerDownNotification represents a peer down notification
type PeerDownNotification struct {
CommonHeader *CommonHeader
Reason uint8
Data []byte
}
// MsgType returns the type of this message
func (p *PeerDownNotification) MsgType() uint8 {
return p.CommonHeader.MsgType
}
func decodePeerDownNotification(buf *bytes.Buffer, ch *CommonHeader) (*PeerDownNotification, error) {
p := &PeerDownNotification{}
fields := []interface{}{
&p.Reason,
}
err := decoder.Decode(buf, fields)
if err != nil {
return nil, err
}
if p.Reason < 1 || p.Reason > 3 {
return p, nil
}
p.Data = make([]byte, ch.MsgLength-CommonHeaderLen-1)
fields = []interface{}{
p.Data,
}
err = decoder.Decode(buf, fields)
if err != nil {
return nil, err
}
return p, nil
}