new day, new libs. use gate library.
This commit is contained in:
parent
36d7ebe8ae
commit
f27a4d9ce2
41
activity.go
41
activity.go
|
@ -29,10 +29,10 @@ import (
|
|||
"os"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"humungus.tedunangst.com/r/webs/cache"
|
||||
"humungus.tedunangst.com/r/webs/gate"
|
||||
"humungus.tedunangst.com/r/webs/httpsig"
|
||||
"humungus.tedunangst.com/r/webs/image"
|
||||
"humungus.tedunangst.com/r/webs/junk"
|
||||
|
@ -117,24 +117,11 @@ func GetJunkHardMode(url string) (junk.Junk, error) {
|
|||
return j, err
|
||||
}
|
||||
|
||||
var flightdeck = make(map[string][]chan JunkError)
|
||||
var decklock sync.Mutex
|
||||
var flightdeck = gate.NewSerializer()
|
||||
|
||||
func GetJunkTimeout(url string, timeout time.Duration) (junk.Junk, error) {
|
||||
decklock.Lock()
|
||||
inflight, ok := flightdeck[url]
|
||||
if ok {
|
||||
log.Printf("awaiting result for %s", url)
|
||||
c := make(chan JunkError)
|
||||
flightdeck[url] = append(inflight, c)
|
||||
decklock.Unlock()
|
||||
je := <-c
|
||||
close(c)
|
||||
return je.Junk, je.Err
|
||||
}
|
||||
flightdeck[url] = inflight
|
||||
decklock.Unlock()
|
||||
|
||||
fn := func() (interface{}, error) {
|
||||
at := thefakename
|
||||
if strings.Contains(url, ".well-known/webfinger?resource") {
|
||||
at = "application/jrd+json"
|
||||
|
@ -144,23 +131,17 @@ func GetJunkTimeout(url string, timeout time.Duration) (junk.Junk, error) {
|
|||
Agent: "honksnonk/5.0; " + serverName,
|
||||
Timeout: timeout,
|
||||
})
|
||||
|
||||
decklock.Lock()
|
||||
inflight = flightdeck[url]
|
||||
delete(flightdeck, url)
|
||||
decklock.Unlock()
|
||||
if len(inflight) > 0 {
|
||||
je := JunkError{Junk: j, Err: err}
|
||||
go func() {
|
||||
for _, c := range inflight {
|
||||
log.Printf("returning awaited result for %s", url)
|
||||
c <- je
|
||||
}
|
||||
}()
|
||||
}
|
||||
return j, err
|
||||
}
|
||||
|
||||
ji, err := flightdeck.Call(url, fn)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
j := ji.(junk.Junk)
|
||||
return j, nil
|
||||
}
|
||||
|
||||
func savedonk(url string, name, desc, media string, localize bool) *Donk {
|
||||
if url == "" {
|
||||
return nil
|
||||
|
|
|
@ -18,8 +18,9 @@ package main
|
|||
import (
|
||||
"log"
|
||||
notrand "math/rand"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"humungus.tedunangst.com/r/webs/gate"
|
||||
)
|
||||
|
||||
func init() {
|
||||
|
@ -60,30 +61,11 @@ func sayitagain(goarounds int64, userid int64, rcpt string, msg []byte) {
|
|||
}
|
||||
}
|
||||
|
||||
var trucksout = 0
|
||||
var maxtrucksout = 20
|
||||
var garagelock sync.Mutex
|
||||
var garagebell = sync.NewCond(&garagelock)
|
||||
|
||||
func truckgoesout() {
|
||||
garagelock.Lock()
|
||||
for trucksout >= maxtrucksout {
|
||||
garagebell.Wait()
|
||||
}
|
||||
trucksout++
|
||||
garagelock.Unlock()
|
||||
}
|
||||
|
||||
func truckcomesin() {
|
||||
garagelock.Lock()
|
||||
trucksout--
|
||||
garagebell.Broadcast()
|
||||
garagelock.Unlock()
|
||||
}
|
||||
var garage = gate.NewLimiter(20)
|
||||
|
||||
func deliverate(goarounds int64, userid int64, rcpt string, msg []byte) {
|
||||
truckgoesout()
|
||||
defer truckcomesin()
|
||||
garage.Start()
|
||||
defer garage.Finish()
|
||||
|
||||
var ki *KeyInfo
|
||||
ok := ziggies.Get(userid, &ki)
|
||||
|
|
2
go.mod
2
go.mod
|
@ -10,7 +10,7 @@ require (
|
|||
golang.org/x/crypto v0.0.0-20190621222207-cc06ce4a13d4
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859
|
||||
humungus.tedunangst.com/r/go-sqlite3 v1.1.3
|
||||
humungus.tedunangst.com/r/webs v0.6.20
|
||||
humungus.tedunangst.com/r/webs v0.6.21
|
||||
)
|
||||
|
||||
go 1.11
|
||||
|
|
6
go.sum
6
go.sum
|
@ -34,7 +34,5 @@ gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0 h1:FVCohIoYO7IJoDDVpV2pdq7SgrMH6wHnuTyrdr
|
|||
gopkg.in/DATA-DOG/go-sqlmock.v1 v1.3.0/go.mod h1:OdE7CF6DbADk7lN8LIKRzRJTTZXIjtWgA5THM5lhBAw=
|
||||
humungus.tedunangst.com/r/go-sqlite3 v1.1.3 h1:G2N4wzDS0NbuvrZtQJhh4F+3X+s7BF8b9ga8k38geUI=
|
||||
humungus.tedunangst.com/r/go-sqlite3 v1.1.3/go.mod h1:FtEEmQM7U2Ey1TuEEOyY1BmphTZnmiEjPsNLEAkpf/M=
|
||||
humungus.tedunangst.com/r/webs v0.6.19 h1:0cxR4JmHDMQmMwboRlycRO+67OPtgtCwLX8fuDu9IRo=
|
||||
humungus.tedunangst.com/r/webs v0.6.19/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps=
|
||||
humungus.tedunangst.com/r/webs v0.6.20 h1:fKTjJ+EQUlxj8vWBtFMhX7aYbMwAnUWbDhY7hotkXq0=
|
||||
humungus.tedunangst.com/r/webs v0.6.20/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps=
|
||||
humungus.tedunangst.com/r/webs v0.6.21 h1:bxI4ZFpxSZw06AbQsaTii5011wjxceF2MOfqJrFnM/w=
|
||||
humungus.tedunangst.com/r/webs v0.6.21/go.mod h1:S9sXpVSbgAIa24yYhnMN0C94LKHG+2rioS+NsiDimps=
|
||||
|
|
Loading…
Reference in New Issue