2020-02-20 13:47:37 +08:00
|
|
|
package test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io"
|
|
|
|
"log"
|
|
|
|
"net"
|
|
|
|
"path/filepath"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/anacrolix/torrent"
|
2022-11-02 20:03:25 +08:00
|
|
|
"github.com/anacrolix/torrent/dialer"
|
2020-02-20 13:47:37 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUnixConns(t *testing.T) {
|
|
|
|
var closers []io.Closer
|
|
|
|
defer func() {
|
|
|
|
for _, c := range closers {
|
|
|
|
c.Close()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
configure := ConfigureClient{
|
|
|
|
Config: func(cfg *torrent.ClientConfig) {
|
|
|
|
cfg.DisableUTP = true
|
|
|
|
cfg.DisableTCP = true
|
|
|
|
cfg.Debug = true
|
|
|
|
},
|
|
|
|
Client: func(cl *torrent.Client) {
|
2022-11-02 20:03:25 +08:00
|
|
|
cl.AddDialer(torrent.NetworkDialer{Network: "unix", Dialer: dialer.Default})
|
2021-02-22 11:30:09 +08:00
|
|
|
l, err := net.Listen("unix", filepath.Join(t.TempDir(), "socket"))
|
2020-02-20 13:47:37 +08:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
log.Printf("created listener %q", l)
|
|
|
|
closers = append(closers, l)
|
|
|
|
cl.AddListener(l)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
testClientTransfer(t, testClientTransferParams{
|
|
|
|
ConfigureSeeder: configure,
|
|
|
|
ConfigureLeecher: configure,
|
|
|
|
})
|
|
|
|
}
|