mirror of
https://github.com/simon-ding/polaris.git
synced 2026-03-01 07:00:47 +08:00
42 lines
733 B
Go
42 lines
733 B
Go
package engine
|
|
|
|
import (
|
|
"net/url"
|
|
"polaris/ent/downloadclients"
|
|
"polaris/pkg/nat"
|
|
"polaris/pkg/qbittorrent"
|
|
"strconv"
|
|
)
|
|
|
|
func (s *Engine) stunProxyDownloadClient() error {
|
|
downloader, e, err := s.GetDownloadClient()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if e.Implementation != downloadclients.ImplementationQbittorrent {
|
|
return nil
|
|
}
|
|
d, ok := downloader.(*qbittorrent.Client)
|
|
if !ok {
|
|
return nil
|
|
}
|
|
n, err := nat.NewNatTraversal()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
addr, err := n.StunAddr()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
err = d.SetListenPort(addr.Port)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
u, err := url.Parse(d.URL)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
return n.StartProxy(u.Hostname() + ":" + strconv.Itoa(addr.Port))
|
|
}
|