Базовый Readme, понятные переменные окружения

This commit is contained in:
set
2026-03-17 14:28:15 +02:00
parent e703ac22e6
commit 3c810407db
5 changed files with 84 additions and 31 deletions

View File

@@ -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()