From c0d59a2d858166ea267b7d1d4a46558840a8711f Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 11 Aug 2016 11:54:44 -0700 Subject: [PATCH] lnwire: rename routing files to match current naming conventions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit drops the “_message” at the end of each of the newly added routing files. --- ...eighbor_ack_message.go => neighbor_ack.go} | 13 ++++++----- ...bor_hello_message.go => neighbor_hello.go} | 22 +++++++++---------- ...message_test.go => neighbor_hello_test.go} | 19 ++++++++-------- ...eighbor_rst_message.go => neighbor_rst.go} | 13 ++++++----- ...eighbor_upd_message.go => neighbor_upd.go} | 17 +++++++------- lnwire/routing_messages.go | 13 ++++++++--- ...st_message.go => routing_table_request.go} | 14 ++++++------ ...r_message.go => routing_table_transfer.go} | 17 +++++++------- 8 files changed, 69 insertions(+), 59 deletions(-) rename lnwire/{neighbor_ack_message.go => neighbor_ack.go} (73%) rename lnwire/{neighbor_hello_message.go => neighbor_hello.go} (78%) rename lnwire/{neighbor_hello_message_test.go => neighbor_hello_test.go} (78%) rename lnwire/{neighbor_rst_message.go => neighbor_rst.go} (73%) rename lnwire/{neighbor_upd_message.go => neighbor_upd.go} (81%) rename lnwire/{routing_table_request_message.go => routing_table_request.go} (77%) rename lnwire/{routing_table_transfer_message.go => routing_table_transfer.go} (82%) diff --git a/lnwire/neighbor_ack_message.go b/lnwire/neighbor_ack.go similarity index 73% rename from lnwire/neighbor_ack_message.go rename to lnwire/neighbor_ack.go index 2a4e30b5..d1fa13fe 100644 --- a/lnwire/neighbor_ack_message.go +++ b/lnwire/neighbor_ack.go @@ -3,6 +3,7 @@ // file LICENSE or http://www.opensource.org/licenses/mit-license.php package lnwire + import ( "fmt" "io" @@ -16,24 +17,24 @@ func (msg *NeighborAckMessage) String() string { return fmt.Sprintf("NeighborAckMessage{%v %v}", msg.SenderID, msg.ReceiverID) } -func (msg *NeighborAckMessage) Command() uint32{ +func (msg *NeighborAckMessage) Command() uint32 { return CmdNeighborAckMessage } -func (msg *NeighborAckMessage) Encode(w io.Writer, pver uint32) error{ +func (msg *NeighborAckMessage) Encode(w io.Writer, pver uint32) error { return nil } -func (msg *NeighborAckMessage) Decode(r io.Reader, pver uint32) error{ +func (msg *NeighborAckMessage) Decode(r io.Reader, pver uint32) error { return nil } -func (msg *NeighborAckMessage) MaxPayloadLength(uint32) uint32{ +func (msg *NeighborAckMessage) MaxPayloadLength(uint32) uint32 { return 0 } -func (msg *NeighborAckMessage) Validate() error{ +func (msg *NeighborAckMessage) Validate() error { return nil } -var _ Message = (*NeighborAckMessage)(nil) \ No newline at end of file +var _ Message = (*NeighborAckMessage)(nil) diff --git a/lnwire/neighbor_hello_message.go b/lnwire/neighbor_hello.go similarity index 78% rename from lnwire/neighbor_hello_message.go rename to lnwire/neighbor_hello.go index dbe16f2a..d26a2352 100644 --- a/lnwire/neighbor_hello_message.go +++ b/lnwire/neighbor_hello.go @@ -5,18 +5,19 @@ package lnwire import ( - "io" - "github.com/BitfuryLightning/tools/rt" "encoding/gob" "fmt" + "io" + + "github.com/BitfuryLightning/tools/rt" ) -type NeighborHelloMessage struct{ +type NeighborHelloMessage struct { RoutingMessageBase RT *rt.RoutingTable } -func (msg *NeighborHelloMessage) Decode(r io.Reader, pver uint32) error{ +func (msg *NeighborHelloMessage) Decode(r io.Reader, pver uint32) error { decoder := gob.NewDecoder(r) rt1 := rt.NewRoutingTable() err := decoder.Decode(rt1.G) @@ -24,29 +25,28 @@ func (msg *NeighborHelloMessage) Decode(r io.Reader, pver uint32) error{ return err } -func (msg *NeighborHelloMessage) Encode(w io.Writer, pver uint32) error{ +func (msg *NeighborHelloMessage) Encode(w io.Writer, pver uint32) error { encoder := gob.NewEncoder(w) err := encoder.Encode(msg.RT.G) return err } -func (msg *NeighborHelloMessage) Command() uint32{ +func (msg *NeighborHelloMessage) Command() uint32 { return CmdNeighborHelloMessage } -func (msg *NeighborHelloMessage) MaxPayloadLength(uint32) uint32{ +func (msg *NeighborHelloMessage) MaxPayloadLength(uint32) uint32 { // TODO: Insert some estimations return 1000000 } -func (msg *NeighborHelloMessage) Validate() error{ +func (msg *NeighborHelloMessage) Validate() error { // TODO: Add validation return nil } -func (msg *NeighborHelloMessage) String() string{ +func (msg *NeighborHelloMessage) String() string { return fmt.Sprintf("NeighborHelloMessage{%v %v %v}", msg.SenderID, msg.ReceiverID, msg.RT) } - -var _ Message = (*NeighborHelloMessage)(nil) +var _ Message = (*NeighborHelloMessage)(nil) diff --git a/lnwire/neighbor_hello_message_test.go b/lnwire/neighbor_hello_test.go similarity index 78% rename from lnwire/neighbor_hello_message_test.go rename to lnwire/neighbor_hello_test.go index 30964cd4..25285979 100644 --- a/lnwire/neighbor_hello_message_test.go +++ b/lnwire/neighbor_hello_test.go @@ -5,37 +5,36 @@ package lnwire import ( - "testing" "bytes" + "testing" + "github.com/BitfuryLightning/tools/rt" "github.com/BitfuryLightning/tools/rt/graph" ) -func TestNeighborHelloMessageEncodeDecode(t *testing.T){ +func TestNeighborHelloMessageEncodeDecode(t *testing.T) { Id1 := graph.NewID(1) Id2 := graph.NewID(2) rt1 := rt.NewRoutingTable() rt1.AddChannel(Id1, Id2, graph.NewEdgeID("1"), &rt.ChannelInfo{1, 1}) b := new(bytes.Buffer) - msg1 := NeighborHelloMessage{RT:rt1} + msg1 := NeighborHelloMessage{RT: rt1} err := msg1.Encode(b, 0) - if err != nil{ + if err != nil { t.Fatalf("Can't encode message ", err) } msg2 := new(NeighborHelloMessage) err = msg2.Decode(b, 0) - if err != nil{ + if err != nil { t.Fatalf("Can't decode message ", err) } - if msg2.RT == nil{ + if msg2.RT == nil { t.Fatal("After decoding RT should not be nil") } - if !msg2.RT.HasChannel(Id1, Id2, nil){ + if !msg2.RT.HasChannel(Id1, Id2, nil) { t.Errorf("msg2.RT.HasChannel(Id1, Id2) = false, want true") } - if !msg2.RT.HasChannel(Id2, Id1, nil){ + if !msg2.RT.HasChannel(Id2, Id1, nil) { t.Errorf("msg2.RT.HasChannel(Id2, Id1) = false, want true") } } - - diff --git a/lnwire/neighbor_rst_message.go b/lnwire/neighbor_rst.go similarity index 73% rename from lnwire/neighbor_rst_message.go rename to lnwire/neighbor_rst.go index 5f3f4f40..f04421e4 100644 --- a/lnwire/neighbor_rst_message.go +++ b/lnwire/neighbor_rst.go @@ -3,6 +3,7 @@ // file LICENSE or http://www.opensource.org/licenses/mit-license.php package lnwire + import ( "fmt" "io" @@ -16,24 +17,24 @@ func (msg *NeighborRstMessage) String() string { return fmt.Sprintf("NeighborRstMessage{%v %v}", msg.SenderID, msg.ReceiverID) } -func (msg *NeighborRstMessage) Command() uint32{ +func (msg *NeighborRstMessage) Command() uint32 { return CmdNeighborRstMessage } -func (msg *NeighborRstMessage) Encode(w io.Writer, pver uint32) error{ +func (msg *NeighborRstMessage) Encode(w io.Writer, pver uint32) error { return nil } -func (msg *NeighborRstMessage) Decode(r io.Reader, pver uint32) error{ +func (msg *NeighborRstMessage) Decode(r io.Reader, pver uint32) error { return nil } -func (msg *NeighborRstMessage) MaxPayloadLength(uint32) uint32{ +func (msg *NeighborRstMessage) MaxPayloadLength(uint32) uint32 { return 0 } -func (msg *NeighborRstMessage) Validate() error{ +func (msg *NeighborRstMessage) Validate() error { return nil } -var _ Message = (*NeighborRstMessage)(nil) \ No newline at end of file +var _ Message = (*NeighborRstMessage)(nil) diff --git a/lnwire/neighbor_upd_message.go b/lnwire/neighbor_upd.go similarity index 81% rename from lnwire/neighbor_upd_message.go rename to lnwire/neighbor_upd.go index fb1cd122..59ff781a 100644 --- a/lnwire/neighbor_upd_message.go +++ b/lnwire/neighbor_upd.go @@ -5,10 +5,11 @@ package lnwire import ( - "fmt" - "github.com/BitfuryLightning/tools/rt" "encoding/gob" + "fmt" "io" + + "github.com/BitfuryLightning/tools/rt" ) type NeighborUpdMessage struct { @@ -16,7 +17,7 @@ type NeighborUpdMessage struct { DiffBuff *rt.DifferenceBuffer } -func (msg *NeighborUpdMessage) Decode(r io.Reader, pver uint32) error{ +func (msg *NeighborUpdMessage) Decode(r io.Reader, pver uint32) error { decoder := gob.NewDecoder(r) diffBuff := new(rt.DifferenceBuffer) err := decoder.Decode(diffBuff) @@ -24,22 +25,22 @@ func (msg *NeighborUpdMessage) Decode(r io.Reader, pver uint32) error{ return err } -func (msg *NeighborUpdMessage) Encode(w io.Writer, pver uint32) error{ +func (msg *NeighborUpdMessage) Encode(w io.Writer, pver uint32) error { encoder := gob.NewEncoder(w) err := encoder.Encode(msg.DiffBuff) return err } -func (msg *NeighborUpdMessage) Command() uint32{ +func (msg *NeighborUpdMessage) Command() uint32 { return CmdNeighborUpdMessage } -func (msg *NeighborUpdMessage) MaxPayloadLength(uint32) uint32{ +func (msg *NeighborUpdMessage) MaxPayloadLength(uint32) uint32 { // TODO: Insert some estimations return 1000000 } -func (msg *NeighborUpdMessage) Validate() error{ +func (msg *NeighborUpdMessage) Validate() error { // TODO: Add validation return nil } @@ -48,4 +49,4 @@ func (msg *NeighborUpdMessage) String() string { return fmt.Sprintf("NeighborUpdMessage{%v %v %v}", msg.SenderID, msg.ReceiverID, *msg.DiffBuff) } -var _ Message = (*NeighborUpdMessage)(nil) \ No newline at end of file +var _ Message = (*NeighborUpdMessage)(nil) diff --git a/lnwire/routing_messages.go b/lnwire/routing_messages.go index 6e09eddf..be67f98c 100644 --- a/lnwire/routing_messages.go +++ b/lnwire/routing_messages.go @@ -8,20 +8,27 @@ import ( "github.com/BitfuryLightning/tools/rt/graph" ) +// RoutingMessageBase is the base struct for all routing messages within the +// lnwire package. type RoutingMessageBase struct { + // SenderID is the ID of the sender of the routing message. SenderID graph.ID + + // ReceiverID is the ID of the receiver of the routig message. ReceiverID graph.ID } -func (msg RoutingMessageBase) GetReceiverID() graph.ID{ +// GetReceiverID returns the ID of the receiver of routing message. +func (msg RoutingMessageBase) GetReceiverID() graph.ID { return msg.ReceiverID } -func (msg RoutingMessageBase) GetSenderID() graph.ID{ +// GetSenderID returns the ID of the sender of the routing message. +func (msg RoutingMessageBase) GetSenderID() graph.ID { return msg.SenderID } -// Interface for all routing messages. All messages have sender and receiver +// RoutingMessageBase is a shared interface for all routing messages. type RoutingMessage interface { GetSenderID() graph.ID GetReceiverID() graph.ID diff --git a/lnwire/routing_table_request_message.go b/lnwire/routing_table_request.go similarity index 77% rename from lnwire/routing_table_request_message.go rename to lnwire/routing_table_request.go index 9656ea35..4780d89f 100644 --- a/lnwire/routing_table_request_message.go +++ b/lnwire/routing_table_request.go @@ -3,6 +3,7 @@ // file LICENSE or http://www.opensource.org/licenses/mit-license.php package lnwire + import ( "fmt" "io" @@ -16,25 +17,24 @@ func (msg *RoutingTableRequestMessage) String() string { return fmt.Sprintf("RoutingTableRequestMessage{%v %v}", msg.SenderID, msg.ReceiverID) } - -func (msg *RoutingTableRequestMessage) Command() uint32{ +func (msg *RoutingTableRequestMessage) Command() uint32 { return CmdRoutingTableRequestMessage } -func (msg *RoutingTableRequestMessage) Encode(w io.Writer, pver uint32) error{ +func (msg *RoutingTableRequestMessage) Encode(w io.Writer, pver uint32) error { return nil } -func (msg *RoutingTableRequestMessage) Decode(r io.Reader, pver uint32) error{ +func (msg *RoutingTableRequestMessage) Decode(r io.Reader, pver uint32) error { return nil } -func (msg *RoutingTableRequestMessage) MaxPayloadLength(uint32) uint32{ +func (msg *RoutingTableRequestMessage) MaxPayloadLength(uint32) uint32 { return 0 } -func (msg *RoutingTableRequestMessage) Validate() error{ +func (msg *RoutingTableRequestMessage) Validate() error { return nil } -var _ Message = (*RoutingTableRequestMessage)(nil) \ No newline at end of file +var _ Message = (*RoutingTableRequestMessage)(nil) diff --git a/lnwire/routing_table_transfer_message.go b/lnwire/routing_table_transfer.go similarity index 82% rename from lnwire/routing_table_transfer_message.go rename to lnwire/routing_table_transfer.go index 529cf010..b4138dce 100644 --- a/lnwire/routing_table_transfer_message.go +++ b/lnwire/routing_table_transfer.go @@ -5,10 +5,11 @@ package lnwire import ( - "io" - "github.com/BitfuryLightning/tools/rt" "encoding/gob" "fmt" + "io" + + "github.com/BitfuryLightning/tools/rt" ) type RoutingTableTransferMessage struct { @@ -20,7 +21,7 @@ func (msg *RoutingTableTransferMessage) String() string { return fmt.Sprintf("RoutingTableTransferMessage{%v %v %v}", msg.SenderID, msg.ReceiverID, msg.RT) } -func (msg *RoutingTableTransferMessage) Decode(r io.Reader, pver uint32) error{ +func (msg *RoutingTableTransferMessage) Decode(r io.Reader, pver uint32) error { decoder := gob.NewDecoder(r) rt1 := rt.NewRoutingTable() err := decoder.Decode(rt1.G) @@ -28,24 +29,24 @@ func (msg *RoutingTableTransferMessage) Decode(r io.Reader, pver uint32) error{ return err } -func (msg *RoutingTableTransferMessage) Encode(w io.Writer, pver uint32) error{ +func (msg *RoutingTableTransferMessage) Encode(w io.Writer, pver uint32) error { encoder := gob.NewEncoder(w) err := encoder.Encode(msg.RT.G) return err } -func (msg *RoutingTableTransferMessage) Command() uint32{ +func (msg *RoutingTableTransferMessage) Command() uint32 { return CmdRoutingTableTransferMessage } -func (msg *RoutingTableTransferMessage) MaxPayloadLength(uint32) uint32{ +func (msg *RoutingTableTransferMessage) MaxPayloadLength(uint32) uint32 { // TODO: Insert some estimations return 1000000 } -func (msg *RoutingTableTransferMessage) Validate() error{ +func (msg *RoutingTableTransferMessage) Validate() error { // TODO: Add validation return nil } -var _ Message = (*RoutingTableTransferMessage)(nil) +var _ Message = (*RoutingTableTransferMessage)(nil)