• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 15561477203

10 Jun 2025 01:54PM UTC coverage: 58.351% (-10.1%) from 68.487%
15561477203

Pull #9356

github

web-flow
Merge 6440b25db into c6d6d4c0b
Pull Request #9356: lnrpc: add incoming/outgoing channel ids filter to forwarding history request

33 of 36 new or added lines in 2 files covered. (91.67%)

28366 existing lines in 455 files now uncovered.

97715 of 167461 relevant lines covered (58.35%)

1.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

59.57
/lnwire/node_announcement.go
1
package lnwire
2

3
import (
4
        "bytes"
5
        "fmt"
6
        "image/color"
7
        "io"
8
        "net"
9
        "unicode/utf8"
10
)
11

12
// ErrUnknownAddrType is an error returned if we encounter an unknown address type
13
// when parsing addresses.
14
type ErrUnknownAddrType struct {
15
        addrType addressType
16
}
17

18
// Error returns a human readable string describing the error.
19
//
20
// NOTE: implements the error interface.
21
func (e ErrUnknownAddrType) Error() string {
×
22
        return fmt.Sprintf("unknown address type: %v", e.addrType)
×
23
}
×
24

25
// ErrInvalidNodeAlias is an error returned if a node alias we parse on the
26
// wire is invalid, as in it has non UTF-8 characters.
27
type ErrInvalidNodeAlias struct{}
28

29
// Error returns a human readable string describing the error.
30
//
31
// NOTE: implements the error interface.
32
func (e ErrInvalidNodeAlias) Error() string {
×
33
        return "node alias has non-utf8 characters"
×
34
}
×
35

36
// NodeAlias is a hex encoded UTF-8 string that may be displayed as an
37
// alternative to the node's ID. Notice that aliases are not unique and may be
38
// freely chosen by the node operators.
39
type NodeAlias [32]byte
40

41
// NewNodeAlias creates a new instance of a NodeAlias. Verification is
42
// performed on the passed string to ensure it meets the alias requirements.
43
func NewNodeAlias(s string) (NodeAlias, error) {
3✔
44
        var n NodeAlias
3✔
45

3✔
46
        if len(s) > 32 {
6✔
47
                return n, fmt.Errorf("alias too large: max is %v, got %v", 32,
3✔
48
                        len(s))
3✔
49
        }
3✔
50

51
        if !utf8.ValidString(s) {
3✔
UNCOV
52
                return n, &ErrInvalidNodeAlias{}
×
UNCOV
53
        }
×
54

55
        copy(n[:], []byte(s))
3✔
56
        return n, nil
3✔
57
}
58

59
// String returns a utf8 string representation of the alias bytes.
60
func (n NodeAlias) String() string {
3✔
61
        // Trim trailing zero-bytes for presentation
3✔
62
        return string(bytes.Trim(n[:], "\x00"))
3✔
63
}
3✔
64

65
// NodeAnnouncement message is used to announce the presence of a Lightning
66
// node and also to signal that the node is accepting incoming connections.
67
// Each NodeAnnouncement authenticating the advertised information within the
68
// announcement via a signature using the advertised node pubkey.
69
type NodeAnnouncement struct {
70
        // Signature is used to prove the ownership of node id.
71
        Signature Sig
72

73
        // Features is the list of protocol features this node supports.
74
        Features *RawFeatureVector
75

76
        // Timestamp allows ordering in the case of multiple announcements.
77
        Timestamp uint32
78

79
        // NodeID is a public key which is used as node identification.
80
        NodeID [33]byte
81

82
        // RGBColor is used to customize their node's appearance in maps and
83
        // graphs
84
        RGBColor color.RGBA
85

86
        // Alias is used to customize their node's appearance in maps and
87
        // graphs
88
        Alias NodeAlias
89

90
        // Address includes two specification fields: 'ipv6' and 'port' on
91
        // which the node is accepting incoming connections.
92
        Addresses []net.Addr
93

94
        // ExtraOpaqueData is the set of data that was appended to this
95
        // message, some of which we may not actually know how to iterate or
96
        // parse. By holding onto this data, we ensure that we're able to
97
        // properly validate the set of signatures that cover these new fields,
98
        // and ensure we're able to make upgrades to the network in a forwards
99
        // compatible manner.
100
        ExtraOpaqueData ExtraOpaqueData
101
}
102

103
// A compile time check to ensure NodeAnnouncement implements the
104
// lnwire.Message interface.
105
var _ Message = (*NodeAnnouncement)(nil)
106

107
// A compile time check to ensure NodeAnnouncement implements the
108
// lnwire.SizeableMessage interface.
109
var _ SizeableMessage = (*NodeAnnouncement)(nil)
110

111
// Decode deserializes a serialized NodeAnnouncement stored in the passed
112
// io.Reader observing the specified protocol version.
113
//
114
// This is part of the lnwire.Message interface.
115
func (a *NodeAnnouncement) Decode(r io.Reader, _ uint32) error {
3✔
116
        err := ReadElements(r,
3✔
117
                &a.Signature,
3✔
118
                &a.Features,
3✔
119
                &a.Timestamp,
3✔
120
                &a.NodeID,
3✔
121
                &a.RGBColor,
3✔
122
                &a.Alias,
3✔
123
                &a.Addresses,
3✔
124
                &a.ExtraOpaqueData,
3✔
125
        )
3✔
126
        if err != nil {
3✔
UNCOV
127
                return err
×
UNCOV
128
        }
×
129

130
        return a.ExtraOpaqueData.ValidateTLV()
3✔
131
}
132

133
// Encode serializes the target NodeAnnouncement into the passed io.Writer
134
// observing the protocol version specified.
135
//
136
// This is part of the lnwire.Message interface.
137
func (a *NodeAnnouncement) Encode(w *bytes.Buffer, pver uint32) error {
3✔
138
        if err := WriteSig(w, a.Signature); err != nil {
3✔
139
                return err
×
140
        }
×
141

142
        if err := WriteRawFeatureVector(w, a.Features); err != nil {
3✔
143
                return err
×
144
        }
×
145

146
        if err := WriteUint32(w, a.Timestamp); err != nil {
3✔
147
                return err
×
148
        }
×
149

150
        if err := WriteBytes(w, a.NodeID[:]); err != nil {
3✔
151
                return err
×
152
        }
×
153

154
        if err := WriteColorRGBA(w, a.RGBColor); err != nil {
3✔
155
                return err
×
156
        }
×
157

158
        if err := WriteNodeAlias(w, a.Alias); err != nil {
3✔
159
                return err
×
160
        }
×
161

162
        if err := WriteNetAddrs(w, a.Addresses); err != nil {
3✔
163
                return err
×
164
        }
×
165

166
        return WriteBytes(w, a.ExtraOpaqueData)
3✔
167
}
168

169
// MsgType returns the integer uniquely identifying this message type on the
170
// wire.
171
//
172
// This is part of the lnwire.Message interface.
173
func (a *NodeAnnouncement) MsgType() MessageType {
3✔
174
        return MsgNodeAnnouncement
3✔
175
}
3✔
176

177
// DataToSign returns the part of the message that should be signed.
178
func (a *NodeAnnouncement) DataToSign() ([]byte, error) {
3✔
179

3✔
180
        // We should not include the signatures itself.
3✔
181
        buffer := make([]byte, 0, MaxMsgBody)
3✔
182
        buf := bytes.NewBuffer(buffer)
3✔
183

3✔
184
        if err := WriteRawFeatureVector(buf, a.Features); err != nil {
3✔
UNCOV
185
                return nil, err
×
UNCOV
186
        }
×
187

188
        if err := WriteUint32(buf, a.Timestamp); err != nil {
3✔
189
                return nil, err
×
190
        }
×
191

192
        if err := WriteBytes(buf, a.NodeID[:]); err != nil {
3✔
193
                return nil, err
×
194
        }
×
195

196
        if err := WriteColorRGBA(buf, a.RGBColor); err != nil {
3✔
197
                return nil, err
×
198
        }
×
199

200
        if err := WriteNodeAlias(buf, a.Alias); err != nil {
3✔
201
                return nil, err
×
202
        }
×
203

204
        if err := WriteNetAddrs(buf, a.Addresses); err != nil {
3✔
205
                return nil, err
×
206
        }
×
207

208
        if err := WriteBytes(buf, a.ExtraOpaqueData); err != nil {
3✔
209
                return nil, err
×
210
        }
×
211

212
        return buf.Bytes(), nil
3✔
213
}
214

215
// SerializedSize returns the serialized size of the message in bytes.
216
//
217
// This is part of the lnwire.SizeableMessage interface.
218
func (a *NodeAnnouncement) SerializedSize() (uint32, error) {
3✔
219
        return MessageSerializedSize(a)
3✔
220
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc