Skip to content

Commit

Permalink
torrent acceptor host can be configured
Browse files Browse the repository at this point in the history
  • Loading branch information
bsergean authored and cenkalti committed Jun 1, 2022
1 parent a7e58b3 commit bbd55e9
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 3 additions & 0 deletions torrent/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ type Config struct {
// If true, torrent files are saved into <data_dir>/<torrent_id>/<torrent_name>.
// Useful if downloading the same torrent from multiple sources.
DataDirIncludesTorrentID bool
// Host to listen for TCP Acceptor. Port is computed automatically
Host string
// New torrents will be listened at selected port in this range.
PortBegin, PortEnd uint16
// At start, client will set max open files limit to this number. (like "ulimit -n" command)
Expand Down Expand Up @@ -196,6 +198,7 @@ var DefaultConfig = Config{
Database: "~/rain/session.db",
DataDir: "~/rain/data",
DataDirIncludesTorrentID: true,
Host: "0.0.0.0",
PortBegin: 20000,
PortEnd: 30000,
MaxOpenFiles: 10240,
Expand Down
3 changes: 2 additions & 1 deletion torrent/torrent_start.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@ func (t *torrent) startAcceptor() {
if t.acceptor != nil {
return
}
listener, err := net.ListenTCP("tcp4", &net.TCPAddr{Port: t.port})
ip := net.ParseIP(t.session.config.Host)
listener, err := net.ListenTCP("tcp4", &net.TCPAddr{IP: ip, Port: t.port})
if err != nil {
t.log.Warningf("cannot listen port %d: %s", t.port, err)
} else {
Expand Down
1 change: 1 addition & 0 deletions torrent/torrent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func newTestSession(t *testing.T) (*Session, func()) {
cfg.DHTEnabled = false
cfg.PEXEnabled = false
cfg.RPCEnabled = false
cfg.Host = "127.0.0.1"
s, err := NewSession(cfg)
if err != nil {
t.Fatal(err)
Expand Down

0 comments on commit bbd55e9

Please sign in to comment.