mirror of
https://github.com/simon-ding/polaris.git
synced 2026-04-22 11:47:30 +08:00
WIP: stun proxy
This commit is contained in:
@@ -61,6 +61,23 @@ func (c *Client) GetAll() ([]pkg.Torrent, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (c *Client) GetListenPort() (int, error) {
|
||||
pref, err := c.c.Preferences()
|
||||
if err != nil {
|
||||
return 0, errors.Wrap(err, "get preferences")
|
||||
}
|
||||
|
||||
return pref.ListenPort, nil
|
||||
}
|
||||
|
||||
func (c *Client) SetListenPort(port int) error {
|
||||
ok, err := c.c.SetPreferences(map[string]any{"listen_port": port})
|
||||
if !ok || err != nil {
|
||||
return errors.Wrap(err, "set preferences")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) Download(link, hash, dir string) (pkg.Torrent, error) {
|
||||
err := c.c.DownloadLinks([]string{link}, qbt.DownloadOptions{Savepath: &dir, Category: &c.category})
|
||||
if err != nil {
|
||||
|
||||
@@ -11,10 +11,17 @@ func Test1(t *testing.T) {
|
||||
log.Errorf("new client error: %v", err)
|
||||
t.Fail()
|
||||
}
|
||||
all, err := c.GetAll()
|
||||
for _, t := range all {
|
||||
name, _ := t.Name()
|
||||
log.Infof("torrent: %+v", name)
|
||||
log.Infof("new client success: %v", c)
|
||||
port, err := c.GetListenPort()
|
||||
if err != nil {
|
||||
log.Errorf("get listen port error: %v", err)
|
||||
t.Fail()
|
||||
} else {
|
||||
log.Infof("listen port: %d", port)
|
||||
err := c.SetListenPort(port + 1)
|
||||
if err!= nil {
|
||||
log.Errorf("set listen port error: %v", err)
|
||||
t.Fail()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user