diff --git a/storage/tracker/mock/conn.go b/storage/tracker/mock/conn.go new file mode 100644 index 0000000..e1136d3 --- /dev/null +++ b/storage/tracker/mock/conn.go @@ -0,0 +1,109 @@ +// 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 + +import ( + "github.com/pushrax/chihaya/storage" +) + +type Conn struct { + *Pool +} + +func (c *Conn) FindUser(passkey string) (*storage.User, bool, error) { + c.usersM.RLock() + defer c.usersM.RUnlock() + user, ok := c.users[passkey] + if !ok { + return nil, false, nil + } + return user, true, nil +} + +func (c *Conn) FindTorrent(infohash string) (*storage.Torrent, bool, error) { + c.torrentsM.RLock() + defer c.torrentsM.RUnlock() + torrent, ok := c.torrents[infohash] + if !ok { + return nil, false, nil + } + return torrent, true, nil +} + +func (c *Conn) ClientWhitelisted(peerID string) (bool, error) { + _, ok := c.whitelist[peerID] + if !ok { + return false, nil + } + return true, nil +} + +func (c *Conn) RecordSnatch(u *storage.User, t *storage.Torrent) error { + return nil +} + +func (c *Conn) MarkActive(t *storage.Torrent) error { + return nil +} + +func (c *Conn) AddLeecher(t *storage.Torrent, p *storage.Peer) error { + return nil +} + +func (c *Conn) AddSeeder(t *storage.Torrent, p *storage.Peer) error { + return nil +} + +func (c *Conn) RemoveLeecher(t *storage.Torrent, p *storage.Peer) error { + return nil +} + +func (c *Conn) RemoveSeeder(t *storage.Torrent, p *storage.Peer) error { + return nil +} + +func (c *Conn) SetLeecher(t *storage.Torrent, p *storage.Peer) error { + return nil +} + +func (c *Conn) SetSeeder(t *storage.Torrent, p *storage.Peer) error { + return nil +} + +func (c *Conn) IncrementSlots(u *storage.User) error { + return nil +} + +func (c *Conn) DecrementSlots(u *storage.User) error { + return nil +} + +func (c *Conn) LeecherFinished(t *storage.Torrent, p *storage.Peer) error { + return nil +} + +func (c *Conn) AddTorrent(t *storage.Torrent) error { + return nil +} + +func (c *Conn) RemoveTorrent(t *storage.Torrent) error { + return nil +} + +func (c *Conn) AddUser(u *storage.User) error { + return nil +} + +func (c *Conn) RemoveUser(u *storage.User) error { + return nil +} + +func (c *Conn) WhitelistClient(peerID string) error { + return nil +} + +func (c *Conn) UnWhitelistClient(peerID string) error { + return nil +} diff --git a/storage/tracker/mock/driver.go b/storage/tracker/mock/driver.go new file mode 100644 index 0000000..7e16c65 --- /dev/null +++ b/storage/tracker/mock/driver.go @@ -0,0 +1,24 @@ +// 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 +// within memory. 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/pushrax/chihaya/config" + "github.com/pushrax/chihaya/storage" + "github.com/pushrax/chihaya/storage/tracker" +) + +type driver struct{} + +func (d *driver) New(conf *config.DataStore) tracker.Pool { + return &Pool{ + users: make(map[string]*storage.User), + torrents: make(map[string]*storage.Torrent), + whitelist: make(map[string]string), + } +} diff --git a/storage/tracker/mock/pool.go b/storage/tracker/mock/pool.go new file mode 100644 index 0000000..28194b2 --- /dev/null +++ b/storage/tracker/mock/pool.go @@ -0,0 +1,32 @@ +// 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 + +import ( + "sync" + + "github.com/pushrax/chihaya/storage" + "github.com/pushrax/chihaya/storage/tracker" +) + +type Pool struct { + users map[string]*storage.User + usersM sync.RWMutex + + torrents map[string]*storage.Torrent + torrentsM sync.RWMutex + + whitelist map[string]string +} + +func (p *Pool) Get() (tracker.Conn, error) { + return &Conn{ + Pool: p, + }, nil +} + +func (p *Pool) Close() error { + return nil +}