mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-09-06 17:47:01 +02:00
lnwire: add warning message wrapping existing Error message structure
This commit adds Warning messages to lnwire, as introduced in bolts/950. It does not include reading/writing of warning messages, which will be covered in followup commits.
This commit is contained in:
@@ -964,6 +964,12 @@ func TestLightningWireProtocol(t *testing.T) {
|
||||
return mainScenario(&m)
|
||||
},
|
||||
},
|
||||
{
|
||||
msgType: MsgWarning,
|
||||
scenario: func(m Warning) bool {
|
||||
return mainScenario(&m)
|
||||
},
|
||||
},
|
||||
{
|
||||
msgType: MsgError,
|
||||
scenario: func(m Error) bool {
|
||||
|
@@ -22,7 +22,8 @@ type MessageType uint16
|
||||
// The currently defined message types within this current version of the
|
||||
// Lightning protocol.
|
||||
const (
|
||||
MsgInit MessageType = 16
|
||||
MsgWarning MessageType = 1
|
||||
MsgInit = 16
|
||||
MsgError = 17
|
||||
MsgPing = 18
|
||||
MsgPong = 19
|
||||
@@ -75,6 +76,8 @@ func ErrorPayloadTooLarge(size int) error {
|
||||
// String return the string representation of message type.
|
||||
func (t MessageType) String() string {
|
||||
switch t {
|
||||
case MsgWarning:
|
||||
return "Warning"
|
||||
case MsgInit:
|
||||
return "Init"
|
||||
case MsgOpenChannel:
|
||||
@@ -175,6 +178,8 @@ func makeEmptyMessage(msgType MessageType) (Message, error) {
|
||||
var msg Message
|
||||
|
||||
switch msgType {
|
||||
case MsgWarning:
|
||||
msg = &Warning{}
|
||||
case MsgInit:
|
||||
msg = &Init{}
|
||||
case MsgOpenChannel:
|
||||
|
22
lnwire/warning.go
Normal file
22
lnwire/warning.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package lnwire
|
||||
|
||||
// A compile time check to ensure Warning implements the lnwire.Message
|
||||
// interface.
|
||||
var _ Message = (*Warning)(nil)
|
||||
|
||||
// Warning is used to express non-critical errors in the protocol, providing
|
||||
// a "soft" way for nodes to communicate failures. Since it has the same
|
||||
// structure as errors, warnings simply include an Error so that we can leverage
|
||||
// their encode/decode functionality, and over write the MsgType function to
|
||||
// differentiate them.
|
||||
type Warning struct {
|
||||
Error
|
||||
}
|
||||
|
||||
// MsgType returns the integer uniquely identifying an Warning message on the
|
||||
// wire.
|
||||
//
|
||||
// This is part of the lnwire.Message interface.
|
||||
func (c *Warning) MsgType() MessageType {
|
||||
return MsgWarning
|
||||
}
|
Reference in New Issue
Block a user