From afa8abb9abb2f9a6b138ee257e4d8e85f11feed4 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Fri, 6 Sep 2013 19:01:02 -0400 Subject: [PATCH] Remove the unimplemented batter driver --- models/models.go | 1 + storage/batter/batter.go | 52 -------------------------------------- storage/gazelle/gazelle.go | 8 +++++- 3 files changed, 8 insertions(+), 53 deletions(-) delete mode 100644 storage/batter/batter.go diff --git a/models/models.go b/models/models.go index 36cfd62..2ea8527 100644 --- a/models/models.go +++ b/models/models.go @@ -45,4 +45,5 @@ type AnnounceDelta struct { Uploaded uint64 Downloaded uint64 Timestamp float64 + Snatched bool } diff --git a/storage/batter/batter.go b/storage/batter/batter.go deleted file mode 100644 index 4badba2..0000000 --- a/storage/batter/batter.go +++ /dev/null @@ -1,52 +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 batter provides a driver for a BitTorrent tracker to interface -// with the postgres database used by batter (github.com/wafflesfm/batter). -package batter - -import ( - "database/sql" - "fmt" - - "github.com/pushrax/chihaya/config" - "github.com/pushrax/chihaya/models" - "github.com/pushrax/chihaya/storage" - - _ "github.com/bmizerany/pq" -) - -type driver struct{} - -func (d *driver) New(conf *config.DataStore) storage.Conn { - dsn := fmt.Sprintf( - "host=%s user=%s password=%s dbname=%s", - conf.Host, - conf.Port, - conf.Username, - conf.Password, - conf.Schema, - ) - db, err := sql.Open("postgres", dsn) - if err != nil { - panic("batter: failed to open connection to postgres") - } - return &Conn{db} -} - -type Conn struct { - *sql.DB -} - -func (c *Conn) UpdateTorrents(t []models.Torrent) error { - return nil -} - -func (c *Conn) UpdateUsers(u []models.User) error { - return nil -} - -func init() { - storage.Register("batter", &driver{}) -} diff --git a/storage/gazelle/gazelle.go b/storage/gazelle/gazelle.go index face4dc..664fbeb 100644 --- a/storage/gazelle/gazelle.go +++ b/storage/gazelle/gazelle.go @@ -75,9 +75,15 @@ func (c *Conn) Close() error { } func (c *Conn) RecordAnnounce(delta *models.AnnounceDelta) error { + snatchCount := 0 + if delta.Snatched { + snatchCount = 1 + } + c.torrentChannel <- fmt.Sprintf( - "('%s','%s','%s','%s','%s')", + "('%d','%d','%d','%d','%d')", delta.Torrent.ID, + snatchCount, len(delta.Torrent.Seeders), len(delta.Torrent.Leechers), delta.Torrent.LastAction,