repurpose drivers from mock to no-op and memory
This commit is contained in:
parent
b321d1f0fa
commit
d2ba9fb9f7
10 changed files with 82 additions and 110 deletions
21
README.md
21
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 [![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)
|
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.
|
||||||
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:
|
Planned features include:
|
||||||
|
|
||||||
- Light resource consumption
|
- 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
|
- Maximum compatibility with what exists of the BitTorrent spec
|
||||||
- Correct IPv6 support
|
- Correct IPv6 support *gasp*
|
||||||
- Generic storage interfaces that are easily adapted to work with any existing web application
|
- Generic storage interfaces that are easily adapted to work with any database.
|
||||||
- Scaling properties that directly correlate with those of the chosen data stores
|
|
||||||
|
|
||||||
### Technical Details
|
### Technical Details
|
||||||
|
|
||||||
|
@ -19,9 +16,7 @@ See [the wiki](https://github.com/chihaya/chihaya/wiki) for a discussion of the
|
||||||
|
|
||||||
## Using Chihaya
|
## Using Chihaya
|
||||||
|
|
||||||
Chihaya is intended to work with existing torrent indexing web frameworks, such as [Batter] and [Gazelle].
|
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.
|
||||||
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.
|
|
||||||
|
|
||||||
[batter]: https://github.com/wafflesfm/batter
|
[batter]: https://github.com/wafflesfm/batter
|
||||||
[gazelle]: https://github.com/whatcd/gazelle
|
[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
|
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
|
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:
|
Tracker:
|
||||||
|
|
||||||
* mock (memory)
|
* memory
|
||||||
* [redis](https://github.com/chihaya/chihaya-redis)
|
* [redis](https://github.com/chihaya/chihaya-redis)
|
||||||
|
|
||||||
Backend:
|
Backend:
|
||||||
|
|
||||||
* mock (memory)
|
* noop (for public trackers)
|
||||||
* [gazelle (mysql)](https://github.com/chihaya/chihaya-gazelle)
|
* [gazelle (mysql)](https://github.com/chihaya/chihaya-gazelle)
|
||||||
|
|
||||||
[implement a new driver]: https://github.com/chihaya/chihaya/wiki/Implementing-a-driver
|
[implement a new driver]: https://github.com/chihaya/chihaya/wiki/Implementing-a-driver
|
||||||
|
|
|
@ -60,10 +60,10 @@ type Config struct {
|
||||||
var DefaultConfig = Config{
|
var DefaultConfig = Config{
|
||||||
Addr: "127.0.0.1:6881",
|
Addr: "127.0.0.1:6881",
|
||||||
Tracker: DriverConfig{
|
Tracker: DriverConfig{
|
||||||
Name: "mock",
|
Name: "memory",
|
||||||
},
|
},
|
||||||
Backend: DriverConfig{
|
Backend: DriverConfig{
|
||||||
Name: "mock",
|
Name: "noop",
|
||||||
},
|
},
|
||||||
Private: false,
|
Private: false,
|
||||||
Freeleech: false,
|
Freeleech: false,
|
||||||
|
|
|
@ -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{})
|
|
||||||
}
|
|
56
drivers/backend/noop/driver.go
Normal file
56
drivers/backend/noop/driver.go
Normal 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{})
|
||||||
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by the BSD 2-Clause license,
|
// Use of this source code is governed by the BSD 2-Clause license,
|
||||||
// which can be found in the LICENSE file.
|
// which can be found in the LICENSE file.
|
||||||
|
|
||||||
package mock
|
package memory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/chihaya/chihaya/drivers/tracker"
|
"github.com/chihaya/chihaya/drivers/tracker"
|
|
@ -2,10 +2,9 @@
|
||||||
// Use of this source code is governed by the BSD 2-Clause license,
|
// Use of this source code is governed by the BSD 2-Clause license,
|
||||||
// which can be found in the LICENSE file.
|
// which can be found in the LICENSE file.
|
||||||
|
|
||||||
// Package mock implements the models interface for a BitTorrent tracker
|
// Package memory implements a Chihaya tracker storage driver within memory.
|
||||||
// within memory. It can be used in production, but isn't recommended.
|
|
||||||
// Stored values will not persist if the tracker is restarted.
|
// Stored values will not persist if the tracker is restarted.
|
||||||
package mock
|
package memory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/chihaya/chihaya/config"
|
"github.com/chihaya/chihaya/config"
|
||||||
|
@ -24,5 +23,5 @@ func (d *driver) New(conf *config.DriverConfig) tracker.Pool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
tracker.Register("mock", &driver{})
|
tracker.Register("memory", &driver{})
|
||||||
}
|
}
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by the BSD 2-Clause license,
|
// Use of this source code is governed by the BSD 2-Clause license,
|
||||||
// which can be found in the LICENSE file.
|
// which can be found in the LICENSE file.
|
||||||
|
|
||||||
package mock
|
package memory
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
|
@ -1,16 +1,16 @@
|
||||||
{
|
{
|
||||||
"network": "tcp",
|
"network": "tcp",
|
||||||
"addr": ":6881",
|
"addr": "127.0.0.1:6881",
|
||||||
|
|
||||||
"tracker": {
|
"tracker": {
|
||||||
"driver": "mock"
|
"driver": "memory"
|
||||||
},
|
},
|
||||||
|
|
||||||
"backend": {
|
"backend": {
|
||||||
"driver": "mock"
|
"driver": "noop"
|
||||||
},
|
},
|
||||||
|
|
||||||
"private": true,
|
"private": false,
|
||||||
"freeleech": false,
|
"freeleech": false,
|
||||||
"whitelist": false,
|
"whitelist": false,
|
||||||
|
|
||||||
|
|
|
@ -13,10 +13,11 @@ import (
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/config"
|
"github.com/chihaya/chihaya/config"
|
||||||
"github.com/chihaya/chihaya/drivers/backend"
|
"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"
|
||||||
_ "github.com/chihaya/chihaya/drivers/tracker/mock"
|
|
||||||
"github.com/chihaya/chihaya/models"
|
"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
|
type primer func(tracker.Pool, backend.Conn) error
|
||||||
|
|
6
main.go
6
main.go
|
@ -13,9 +13,11 @@ import (
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
|
|
||||||
"github.com/chihaya/chihaya/config"
|
"github.com/chihaya/chihaya/config"
|
||||||
_ "github.com/chihaya/chihaya/drivers/backend/mock"
|
|
||||||
_ "github.com/chihaya/chihaya/drivers/tracker/mock"
|
|
||||||
"github.com/chihaya/chihaya/http"
|
"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 (
|
var (
|
||||||
|
|
Loading…
Add table
Reference in a new issue