10 Star 38 Fork 19

Gitee 极速下载 / Pion-WebRTC

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/pion/webrtc
克隆/下载
stun.go 1.45 KB
一键复制 编辑 原始数据 按行查看 历史
backkem 提交于 2018-10-06 17:33 . ICE: Fix reflective candidates sending
package stun
import (
"fmt"
"net"
"time"
"github.com/pions/pkg/stun"
"github.com/pions/webrtc/pkg/ice"
"github.com/pkg/errors"
)
// TODO: This file doesn't make sense
// Package ICE should rely on stun, not the other way around.
// AllocateUDP crafts and sends a STUN binding
// On success will return our XORMappedAddress
func AllocateUDP(url *ice.URL) (*net.UDPAddr, *stun.XorAddress, error) {
// TODO Do we want the timeout to be configurable?
// proto := url.Proto.String()
// TODO: Temporary fix for nat traversal issue: Find a permanent solution.
client, err := stun.NewClient("udp4", fmt.Sprintf("%s:%d", url.Host, url.Port), time.Second*5)
if err != nil {
return nil, nil, errors.Wrapf(err, "Failed to create STUN client")
}
localAddr, ok := client.LocalAddr().(*net.UDPAddr)
if !ok {
return nil, nil, errors.Errorf("Failed to cast STUN client to UDPAddr")
}
resp, err := client.Request()
if err != nil {
return nil, nil, errors.Wrapf(err, "Failed to make STUN request")
}
if err = client.Close(); err != nil {
return nil, nil, errors.Wrapf(err, "Failed to close STUN client")
}
attr, ok := resp.GetOneAttribute(stun.AttrXORMappedAddress)
if !ok {
return nil, nil, errors.Errorf("Got respond from STUN server that did not contain XORAddress")
}
var addr stun.XorAddress
if err = addr.Unpack(resp, attr); err != nil {
return nil, nil, errors.Wrapf(err, "Failed to unpack STUN XorAddress response")
}
return localAddr, &addr, nil
}
1
https://gitee.com/mirrors/Pion-WebRTC.git
git@gitee.com:mirrors/Pion-WebRTC.git
mirrors
Pion-WebRTC
Pion-WebRTC
v1.1.1

搜索帮助