// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT

package allocation

import (
	
)

// Protocol is an enum for relay protocol.
type Protocol uint8

// Network protocols for relay.
const (
	UDP Protocol = iota
	TCP
)

// FiveTuple is the combination (client IP address and port, server IP
// address and port, and transport protocol (currently one of UDP,
// TCP, or TLS)) used to communicate between the client and the
// server.  The 5-tuple uniquely identifies this communication
// stream.  The 5-tuple also uniquely identifies the Allocation on
// the server.
type FiveTuple struct {
	Protocol
	SrcAddr, DstAddr net.Addr
}

// Equal asserts if two FiveTuples are equal.
func ( *FiveTuple) ( *FiveTuple) bool {
	return .Fingerprint() == .Fingerprint()
}

// FiveTupleFingerprint is a comparable representation of a FiveTuple.
type FiveTupleFingerprint struct {
	srcIP, dstIP     [16]byte
	srcPort, dstPort uint16
	protocol         Protocol
}

// Fingerprint is the identity of a FiveTuple.
func ( *FiveTuple) () ( FiveTupleFingerprint) {
	,  := netAddrIPAndPort(.SrcAddr)
	copy(.srcIP[:], )
	.srcPort = 
	,  := netAddrIPAndPort(.DstAddr)
	copy(.dstIP[:], )
	.dstPort = 
	.protocol = .Protocol

	return
}

func netAddrIPAndPort( net.Addr) (net.IP, uint16) {
	switch a := .(type) {
	case *net.UDPAddr:
		return .IP.To16(), uint16(.Port) // nolint:gosec // G115
	case *net.TCPAddr:
		return .IP.To16(), uint16(.Port) // nolint:gosec // G115
	default:
		return nil, 0
	}
}