mirror of
https://github.com/sot-tech/mochi.git
synced 2026-07-27 17:48:11 -07:00
s/backend/middleware
This commit is contained in:
@@ -71,15 +71,15 @@ type Config struct {
|
||||
type Frontend struct {
|
||||
grace *graceful.Server
|
||||
|
||||
backend frontend.TrackerLogic
|
||||
logic frontend.TrackerLogic
|
||||
Config
|
||||
}
|
||||
|
||||
// NewFrontend allocates a new instance of a Frontend.
|
||||
func NewFrontend(backend frontend.TrackerLogic, cfg Config) *Frontend {
|
||||
func NewFrontend(logic frontend.TrackerLogic, cfg Config) *Frontend {
|
||||
return &Frontend{
|
||||
backend: backend,
|
||||
Config: cfg,
|
||||
logic: logic,
|
||||
Config: cfg,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func (t *Frontend) announceRoute(w http.ResponseWriter, r *http.Request, _ httpr
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := t.backend.HandleAnnounce(context.TODO(), req)
|
||||
resp, err := t.logic.HandleAnnounce(context.TODO(), req)
|
||||
if err != nil {
|
||||
WriteError(w, err)
|
||||
return
|
||||
@@ -162,7 +162,7 @@ func (t *Frontend) announceRoute(w http.ResponseWriter, r *http.Request, _ httpr
|
||||
return
|
||||
}
|
||||
|
||||
go t.backend.AfterAnnounce(context.TODO(), req, resp)
|
||||
go t.logic.AfterAnnounce(context.TODO(), req, resp)
|
||||
}
|
||||
|
||||
// scrapeRoute parses and responds to a Scrape by using t.TrackerLogic.
|
||||
@@ -177,7 +177,7 @@ func (t *Frontend) scrapeRoute(w http.ResponseWriter, r *http.Request, _ httprou
|
||||
return
|
||||
}
|
||||
|
||||
resp, err := t.backend.HandleScrape(context.TODO(), req)
|
||||
resp, err := t.logic.HandleScrape(context.TODO(), req)
|
||||
if err != nil {
|
||||
WriteError(w, err)
|
||||
return
|
||||
@@ -189,5 +189,5 @@ func (t *Frontend) scrapeRoute(w http.ResponseWriter, r *http.Request, _ httprou
|
||||
return
|
||||
}
|
||||
|
||||
go t.backend.AfterScrape(context.TODO(), req, resp)
|
||||
go t.logic.AfterScrape(context.TODO(), req, resp)
|
||||
}
|
||||
|
||||
@@ -74,15 +74,15 @@ type Frontend struct {
|
||||
closing chan struct{}
|
||||
wg sync.WaitGroup
|
||||
|
||||
backend frontend.TrackerLogic
|
||||
logic frontend.TrackerLogic
|
||||
Config
|
||||
}
|
||||
|
||||
// NewFrontend allocates a new instance of a Frontend.
|
||||
func NewFrontend(backend frontend.TrackerLogic, cfg Config) *Frontend {
|
||||
func NewFrontend(logic frontend.TrackerLogic, cfg Config) *Frontend {
|
||||
return &Frontend{
|
||||
closing: make(chan struct{}),
|
||||
backend: backend,
|
||||
logic: logic,
|
||||
Config: cfg,
|
||||
}
|
||||
}
|
||||
@@ -221,7 +221,7 @@ func (t *Frontend) handleRequest(r Request, w ResponseWriter) (response []byte,
|
||||
}
|
||||
|
||||
var resp *bittorrent.AnnounceResponse
|
||||
resp, err = t.backend.HandleAnnounce(context.TODO(), req)
|
||||
resp, err = t.logic.HandleAnnounce(context.TODO(), req)
|
||||
if err != nil {
|
||||
WriteError(w, txID, err)
|
||||
return
|
||||
@@ -229,8 +229,7 @@ func (t *Frontend) handleRequest(r Request, w ResponseWriter) (response []byte,
|
||||
|
||||
WriteAnnounce(w, txID, resp)
|
||||
|
||||
// TODO(mrd0ll4r): evaluate if it's worth spawning another goroutine.
|
||||
go t.backend.AfterAnnounce(context.TODO(), req, resp)
|
||||
go t.logic.AfterAnnounce(context.TODO(), req, resp)
|
||||
|
||||
return
|
||||
|
||||
@@ -245,7 +244,7 @@ func (t *Frontend) handleRequest(r Request, w ResponseWriter) (response []byte,
|
||||
}
|
||||
|
||||
var resp *bittorrent.ScrapeResponse
|
||||
resp, err = t.backend.HandleScrape(context.TODO(), req)
|
||||
resp, err = t.logic.HandleScrape(context.TODO(), req)
|
||||
if err != nil {
|
||||
WriteError(w, txID, err)
|
||||
return
|
||||
@@ -253,7 +252,7 @@ func (t *Frontend) handleRequest(r Request, w ResponseWriter) (response []byte,
|
||||
|
||||
WriteScrape(w, txID, resp)
|
||||
|
||||
go t.backend.AfterScrape(context.TODO(), req, resp)
|
||||
go t.logic.AfterScrape(context.TODO(), req, resp)
|
||||
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user