lnwire: rename routing files to match current naming conventions

This commit drops the “_message” at the end of each of the newly added
routing files.
This commit is contained in:
Olaoluwa Osuntokun 2016-08-11 11:54:44 -07:00
parent 3563d0e6b9
commit c0d59a2d85
No known key found for this signature in database
GPG Key ID: 9CC5B105D03521A2
8 changed files with 69 additions and 59 deletions

@ -3,6 +3,7 @@
// file LICENSE or http://www.opensource.org/licenses/mit-license.php // file LICENSE or http://www.opensource.org/licenses/mit-license.php
package lnwire package lnwire
import ( import (
"fmt" "fmt"
"io" "io"
@ -16,23 +17,23 @@ func (msg *NeighborAckMessage) String() string {
return fmt.Sprintf("NeighborAckMessage{%v %v}", msg.SenderID, msg.ReceiverID) return fmt.Sprintf("NeighborAckMessage{%v %v}", msg.SenderID, msg.ReceiverID)
} }
func (msg *NeighborAckMessage) Command() uint32{ func (msg *NeighborAckMessage) Command() uint32 {
return CmdNeighborAckMessage return CmdNeighborAckMessage
} }
func (msg *NeighborAckMessage) Encode(w io.Writer, pver uint32) error{ func (msg *NeighborAckMessage) Encode(w io.Writer, pver uint32) error {
return nil return nil
} }
func (msg *NeighborAckMessage) Decode(r io.Reader, pver uint32) error{ func (msg *NeighborAckMessage) Decode(r io.Reader, pver uint32) error {
return nil return nil
} }
func (msg *NeighborAckMessage) MaxPayloadLength(uint32) uint32{ func (msg *NeighborAckMessage) MaxPayloadLength(uint32) uint32 {
return 0 return 0
} }
func (msg *NeighborAckMessage) Validate() error{ func (msg *NeighborAckMessage) Validate() error {
return nil return nil
} }

@ -5,18 +5,19 @@
package lnwire package lnwire
import ( import (
"io"
"github.com/BitfuryLightning/tools/rt"
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"io"
"github.com/BitfuryLightning/tools/rt"
) )
type NeighborHelloMessage struct{ type NeighborHelloMessage struct {
RoutingMessageBase RoutingMessageBase
RT *rt.RoutingTable 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) decoder := gob.NewDecoder(r)
rt1 := rt.NewRoutingTable() rt1 := rt.NewRoutingTable()
err := decoder.Decode(rt1.G) err := decoder.Decode(rt1.G)
@ -24,29 +25,28 @@ func (msg *NeighborHelloMessage) Decode(r io.Reader, pver uint32) error{
return err 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) encoder := gob.NewEncoder(w)
err := encoder.Encode(msg.RT.G) err := encoder.Encode(msg.RT.G)
return err return err
} }
func (msg *NeighborHelloMessage) Command() uint32{ func (msg *NeighborHelloMessage) Command() uint32 {
return CmdNeighborHelloMessage return CmdNeighborHelloMessage
} }
func (msg *NeighborHelloMessage) MaxPayloadLength(uint32) uint32{ func (msg *NeighborHelloMessage) MaxPayloadLength(uint32) uint32 {
// TODO: Insert some estimations // TODO: Insert some estimations
return 1000000 return 1000000
} }
func (msg *NeighborHelloMessage) Validate() error{ func (msg *NeighborHelloMessage) Validate() error {
// TODO: Add validation // TODO: Add validation
return nil 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) return fmt.Sprintf("NeighborHelloMessage{%v %v %v}", msg.SenderID, msg.ReceiverID, msg.RT)
} }
var _ Message = (*NeighborHelloMessage)(nil) var _ Message = (*NeighborHelloMessage)(nil)

@ -5,37 +5,36 @@
package lnwire package lnwire
import ( import (
"testing"
"bytes" "bytes"
"testing"
"github.com/BitfuryLightning/tools/rt" "github.com/BitfuryLightning/tools/rt"
"github.com/BitfuryLightning/tools/rt/graph" "github.com/BitfuryLightning/tools/rt/graph"
) )
func TestNeighborHelloMessageEncodeDecode(t *testing.T){ func TestNeighborHelloMessageEncodeDecode(t *testing.T) {
Id1 := graph.NewID(1) Id1 := graph.NewID(1)
Id2 := graph.NewID(2) Id2 := graph.NewID(2)
rt1 := rt.NewRoutingTable() rt1 := rt.NewRoutingTable()
rt1.AddChannel(Id1, Id2, graph.NewEdgeID("1"), &rt.ChannelInfo{1, 1}) rt1.AddChannel(Id1, Id2, graph.NewEdgeID("1"), &rt.ChannelInfo{1, 1})
b := new(bytes.Buffer) b := new(bytes.Buffer)
msg1 := NeighborHelloMessage{RT:rt1} msg1 := NeighborHelloMessage{RT: rt1}
err := msg1.Encode(b, 0) err := msg1.Encode(b, 0)
if err != nil{ if err != nil {
t.Fatalf("Can't encode message ", err) t.Fatalf("Can't encode message ", err)
} }
msg2 := new(NeighborHelloMessage) msg2 := new(NeighborHelloMessage)
err = msg2.Decode(b, 0) err = msg2.Decode(b, 0)
if err != nil{ if err != nil {
t.Fatalf("Can't decode message ", err) t.Fatalf("Can't decode message ", err)
} }
if msg2.RT == nil{ if msg2.RT == nil {
t.Fatal("After decoding RT should not be 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") 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") t.Errorf("msg2.RT.HasChannel(Id2, Id1) = false, want true")
} }
} }

@ -3,6 +3,7 @@
// file LICENSE or http://www.opensource.org/licenses/mit-license.php // file LICENSE or http://www.opensource.org/licenses/mit-license.php
package lnwire package lnwire
import ( import (
"fmt" "fmt"
"io" "io"
@ -16,23 +17,23 @@ func (msg *NeighborRstMessage) String() string {
return fmt.Sprintf("NeighborRstMessage{%v %v}", msg.SenderID, msg.ReceiverID) return fmt.Sprintf("NeighborRstMessage{%v %v}", msg.SenderID, msg.ReceiverID)
} }
func (msg *NeighborRstMessage) Command() uint32{ func (msg *NeighborRstMessage) Command() uint32 {
return CmdNeighborRstMessage return CmdNeighborRstMessage
} }
func (msg *NeighborRstMessage) Encode(w io.Writer, pver uint32) error{ func (msg *NeighborRstMessage) Encode(w io.Writer, pver uint32) error {
return nil return nil
} }
func (msg *NeighborRstMessage) Decode(r io.Reader, pver uint32) error{ func (msg *NeighborRstMessage) Decode(r io.Reader, pver uint32) error {
return nil return nil
} }
func (msg *NeighborRstMessage) MaxPayloadLength(uint32) uint32{ func (msg *NeighborRstMessage) MaxPayloadLength(uint32) uint32 {
return 0 return 0
} }
func (msg *NeighborRstMessage) Validate() error{ func (msg *NeighborRstMessage) Validate() error {
return nil return nil
} }

@ -5,10 +5,11 @@
package lnwire package lnwire
import ( import (
"fmt"
"github.com/BitfuryLightning/tools/rt"
"encoding/gob" "encoding/gob"
"fmt"
"io" "io"
"github.com/BitfuryLightning/tools/rt"
) )
type NeighborUpdMessage struct { type NeighborUpdMessage struct {
@ -16,7 +17,7 @@ type NeighborUpdMessage struct {
DiffBuff *rt.DifferenceBuffer 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) decoder := gob.NewDecoder(r)
diffBuff := new(rt.DifferenceBuffer) diffBuff := new(rt.DifferenceBuffer)
err := decoder.Decode(diffBuff) err := decoder.Decode(diffBuff)
@ -24,22 +25,22 @@ func (msg *NeighborUpdMessage) Decode(r io.Reader, pver uint32) error{
return err 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) encoder := gob.NewEncoder(w)
err := encoder.Encode(msg.DiffBuff) err := encoder.Encode(msg.DiffBuff)
return err return err
} }
func (msg *NeighborUpdMessage) Command() uint32{ func (msg *NeighborUpdMessage) Command() uint32 {
return CmdNeighborUpdMessage return CmdNeighborUpdMessage
} }
func (msg *NeighborUpdMessage) MaxPayloadLength(uint32) uint32{ func (msg *NeighborUpdMessage) MaxPayloadLength(uint32) uint32 {
// TODO: Insert some estimations // TODO: Insert some estimations
return 1000000 return 1000000
} }
func (msg *NeighborUpdMessage) Validate() error{ func (msg *NeighborUpdMessage) Validate() error {
// TODO: Add validation // TODO: Add validation
return nil return nil
} }

@ -8,20 +8,27 @@ import (
"github.com/BitfuryLightning/tools/rt/graph" "github.com/BitfuryLightning/tools/rt/graph"
) )
// RoutingMessageBase is the base struct for all routing messages within the
// lnwire package.
type RoutingMessageBase struct { type RoutingMessageBase struct {
// SenderID is the ID of the sender of the routing message.
SenderID graph.ID SenderID graph.ID
// ReceiverID is the ID of the receiver of the routig message.
ReceiverID graph.ID 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 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 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 { type RoutingMessage interface {
GetSenderID() graph.ID GetSenderID() graph.ID
GetReceiverID() graph.ID GetReceiverID() graph.ID

@ -3,6 +3,7 @@
// file LICENSE or http://www.opensource.org/licenses/mit-license.php // file LICENSE or http://www.opensource.org/licenses/mit-license.php
package lnwire package lnwire
import ( import (
"fmt" "fmt"
"io" "io"
@ -16,24 +17,23 @@ func (msg *RoutingTableRequestMessage) String() string {
return fmt.Sprintf("RoutingTableRequestMessage{%v %v}", msg.SenderID, msg.ReceiverID) return fmt.Sprintf("RoutingTableRequestMessage{%v %v}", msg.SenderID, msg.ReceiverID)
} }
func (msg *RoutingTableRequestMessage) Command() uint32 {
func (msg *RoutingTableRequestMessage) Command() uint32{
return CmdRoutingTableRequestMessage return CmdRoutingTableRequestMessage
} }
func (msg *RoutingTableRequestMessage) Encode(w io.Writer, pver uint32) error{ func (msg *RoutingTableRequestMessage) Encode(w io.Writer, pver uint32) error {
return nil return nil
} }
func (msg *RoutingTableRequestMessage) Decode(r io.Reader, pver uint32) error{ func (msg *RoutingTableRequestMessage) Decode(r io.Reader, pver uint32) error {
return nil return nil
} }
func (msg *RoutingTableRequestMessage) MaxPayloadLength(uint32) uint32{ func (msg *RoutingTableRequestMessage) MaxPayloadLength(uint32) uint32 {
return 0 return 0
} }
func (msg *RoutingTableRequestMessage) Validate() error{ func (msg *RoutingTableRequestMessage) Validate() error {
return nil return nil
} }

@ -5,10 +5,11 @@
package lnwire package lnwire
import ( import (
"io"
"github.com/BitfuryLightning/tools/rt"
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"io"
"github.com/BitfuryLightning/tools/rt"
) )
type RoutingTableTransferMessage struct { 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) 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) decoder := gob.NewDecoder(r)
rt1 := rt.NewRoutingTable() rt1 := rt.NewRoutingTable()
err := decoder.Decode(rt1.G) err := decoder.Decode(rt1.G)
@ -28,22 +29,22 @@ func (msg *RoutingTableTransferMessage) Decode(r io.Reader, pver uint32) error{
return err 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) encoder := gob.NewEncoder(w)
err := encoder.Encode(msg.RT.G) err := encoder.Encode(msg.RT.G)
return err return err
} }
func (msg *RoutingTableTransferMessage) Command() uint32{ func (msg *RoutingTableTransferMessage) Command() uint32 {
return CmdRoutingTableTransferMessage return CmdRoutingTableTransferMessage
} }
func (msg *RoutingTableTransferMessage) MaxPayloadLength(uint32) uint32{ func (msg *RoutingTableTransferMessage) MaxPayloadLength(uint32) uint32 {
// TODO: Insert some estimations // TODO: Insert some estimations
return 1000000 return 1000000
} }
func (msg *RoutingTableTransferMessage) Validate() error{ func (msg *RoutingTableTransferMessage) Validate() error {
// TODO: Add validation // TODO: Add validation
return nil return nil
} }