repurpose drivers from mock to no-op and memory

This commit is contained in:
Jimmy Zelinskie 2014-07-15 00:22:04 -04:00
parent b321d1f0fa
commit d2ba9fb9f7
10 changed files with 82 additions and 110 deletions

View file

@ -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

View file

@ -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,

View file

@ -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{})
}

View file

@ -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{})
}

View file

@ -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"

View file

@ -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{})
}

View file

@ -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"

View file

@ -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,

View file

@ -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

View file

@ -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 (