move tracker to goroutine
Ted Unangst tedu@tedunangst.com
Fri, 08 Nov 2019 15:14:11 -0500
1 files changed,
28 insertions(+),
2 deletions(-)
jump to
M
web.go
→
web.go
@@ -854,12 +854,37 @@ log.Print(err)
} } +type Track struct { + xid string + who string +} + +var trackchan = make(chan Track) + +func tracker() { + var track Track + for { + + select { + case track = <-trackchan: + log.Printf("%s fetched by %s", track.xid, track.who) + } + } +} + +var re_keyholder = regexp.MustCompile(`keyId="([^"]+)"`) + func trackback(xid string, r *http.Request) { agent := r.UserAgent() who := originate(agent) sig := r.Header.Get("Signature") - - log.Printf("(%s) fetched %s (%s)", who, xid, sig) + if sig != "" { + m := re_keyholder.FindStringSubmatch(sig) + if len(m) > 2 { + who = m[1] + } + } + trackchan <- Track{xid:xid, who: who} } func showonehonk(w http.ResponseWriter, r *http.Request) {@@ -1943,6 +1968,7 @@ if err != nil {
log.Fatal(err) } go redeliverator() + go tracker() debug := false getconfig("debug", &debug)