turn icon indicating copy to clipboard operation
turn copied to clipboard

Forcing relay only on my clients and a port allocator results in never allocating a port

Open doctorpangloss opened this issue 2 years ago • 0 comments

Your environment.

  • Version: 72ffd594f7c6104b5680a4fea5651928e3b6ddb4
  • Browser: Mobile Safari on iOS 12.7, Chrome 92

What did you do?

I added logging to RelayAddressGeneratorPortRange to see if a port is ever allocated.

	for try := 0; try < r.MaxRetries; try++ {
		port := r.MinPort + uint16(r.Rand.Intn(int((r.MaxPort+1)-r.MinPort)))
		conn, err := r.Net.ListenPacket(network, fmt.Sprintf("%s:%d", r.Address, port))
		if err != nil {
		  log.Printf("could not allocate port %d", port)
			continue
		}

		relayAddr := conn.LocalAddr().(*net.UDPAddr)
		relayAddr.IP = r.RelayAddress
		log.Printf("allocated %d")
		return conn, relayAddr, nil
	}

What did you expect?

Ports should be allocated.

What happened?

A port is never allocated randomly within the range. I see multiple of the following errors:

turn ERROR: 2021/08/19 20:17:08 error when handling datagram: failed to handle Allocate-request from 192.168.88.162:61561: relay already allocated for 5-TUPLE

doctorpangloss avatar Aug 20 '21 03:08 doctorpangloss