mirror of
https://github.com/simon-ding/polaris.git
synced 2026-06-09 03:27:39 +08:00
udp stun proxy
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
||||
"polaris/pkg/tmdb"
|
||||
"polaris/pkg/transmission"
|
||||
"polaris/pkg/utils"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/robfig/cron"
|
||||
@@ -50,6 +51,12 @@ func (c *Engine) Init() {
|
||||
go c.reloadTasks()
|
||||
c.addSysCron()
|
||||
go c.checkW500PosterOnStartup()
|
||||
go func() {
|
||||
time.Sleep(10*time.Second)
|
||||
if err := c.stunProxyDownloadClient(); err != nil {
|
||||
log.Errorf("stun proxy error: %v", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (c *Engine) GetTask(id int) (*Task, bool) {
|
||||
|
||||
41
engine/stun.go
Normal file
41
engine/stun.go
Normal file
@@ -0,0 +1,41 @@
|
||||
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))
|
||||
}
|
||||
Reference in New Issue
Block a user