lnwire+peer: implement new ping/pong messages and behavior

This commit implements the new ping/pong messages along with their new
behavior. The new set of ping/pong messages allow clients to generate
fake cover traffic as the ping messages tells the pong message how many
bytes to included and can also be padded itself.
This commit is contained in:
Olaoluwa Osuntokun committed 2017-04-16 18:11:45 -07:00
1 parent 83c72eb082
commit feec611531
8 files changed
+109 -65

No files matched your search

+13 -12
View File
@@ -6,26 +6,27 @@ import (
"testing"
)
func TestPongEncodeDecode(t *testing.T) {
pong := &Pong{
Nonce: 9,
func TestPingEncodeDecode(t *testing.T) {
ping := &Ping{
NumPongBytes: 10,
PaddingBytes: bytes.Repeat([]byte("A"), 100),
}
// Next encode the pong message into an empty bytes buffer.
// Next encode the ping message into an empty bytes buffer.
var b bytes.Buffer
if err := pong.Encode(&b, 0); err != nil {
t.Fatalf("unable to encode pong: %v", err)
if err := ping.Encode(&b, 0); err != nil {
t.Fatalf("unable to encode ping: %v", err)
}
// Deserialize the encoded pong message into a new empty struct.
pong2 := &Pong{}
if err := pong2.Decode(&b, 0); err != nil {
// Deserialize the encoded ping message into a new empty struct.
ping2 := &Ping{}
if err := ping2.Decode(&b, 0); err != nil {
t.Fatalf("unable to decode ping: %v", err)
}
// Assert equality of the two instances.
if !reflect.DeepEqual(pong, pong2) {
t.Fatalf("encode/decode pong messages don't match %#v vs %#v",
pong, pong2)
if !reflect.DeepEqual(ping, ping2) {
t.Fatalf("encode/decode ping messages don't match %#v vs %#v",
ping, ping2)
}
}