Базовый Readme, понятные переменные окружения
This commit is contained in:
36
turn/turn.go
36
turn/turn.go
@@ -19,6 +19,25 @@ type Config struct {
|
||||
Realm string
|
||||
Username string
|
||||
Password string
|
||||
|
||||
MinRelayPort uint16
|
||||
MaxRelayPort uint16
|
||||
}
|
||||
|
||||
func relayGen(ip net.IP, minPort, maxPort uint16) pionturn.RelayAddressGenerator {
|
||||
if minPort != 0 && maxPort != 0 && minPort <= maxPort {
|
||||
return &pionturn.RelayAddressGeneratorPortRange{
|
||||
RelayAddress: ip,
|
||||
Address: "0.0.0.0",
|
||||
MinPort: minPort,
|
||||
MaxPort: maxPort,
|
||||
}
|
||||
}
|
||||
|
||||
return &pionturn.RelayAddressGeneratorStatic{
|
||||
RelayAddress: ip,
|
||||
Address: "0.0.0.0",
|
||||
}
|
||||
}
|
||||
|
||||
func Start(cfg Config) (*Server, error) {
|
||||
@@ -38,6 +57,8 @@ func Start(cfg Config) (*Server, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rg := relayGen(ip, cfg.MinRelayPort, cfg.MaxRelayPort)
|
||||
|
||||
srv, err := pionturn.NewServer(pionturn.ServerConfig{
|
||||
Realm: cfg.Realm,
|
||||
AuthHandler: func(username, realm string, srcAddr net.Addr) ([]byte, bool) {
|
||||
@@ -48,23 +69,18 @@ func Start(cfg Config) (*Server, error) {
|
||||
},
|
||||
PacketConnConfigs: []pionturn.PacketConnConfig{
|
||||
{
|
||||
PacketConn: udpConn,
|
||||
RelayAddressGenerator: &pionturn.RelayAddressGeneratorStatic{
|
||||
RelayAddress: ip,
|
||||
Address: "0.0.0.0",
|
||||
},
|
||||
PacketConn: udpConn,
|
||||
RelayAddressGenerator: rg,
|
||||
},
|
||||
},
|
||||
ListenerConfigs: []pionturn.ListenerConfig{
|
||||
{
|
||||
Listener: tcpListener,
|
||||
RelayAddressGenerator: &pionturn.RelayAddressGeneratorStatic{
|
||||
RelayAddress: ip,
|
||||
Address: "0.0.0.0",
|
||||
},
|
||||
Listener: tcpListener,
|
||||
RelayAddressGenerator: rg,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
_ = tcpListener.Close()
|
||||
_ = udpConn.Close()
|
||||
|
||||
Reference in New Issue
Block a user