s/trackerfuncs/trackerlogic

This commit is contained in:
Jimmy Zelinskie 2016-08-09 19:28:59 -04:00
parent bff3d203a2
commit 11d90b088c
5 changed files with 18 additions and 18 deletions

View file

@ -12,9 +12,8 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
// Package trakr implements a BitTorrent Tracker that supports multiple // Package backend implements the TrackerLogic interface by executing
// protocols and configurable Hooks that execute before and after a Response // a series of middleware hooks.
// has been delivered to a BitTorrent client.
package backend package backend
import ( import (
@ -31,7 +30,7 @@ type BackendConfig struct {
AnnounceInterval time.Duration `yaml:"announce_interval"` AnnounceInterval time.Duration `yaml:"announce_interval"`
} }
var _ frontend.TrackerFuncs = &Backend{} var _ frontend.TrackerLogic = &Backend{}
func New(config BackendConfig, peerStore PeerStore, announcePreHooks, announcePostHooks, scrapePreHooks, scrapePostHooks []Hook) (*Backend, error) { func New(config BackendConfig, peerStore PeerStore, announcePreHooks, announcePostHooks, scrapePreHooks, scrapePostHooks []Hook) (*Backend, error) {
toReturn := &Backend{ toReturn := &Backend{
@ -86,8 +85,8 @@ func (b *Backend) HandleAnnounce(ctx context.Context, req *bittorrent.AnnounceRe
return resp, nil return resp, nil
} }
// AfterAnnounce does something with the results of an Announce after it // AfterAnnounce does something with the results of an Announce after it has
// has been completed. // been completed.
func (b *Backend) AfterAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, resp *bittorrent.AnnounceResponse) { func (b *Backend) AfterAnnounce(ctx context.Context, req *bittorrent.AnnounceRequest, resp *bittorrent.AnnounceResponse) {
for _, h := range b.announcePostHooks { for _, h := range b.announcePostHooks {
if err := h.HandleAnnounce(ctx, req, resp); err != nil { if err := h.HandleAnnounce(ctx, req, resp); err != nil {
@ -111,7 +110,8 @@ func (b *Backend) HandleScrape(ctx context.Context, req *bittorrent.ScrapeReques
return resp, nil return resp, nil
} }
// AfterScrape does something with the results of a Scrape after it has been completed. // AfterScrape does something with the results of a Scrape after it has been
// completed.
func (b *Backend) AfterScrape(ctx context.Context, req *bittorrent.ScrapeRequest, resp *bittorrent.ScrapeResponse) { func (b *Backend) AfterScrape(ctx context.Context, req *bittorrent.ScrapeRequest, resp *bittorrent.ScrapeResponse) {
for _, h := range b.scrapePostHooks { for _, h := range b.scrapePostHooks {
if err := h.HandleScrape(ctx, req, resp); err != nil { if err := h.HandleScrape(ctx, req, resp); err != nil {

View file

@ -107,7 +107,7 @@ func main() {
var uFrontend *udpfrontend.Frontend var uFrontend *udpfrontend.Frontend
if configFile.Config.HTTPConfig.Addr != "" { if configFile.Config.HTTPConfig.Addr != "" {
// TODO get the real TrackerFuncs // TODO get the real TrackerLogic
hFrontend = httpfrontend.NewFrontend(trackerBackend, configFile.Config.HTTPConfig) hFrontend = httpfrontend.NewFrontend(trackerBackend, configFile.Config.HTTPConfig)
go func() { go func() {
@ -119,7 +119,7 @@ func main() {
} }
if configFile.Config.UDPConfig.Addr != "" { if configFile.Config.UDPConfig.Addr != "" {
// TODO get the real TrackerFuncs // TODO get the real TrackerLogic
uFrontend = udpfrontend.NewFrontend(trackerBackend, configFile.Config.UDPConfig) uFrontend = udpfrontend.NewFrontend(trackerBackend, configFile.Config.UDPConfig)
go func() { go func() {

View file

@ -6,10 +6,10 @@ import (
"github.com/jzelinskie/trakr/bittorrent" "github.com/jzelinskie/trakr/bittorrent"
) )
// TrackerFuncs is the collection of callback functions provided by the Backend // TrackerLogic is the interface used by a frontend in order to: (1) generate a
// to (1) generate a response from a parsed request, and (2) observe anything // response from a parsed request, and (2) asynchronously observe anything
// after the response has been delivered to the client. // after the response has been delivered to the client.
type TrackerFuncs interface { type TrackerLogic interface {
// HandleAnnounce generates a response for an Announce. // HandleAnnounce generates a response for an Announce.
HandleAnnounce(context.Context, *bittorrent.AnnounceRequest) (*bittorrent.AnnounceResponse, error) HandleAnnounce(context.Context, *bittorrent.AnnounceRequest) (*bittorrent.AnnounceResponse, error)

View file

@ -71,12 +71,12 @@ type Config struct {
type Frontend struct { type Frontend struct {
grace *graceful.Server grace *graceful.Server
backend frontend.TrackerFuncs backend frontend.TrackerLogic
Config Config
} }
// NewFrontend allocates a new instance of a Frontend. // NewFrontend allocates a new instance of a Frontend.
func NewFrontend(backend frontend.TrackerFuncs, cfg Config) *Frontend { func NewFrontend(backend frontend.TrackerLogic, cfg Config) *Frontend {
return &Frontend{ return &Frontend{
backend: backend, backend: backend,
Config: cfg, Config: cfg,
@ -138,7 +138,7 @@ func (t *Frontend) ListenAndServe() error {
return nil return nil
} }
// announceRoute parses and responds to an Announce by using t.TrackerFuncs. // announceRoute parses and responds to an Announce by using t.TrackerLogic.
func (t *Frontend) announceRoute(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { func (t *Frontend) announceRoute(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
var err error var err error
start := time.Now() start := time.Now()
@ -165,7 +165,7 @@ func (t *Frontend) announceRoute(w http.ResponseWriter, r *http.Request, _ httpr
go t.backend.AfterAnnounce(context.TODO(), req, resp) go t.backend.AfterAnnounce(context.TODO(), req, resp)
} }
// scrapeRoute parses and responds to a Scrape by using t.TrackerFuncs. // scrapeRoute parses and responds to a Scrape by using t.TrackerLogic.
func (t *Frontend) scrapeRoute(w http.ResponseWriter, r *http.Request, _ httprouter.Params) { func (t *Frontend) scrapeRoute(w http.ResponseWriter, r *http.Request, _ httprouter.Params) {
var err error var err error
start := time.Now() start := time.Now()

View file

@ -74,12 +74,12 @@ type Frontend struct {
closing chan struct{} closing chan struct{}
wg sync.WaitGroup wg sync.WaitGroup
backend frontend.TrackerFuncs backend frontend.TrackerLogic
Config Config
} }
// NewFrontend allocates a new instance of a Frontend. // NewFrontend allocates a new instance of a Frontend.
func NewFrontend(backend frontend.TrackerFuncs, cfg Config) *Frontend { func NewFrontend(backend frontend.TrackerLogic, cfg Config) *Frontend {
return &Frontend{ return &Frontend{
closing: make(chan struct{}), closing: make(chan struct{}),
backend: backend, backend: backend,