2021-07-14 12:35:52 +08:00
|
|
|
//go:build cgo && !disable_libutp
|
2021-10-28 16:53:04 +08:00
|
|
|
// +build cgo,!disable_libutp
|
2017-06-16 16:08:24 +08:00
|
|
|
|
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
2021-12-12 18:32:29 +08:00
|
|
|
utp "github.com/anacrolix/go-libutp"
|
2017-06-16 16:08:24 +08:00
|
|
|
)
|
|
|
|
|
2018-07-25 15:11:09 +08:00
|
|
|
func NewUtpSocket(network, addr string, fc firewallCallback) (utpSocket, error) {
|
2017-09-13 22:25:29 +08:00
|
|
|
s, err := utp.NewSocket(network, addr)
|
|
|
|
if s == nil {
|
|
|
|
return nil, err
|
2018-07-25 15:11:09 +08:00
|
|
|
}
|
|
|
|
if err != nil {
|
2017-09-13 22:25:29 +08:00
|
|
|
return s, err
|
|
|
|
}
|
2018-07-25 15:11:09 +08:00
|
|
|
if fc != nil {
|
2021-12-16 06:44:59 +08:00
|
|
|
s.SetSyncFirewallCallback(utp.FirewallCallback(fc))
|
2018-07-25 15:11:09 +08:00
|
|
|
}
|
|
|
|
return s, err
|
2017-06-16 16:08:24 +08:00
|
|
|
}
|