From b5dd462e13ea3e3f85445843c2c90139b5d11a2d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Mon, 26 Dec 2016 22:08:54 -0600 Subject: [PATCH] lnwire: remove old routing/discovery messages MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- lnwire/lnwire.go | 56 -------------------- lnwire/message.go | 20 +------ lnwire/neighbor_ack.go | 53 ------------------- lnwire/neighbor_ack_test.go | 44 ---------------- lnwire/neighbor_hello.go | 45 ---------------- lnwire/neighbor_hello_test.go | 98 ----------------------------------- lnwire/neighbor_rst.go | 50 ------------------ lnwire/neighbor_rst_test.go | 44 ---------------- lnwire/neighbor_upd.go | 44 ---------------- lnwire/neighbor_upd_test.go | 87 ------------------------------- 10 files changed, 2 insertions(+), 539 deletions(-) delete mode 100644 lnwire/neighbor_ack.go delete mode 100644 lnwire/neighbor_ack_test.go delete mode 100644 lnwire/neighbor_hello.go delete mode 100644 lnwire/neighbor_hello_test.go delete mode 100644 lnwire/neighbor_rst.go delete mode 100644 lnwire/neighbor_rst_test.go delete mode 100644 lnwire/neighbor_upd.go delete mode 100644 lnwire/neighbor_upd_test.go diff --git a/lnwire/lnwire.go b/lnwire/lnwire.go index 802a0444d..8c161a927 100644 --- a/lnwire/lnwire.go +++ b/lnwire/lnwire.go @@ -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 { diff --git a/lnwire/message.go b/lnwire/message.go index 266c74054..d0040f100 100644 --- a/lnwire/message.go +++ b/lnwire/message.go @@ -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: diff --git a/lnwire/neighbor_ack.go b/lnwire/neighbor_ack.go deleted file mode 100644 index c28883250..000000000 --- a/lnwire/neighbor_ack.go +++ /dev/null @@ -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) diff --git a/lnwire/neighbor_ack_test.go b/lnwire/neighbor_ack_test.go deleted file mode 100644 index 6e921d724..000000000 --- a/lnwire/neighbor_ack_test.go +++ /dev/null @@ -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") - } -} - diff --git a/lnwire/neighbor_hello.go b/lnwire/neighbor_hello.go deleted file mode 100644 index 118b16781..000000000 --- a/lnwire/neighbor_hello.go +++ /dev/null @@ -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) diff --git a/lnwire/neighbor_hello_test.go b/lnwire/neighbor_hello_test.go deleted file mode 100644 index 6f2c79f66..000000000 --- a/lnwire/neighbor_hello_test.go +++ /dev/null @@ -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