I a m writting a P2P application, and I want to decide to send a message to a peer using TCP or QUIC, for a benchmark of the protocols and also for leting the user decide (I want the quic protocol to the the pefered one). But i am having trouble to do so. Currently I divide the the remote host addr into quic and tcp addreses and then issue a connectin with each one, but sometimes the tcp addr connect to udp and viceversa. I dont know if this is the best approach
I have tried to slit the addrs, connecting using TCP, QUIC and also to the addr received from the DHT rendezvous.
quicaddr := selectAddrs(peeraddr.Addrs, "quic")
tcpaddr := selectAddrs(peeraddr.Addrs, "tcp")
fmt.Println("[*] Using TCP protocol")
var peeraddrTCP peer.AddrInfo
peeraddrTCP.ID = peeraddr.ID
peeraddrTCP.Addrs = tcpaddr
fmt.Println(peeraddrTCP.Addrs)
err = Host.Connect(ctx, peeraddrTCP)
conn2 := Host.Network().ConnsToPeer(peeraddr.ID)
for _, c := range conn2 {
fmt.Println("Using: ", c.ConnState().Transport)
fmt.Println(c.RemoteMultiaddr())
available_add = append(available_add, c.RemoteMultiaddr())
c.Close()
}
fmt.Println("[*] Using QUIC protocol")
var peeraddrQUIC peer.AddrInfo
peeraddrQUIC.ID = peeraddr.ID
peeraddrQUIC.Addrs = quicaddr
fmt.Println(peeraddrQUIC.Addrs)
err = Host.Connect(ctx, peeraddrQUIC)
conn1 := Host.Network().ConnsToPeer(peeraddrQUIC.ID)
for _, c := range conn1 {
fmt.Println("Using: ", c.ConnState().Transport)
fmt.Println(c.RemoteMultiaddr())
available_add = append(available_add, c.RemoteMultiaddr())
c.Close()
}
Basically I would like to know if it is posible to have one connection with both tcp and quic. Sorry for my english.
I made a function to change to QUIC or TCP i post it in case anyone is interested, in anyone has a better options please share, thanks!
func setTransport(ctx context.Context, peerid peer.ID, preferQUIC bool) bool {
}