2016-07-15 13:02:59 +02:00
|
|
|
// 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 (
|
|
|
|
"encoding/gob"
|
2016-08-11 20:54:44 +02:00
|
|
|
"fmt"
|
2016-07-15 13:02:59 +02:00
|
|
|
"io"
|
2016-08-11 20:54:44 +02:00
|
|
|
|
|
|
|
"github.com/BitfuryLightning/tools/rt"
|
2016-07-15 13:02:59 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
type NeighborUpdMessage struct {
|
|
|
|
RoutingMessageBase
|
|
|
|
DiffBuff *rt.DifferenceBuffer
|
|
|
|
}
|
|
|
|
|
2016-08-11 20:54:44 +02:00
|
|
|
func (msg *NeighborUpdMessage) Decode(r io.Reader, pver uint32) error {
|
2016-07-15 13:02:59 +02:00
|
|
|
decoder := gob.NewDecoder(r)
|
|
|
|
diffBuff := new(rt.DifferenceBuffer)
|
|
|
|
err := decoder.Decode(diffBuff)
|
|
|
|
msg.DiffBuff = diffBuff
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-08-11 20:54:44 +02:00
|
|
|
func (msg *NeighborUpdMessage) Encode(w io.Writer, pver uint32) error {
|
2016-07-15 13:02:59 +02:00
|
|
|
encoder := gob.NewEncoder(w)
|
|
|
|
err := encoder.Encode(msg.DiffBuff)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2016-08-11 20:54:44 +02:00
|
|
|
func (msg *NeighborUpdMessage) Command() uint32 {
|
2016-07-15 13:02:59 +02:00
|
|
|
return CmdNeighborUpdMessage
|
|
|
|
}
|
|
|
|
|
2016-08-11 20:54:44 +02:00
|
|
|
func (msg *NeighborUpdMessage) MaxPayloadLength(uint32) uint32 {
|
2016-07-15 13:02:59 +02:00
|
|
|
// TODO: Insert some estimations
|
|
|
|
return 1000000
|
|
|
|
}
|
|
|
|
|
2016-08-11 20:54:44 +02:00
|
|
|
func (msg *NeighborUpdMessage) Validate() error {
|
2016-07-15 13:02:59 +02:00
|
|
|
// TODO: Add validation
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (msg *NeighborUpdMessage) String() string {
|
|
|
|
return fmt.Sprintf("NeighborUpdMessage{%v %v %v}", msg.SenderID, msg.ReceiverID, *msg.DiffBuff)
|
|
|
|
}
|
|
|
|
|
2016-08-11 20:54:44 +02:00
|
|
|
var _ Message = (*NeighborUpdMessage)(nil)
|