package holepunch

import (
	
	

	
	
	

	ma 
)

func removeRelayAddrs( []ma.Multiaddr) []ma.Multiaddr {
	return slices.DeleteFunc(, isRelayAddress)
}

func isRelayAddress( ma.Multiaddr) bool {
	,  := .ValueForProtocol(ma.P_CIRCUIT)
	return  == nil
}

func addrsToBytes( []ma.Multiaddr) [][]byte {
	 := make([][]byte, 0, len())
	for ,  := range  {
		 = append(, .Bytes())
	}
	return 
}

func addrsFromBytes( [][]byte) []ma.Multiaddr {
	 := make([]ma.Multiaddr, 0, len())
	for ,  := range  {
		,  := ma.NewMultiaddrBytes()
		if  == nil {
			 = append(, )
		}
	}
	return 
}

func getDirectConnection( host.Host,  peer.ID) network.Conn {
	for ,  := range .Network().ConnsToPeer() {
		if !isRelayAddress(.RemoteMultiaddr()) {
			return 
		}
	}
	return nil
}

func holePunchConnect( context.Context,  host.Host,  peer.AddrInfo,  bool) error {
	 := network.WithSimultaneousConnect(, , "hole-punching")
	 := network.WithForceDirectDial(, "hole-punching")

	log.Debugw("holepunchConnect", "host", .ID(), "peer", .ID, "addrs", .Addrs)
	if  := .Connect(, );  != nil {
		log.Debugw("hole punch attempt with peer failed", "peer ID", .ID, "error", )
		return 
	}
	log.Debugw("hole punch successful", "peer", .ID)
	return nil
}