lnwire: remove old routing/discovery messages
This commit removes the older routing/discovery messages from the unwire package, as we’ll be converging towards BOLT07 in the near-term. In the mid to far term we’ll be revisiting integrating Flare into the newer scheme in order to take advantage of its scaling characteristics.
This commit is contained in:
parent
afd2323d10
commit
b5dd462e13
@ -65,14 +65,6 @@ func (c CreditsAmount) ToSatoshi() int64 {
|
||||
return int64(c / 1000)
|
||||
}
|
||||
|
||||
type ChannelOperation struct {
|
||||
NodePubKey1, NodePubKey2 [33]byte
|
||||
ChannelId *wire.OutPoint
|
||||
Capacity int64
|
||||
Weight float64
|
||||
Operation byte
|
||||
}
|
||||
|
||||
// writeElement is a one-stop shop to write the big endian representation of
|
||||
// any element which is to be serialized for the wire protocol. The passed
|
||||
// io.Writer should be backed by an appropriatly sized byte slice, or be able
|
||||
@ -304,29 +296,6 @@ func writeElement(w io.Writer, element interface{}) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case []ChannelOperation:
|
||||
err := writeElement(w, uint64(len(e)))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for i := 0; i < len(e); i++ {
|
||||
err := writeElement(w, e[i])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
case ChannelOperation:
|
||||
err := writeElements(w,
|
||||
e.NodePubKey1,
|
||||
e.NodePubKey2,
|
||||
e.ChannelId,
|
||||
e.Capacity,
|
||||
e.Weight,
|
||||
e.Operation,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case ChannelID:
|
||||
// Check that field fit in 3 bytes and write the blockHeight
|
||||
if e.BlockHeight > ((1 << 24) - 1) {
|
||||
@ -645,31 +614,6 @@ func readElement(r io.Reader, element interface{}) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case *[]ChannelOperation:
|
||||
var nChannels uint64
|
||||
err := readElement(r, &nChannels)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*e = make([]ChannelOperation, nChannels)
|
||||
for i := uint64(0); i < nChannels; i++ {
|
||||
err := readElement(r, &((*e)[i]))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
case *ChannelOperation:
|
||||
err := readElements(r,
|
||||
&e.NodePubKey1,
|
||||
&e.NodePubKey2,
|
||||
&e.ChannelId,
|
||||
&e.Capacity,
|
||||
&e.Weight,
|
||||
&e.Operation,
|
||||
)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
case *ChannelID:
|
||||
var blockHeight [4]byte
|
||||
if _, err = io.ReadFull(r, blockHeight[1:]); err != nil {
|
||||
|
@ -44,21 +44,13 @@ const (
|
||||
CmdCommitSignature = uint32(2000)
|
||||
CmdCommitRevocation = uint32(2010)
|
||||
|
||||
// Commands for routing
|
||||
CmdNeighborHelloMessage = uint32(3000)
|
||||
CmdNeighborUpdMessage = uint32(3010)
|
||||
CmdNeighborAckMessage = uint32(3020)
|
||||
CmdNeighborRstMessage = uint32(3030)
|
||||
CmdRoutingTableRequestMessage = uint32(3040)
|
||||
CmdRoutingTableTransferMessage = uint32(3050)
|
||||
|
||||
// Commands for reporting protocol errors.
|
||||
CmdErrorGeneric = uint32(4000)
|
||||
|
||||
// Commands for discovery service.
|
||||
CmdChannelAnnoucmentMessage = uint32(5000)
|
||||
CmdChannelAnnoucmentMessage = uint32(5000)
|
||||
CmdChannelUpdateAnnoucmentMessage = uint32(5010)
|
||||
CmdNodeAnnoucmentMessage = uint32(5020)
|
||||
CmdNodeAnnoucmentMessage = uint32(5020)
|
||||
|
||||
// Commands for connection keep-alive.
|
||||
CmdPing = uint32(6000)
|
||||
@ -111,14 +103,6 @@ func makeEmptyMessage(command uint32) (Message, error) {
|
||||
msg = &CommitRevocation{}
|
||||
case CmdErrorGeneric:
|
||||
msg = &ErrorGeneric{}
|
||||
case CmdNeighborHelloMessage:
|
||||
msg = &NeighborHelloMessage{}
|
||||
case CmdNeighborUpdMessage:
|
||||
msg = &NeighborUpdMessage{}
|
||||
case CmdNeighborAckMessage:
|
||||
msg = &NeighborAckMessage{}
|
||||
case CmdNeighborRstMessage:
|
||||
msg = &NeighborRstMessage{}
|
||||
case CmdChannelAnnoucmentMessage:
|
||||
msg = &ChannelAnnouncement{}
|
||||
case CmdChannelUpdateAnnoucmentMessage:
|
||||
|
@ -1,53 +0,0 @@
|
||||
// Copyright (c) 2016 Bitfury Group Limited
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file LICENSE or http://www.opensource.org/licenses/mit-license.php
|
||||
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"bytes"
|
||||
)
|
||||
|
||||
type NeighborAckMessage struct {
|
||||
}
|
||||
|
||||
func (msg *NeighborAckMessage) String() string {
|
||||
return fmt.Sprintf("NeighborAckMessage{}",)
|
||||
}
|
||||
|
||||
func (msg *NeighborAckMessage) Command() uint32 {
|
||||
return CmdNeighborAckMessage
|
||||
}
|
||||
|
||||
func (msg *NeighborAckMessage) Encode(w io.Writer, pver uint32) error {
|
||||
// Transmission function work incorrect with empty messages so write some random string to make message not empty
|
||||
w.Write([]byte("NeighborAckMessage"))
|
||||
return nil
|
||||
}
|
||||
|
||||
func (msg *NeighborAckMessage) Decode(r io.Reader, pver uint32) error {
|
||||
buff := make([]byte, 18)
|
||||
_, err := r.Read(buff)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !bytes.Equal(buff, []byte("NeighborAckMessage")) {
|
||||
fmt.Errorf("Can't decode NeighborAckMessage message")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (msg *NeighborAckMessage) MaxPayloadLength(uint32) uint32 {
|
||||
// Length of the string "NeighborAckMessage" used in Encode
|
||||
// Transmission functions work bad if it is 0
|
||||
return 18
|
||||
|
||||
}
|
||||
|
||||
func (msg *NeighborAckMessage) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ Message = (*NeighborAckMessage)(nil)
|
@ -1,44 +0,0 @@
|
||||
// Copyright (c) 2016 Bitfury Group Limited
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file LICENSE or http://www.opensource.org/licenses/mit-license.php
|
||||
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
)
|
||||
|
||||
func TestNeighborAckMessageEncodeDecode(t *testing.T) {
|
||||
b := new(bytes.Buffer)
|
||||
msg1 := NeighborAckMessage{}
|
||||
err := msg1.Encode(b, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't encode message ", err)
|
||||
}
|
||||
msg2 := new(NeighborAckMessage)
|
||||
err = msg2.Decode(b, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't decode message ", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNeighborAckMessageReadWrite(t *testing.T){
|
||||
b := new(bytes.Buffer)
|
||||
msg1 := &NeighborAckMessage{}
|
||||
_, err := WriteMessage(b, msg1, 0, wire.SimNet)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't write message %v", err)
|
||||
}
|
||||
_, msg2, _, err := ReadMessage(b, 0, wire.SimNet)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't read message %v", err)
|
||||
}
|
||||
_, ok := msg2.(*NeighborAckMessage)
|
||||
if !ok {
|
||||
t.Fatalf("Can't convert to *NeighborAckMessage")
|
||||
}
|
||||
}
|
||||
|
@ -1,45 +0,0 @@
|
||||
// Copyright (c) 2016 Bitfury Group Limited
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file LICENSE or http://www.opensource.org/licenses/mit-license.php
|
||||
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
type NeighborHelloMessage struct {
|
||||
// List of channels
|
||||
Channels []ChannelOperation
|
||||
}
|
||||
|
||||
func (msg *NeighborHelloMessage) Decode(r io.Reader, pver uint32) error {
|
||||
err := readElements(r, &msg.Channels)
|
||||
return err
|
||||
}
|
||||
|
||||
func (msg *NeighborHelloMessage) Encode(w io.Writer, pver uint32) error {
|
||||
err := writeElement(w, msg.Channels)
|
||||
return err
|
||||
}
|
||||
|
||||
func (msg *NeighborHelloMessage) Command() uint32 {
|
||||
return CmdNeighborHelloMessage
|
||||
}
|
||||
|
||||
func (msg *NeighborHelloMessage) MaxPayloadLength(uint32) uint32 {
|
||||
// TODO: Insert some estimations
|
||||
return 1000000
|
||||
}
|
||||
|
||||
func (msg *NeighborHelloMessage) Validate() error {
|
||||
// TODO: Add validation
|
||||
return nil
|
||||
}
|
||||
|
||||
func (msg *NeighborHelloMessage) String() string {
|
||||
return fmt.Sprintf("NeighborHelloMessage{%v}", msg.Channels)
|
||||
}
|
||||
|
||||
var _ Message = (*NeighborHelloMessage)(nil)
|
@ -1,98 +0,0 @@
|
||||
// Copyright (c) 2016 Bitfury Group Limited
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file LICENSE or http://www.opensource.org/licenses/mit-license.php
|
||||
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
|
||||
func samplePubKey(b byte) [33]byte {
|
||||
var a [33]byte
|
||||
for i:=0; i<33; i++ {
|
||||
a[i] = b
|
||||
}
|
||||
return a
|
||||
}
|
||||
|
||||
func sampleOutPoint(b byte) wire.OutPoint {
|
||||
var w wire.OutPoint
|
||||
for i:=0; i<len(w.Hash); i++ {
|
||||
w.Hash[i] = b
|
||||
}
|
||||
w.Index = uint32(b)
|
||||
return w
|
||||
}
|
||||
|
||||
func genNeighborHelloMessage() *NeighborHelloMessage {
|
||||
p1 := samplePubKey(1)
|
||||
p2 := samplePubKey(2)
|
||||
p3 := samplePubKey(3)
|
||||
e1 := sampleOutPoint(4)
|
||||
e2 := sampleOutPoint(5)
|
||||
|
||||
msg := NeighborHelloMessage{
|
||||
Channels: []ChannelOperation{
|
||||
{
|
||||
NodePubKey1: p1,
|
||||
NodePubKey2: p2,
|
||||
ChannelId: &e1,
|
||||
Capacity: 100000,
|
||||
Weight: 1.0,
|
||||
Operation: 0,
|
||||
},
|
||||
{
|
||||
NodePubKey1: p2,
|
||||
NodePubKey2: p3,
|
||||
ChannelId: &e2,
|
||||
Capacity: 210000,
|
||||
Weight: 2.0,
|
||||
Operation: 0,
|
||||
},
|
||||
},
|
||||
}
|
||||
return &msg
|
||||
}
|
||||
|
||||
func TestNeighborHelloMessageEncodeDecode(t *testing.T) {
|
||||
msg1 := genNeighborHelloMessage()
|
||||
|
||||
b := new(bytes.Buffer)
|
||||
err := msg1.Encode(b, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't encode message ", err)
|
||||
}
|
||||
msg2 := new(NeighborHelloMessage)
|
||||
err = msg2.Decode(b, 0)
|
||||
|
||||
// Assert equality of the two instances.
|
||||
if !reflect.DeepEqual(msg1, msg2) {
|
||||
t.Fatalf("encode/decode error messages don't match %v vs %v",
|
||||
msg1, msg2)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNeighborHelloMessageReadWrite(t *testing.T) {
|
||||
msg1 := genNeighborHelloMessage()
|
||||
|
||||
b := new(bytes.Buffer)
|
||||
_, err := WriteMessage(b, msg1, 0, wire.SimNet)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't write message %v", err)
|
||||
}
|
||||
_, msg2, _, err := ReadMessage(b, 0, wire.SimNet)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't read message %v", err)
|
||||
}
|
||||
|
||||
// Assert equality of the two instances.
|
||||
if !reflect.DeepEqual(msg1, msg2) {
|
||||
t.Fatalf("encode/decode error messages don't match %v vs %v",
|
||||
msg1, msg2)
|
||||
}
|
||||
}
|
@ -1,50 +0,0 @@
|
||||
// Copyright (c) 2016 Bitfury Group Limited
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file LICENSE or http://www.opensource.org/licenses/mit-license.php
|
||||
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
type NeighborRstMessage struct {
|
||||
}
|
||||
|
||||
func (msg *NeighborRstMessage) String() string {
|
||||
return fmt.Sprintf("NeighborRstMessage{}")
|
||||
}
|
||||
|
||||
func (msg *NeighborRstMessage) Command() uint32 {
|
||||
return CmdNeighborRstMessage
|
||||
}
|
||||
|
||||
func (msg *NeighborRstMessage) Encode(w io.Writer, pver uint32) error {
|
||||
_, err := w.Write([]byte("NeighborRstMessage"))
|
||||
return err
|
||||
}
|
||||
|
||||
func (msg *NeighborRstMessage) Decode(r io.Reader, pver uint32) error {
|
||||
// 18 is the length of "NeighborRstMessage"
|
||||
var b [18]byte
|
||||
_, err := r.Read(b[:])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if string(b[:]) != "NeighborRstMessage" {
|
||||
return fmt.Errorf("Incorrect content of NeighborRstMessage")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (msg *NeighborRstMessage) MaxPayloadLength(uint32) uint32 {
|
||||
// 18 is the length of "NeighborRstMessage"
|
||||
return 18
|
||||
}
|
||||
|
||||
func (msg *NeighborRstMessage) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
var _ Message = (*NeighborRstMessage)(nil)
|
@ -1,44 +0,0 @@
|
||||
// Copyright (c) 2016 Bitfury Group Limited
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file LICENSE or http://www.opensource.org/licenses/mit-license.php
|
||||
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
)
|
||||
|
||||
func TestNeighborRstMessageEncodeDecode(t *testing.T) {
|
||||
b := new(bytes.Buffer)
|
||||
msg1 := NeighborRstMessage{}
|
||||
err := msg1.Encode(b, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't encode message ", err)
|
||||
}
|
||||
msg2 := new(NeighborRstMessage)
|
||||
err = msg2.Decode(b, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't decode message %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNeighborRstMessageReadWrite(t *testing.T){
|
||||
b := new(bytes.Buffer)
|
||||
msg1 := &NeighborRstMessage{}
|
||||
_, err := WriteMessage(b, msg1, 0, wire.SimNet)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't write message %v", err)
|
||||
}
|
||||
_, msg2, _, err := ReadMessage(b, 0, wire.SimNet)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't read message %v", err)
|
||||
}
|
||||
_, ok := msg2.(*NeighborRstMessage)
|
||||
if !ok {
|
||||
t.Fatalf("Can't convert to *NeighborRstMessage")
|
||||
}
|
||||
}
|
||||
|
@ -1,44 +0,0 @@
|
||||
// Copyright (c) 2016 Bitfury Group Limited
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file LICENSE or http://www.opensource.org/licenses/mit-license.php
|
||||
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
)
|
||||
|
||||
type NeighborUpdMessage struct {
|
||||
Updates []ChannelOperation
|
||||
}
|
||||
|
||||
func (msg *NeighborUpdMessage) Decode(r io.Reader, pver uint32) error {
|
||||
err := readElements(r, &msg.Updates)
|
||||
return err
|
||||
}
|
||||
|
||||
func (msg *NeighborUpdMessage) Encode(w io.Writer, pver uint32) error {
|
||||
err := writeElements(w, msg.Updates)
|
||||
return err
|
||||
}
|
||||
|
||||
func (msg *NeighborUpdMessage) Command() uint32 {
|
||||
return CmdNeighborUpdMessage
|
||||
}
|
||||
|
||||
func (msg *NeighborUpdMessage) MaxPayloadLength(uint32) uint32 {
|
||||
// TODO: Insert some estimations
|
||||
return 1000000
|
||||
}
|
||||
|
||||
func (msg *NeighborUpdMessage) Validate() error {
|
||||
// TODO: Add validation
|
||||
return nil
|
||||
}
|
||||
|
||||
func (msg *NeighborUpdMessage) String() string {
|
||||
return fmt.Sprintf("NeighborUpdMessage{%v}", msg.Updates)
|
||||
}
|
||||
|
||||
var _ Message = (*NeighborUpdMessage)(nil)
|
@ -1,87 +0,0 @@
|
||||
// Copyright (c) 2016 Bitfury Group Limited
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file LICENSE or http://www.opensource.org/licenses/mit-license.php
|
||||
|
||||
package lnwire
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
|
||||
"github.com/roasbeef/btcd/wire"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
func genNeighborUpdMessage() *NeighborUpdMessage {
|
||||
p1 := samplePubKey(1)
|
||||
p2 := samplePubKey(2)
|
||||
p3 := samplePubKey(3)
|
||||
e1 := sampleOutPoint(4)
|
||||
e2 := sampleOutPoint(5)
|
||||
|
||||
msg := NeighborUpdMessage{
|
||||
Updates: []ChannelOperation{
|
||||
{
|
||||
NodePubKey1: p1,
|
||||
NodePubKey2: p2,
|
||||
ChannelId: &e1,
|
||||
Capacity: 100000,
|
||||
Weight: 1.0,
|
||||
Operation: 0,
|
||||
},
|
||||
{
|
||||
NodePubKey1: p2,
|
||||
NodePubKey2: p3,
|
||||
ChannelId: &e2,
|
||||
Capacity: 210000,
|
||||
Weight: 2.0,
|
||||
Operation: 1,
|
||||
},
|
||||
},
|
||||
}
|
||||
return &msg
|
||||
}
|
||||
|
||||
func TestNeighborUpdMessageEncodeDecode(t *testing.T) {
|
||||
msg1 := genNeighborUpdMessage()
|
||||
b := new(bytes.Buffer)
|
||||
err := msg1.Encode(b, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't encode message: %v", err)
|
||||
}
|
||||
msg2 := new(NeighborUpdMessage)
|
||||
err = msg2.Decode(b, 0)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't decode message: %v", err)
|
||||
}
|
||||
|
||||
// Assert equality of the two instances.
|
||||
if !reflect.DeepEqual(msg1, msg2) {
|
||||
t.Fatalf("encode/decode error messages don't match %v vs %v",
|
||||
msg1, msg2)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestNeighborUpdMessageReadWrite(t *testing.T) {
|
||||
msg1 := genNeighborUpdMessage()
|
||||
b := new(bytes.Buffer)
|
||||
_, err := WriteMessage(b, msg1, 0, wire.SimNet)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't write message %v", err)
|
||||
}
|
||||
_, msg2, _, err := ReadMessage(b, 0, wire.SimNet)
|
||||
if err != nil {
|
||||
t.Fatalf("Can't read message %v", err)
|
||||
}
|
||||
_, ok := msg2.(*NeighborUpdMessage)
|
||||
if !ok {
|
||||
t.Fatalf("Can't convert to *NeighborUpdMessage")
|
||||
}
|
||||
// Assert equality of the two instances.
|
||||
if !reflect.DeepEqual(msg1, msg2) {
|
||||
t.Fatalf("encode/decode error messages don't match %v vs %v",
|
||||
msg1, msg2)
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user