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

lightningnetwork / lnd / 18197857992

02 Oct 2025 03:32PM UTC coverage: 66.622% (-0.02%) from 66.646%
18197857992

Pull #10267

github

web-flow
Merge 0d9bfccfe into 1c2ff4a7e
Pull Request #10267: [g175] multi: small G175 preparations

24 of 141 new or added lines in 12 files covered. (17.02%)

64 existing lines in 20 files now uncovered.

137216 of 205963 relevant lines covered (66.62%)

21302.01 hits per line

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

60.0
/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) {
449✔
44
        var n NodeAlias
449✔
45

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

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

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

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

65
// NodeAnnouncement1 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 NodeAnnouncement1 authenticating the advertised information within the
68
// announcement via a signature using the advertised node pubkey.
69
type NodeAnnouncement1 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 NodeAnnouncement1 implements the
104
// lnwire.Message interface.
105
var _ Message = (*NodeAnnouncement1)(nil)
106

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

111
// A compile time check to ensure NodeAnnouncement1 implements the
112
// lnwire.SizeableMessage interface.
113
var _ SizeableMessage = (*NodeAnnouncement1)(nil)
114

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

134
        return a.ExtraOpaqueData.ValidateTLV()
351✔
135
}
136

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

146
        if err := WriteRawFeatureVector(w, a.Features); err != nil {
213✔
147
                return err
2✔
148
        }
2✔
149

150
        if err := WriteUint32(w, a.Timestamp); err != nil {
209✔
151
                return err
×
152
        }
×
153

154
        if err := WriteBytes(w, a.NodeID[:]); err != nil {
209✔
155
                return err
×
156
        }
×
157

158
        if err := WriteColorRGBA(w, a.RGBColor); err != nil {
209✔
159
                return err
×
160
        }
×
161

162
        if err := WriteNodeAlias(w, a.Alias); err != nil {
209✔
163
                return err
×
164
        }
×
165

166
        if err := WriteNetAddrs(w, a.Addresses); err != nil {
209✔
167
                return err
×
168
        }
×
169

170
        return WriteBytes(w, a.ExtraOpaqueData)
209✔
171
}
172

173
// MsgType returns the integer uniquely identifying this message type on the
174
// wire.
175
//
176
// This is part of the lnwire.Message interface.
177
func (a *NodeAnnouncement1) MsgType() MessageType {
279✔
178
        return MsgNodeAnnouncement
279✔
179
}
279✔
180

181
// DataToSign returns the part of the message that should be signed.
182
func (a *NodeAnnouncement1) DataToSign() ([]byte, error) {
64✔
183
        // We should not include the signatures itself.
64✔
184
        buffer := make([]byte, 0, MaxMsgBody)
64✔
185
        buf := bytes.NewBuffer(buffer)
64✔
186

64✔
187
        if err := WriteRawFeatureVector(buf, a.Features); err != nil {
65✔
188
                return nil, err
1✔
189
        }
1✔
190

191
        if err := WriteUint32(buf, a.Timestamp); err != nil {
63✔
192
                return nil, err
×
193
        }
×
194

195
        if err := WriteBytes(buf, a.NodeID[:]); err != nil {
63✔
196
                return nil, err
×
197
        }
×
198

199
        if err := WriteColorRGBA(buf, a.RGBColor); err != nil {
63✔
200
                return nil, err
×
201
        }
×
202

203
        if err := WriteNodeAlias(buf, a.Alias); err != nil {
63✔
204
                return nil, err
×
205
        }
×
206

207
        if err := WriteNetAddrs(buf, a.Addresses); err != nil {
63✔
208
                return nil, err
×
209
        }
×
210

211
        if err := WriteBytes(buf, a.ExtraOpaqueData); err != nil {
63✔
212
                return nil, err
×
213
        }
×
214

215
        return buf.Bytes(), nil
63✔
216
}
217

218
// SerializedSize returns the serialized size of the message in bytes.
219
//
220
// This is part of the lnwire.SizeableMessage interface.
221
func (a *NodeAnnouncement1) SerializedSize() (uint32, error) {
5✔
222
        return MessageSerializedSize(a)
5✔
223
}
5✔
224

225
// NodePub returns the identity public key of the node.
226
//
227
// NOTE: part of the NodeAnnouncement interface.
NEW
228
func (a *NodeAnnouncement1) NodePub() [33]byte {
×
NEW
229
        return a.NodeID
×
NEW
230
}
×
231

232
// NodeFeatures returns the set of features supported by the node.
233
//
234
// NOTE: part of the NodeAnnouncement interface.
NEW
235
func (a *NodeAnnouncement1) NodeFeatures() *FeatureVector {
×
NEW
236
        return NewFeatureVector(a.Features, Features)
×
NEW
237
}
×
238

239
// TimestampDesc returns a human-readable description of the timestamp of the
240
// announcement.
241
//
242
// NOTE: part of the NodeAnnouncement interface.
NEW
243
func (a *NodeAnnouncement1) TimestampDesc() string {
×
NEW
244
        return fmt.Sprintf("timestamp=%d", a.Timestamp)
×
NEW
245
}
×
246

247
// GossipVersion returns the gossip version that this message is part of.
248
//
249
// NOTE: this is part of the GossipMessage interface.
NEW
250
func (a *NodeAnnouncement1) GossipVersion() GossipVersion {
×
NEW
251
        return GossipVersion1
×
NEW
252
}
×
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