rm driver deps

This commit is contained in:
Jimmy Zelinskie 2013-12-02 05:00:28 -05:00
parent d99103643e
commit 76f03e209f
12 changed files with 55 additions and 109 deletions

View file

@ -2,9 +2,6 @@ language: go
go: 1.2 go: 1.2
env:
- TESTCONFIGPATH=/home/travis/gopath/src/github.com/chihaya/chihaya/config/example.json
services: services:
- redis-server - redis-server

View file

@ -42,12 +42,8 @@ flag. An example configuration file can be found
### Running the tests ### Running the tests
The tests require a running redis server to function correctly, and a config to use for the tests.
The `$TESTCONFIGPATH` environment variable is required for the tests to function:
```sh ```sh
$ cd $GOPATH/src/github.com/chihaya/chihaya $ cd $GOPATH/src/github.com/chihaya/chihaya
$ export TESTCONFIGPATH=$GOPATH/src/github.com/chihaya/chihaya/config/example.json
$ go test -v ./... $ go test -v ./...
``` ```
@ -59,11 +55,12 @@ are a number of drivers that will be directly supported:
Tracker: Tracker:
* mock (memory)
* [redis](https://github.com/chihaya/chihaya-redis) * [redis](https://github.com/chihaya/chihaya-redis)
* memory
Backend: Backend:
* mock (memory)
* [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

View file

@ -46,13 +46,11 @@ type DataStore struct {
// Config represents a configuration for a server.Server. // Config represents a configuration for a server.Server.
type Config struct { type Config struct {
Addr string `json:"addr"` Addr string `json:"addr"`
PubAddr string `json:"pub_addr"` Tracker DataStore `json:"tracker"`
Cache DataStore `json:"cache"` Backend DataStore `json:"backend"`
Storage DataStore `json:"storage"`
Private bool `json:"private"` Private bool `json:"private"`
Freeleech bool `json:"freeleech"` Freeleech bool `json:"freeleech"`
Slots bool `json:"slots"`
Announce Duration `json:"announce"` Announce Duration `json:"announce"`
MinAnnounce Duration `json:"min_announce"` MinAnnounce Duration `json:"min_announce"`

View file

@ -1,29 +0,0 @@
// Copyright 2013 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 config
import (
"bytes"
"io/ioutil"
"os"
"testing"
)
func TestOpenConfig(t *testing.T) {
if _, err := Open(os.Getenv("TESTCONFIGPATH")); err != nil {
t.Error(err)
}
}
func TestNewConfig(t *testing.T) {
contents, err := ioutil.ReadFile(os.Getenv("TESTCONFIGPATH"))
if err != nil {
t.Error(err)
}
buff := bytes.NewBuffer(contents)
if _, err := newConfig(buff); err != nil {
t.Error(err)
}
}

View file

@ -1,35 +0,0 @@
{
"network": "tcp",
"addr": ":80",
"cache": {
"driver": "mock",
"network": "tcp",
"host": "127.0.0.1",
"port": "6379",
"user": "root",
"pass": "",
"prefix": "test:",
"max_idle_conns": 3,
"idle_timeout": "240s"
},
"storage": {
"driver": "gazelle",
"host": "127.0.0.1",
"port": "5432",
"user": "postgres",
"pass": ""
},
"private": true,
"freeleech": false,
"announce": "30m",
"min_announce": "15m",
"read_timeout": "20s",
"default_num_want": 50
}

25
config/mock_config.go Normal file
View file

@ -0,0 +1,25 @@
// Copyright 2013 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 config
import (
"time"
)
var MockConfig = Config{
Addr: ":80",
Tracker: DataStore{
Driver: "mock",
},
Backend: DataStore{
Driver: "mock",
},
Private: true,
Freeleech: false,
Announce: Duration{30 * time.Minute},
MinAnnounce: Duration{15 * time.Minute},
ReadTimeout: Duration{20 % time.Second},
DefaultNumWant: 50,
}

View file

@ -14,9 +14,6 @@ import (
"github.com/chihaya/chihaya/config" "github.com/chihaya/chihaya/config"
"github.com/chihaya/chihaya/server" "github.com/chihaya/chihaya/server"
_ "github.com/chihaya/chihaya-gazelle"
_ "github.com/chihaya/chihaya-redis"
) )
var ( var (

View file

@ -114,14 +114,6 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
} }
default: default:
// Check the user's slots to see if they're allowed to leech
if s.conf.Slots && user.Slots != -1 && left != 0 {
if user.SlotsUsed >= user.Slots {
fail(errors.New("You've run out of download slots."), w, r)
return
}
}
if left == 0 { if left == 0 {
// Save the peer as a new seeder // Save the peer as a new seeder
err := conn.AddSeeder(torrent, peer) err := conn.AddSeeder(torrent, peer)
@ -129,11 +121,6 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
log.Panicf("server: %s", err) log.Panicf("server: %s", err)
} }
} else { } else {
// Save the peer as a new leecher and increment the user's slots
err := conn.IncrementSlots(user)
if err != nil {
log.Panicf("server: %s", err)
}
err = conn.AddLeecher(torrent, peer) err = conn.AddLeecher(torrent, peer)
if err != nil { if err != nil {
log.Panicf("server: %s", err) log.Panicf("server: %s", err)
@ -155,10 +142,6 @@ func (s Server) serveAnnounce(w http.ResponseWriter, r *http.Request) {
if err != nil { if err != nil {
log.Panicf("server: %s", err) log.Panicf("server: %s", err)
} }
err = conn.DecrementSlots(user)
if err != nil {
log.Panicf("server: %s", err)
}
} }
case event == "completed": case event == "completed":

View file

@ -37,7 +37,7 @@ type Server struct {
} }
func New(conf *config.Config) (*Server, error) { func New(conf *config.Config) (*Server, error) {
pool, err := tracker.Open(&conf.Cache) pool, err := tracker.Open(&conf.Tracker)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -8,22 +8,15 @@ import (
"errors" "errors"
"net/http" "net/http"
"net/http/httptest" "net/http/httptest"
"os"
"testing" "testing"
"github.com/chihaya/chihaya/config" "github.com/chihaya/chihaya/config"
_ "github.com/chihaya/chihaya/storage/backend/mock"
_ "github.com/chihaya/chihaya-gazelle"
_ "github.com/chihaya/chihaya/storage/tracker/mock" _ "github.com/chihaya/chihaya/storage/tracker/mock"
) )
func newTestServer() (*Server, error) { func newTestServer() (*Server, error) {
testConfig, err := config.Open(os.Getenv("TESTCONFIGPATH")) s, err := New(&config.MockConfig)
if err != nil {
return nil, err
}
s, err := New(testConfig)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View file

@ -0,0 +1,23 @@
// Copyright 2013 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 storage interface for a BitTorrent tracker's
// backend storage. It can be used in production, but isn't recommended.
// Stored values will not persist if the tracker is restarted.
package mock
import (
"github.com/chihaya/chihaya/config"
"github.com/chihaya/chihaya/storage/backend"
)
type driver struct{}
func (d *driver) New(conf *config.DataStore) backend.Conn {
return nil
}
func init() {
backend.Register("mock", &driver{})
}

View file

@ -67,15 +67,12 @@ type Conn interface {
// Writes // Writes
RecordSnatch(u *storage.User, t *storage.Torrent) error RecordSnatch(u *storage.User, t *storage.Torrent) error
MarkActive(t *storage.Torrent) error MarkActive(t *storage.Torrent) error
MarkInactive(t *storage.Torrent) error
AddLeecher(t *storage.Torrent, p *storage.Peer) error AddLeecher(t *storage.Torrent, p *storage.Peer) error
AddSeeder(t *storage.Torrent, p *storage.Peer) error AddSeeder(t *storage.Torrent, p *storage.Peer) error
RemoveLeecher(t *storage.Torrent, p *storage.Peer) error RemoveLeecher(t *storage.Torrent, p *storage.Peer) error
RemoveSeeder(t *storage.Torrent, p *storage.Peer) error RemoveSeeder(t *storage.Torrent, p *storage.Peer) error
SetLeecher(t *storage.Torrent, p *storage.Peer) error SetLeecher(t *storage.Torrent, p *storage.Peer) error
SetSeeder(t *storage.Torrent, p *storage.Peer) error SetSeeder(t *storage.Torrent, p *storage.Peer) error
IncrementSlots(u *storage.User) error
DecrementSlots(u *storage.User) error
LeecherFinished(t *storage.Torrent, p *storage.Peer) error LeecherFinished(t *storage.Torrent, p *storage.Peer) error
// Priming / Testing // Priming / Testing