package peer

/*
// ----------------------------------------------------------------------------

// Testing that we can create and verify a local discovery packet.
func TestVerifyLocalDiscoveryPacket_valid(t *testing.T) {
	keys := generateKeys()

	created := createLocalDiscoveryPacket(55, keys.PrivSignKey)

	header, ok := headerFromLocalDiscoveryPacket(created)
	if !ok {
		t.Fatal(ok)
	}
	if header.SourceIP != 55 || header.DestIP != 255 {
		t.Fatal(header)
	}

	if !verifyLocalDiscoveryPacket(created, make([]byte, 1024), keys.PubSignKey) {
		t.Fatal("Not valid")
	}
}

// Testing that we don't try to parse short packets.
func TestVerifyLocalDiscoveryPacket_tooShort(t *testing.T) {
	keys := generateKeys()

	created := createLocalDiscoveryPacket(55, keys.PrivSignKey)

	_, ok := headerFromLocalDiscoveryPacket(created[:len(created)-1])
	if ok {
		t.Fatal(ok)
	}
}

// Testing that modifying a packet makes it invalid.
func TestVerifyLocalDiscoveryPacket_invalid(t *testing.T) {
	keys := generateKeys()

	created := createLocalDiscoveryPacket(55, keys.PrivSignKey)
	buf := make([]byte, 1024)
	for i := range created {
		modified := bytes.Clone(created)
		modified[i]++
		if verifyLocalDiscoveryPacket(modified, buf, keys.PubSignKey) {
			t.Fatal("Verification should have failed.")
		}
	}
}

// ----------------------------------------------------------------------------

type testUDPWriter struct {
	written [][]byte
}

func (w *testUDPWriter) WriteToUDP(b []byte, addr *net.UDPAddr) (int, error) {
	w.written = append(w.written, bytes.Clone(b))
	return len(b), nil
}

func (w *testUDPWriter) Written() [][]byte {
	out := w.written
	w.written = [][]byte{}
	return out
}

// ----------------------------------------------------------------------------

// Testing that the mcWriter sends local discovery packets as expected.
func TestMCWriter_SendLocalDiscovery(t *testing.T) {
	keys := generateKeys()
	writer := &testUDPWriter{}

	mcw := newMCWriter(writer, 42, keys.PrivSignKey)
	mcw.SendLocalDiscovery()

	out := writer.Written()
	if len(out) != 1 {
		t.Fatal(out)
	}

	pkt := out[0]

	header, ok := headerFromLocalDiscoveryPacket(pkt)
	if !ok {
		t.Fatal(ok)
	}
	if header.SourceIP != 42 || header.DestIP != 255 {
		t.Fatal(header)
	}

	if !verifyLocalDiscoveryPacket(pkt, make([]byte, 1024), keys.PubSignKey) {
		t.Fatal("Verification should succeed.")
	}
}
*/
