Skip to content

Commit

Permalink
lnwire: add NodeAnnouncement2
Browse files Browse the repository at this point in the history
  • Loading branch information
ellemouton committed Dec 4, 2023
1 parent 3ec46aa commit 7d3db71
Show file tree
Hide file tree
Showing 3 changed files with 633 additions and 0 deletions.
73 changes: 73 additions & 0 deletions lnwire/lnwire_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lnwire

import (
"bytes"
"encoding/base64"
"encoding/binary"
"encoding/hex"
"fmt"
Expand Down Expand Up @@ -1347,6 +1348,72 @@ func TestLightningWireProtocol(t *testing.T) {
require.NoError(t, err)
}
},
MsgNodeAnnouncement2: func(v []reflect.Value, r *rand.Rand) {
req := NodeAnnouncement2{
Signature: testSchnorrSig,
BlockHeight: r.Uint32(),
NodeID: randRawKey(t),
ExtraOpaqueData: make([]byte, 0),
}

features := randRawFeatureVector(r)
req.Features = *features

// Sometimes set the colour field.
if r.Int31()%2 == 0 {
req.RGBColor = fn.Some(color.RGBA{
R: uint8(r.Int31()),
G: uint8(r.Int31()),
B: uint8(r.Int31()),
})
}

n := r.Intn(33)
b := make([]byte, n)
_, err := rand.Read(b)
require.NoError(t, err)

if n > 0 {
req.Alias = []byte(
base64.StdEncoding.EncodeToString(b),
)
if len(req.Alias) > 32 {
req.Alias = req.Alias[:32]
}
}

// Sometimes add some ipv4 addrs.
if r.Int31()%2 == 0 {
ipv4Addr, err := randTCP4Addr(r)
require.NoError(t, err)
req.Addresses = append(req.Addresses, ipv4Addr)
}

// Sometimes add some ipv6 addrs.
if r.Int31()%2 == 0 {
ipv6Addr, err := randTCP6Addr(r)
require.NoError(t, err)
req.Addresses = append(req.Addresses, ipv6Addr)
}

// Sometimes add some torv3 addrs.
if r.Int31()%2 == 0 {
ipv6Addr, err := randV3OnionAddr(r)
require.NoError(t, err)
req.Addresses = append(req.Addresses, ipv6Addr)
}

numExtraBytes := r.Int31n(1000)
if numExtraBytes > 0 {
req.ExtraOpaqueData = make(
[]byte, numExtraBytes,
)
_, err := r.Read(req.ExtraOpaqueData[:])
require.NoError(t, err)
}

v[0] = reflect.ValueOf(req)
},
}

// With the above types defined, we'll now generate a slice of
Expand Down Expand Up @@ -1569,6 +1636,12 @@ func TestLightningWireProtocol(t *testing.T) {
return mainScenario(&m)
},
},
{
msgType: MsgNodeAnnouncement2,
scenario: func(m NodeAnnouncement2) bool {
return mainScenario(&m)
},
},
}
for _, test := range tests {
var config *quick.Config
Expand Down
5 changes: 5 additions & 0 deletions lnwire/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
MsgReplyChannelRange = 264
MsgGossipTimestampRange = 265
MsgChannelAnnouncement2 = 267
MsgNodeAnnouncement2 = 269
MsgChannelUpdate2 = 271
MsgKickoffSig = 777
)
Expand Down Expand Up @@ -155,6 +156,8 @@ func (t MessageType) String() string {
return "ChannelAnnouncement2"
case MsgChannelUpdate2:
return "ChannelUpdate2"
case MsgNodeAnnouncement2:
return "NodeAnnouncement2"
default:
return "<unknown>"
}
Expand Down Expand Up @@ -271,6 +274,8 @@ func makeEmptyMessage(msgType MessageType) (Message, error) {
msg = &ChannelAnnouncement2{}
case MsgChannelUpdate2:
msg = &ChannelUpdate2{}
case MsgNodeAnnouncement2:
msg = &NodeAnnouncement2{}
default:
// If the message is not within our custom range and has not
// specifically been overridden, return an unknown message.
Expand Down
Loading

0 comments on commit 7d3db71

Please sign in to comment.