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

Fix: tcp-alloc example #394

Merged
merged 1 commit into from
Apr 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ This mechanism is described in https://datatracker.ietf.org/doc/html/draft-ubert
This example demonstrates the use of a permission handler in the PION TURN server. The example implements a filtering policy that lets clients to connect back to their own host or server-reflexive address but will drop everything else. This will let the client ping-test through but will block essentially all other peer connection attempts.

## turn-client
The `turn-client` directory contains 2 examples that show common Pion TURN usages. All of these examples take the following arguments.
The `turn-client` directory contains 3 examples that show common Pion TURN usages.

All of these examples except `tcp-alloc` take the following arguments.

* -host : TURN server host
* -ping : Run ping test
Expand Down Expand Up @@ -126,3 +128,41 @@ Following diagram shows what turn-client does:
> mappedAddr and the external IP:port (*3) are the same) This process is known as
> "UDP hole punching" and TURN server exhibits "Address-restricted" behavior. Once it is done,
> packets coming from (*3) will be received by relayConn.


#### tcp-alloc
The `tcp-alloc` exemplifies how to create client TCP allocations and use them to exchange messages between peers. It simulates two clients and creates a TCP allocation for each. Then, both clients exchange their relayed addresses with each other through a signaling server. Finally, each client uses its TCP allocation and the relayed address of the other client to send and receive a single message.

The `tcp-alloc` takes the following arguments:

* -host : TURN server host
* -port : Listening port (defaults to 3478)
* -user : <username>=<password> pair
rg0now marked this conversation as resolved.
Show resolved Hide resolved
* -realm : Realm name (defaults to "pion.ly")
* -signaling : Run the signaling server


To run the example:

1) Start one client and the signaling server used to exchange the relayed addresses:

```sh
go build
./tcp-alloc -host <turn-server-name> -port <port> -user=<username=password> -signaling=true
```

2) Start the other client without starting the signaling server:

```sh
./tcp-alloc -host <turn-server-name> -port <port> -user=<username=password> -signaling=false
```

A Coturn TURN server can be locally deployed and used for testing with the following command (this is a test configuration of the Coturn TURN server and should not be used for production):

```sh
/bin/turnserver -lt-cred-mech -u <username:password> -r pion.ly --allow-loopback-peers --cli-password=<clipassword>
```

>If using this Coturn TURN server deployment:
>* turn-server-name : 127.0.0.1
>* port : 3478
5 changes: 5 additions & 0 deletions internal/client/tcp_alloc.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@
IP: addr.IP,
Port: addr.Port,
}
} else if addr, ok := a.serverAddr.(*net.UDPAddr); ok {
rAddrServer = &net.TCPAddr{
IP: addr.IP,
Port: addr.Port,

Check warning on line 157 in internal/client/tcp_alloc.go

View check run for this annotation

Codecov / codecov/patch

internal/client/tcp_alloc.go#L154-L157

Added lines #L154 - L157 were not covered by tests
}
} else {
return nil, errInvalidTURNAddress
}
Expand Down
Loading