Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TURN-client tcp-alloc example #391

Closed
AfonsoVilalonga opened this issue Apr 20, 2024 · 8 comments
Closed

TURN-client tcp-alloc example #391

AfonsoVilalonga opened this issue Apr 20, 2024 · 8 comments

Comments

@AfonsoVilalonga
Copy link
Contributor

Hello,

I would like to ask if the TCP allocation example for the TURN client works correctly. I am utilizing a TURN server provided by Open Relay: Free WebRTC TURN Server (metered). However, I encounter the following error:

Failed to dial: invalid TURN server address

This error occurs at line 151 in the example, specifically at conn, err := allocation.DialTCP("tcp", nil, peerAddr). I have not made any changes to the code. I run a local instance of the example using the following commands:

go run test.go -host turn_domain -user=user -password=password -signaling true

and then a second instance with:

go run test.go -host turn_domain -user=user -password=password

I am running Windows 10 with Go version go1.21.2 windows/amd64.

Thank you very much for your help and attention.

@rg0now
Copy link
Contributor

rg0now commented Apr 20, 2024

It seems to at least get until the point to create a TURN allocation successfully. Make sure you set the flags correctly:

PION_LOG_TRACE=all go run main.go -host global.relay.metered.ca -port 80 -user="<my-username>=<my-password>" -signaling=true
turnc DEBUG: 21:22:51.873366 client.go:110: Resolved STUN server global.relay.metered.ca:80 to A.B.C.108:80
turnc DEBUG: 21:22:51.899976 client.go:119: Resolved TURN server global.relay.metered.ca:80 to A.B.C.108:80
turnc TRACE: 21:22:51.900270 client.go:428: Start Allocate request transaction NCOmBahyfFWiTnnE to A.B.C.108:80
turnc TRACE: 21:22:51.942674 client.go:428: Start Allocate request transaction FDm5NFyzmngcJFg5 to A.B.C.108:80
turnc DEBUG: 21:22:51.990052 tcp_alloc.go:57: Initial lifetime: 600 seconds
turnc DEBUG: 21:22:51.990263 tcp_alloc.go:72: Started refreshAllocTimer
turnc DEBUG: 21:22:51.990326 tcp_alloc.go:75: Started refreshPermsTimer
2024/04/20 21:22:51 relayed-address=A.B.C.108:57328

I still need to understand what should happen afterwards. Unfortunately, we don't have seem to have docs for this example. Some info can be found in the original PR.

@AfonsoVilalonga
Copy link
Contributor Author

AfonsoVilalonga commented Apr 20, 2024

Thank you for the response. I will also take a look at the PR.

However, I believe I configured the flags correctly. I even tried running the command you provided, and I see essentially the same output as you:

Instance with signaling=true:

turnc DEBUG: 21:12:33.627269 client.go:110: Resolved STUN server global.relay.metered.ca:80 to A.B.C.D:80
turnc DEBUG: 21:12:33.697741 client.go:119: Resolved TURN server global.relay.metered.ca:80 to A.B.C.D:80
turnc TRACE: 21:12:33.697741 client.go:428: Start Allocate request transaction GnAlBhuLMCSmKf9z to A.B.C.D:80
turnc TRACE: 21:12:33.747740 client.go:428: Start Allocate request transaction vBX2YH9sviciBJSF to A.B.C.D:80
turnc DEBUG: 21:12:33.802856 tcp_alloc.go:57: Initial lifetime: 600 seconds
turnc DEBUG: 21:12:33.803378 tcp_alloc.go:72: Started refreshAllocTimer
turnc DEBUG: 21:12:33.805193 tcp_alloc.go:75: Started refreshPermsTimer
2024/04/20 21:12:33 relayed-address=A.B.C.D:PORT
2024/04/20 21:12:56 Received peer address: A.B.C.D:PORT_PEER
2024/04/20 21:12:56 Failed to dial: invalid TURN server address
turnc DEBUG: 21:12:56.592590 allocation.go:77: Send refresh request (dontWait=true)
turnc TRACE: 21:12:56.595350 client.go:428: Start Refresh request transaction +AZlvdzpR5Uil8K7 to A.B.C.D:80
turnc DEBUG: 21:12:56.596430 allocation.go:84: Refresh request sent
panic: Failed to dial: invalid TURN server address

Instance with signaling=false:

turnc DEBUG: 21:12:56.453395 client.go:110: Resolved STUN server global.relay.metered.ca:80 to A.B.C.D:80
turnc DEBUG: 21:12:56.498146 client.go:119: Resolved TURN server global.relay.metered.ca:80 to A.B.C.D:80
turnc TRACE: 21:12:56.499145 client.go:428: Start Allocate request transaction e7LnmSrKkWkKDkDY to A.B.C.D:80
turnc TRACE: 21:12:56.544914 client.go:428: Start Allocate request transaction ddadMcLSoFAV1xnc to A.B.C.D:80
turnc DEBUG: 21:12:56.589261 tcp_alloc.go:57: Initial lifetime: 600 seconds
turnc DEBUG: 21:12:56.589261 tcp_alloc.go:72: Started refreshAllocTimer
turnc DEBUG: 21:12:56.589802 tcp_alloc.go:75: Started refreshPermsTimer
2024/04/20 21:12:56 relayed-address=A.B.C.D:PORT
2024/04/20 21:12:56 Received peer address: A.B.C.D:PORT_PEER
turnc TRACE: 21:12:56.591428 client.go:428: Start CreatePermission request transaction E6Pu7lspCSuwX14t to A.B.C.D:80

This seems to make sense because I can't establish the allocation.DialTCP("tcp", nil, peerAddr) connection. It returns the error "invalid TURN server address". Consequently, the instance with signaling=false remains blocked on the conn, err := allocation.AcceptTCP() line because there is no incoming connection.

On the line allocation.DialTCP("TCP", nil, peerAddr), it appears that the error is originating from this block of code (inside the DialTCP function):

var rAddrServer *net.TCPAddr
if addr, ok := a.serverAddr.(*net.TCPAddr); ok {
	rAddrServer = &net.TCPAddr{
		IP:   addr.IP,
		Port: addr.Port,
	}
} else {
	return nil, errInvalidTURNAddress
}

@rg0now
Copy link
Contributor

rg0now commented Apr 20, 2024

You're perfectly right, sorry, I forgot how TCP allocation works.

It seems you're right: the problem is indeed in DialTCP. We assume the TCPAllocation holds the server address as a net.TCPAddr, whereas, quite strangely, it is a net.UDPAddr. This is despite that we're making the allocation on TCP.

Anyway, if you add this to DialTCP then it works:

if addr, ok := a.serverAddr.(*net.TCPAddr); ok {
	rAddrServer = &net.TCPAddr{
		IP:   addr.IP,
		Port: addr.Port,
	}
} else if addr, ok := a.serverAddr.(*net.UDPAddr); ok {
	rAddrServer = &net.TCPAddr{
		IP:   addr.IP,
		Port: addr.Port,
	}
} else {
	return nil, errInvalidTURNAddress
}

Unfortunately, I don't have time now to track this further. Did this ever work? Did we break this sometime after the TCP alloc client got merged? The terrible truth is that we cannot test the TCP alloc code until the server part (#315) gets merged so I can certainly imagine we broke this somehow.

Feel like submitting a PR?

@AfonsoVilalonga
Copy link
Contributor Author

Thank you for the feedback!

With the changes, it works!

I can try to make a PR; I just have to first get comfortable with making PRs since it is my first time :)

@Sean-Der
Copy link
Member

We would love to have you involved! If you need help/have questions we are here :)

@rg0now
Copy link
Contributor

rg0now commented Apr 21, 2024

I can try to make a PR; I just have to first get comfortable with making PRs since it is my first time :)

If you are at it: can you please add some documentation here? No need to be super detailed, just the basic command lines for making it work. Also, you don't have to test against a global TURN server, the original PR contains some info on how to make this work with coturn.

@AfonsoVilalonga
Copy link
Contributor Author

AfonsoVilalonga commented Apr 21, 2024

Thank you both, @Sean-Der and @rg0now!

I can add some documentation on how to use the example.

Just one question, is there any information on how to use these scripts:

scripts/lint-commit-message.sh
scripts/assert-contributors.sh
scripts/lint-disallowed-functions-in-library.sh
scripts/lint-filename.sh

@rg0now
Copy link
Contributor

rg0now commented Apr 28, 2024

Fixed by #394

@rg0now rg0now closed this as completed Apr 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants