代码拉取完成,页面将自动刷新
// SPDX-FileCopyrightText: 2023 The Pion community <https://pion.ly>
// SPDX-License-Identifier: MIT
package turn
import (
"fmt"
"net"
"strconv"
"github.com/pion/transport/v3"
"github.com/pion/transport/v3/stdnet"
)
// RelayAddressGeneratorNone returns the listener with no modifications
type RelayAddressGeneratorNone struct {
// Address is passed to Listen/ListenPacket when creating the Relay
Address string
Net transport.Net
}
// Validate is called on server startup and confirms the RelayAddressGenerator is properly configured
func (r *RelayAddressGeneratorNone) Validate() error {
if r.Net == nil {
var err error
r.Net, err = stdnet.NewNet()
if err != nil {
return fmt.Errorf("failed to create network: %w", err)
}
}
switch {
case r.Address == "":
return errListeningAddressInvalid
default:
return nil
}
}
// AllocatePacketConn generates a new PacketConn to receive traffic on and the IP/Port to populate the allocation response with
func (r *RelayAddressGeneratorNone) AllocatePacketConn(network string, requestedPort int) (net.PacketConn, net.Addr, error) {
conn, err := r.Net.ListenPacket(network, r.Address+":"+strconv.Itoa(requestedPort))
if err != nil {
return nil, nil, err
}
return conn, conn.LocalAddr(), nil
}
// AllocateConn generates a new Conn to receive traffic on and the IP/Port to populate the allocation response with
func (r *RelayAddressGeneratorNone) AllocateConn(string, int) (net.Conn, net.Addr, error) {
return nil, nil, errTODO
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。