-
Notifications
You must be signed in to change notification settings - Fork 323
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support stand alone STUN server mode
Running in stand alone STUN server does not start due to packet conn config requiring relay address config during validation. To enable that mode, bypass validation if relay address config in packet conn config is nil. Note that it is still validated in `ListenerConfig`.
- Loading branch information
Showing
6 changed files
with
131 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly> | ||
// SPDX-License-Identifier: MIT | ||
|
||
// Package main implements a simple TURN server | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"log" | ||
"net" | ||
"os" | ||
"os/signal" | ||
"strconv" | ||
"syscall" | ||
|
||
"github.com/pion/turn/v3" | ||
) | ||
|
||
func main() { | ||
publicIP := flag.String("public-ip", "", "IP Address that STUN can be contacted by.") | ||
port := flag.Int("port", 3478, "Listening port.") | ||
flag.Parse() | ||
|
||
if len(*publicIP) == 0 { | ||
log.Fatalf("'public-ip' is required") | ||
} | ||
|
||
// Create a UDP listener to pass into pion/turn | ||
// pion/turn itself doesn't allocate any UDP sockets, but lets the user pass them in | ||
// this allows us to add logging, storage or modify inbound/outbound traffic | ||
udpListener, err := net.ListenPacket("udp4", "0.0.0.0:"+strconv.Itoa(*port)) | ||
if err != nil { | ||
log.Panicf("Failed to create STUN server listener: %s", err) | ||
} | ||
|
||
s, err := turn.NewServer(turn.ServerConfig{ | ||
// PacketConnConfigs is a list of UDP Listeners and the configuration around them | ||
PacketConnConfigs: []turn.PacketConnConfig{ | ||
{ | ||
PacketConn: udpListener, | ||
}, | ||
}, | ||
}) | ||
if err != nil { | ||
log.Panic(err) | ||
} | ||
|
||
// Block until user sends SIGINT or SIGTERM | ||
sigs := make(chan os.Signal, 1) | ||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM) | ||
<-sigs | ||
|
||
if err = s.Close(); err != nil { | ||
log.Panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters