Ittt #52

Merged
anbsky merged 62 commits from ittt into master 2021-07-24 02:35:22 +02:00
2 changed files with 6 additions and 5 deletions
Showing only changes of commit 215103cb33 - Show all commits

View file

@ -11,6 +11,7 @@ import (
"math/big" "math/big"
"net/http" "net/http"
"strconv" "strconv"
"sync"
"time" "time"
"github.com/lbryio/reflector.go/internal/metrics" "github.com/lbryio/reflector.go/internal/metrics"
@ -70,11 +71,10 @@ func (s *Server) Start(address string) error {
} }
r := mux.NewRouter() r := mux.NewRouter()
r.HandleFunc("/get/{hash}", func(w http.ResponseWriter, r *http.Request) { r.HandleFunc("/get/{hash}", func(w http.ResponseWriter, r *http.Request) {
waiter := stop.New() waiter := &sync.WaitGroup{}
waiter.Add(1)
enqueue(&blobRequest{request: r, reply: w, finished: waiter}) enqueue(&blobRequest{request: r, reply: w, finished: waiter})
select { waiter.Wait()
case <-waiter.Ch():
}
}) })
r.HandleFunc("/has/{hash}", func(w http.ResponseWriter, r *http.Request) { r.HandleFunc("/has/{hash}", func(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)

View file

@ -2,6 +2,7 @@ package http3
import ( import (
"net/http" "net/http"
"sync"
"github.com/lbryio/reflector.go/internal/metrics" "github.com/lbryio/reflector.go/internal/metrics"
@ -11,7 +12,7 @@ import (
type blobRequest struct { type blobRequest struct {
request *http.Request request *http.Request
reply http.ResponseWriter reply http.ResponseWriter
finished *stop.Group finished *sync.WaitGroup
} }
var getReqCh = make(chan *blobRequest) var getReqCh = make(chan *blobRequest)