diff --git a/README.md b/README.md index 503f456..8ac0992 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,14 @@ # Chihaya [![Build Status](https://api.travis-ci.org/chihaya/chihaya.svg?branch=master)](https://travis-ci.org/chihaya/chihaya) -Chihaya is a high-performance [BitTorrent tracker](http://en.wikipedia.org/wiki/BitTorrent_tracker) -written in the Go programming language. It is still heavily under development and the current `master` branch -should not be used in production. +Chihaya is a high-performance [BitTorrent tracker](http://en.wikipedia.org/wiki/BitTorrent_tracker) written in the Go programming language. It is still heavily under development and the current `master` branch should not be used in production. Planned features include: - Light resource consumption -- Fast request processing, sparing the network from exorbitant connection counts +- Fast request processing using connection pools to spare the network from exorbitant connections - Maximum compatibility with what exists of the BitTorrent spec -- Correct IPv6 support -- Generic storage interfaces that are easily adapted to work with any existing web application -- Scaling properties that directly correlate with those of the chosen data stores +- Correct IPv6 support *gasp* +- Generic storage interfaces that are easily adapted to work with any database. ### Technical Details @@ -19,9 +16,7 @@ See [the wiki](https://github.com/chihaya/chihaya/wiki) for a discussion of the ## Using Chihaya -Chihaya is intended to work with existing torrent indexing web frameworks, such as [Batter] and [Gazelle]. -Following the Unix way, it is built to perform a specific task, and interface with any system that -needs its functionality. See [below](#drivers) for more info. +Chihaya can be ran as a public or private tracker and is intended to work with existing torrent-indexing web frameworks, such as [Gazelle], [Batter] and any others that spring up. Following the Unix way, it is built to perform one specific task: handling announces and scrapes. By cleanly separating the concerns between tracker and database, we can provide an interface that can be used by system that needs its functionality. See [below](#drivers) for more info. [batter]: https://github.com/wafflesfm/batter [gazelle]: https://github.com/whatcd/gazelle @@ -54,16 +49,16 @@ $ go test -v ./... Chihaya is designed to remain agnostic about the choice of data store for an application, and it is straightforward to [implement a new driver]. However, there -are a number of drivers that will be directly supported: +are a number of drivers that will be directly supported "out of the box": Tracker: -* mock (memory) +* memory * [redis](https://github.com/chihaya/chihaya-redis) Backend: -* mock (memory) +* noop (for public trackers) * [gazelle (mysql)](https://github.com/chihaya/chihaya-gazelle) [implement a new driver]: https://github.com/chihaya/chihaya/wiki/Implementing-a-driver diff --git a/config/config.go b/config/config.go index e03f07c..84a73b7 100644 --- a/config/config.go +++ b/config/config.go @@ -60,10 +60,10 @@ type Config struct { var DefaultConfig = Config{ Addr: "127.0.0.1:6881", Tracker: DriverConfig{ - Name: "mock", + Name: "memory", }, Backend: DriverConfig{ - Name: "mock", + Name: "noop", }, Private: false, Freeleech: false, diff --git a/drivers/backend/mock/driver.go b/drivers/backend/mock/driver.go deleted file mode 100644 index 745ccbc..0000000 --- a/drivers/backend/mock/driver.go +++ /dev/null @@ -1,81 +0,0 @@ -// 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 mock implements the models interface for a BitTorrent tracker's -// backend models. It can be used in production, but isn't recommended. -// Stored values will not persist if the tracker is restarted. -package mock - -import ( - "sync" - - "github.com/chihaya/chihaya/config" - "github.com/chihaya/chihaya/drivers/backend" - "github.com/chihaya/chihaya/models" -) - -type driver struct{} - -// Mock is a concrete implementation of the backend.Conn interface (plus some -// debugging methods) that stores deltas in memory. -type Mock struct { - deltaHistory []*models.AnnounceDelta - deltaHistoryM sync.RWMutex -} - -func (d *driver) New(conf *config.DriverConfig) (backend.Conn, error) { - return &Mock{}, nil -} - -// Close returns nil. -func (m *Mock) Close() error { - return nil -} - -// RecordAnnounce adds a delta to the history. -func (m *Mock) RecordAnnounce(delta *models.AnnounceDelta) error { - m.deltaHistoryM.Lock() - defer m.deltaHistoryM.Unlock() - - m.deltaHistory = append(m.deltaHistory, delta) - - return nil -} - -// DeltaHistory safely copies and returns the history of recorded deltas. -func (m *Mock) DeltaHistory() []models.AnnounceDelta { - m.deltaHistoryM.Lock() - defer m.deltaHistoryM.Unlock() - - cp := make([]models.AnnounceDelta, len(m.deltaHistory)) - for index, delta := range m.deltaHistory { - cp[index] = *delta - } - - return cp -} - -// LoadTorrents returns (nil, nil). -func (m *Mock) LoadTorrents(ids []uint64) ([]*models.Torrent, error) { - return nil, nil -} - -// LoadAllTorrents returns (nil, nil). -func (m *Mock) LoadAllTorrents() ([]*models.Torrent, error) { - return nil, nil -} - -// LoadUsers returns (nil, nil). -func (m *Mock) LoadUsers(ids []uint64) ([]*models.User, error) { - return nil, nil -} - -// LoadAllUsers returns (nil, nil). -func (m *Mock) LoadAllUsers(ids []uint64) ([]*models.User, error) { - return nil, nil -} - -func init() { - backend.Register("mock", &driver{}) -} diff --git a/drivers/backend/noop/driver.go b/drivers/backend/noop/driver.go new file mode 100644 index 0000000..edb7e56 --- /dev/null +++ b/drivers/backend/noop/driver.go @@ -0,0 +1,56 @@ +// 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 noop implements a Chihaya backend storage driver as a no-op. This is +// useful for running Chihaya as a public tracker. +package noop + +import ( + "github.com/chihaya/chihaya/config" + "github.com/chihaya/chihaya/drivers/backend" + "github.com/chihaya/chihaya/models" +) + +type driver struct{} + +type NoOp struct{} + +// New returns a new Chihaya backend driver that does nothing. +func (d *driver) New(cfg *config.DriverConfig) (backend.Conn, error) { + return &NoOp{}, nil +} + +// Close returns nil. +func (n *NoOp) Close() error { + return nil +} + +// RecordAnnounce returns nil. +func (n *NoOp) RecordAnnounce(delta *models.AnnounceDelta) error { + return nil +} + +// LoadTorrents returns (nil, nil). +func (n *NoOp) LoadTorrents(ids []uint64) ([]*models.Torrent, error) { + return nil, nil +} + +// LoadAllTorrents returns (nil, nil). +func (n *NoOp) LoadAllTorrents() ([]*models.Torrent, error) { + return nil, nil +} + +// LoadUsers returns (nil, nil). +func (n *NoOp) LoadUsers(ids []uint64) ([]*models.User, error) { + return nil, nil +} + +// LoadAllUsers returns (nil, nil). +func (n *NoOp) LoadAllUsers(ids []uint64) ([]*models.User, error) { + return nil, nil +} + +func init() { + backend.Register("noop", &driver{}) +} diff --git a/drivers/tracker/mock/conn.go b/drivers/tracker/memory/conn.go similarity index 99% rename from drivers/tracker/mock/conn.go rename to drivers/tracker/memory/conn.go index bc5a6ff..6891d9e 100644 --- a/drivers/tracker/mock/conn.go +++ b/drivers/tracker/memory/conn.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the BSD 2-Clause license, // which can be found in the LICENSE file. -package mock +package memory import ( "github.com/chihaya/chihaya/drivers/tracker" diff --git a/drivers/tracker/mock/driver.go b/drivers/tracker/memory/driver.go similarity index 76% rename from drivers/tracker/mock/driver.go rename to drivers/tracker/memory/driver.go index f33744d..2d9c9b8 100644 --- a/drivers/tracker/mock/driver.go +++ b/drivers/tracker/memory/driver.go @@ -2,10 +2,9 @@ // Use of this source code is governed by the BSD 2-Clause license, // which can be found in the LICENSE file. -// Package mock implements the models interface for a BitTorrent tracker -// within memory. It can be used in production, but isn't recommended. +// Package memory implements a Chihaya tracker storage driver within memory. // Stored values will not persist if the tracker is restarted. -package mock +package memory import ( "github.com/chihaya/chihaya/config" @@ -24,5 +23,5 @@ func (d *driver) New(conf *config.DriverConfig) tracker.Pool { } func init() { - tracker.Register("mock", &driver{}) + tracker.Register("memory", &driver{}) } diff --git a/drivers/tracker/mock/pool.go b/drivers/tracker/memory/pool.go similarity index 97% rename from drivers/tracker/mock/pool.go rename to drivers/tracker/memory/pool.go index 90cdda3..7dbb440 100644 --- a/drivers/tracker/mock/pool.go +++ b/drivers/tracker/memory/pool.go @@ -2,7 +2,7 @@ // Use of this source code is governed by the BSD 2-Clause license, // which can be found in the LICENSE file. -package mock +package memory import ( "sync" diff --git a/example.json b/example.json index 27bc39d..334d11d 100644 --- a/example.json +++ b/example.json @@ -1,16 +1,16 @@ { "network": "tcp", - "addr": ":6881", + "addr": "127.0.0.1:6881", "tracker": { - "driver": "mock" + "driver": "memory" }, "backend": { - "driver": "mock" + "driver": "noop" }, - "private": true, + "private": false, "freeleech": false, "whitelist": false, diff --git a/http/announce_test.go b/http/announce_test.go index 9efb8e5..a71dc19 100644 --- a/http/announce_test.go +++ b/http/announce_test.go @@ -13,10 +13,11 @@ import ( "github.com/chihaya/chihaya/config" "github.com/chihaya/chihaya/drivers/backend" - _ "github.com/chihaya/chihaya/drivers/backend/mock" "github.com/chihaya/chihaya/drivers/tracker" - _ "github.com/chihaya/chihaya/drivers/tracker/mock" "github.com/chihaya/chihaya/models" + + _ "github.com/chihaya/chihaya/drivers/backend/noop" + _ "github.com/chihaya/chihaya/drivers/tracker/memory" ) type primer func(tracker.Pool, backend.Conn) error diff --git a/main.go b/main.go index 30ca9b1..29431b5 100644 --- a/main.go +++ b/main.go @@ -13,9 +13,11 @@ import ( "github.com/golang/glog" "github.com/chihaya/chihaya/config" - _ "github.com/chihaya/chihaya/drivers/backend/mock" - _ "github.com/chihaya/chihaya/drivers/tracker/mock" "github.com/chihaya/chihaya/http" + + // All drivers are imported here. + _ "github.com/chihaya/chihaya/drivers/backend/noop" + _ "github.com/chihaya/chihaya/drivers/tracker/memory" ) var (