lnwire: add ping and pong messages

This commit adds Ping and Pong messages to the suite of lnwire
messages. The usage of these messages within the daemon are similar to
the usage of Bitcoin’s ping/pong messages. Pings are to be sent
periodically with a random nonce to check connection activity and also
to gauge latency. Pong’s are to be sent in reply to ping messages,
echo’ing the same nonce used.
This commit is contained in:
Olaoluwa Osuntokun committed 2016-11-10 17:09:27 -08:00
1 parent f12b9b4bd7
commit 3f39f5413e
5 files changed
+223 -1

No files matched your search

+8 -1
View File
@@ -54,6 +54,10 @@ const (
// Commands for reporting protocol errors.
CmdErrorGeneric = uint32(4000)
// Commands for connection keep-alive.
CmdPing = uint32(5000)
CmdPong = uint32(5010)
)
// Message is an interface that defines a lightning wire protocol message. The
@@ -65,7 +69,6 @@ type Message interface {
Command() uint32
MaxPayloadLength(uint32) uint32
Validate() error
String() string
}
// makeEmptyMessage creates a new empty message of the proper concrete type
@@ -114,6 +117,10 @@ func makeEmptyMessage(command uint32) (Message, error) {
msg = &RoutingTableRequestMessage{}
case CmdRoutingTableTransferMessage:
msg = &RoutingTableTransferMessage{}
case CmdPing:
msg = &Ping{}
case CmdPong:
msg = &Pong{}
default:
return nil, fmt.Errorf("unhandled command [%d]", command)
}