mirror of
https://github.com/sot-tech/mochi.git
synced 2026-04-28 08:29:59 -07:00
44 lines
870 B
Go
44 lines
870 B
Go
// Copyright 2014 The Chihaya Authors. All rights reserved.
|
|
// Use of this source code is governed by the BSD 2-Clause license,
|
|
// which can be found in the LICENSE file.
|
|
|
|
// Package tracker provides a generic interface for manipulating a
|
|
// BitTorrent tracker's fast-moving data.
|
|
package tracker
|
|
|
|
import (
|
|
"github.com/chihaya/chihaya/config"
|
|
"github.com/chihaya/chihaya/drivers/backend"
|
|
)
|
|
|
|
type Tracker struct {
|
|
cfg *config.Config
|
|
Pool Pool
|
|
backend backend.Conn
|
|
}
|
|
|
|
func New(cfg *config.Config) (*Tracker, error) {
|
|
pool, err := Open(&cfg.Tracker)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
bc, err := backend.Open(&cfg.Backend)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
go PurgeInactivePeers(
|
|
pool,
|
|
cfg.PurgeInactiveTorrents,
|
|
cfg.Announce.Duration*2,
|
|
cfg.Announce.Duration,
|
|
)
|
|
|
|
return &Tracker{
|
|
cfg: cfg,
|
|
Pool: pool,
|
|
backend: bc,
|
|
}, nil
|
|
}
|