routing: Fix bugs with not sending routing messages
LIGHT-138, LIGHT-141. Due to some issues in sending/receiving parts of lnd, messages with zero length are not sent. So added some mock content to NeighborAck. Moved sender/receiver from routing message to wrap message which contains lnwire routing message.
This commit is contained in:
parent
b5f07ede46
commit
d8bceb16f9
@ -585,10 +585,9 @@ func (f *fundingManager) handleFundingSignComplete(fmsg *fundingSignCompleteMsg)
|
|||||||
// finding.
|
// finding.
|
||||||
chanInfo := openChan.StateSnapshot()
|
chanInfo := openChan.StateSnapshot()
|
||||||
capacity := float64(chanInfo.Capacity)
|
capacity := float64(chanInfo.Capacity)
|
||||||
fmsg.peer.server.routingMgr.AddChannel(
|
fmsg.peer.server.routingMgr.OpenChannel(
|
||||||
graph.NewID(fmsg.peer.server.lightningID),
|
|
||||||
graph.NewID(chanInfo.RemoteID),
|
graph.NewID(chanInfo.RemoteID),
|
||||||
graph.NewEdgeID(fundingPoint.Hash.String()),
|
graph.NewEdgeID(fundingPoint.String()),
|
||||||
&rt.ChannelInfo{
|
&rt.ChannelInfo{
|
||||||
Cpt: capacity,
|
Cpt: capacity,
|
||||||
},
|
},
|
||||||
@ -657,8 +656,7 @@ func (f *fundingManager) handleFundingOpen(fmsg *fundingOpenMsg) {
|
|||||||
// Notify the L3 routing manager of the newly active channel link.
|
// Notify the L3 routing manager of the newly active channel link.
|
||||||
capacity := float64(resCtx.reservation.OurContribution().FundingAmount +
|
capacity := float64(resCtx.reservation.OurContribution().FundingAmount +
|
||||||
resCtx.reservation.TheirContribution().FundingAmount)
|
resCtx.reservation.TheirContribution().FundingAmount)
|
||||||
fmsg.peer.server.routingMgr.AddChannel(
|
fmsg.peer.server.routingMgr.OpenChannel(
|
||||||
graph.NewID(fmsg.peer.server.lightningID),
|
|
||||||
graph.NewID([32]byte(fmsg.peer.lightningID)),
|
graph.NewID([32]byte(fmsg.peer.lightningID)),
|
||||||
graph.NewEdgeID(resCtx.reservation.FundingOutpoint().String()),
|
graph.NewEdgeID(resCtx.reservation.FundingOutpoint().String()),
|
||||||
&rt.ChannelInfo{
|
&rt.ChannelInfo{
|
||||||
|
@ -10,11 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type NeighborAckMessage struct {
|
type NeighborAckMessage struct {
|
||||||
RoutingMessageBase
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NeighborAckMessage) String() string {
|
func (msg *NeighborAckMessage) String() string {
|
||||||
return fmt.Sprintf("NeighborAckMessage{%v %v}", msg.SenderID, msg.ReceiverID)
|
return fmt.Sprintf("NeighborAckMessage{}",)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NeighborAckMessage) Command() uint32 {
|
func (msg *NeighborAckMessage) Command() uint32 {
|
||||||
@ -22,6 +21,8 @@ func (msg *NeighborAckMessage) Command() uint32 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NeighborAckMessage) Encode(w io.Writer, pver uint32) error {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +31,9 @@ func (msg *NeighborAckMessage) Decode(r io.Reader, pver uint32) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NeighborAckMessage) MaxPayloadLength(uint32) uint32 {
|
func (msg *NeighborAckMessage) MaxPayloadLength(uint32) uint32 {
|
||||||
return 0
|
// Some random number. Transmission functions work bad if it is 0
|
||||||
|
return 100
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NeighborAckMessage) Validate() error {
|
func (msg *NeighborAckMessage) Validate() error {
|
||||||
|
44
lnwire/neighbor_ack_test.go
Normal file
44
lnwire/neighbor_ack_test.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// 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")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,7 +12,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type NeighborHelloMessage struct {
|
type NeighborHelloMessage struct {
|
||||||
RoutingMessageBase
|
|
||||||
RT *rt.RoutingTable
|
RT *rt.RoutingTable
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,7 +41,7 @@ func (msg *NeighborHelloMessage) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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}", msg.RT)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Message = (*NeighborHelloMessage)(nil)
|
var _ Message = (*NeighborHelloMessage)(nil)
|
||||||
|
@ -10,6 +10,7 @@ import (
|
|||||||
|
|
||||||
"github.com/BitfuryLightning/tools/rt"
|
"github.com/BitfuryLightning/tools/rt"
|
||||||
"github.com/BitfuryLightning/tools/rt/graph"
|
"github.com/BitfuryLightning/tools/rt/graph"
|
||||||
|
"github.com/roasbeef/btcd/wire"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNeighborHelloMessageEncodeDecode(t *testing.T) {
|
func TestNeighborHelloMessageEncodeDecode(t *testing.T) {
|
||||||
@ -31,10 +32,40 @@ func TestNeighborHelloMessageEncodeDecode(t *testing.T) {
|
|||||||
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, graph.NewEdgeID("1")) {
|
||||||
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, graph.NewEdgeID("1")) {
|
||||||
|
t.Errorf("msg2.RT.HasChannel(Id2, Id1) = false, want true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestNeighborHelloMessageReadWrite(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}
|
||||||
|
_, 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)
|
||||||
|
}
|
||||||
|
msg2c, ok := msg2.(*NeighborHelloMessage)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("Can't convert to *NeighborHelloMessage")
|
||||||
|
}
|
||||||
|
if msg2c.RT == nil {
|
||||||
|
t.Fatal("After decoding RT should not be nil")
|
||||||
|
}
|
||||||
|
if !msg2c.RT.HasChannel(Id1, Id2, graph.NewEdgeID("1")) {
|
||||||
|
t.Errorf("msg2.RT.HasChannel(Id1, Id2) = false, want true")
|
||||||
|
}
|
||||||
|
if !msg2c.RT.HasChannel(Id2, Id1, graph.NewEdgeID("1")) {
|
||||||
t.Errorf("msg2.RT.HasChannel(Id2, Id1) = false, want true")
|
t.Errorf("msg2.RT.HasChannel(Id2, Id1) = false, want true")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,11 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type NeighborRstMessage struct {
|
type NeighborRstMessage struct {
|
||||||
RoutingMessageBase
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NeighborRstMessage) String() string {
|
func (msg *NeighborRstMessage) String() string {
|
||||||
return fmt.Sprintf("NeighborRstMessage{%v %v}", msg.SenderID, msg.ReceiverID)
|
return fmt.Sprintf("NeighborRstMessage{}")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NeighborRstMessage) Command() uint32 {
|
func (msg *NeighborRstMessage) Command() uint32 {
|
||||||
|
@ -13,7 +13,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type NeighborUpdMessage struct {
|
type NeighborUpdMessage struct {
|
||||||
RoutingMessageBase
|
|
||||||
DiffBuff *rt.DifferenceBuffer
|
DiffBuff *rt.DifferenceBuffer
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +45,7 @@ func (msg *NeighborUpdMessage) Validate() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (msg *NeighborUpdMessage) String() string {
|
func (msg *NeighborUpdMessage) String() string {
|
||||||
return fmt.Sprintf("NeighborUpdMessage{%v %v %v}", msg.SenderID, msg.ReceiverID, *msg.DiffBuff)
|
return fmt.Sprintf("NeighborUpdMessage{%v}", *msg.DiffBuff)
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ Message = (*NeighborUpdMessage)(nil)
|
var _ Message = (*NeighborUpdMessage)(nil)
|
||||||
|
@ -1,35 +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 (
|
|
||||||
"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
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetReceiverID returns the ID of the receiver of routing message.
|
|
||||||
func (msg RoutingMessageBase) GetReceiverID() graph.ID {
|
|
||||||
return msg.ReceiverID
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetSenderID returns the ID of the sender of the routing message.
|
|
||||||
func (msg RoutingMessageBase) GetSenderID() graph.ID {
|
|
||||||
return msg.SenderID
|
|
||||||
}
|
|
||||||
|
|
||||||
// RoutingMessageBase is a shared interface for all routing messages.
|
|
||||||
type RoutingMessage interface {
|
|
||||||
GetSenderID() graph.ID
|
|
||||||
GetReceiverID() graph.ID
|
|
||||||
}
|
|
@ -10,11 +10,10 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type RoutingTableRequestMessage struct {
|
type RoutingTableRequestMessage struct {
|
||||||
RoutingMessageBase
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *RoutingTableRequestMessage) String() string {
|
func (msg *RoutingTableRequestMessage) String() string {
|
||||||
return fmt.Sprintf("RoutingTableRequestMessage{%v %v}", msg.SenderID, msg.ReceiverID)
|
return fmt.Sprintf("RoutingTableRequestMessage{}")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *RoutingTableRequestMessage) Command() uint32 {
|
func (msg *RoutingTableRequestMessage) Command() uint32 {
|
||||||
|
@ -13,12 +13,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type RoutingTableTransferMessage struct {
|
type RoutingTableTransferMessage struct {
|
||||||
RoutingMessageBase
|
|
||||||
RT *rt.RoutingTable
|
RT *rt.RoutingTable
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *RoutingTableTransferMessage) String() string {
|
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.RT)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (msg *RoutingTableTransferMessage) Decode(r io.Reader, pver uint32) error {
|
func (msg *RoutingTableTransferMessage) Decode(r io.Reader, pver uint32) error {
|
||||||
|
6
peer.go
6
peer.go
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/roasbeef/btcd/txscript"
|
"github.com/roasbeef/btcd/txscript"
|
||||||
"github.com/roasbeef/btcd/wire"
|
"github.com/roasbeef/btcd/wire"
|
||||||
"github.com/roasbeef/btcutil"
|
"github.com/roasbeef/btcutil"
|
||||||
|
"github.com/BitfuryLightning/tools/rt/graph"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -385,9 +386,8 @@ out:
|
|||||||
*lnwire.NeighborUpdMessage,
|
*lnwire.NeighborUpdMessage,
|
||||||
*lnwire.RoutingTableRequestMessage,
|
*lnwire.RoutingTableRequestMessage,
|
||||||
*lnwire.RoutingTableTransferMessage:
|
*lnwire.RoutingTableTransferMessage:
|
||||||
|
// Convert to base routing message and set sender and receiver
|
||||||
// TODO(mkl): determine sender and receiver of message
|
p.server.routingMgr.ReceiveRoutingMessage(msg, graph.NewID(([32]byte)(p.lightningID)))
|
||||||
p.server.routingMgr.ChIn <- msg
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if isChanUpate {
|
if isChanUpate {
|
||||||
|
10
server.go
10
server.go
@ -13,7 +13,6 @@ import (
|
|||||||
"github.com/lightningnetwork/lnd/lndc"
|
"github.com/lightningnetwork/lnd/lndc"
|
||||||
"github.com/lightningnetwork/lnd/lnrpc"
|
"github.com/lightningnetwork/lnd/lnrpc"
|
||||||
"github.com/lightningnetwork/lnd/lnwallet"
|
"github.com/lightningnetwork/lnd/lnwallet"
|
||||||
"github.com/lightningnetwork/lnd/lnwire"
|
|
||||||
"github.com/roasbeef/btcd/btcec"
|
"github.com/roasbeef/btcd/btcec"
|
||||||
"github.com/roasbeef/btcutil"
|
"github.com/roasbeef/btcutil"
|
||||||
|
|
||||||
@ -284,8 +283,11 @@ out:
|
|||||||
s.handleOpenChanReq(msg)
|
s.handleOpenChanReq(msg)
|
||||||
}
|
}
|
||||||
case msg := <-s.routingMgr.ChOut:
|
case msg := <-s.routingMgr.ChOut:
|
||||||
msg1 := msg.(lnwire.RoutingMessage)
|
msg1 := msg.(*routing.RoutingMessage)
|
||||||
receiverID := msg1.GetReceiverID().ToByte32()
|
if msg1.ReceiverID == nil{
|
||||||
|
peerLog.Critical("msg1.GetReceiverID() == nil")
|
||||||
|
}
|
||||||
|
receiverID := msg1.ReceiverID.ToByte32()
|
||||||
var targetPeer *peer
|
var targetPeer *peer
|
||||||
for _, peer := range s.peers { // TODO: threadsafe api
|
for _, peer := range s.peers { // TODO: threadsafe api
|
||||||
// We found the the target
|
// We found the the target
|
||||||
@ -297,7 +299,7 @@ out:
|
|||||||
if targetPeer != nil {
|
if targetPeer != nil {
|
||||||
fndgLog.Info("Peer found. Sending message")
|
fndgLog.Info("Peer found. Sending message")
|
||||||
done := make(chan struct{}, 1)
|
done := make(chan struct{}, 1)
|
||||||
targetPeer.queueMsg(msg.(lnwire.Message), done)
|
targetPeer.queueMsg(msg1.Msg, done)
|
||||||
} else {
|
} else {
|
||||||
srvrLog.Errorf("Can't find peer to send message %v", receiverID)
|
srvrLog.Errorf("Can't find peer to send message %v", receiverID)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user