package peer

/*
type mcMockConn struct {
	packets chan []byte
}

func newMCMockConn() *mcMockConn {
	return &mcMockConn{make(chan []byte, 32)}
}

func (c *mcMockConn) WriteToUDP(in []byte, addr *net.UDPAddr) (int, error) {
	c.packets <- bytes.Clone(in)
	return len(in), nil
}

func (c *mcMockConn) ReadFromUDPAddrPort(b []byte) (n int, addr netip.AddrPort, err error) {
	buf := <-c.packets
	b = b[:len(buf)]
	copy(b, buf)
	return len(b), netip.AddrPort{}, nil
}

func TestMCReader(t *testing.T) {
	keys := generateKeys()
	super := &mockControlMsgHandler{}
	conn := newMCMockConn()

	peers := [256]*atomic.Pointer[RemotePeer]{}
	peer := &RemotePeer{
		IP:         1,
		Up:         true,
		PubSignKey: keys.PubSignKey,
	}
	peers[1] = &atomic.Pointer[RemotePeer]{}
	peers[1].Store(peer)

	w := newMCWriter(conn, 1, keys.PrivSignKey)
	r := newMCReader(conn, super, peers)

	w.SendLocalDiscovery()
	r.handleNextPacket()

	if len(super.Messages) != 1 {
		t.Fatal(super.Messages)
	}
	msg, ok := super.Messages[0].(controlMsg[PacketLocalDiscovery])
	if !ok || msg.SrcIP != 1 {
		t.Fatal(ok, msg)
	}
}

func TestMCReader_noHeader(t *testing.T) {
	keys := generateKeys()
	super := &mockControlMsgHandler{}
	conn := newMCMockConn()

	peers := [256]*atomic.Pointer[RemotePeer]{}
	peer := &RemotePeer{
		IP:         1,
		Up:         true,
		PubSignKey: keys.PubSignKey,
	}
	peers[1] = &atomic.Pointer[RemotePeer]{}
	peers[1].Store(peer)

	r := newMCReader(conn, super, peers)
	conn.WriteToUDP([]byte("0123546789"), nil)
	r.handleNextPacket()

	if len(super.Messages) != 0 {
		t.Fatal(super.Messages)
	}
}

func TestMCReader_noPeer(t *testing.T) {
	keys := generateKeys()
	super := &mockControlMsgHandler{}
	conn := newMCMockConn()

	peers := [256]*atomic.Pointer[RemotePeer]{}
	peer := &RemotePeer{
		IP:         1,
		Up:         true,
		PubSignKey: keys.PubSignKey,
	}
	peers[1] = &atomic.Pointer[RemotePeer]{}
	peers[2] = &atomic.Pointer[RemotePeer]{}
	peers[1].Store(peer)

	w := newMCWriter(conn, 2, keys.PrivSignKey)
	r := newMCReader(conn, super, peers)

	w.SendLocalDiscovery()
	r.handleNextPacket()

	if len(super.Messages) != 0 {
		t.Fatal(super.Messages)
	}
}

func TestMCReader_badSignature(t *testing.T) {
	keys := generateKeys()
	super := &mockControlMsgHandler{}
	conn := newMCMockConn()

	peers := [256]*atomic.Pointer[RemotePeer]{}
	peer := &RemotePeer{
		IP:         1,
		Up:         true,
		PubSignKey: keys.PubSignKey,
	}
	peers[1] = &atomic.Pointer[RemotePeer]{}
	peers[1].Store(peer)

	w := newMCWriter(conn, 1, keys.PrivSignKey)
	w.SendLocalDiscovery()

	// Break signing.
	packet := <-conn.packets
	packet[0]++
	conn.packets <- packet

	r := newMCReader(conn, super, peers)

	r.handleNextPacket()

	if len(super.Messages) != 0 {
		t.Fatal(super.Messages)
	}
}
*/
