all repos — honk @ 3e30b0231c4d440da95d270422dd70493ea94470

my fork of honk

fun.go (view raw)

  1//
  2// Copyright (c) 2019 Ted Unangst <tedu@tedunangst.com>
  3//
  4// Permission to use, copy, modify, and distribute this software for any
  5// purpose with or without fee is hereby granted, provided that the above
  6// copyright notice and this permission notice appear in all copies.
  7//
  8// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 10// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 11// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 12// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 13// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 14// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 15
 16package main
 17
 18import (
 19	"crypto/rand"
 20	"crypto/sha512"
 21	"fmt"
 22	"html/template"
 23	"io"
 24	"net/http"
 25	"net/url"
 26	"os"
 27	"path"
 28	"regexp"
 29	"strconv"
 30	"strings"
 31	"time"
 32
 33	"github.com/dustin/go-humanize"
 34	"golang.org/x/net/html"
 35	"humungus.tedunangst.com/r/webs/gencache"
 36	"humungus.tedunangst.com/r/webs/htfilter"
 37	"humungus.tedunangst.com/r/webs/httpsig"
 38	"humungus.tedunangst.com/r/webs/mz"
 39	"humungus.tedunangst.com/r/webs/templates"
 40)
 41
 42var allowedclasses = make(map[string]bool)
 43
 44func init() {
 45	allowedclasses["kw"] = true
 46	allowedclasses["bi"] = true
 47	allowedclasses["st"] = true
 48	allowedclasses["nm"] = true
 49	allowedclasses["tp"] = true
 50	allowedclasses["op"] = true
 51	allowedclasses["cm"] = true
 52	allowedclasses["al"] = true
 53	allowedclasses["dl"] = true
 54}
 55
 56var relingo = make(map[string]string)
 57
 58func loadLingo() {
 59	for _, l := range []string{"honked", "bonked", "honked back", "qonked", "evented"} {
 60		v := l
 61		k := "lingo-" + strings.ReplaceAll(l, " ", "")
 62		getconfig(k, &v)
 63		relingo[l] = v
 64	}
 65}
 66
 67func prettifydate(d time.Time) string {
 68	var customMags = []humanize.RelTimeMagnitude{
 69		{time.Second, "now", time.Second},
 70		{2 * time.Second, "1s %s", 1},
 71		{time.Minute, "%ds %s", time.Second},
 72		{2 * time.Minute, "1m %s", 1},
 73		{time.Hour, "%dm %s", time.Minute},
 74		{2 * time.Hour, "1h %s", 1},
 75		{humanize.Day, "%dh %s", time.Hour},
 76		{2 * humanize.Day, "1d %s", 1},
 77		{humanize.Week, "%dd %s", humanize.Day},
 78		{2 * humanize.Week, "1w %s", 1},
 79		{humanize.Month, "%dw %s", humanize.Week},
 80	}
 81
 82	since := time.Since(d)
 83	// More than a month, return the actual date.
 84	if since.Hours() > 730 {
 85		return d.Format("02 Jan 2006 15:04")
 86	}
 87
 88	return humanize.CustomRelTime(d, time.Now(), "", "from now", customMags)
 89}
 90func reverbolate(userid UserID, honks []*Honk) {
 91	user, _ := somenumberedusers.Get(userid)
 92	for _, h := range honks {
 93		// idk where else to put this
 94		h.DatePretty = prettifydate(h.Date)
 95		h.What += "ed"
 96		if h.What == "honked" && h.RID != "" {
 97			h.What = "honked back"
 98			h.Style += " subtle"
 99		}
100		if !h.Public {
101			h.Style += " limited"
102		}
103		if h.Whofore == 1 {
104			h.Style += " atme"
105		}
106		translate(h)
107		local := false
108		if h.Whofore == 2 || h.Whofore == 3 {
109			local = true
110		}
111		if local && h.What != "bonked" {
112			h.Noise = re_retag.ReplaceAllString(h.Noise, "")
113			h.Noise = re_memes.ReplaceAllString(h.Noise, "")
114		}
115		h.Username, h.Handle = handles(h.Honker)
116		if !local {
117			short := shortname(userid, h.Honker)
118			if short != "" {
119				h.Username = short
120			} else {
121				h.Username = h.Handle
122				if len(h.Username) > 20 {
123					h.Username = h.Username[:20] + ".."
124				}
125			}
126		}
127		if user != nil {
128			hset := []string{}
129			if h.Honker != user.URL {
130				hset = append(hset, "@"+h.Handle)
131			}
132			if user.Options.MentionAll {
133				for _, a := range h.Audience {
134					if a == h.Honker || a == user.URL {
135						continue
136					}
137					_, hand := handles(a)
138					if hand != "" {
139						hand = "@" + hand
140						hset = append(hset, hand)
141					}
142				}
143			}
144			h.Handles = strings.Join(hset, " ")
145		}
146		if h.URL == "" {
147			h.URL = h.XID
148		}
149		if h.Oonker != "" {
150			_, h.Oondle = handles(h.Oonker)
151		}
152		h.Precis = demoji(h.Precis)
153		h.Noise = demoji(h.Noise)
154		h.Open = "open"
155		var misto string
156		for _, m := range h.Mentions {
157			if m.Where != h.Honker && !m.IsPresent(h.Noise) {
158				misto += " " + m.Who
159			}
160		}
161		var mistag string
162		for _, o := range h.Onts {
163			if !OntIsPresent(o, h.Noise) {
164				mistag += " " + o
165			}
166		}
167		if len(misto) > 0 || len(mistag) > 0 {
168			if len(misto) > 0 {
169				misto = "(" + misto[1:] + ")<p>"
170			}
171			if len(mistag) > 0 {
172				mistag = "<p>(" + mistag[1:] + ")"
173			}
174			h.Noise = misto + h.Noise + mistag
175		}
176
177		zap := make(map[string]bool)
178		{
179			var htf htfilter.Filter
180			htf.Imager = replaceimgsand(zap, false, h)
181			htf.SpanClasses = allowedclasses
182			htf.BaseURL, _ = url.Parse(h.XID)
183			emuxifier := func(e string) string {
184				for _, d := range h.Donks {
185					if d.Name == e {
186						zap[d.XID] = true
187						if d.Local {
188							return fmt.Sprintf(`<img class="emu" title="%s" src="/d/%s">`, d.Name, d.XID)
189						}
190					}
191				}
192				if local && h.What != "bonked" {
193					emu, _ := emucache.Get(e)
194					if emu != nil {
195						return fmt.Sprintf(`<img class="emu" title="%s" src="%s">`, emu.Name, emu.ID)
196					}
197				}
198				return e
199			}
200			htf.FilterText = func(w io.Writer, data string) {
201				data = htfilter.EscapeText(data)
202				data = re_emus.ReplaceAllStringFunc(data, emuxifier)
203				io.WriteString(w, data)
204			}
205			if user != nil {
206				htf.RetargetLink = func(href string) string {
207					h2 := strings.ReplaceAll(href, "/@", "/users/")
208					for _, m := range h.Mentions {
209						if h2 == m.Where || href == m.Where {
210							return "/h?xid=" + url.QueryEscape(m.Where)
211						}
212					}
213					return href
214				}
215			}
216			p, _ := htf.String(h.Precis)
217			n, _ := htf.String(h.Noise)
218			h.Precis = string(p)
219			h.Noise = string(n)
220		}
221		j := 0
222		for i := 0; i < len(h.Donks); i++ {
223			if !zap[h.Donks[i].XID] {
224				h.Donks[j] = h.Donks[i]
225				j++
226			}
227		}
228		h.Donks = h.Donks[:j]
229	}
230
231	unsee(honks, userid)
232
233	for _, h := range honks {
234		renderflags(h)
235
236		h.HTPrecis = template.HTML(h.Precis)
237		h.HTML = template.HTML(h.Noise)
238		if redo := relingo[h.What]; redo != "" {
239			h.What = redo
240		}
241	}
242}
243
244func replaceimgsand(zap map[string]bool, absolute bool, honk *Honk) func(node *html.Node) string {
245	return func(node *html.Node) string {
246		src := htfilter.GetAttr(node, "src")
247		alt := htfilter.GetAttr(node, "alt")
248		//title := GetAttr(node, "title")
249		if htfilter.HasClass(node, "Emoji") && alt != "" {
250			return alt
251		}
252		base := path.Base(src)
253		didx, _ := strconv.Atoi(base)
254		var d *Donk
255		if strings.HasPrefix(src, serverPrefix) && didx > 0 && didx <= len(honk.Donks) {
256			d = honk.Donks[didx-1]
257		} else {
258			d = finddonk(src)
259		}
260		if d != nil {
261			zap[d.XID] = true
262			base := ""
263			if absolute {
264				base = serverURL("")
265			}
266			return string(templates.Sprintf(`<img alt="%s" title="%s" src="%s/d/%s">`, alt, alt, base, d.XID))
267		}
268		return string(templates.Sprintf(`&lt;img alt="%s" src="<a href="%s">%s</a>"&gt;`, alt, src, src))
269	}
270}
271
272func translatechonk(ch *Chonk) {
273	noise := ch.Noise
274	if ch.Format == "markdown" {
275		var marker mz.Marker
276		noise = marker.Mark(noise)
277	}
278	var htf htfilter.Filter
279	htf.SpanClasses = allowedclasses
280	htf.BaseURL, _ = url.Parse(ch.XID)
281	ch.HTML, _ = htf.String(noise)
282}
283
284func filterchonk(ch *Chonk) {
285	translatechonk(ch)
286
287	noise := string(ch.HTML)
288
289	local := originate(ch.XID) == serverName
290
291	zap := make(map[string]bool)
292	emuxifier := func(e string) string {
293		for _, d := range ch.Donks {
294			if d.Name == e {
295				zap[d.XID] = true
296				if d.Local {
297					return fmt.Sprintf(`<img class="emu" title="%s" src="/d/%s">`, d.Name, d.XID)
298				}
299			}
300		}
301		if local {
302			emu, _ := emucache.Get(e)
303			if emu != nil {
304				return fmt.Sprintf(`<img class="emu" title="%s" src="%s">`, emu.Name, emu.ID)
305			}
306		}
307		return e
308	}
309	noise = re_emus.ReplaceAllStringFunc(noise, emuxifier)
310	j := 0
311	for i := 0; i < len(ch.Donks); i++ {
312		if !zap[ch.Donks[i].XID] {
313			ch.Donks[j] = ch.Donks[i]
314			j++
315		}
316	}
317	ch.Donks = ch.Donks[:j]
318
319	if strings.HasPrefix(noise, "<p>") {
320		noise = noise[3:]
321	}
322	ch.HTML = template.HTML(noise)
323	if short := shortname(ch.UserID, ch.Who); short != "" {
324		ch.Handle = short
325	} else {
326		ch.Handle, _ = handles(ch.Who)
327	}
328
329}
330
331func inlineimgsfor(honk *Honk) func(node *html.Node) string {
332	return func(node *html.Node) string {
333		src := htfilter.GetAttr(node, "src")
334		alt := htfilter.GetAttr(node, "alt")
335		base := path.Base(src)
336		didx, _ := strconv.Atoi(base)
337		if strings.HasPrefix(src, serverPrefix) && didx > 0 && didx <= len(honk.Donks) {
338			dlog.Printf("skipping inline image %s", src)
339			return ""
340		}
341		d := savedonk(src, "image", alt, "image", true)
342		if d != nil {
343			honk.Donks = append(honk.Donks, d)
344		}
345		dlog.Printf("inline img with src: %s", src)
346		return ""
347	}
348}
349
350func imaginate(honk *Honk) {
351	var htf htfilter.Filter
352	htf.Imager = inlineimgsfor(honk)
353	htf.BaseURL, _ = url.Parse(honk.XID)
354	htf.String(honk.Noise)
355}
356
357var re_dangerous = regexp.MustCompile("^[a-zA-Z]{2}:")
358
359func precipitate(honk *Honk) {
360	noise := honk.Noise
361	if re_dangerous.MatchString(noise) {
362		idx := strings.Index(noise, "\n")
363		if idx == -1 {
364			honk.Precis = noise
365			noise = ""
366		} else {
367			honk.Precis = noise[:idx]
368			noise = noise[idx+1:]
369		}
370		var marker mz.Marker
371		marker.Short = true
372		honk.Precis = marker.Mark(strings.TrimSpace(honk.Precis))
373		honk.Noise = noise
374	}
375}
376
377func translate(honk *Honk) {
378	if honk.Format == "html" {
379		return
380	}
381	noise := honk.Noise
382
383	var marker mz.Marker
384	marker.HashLinker = ontoreplacer
385	marker.AtLinker = attoreplacer
386	marker.AllowImages = true
387	noise = strings.TrimSpace(noise)
388	noise = marker.Mark(noise)
389	honk.Noise = noise
390	honk.Onts = append(honk.Onts, marker.HashTags...)
391	honk.Mentions = bunchofgrapes(marker.Mentions)
392	for _, t := range oneofakind(strings.Split(honk.Onties, " ")) {
393		if t[0] != '#' {
394			t = "#" + t
395		}
396		honk.Onts = append(honk.Onts, t)
397	}
398	honk.Onts = oneofakind(honk.Onts)
399	honk.Mentions = append(honk.Mentions, bunchofgrapes(oneofakind(strings.Split(honk.SeeAlso, " ")))...)
400}
401
402func redoimages(honk *Honk) {
403	zap := make(map[string]bool)
404	{
405		var htf htfilter.Filter
406		htf.Imager = replaceimgsand(zap, true, honk)
407		htf.SpanClasses = allowedclasses
408		htf.BaseURL, _ = url.Parse(honk.XID)
409		p, _ := htf.String(honk.Precis)
410		n, _ := htf.String(honk.Noise)
411		honk.Precis = string(p)
412		honk.Noise = string(n)
413	}
414	j := 0
415	for i := 0; i < len(honk.Donks); i++ {
416		if !zap[honk.Donks[i].XID] {
417			honk.Donks[j] = honk.Donks[i]
418			j++
419		}
420	}
421	honk.Donks = honk.Donks[:j]
422
423	honk.Noise = re_memes.ReplaceAllString(honk.Noise, "")
424	honk.Noise = strings.Replace(honk.Noise, "<a href=", "<a class=\"mention u-url\" href=", -1)
425}
426
427func xcelerate(b []byte) string {
428	letters := "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz1234567891234567891234"
429	for i, c := range b {
430		b[i] = letters[c&63]
431	}
432	s := string(b)
433	return s
434}
435
436func shortxid(xid string) string {
437	h := sha512.New512_256()
438	io.WriteString(h, xid)
439	return xcelerate(h.Sum(nil)[:20])
440}
441
442func xfiltrate() string {
443	var b [18]byte
444	rand.Read(b[:])
445	return xcelerate(b[:])
446}
447
448func grapevine(mentions []Mention) []string {
449	var s []string
450	for _, m := range mentions {
451		s = append(s, m.Where)
452	}
453	return s
454}
455
456func bunchofgrapes(m []string) []Mention {
457	var mentions []Mention
458	for i := range m {
459		who := m[i]
460		if strings.HasPrefix(who, "@https://") {
461			mentions = append(mentions, Mention{Who: who, Where: who[1:]})
462			continue
463		}
464		where := gofish(who)
465		if where != "" {
466			mentions = append(mentions, Mention{Who: who, Where: where})
467		}
468	}
469	return mentions
470}
471
472type Emu struct {
473	ID   string
474	Name string
475	Type string
476}
477
478var re_emus = regexp.MustCompile(`:[[:alnum:]_-]+:`)
479
480var emucache = gencache.New(gencache.Options[string, *Emu]{Fill: func(ename string) (*Emu, bool) {
481	fname := ename[1 : len(ename)-1]
482	exts := []string{".png", ".gif"}
483	for _, ext := range exts {
484		_, err := os.Stat(dataDir + "/emus/" + fname + ext)
485		if err != nil {
486			continue
487		}
488		url := serverURL("/emu/%s%s", fname, ext)
489		if develMode {
490			url = fmt.Sprintf("/emu/%s%s", fname, ext)
491		}
492		return &Emu{ID: url, Name: ename, Type: "image/" + ext[1:]}, true
493	}
494	return nil, true
495}, Duration: 10 * time.Second})
496
497func herdofemus(noise string) []*Emu {
498	m := re_emus.FindAllString(noise, -1)
499	m = oneofakind(m)
500	var emus []*Emu
501	for _, e := range m {
502		emu, _ := emucache.Get(e)
503		if emu == nil {
504			continue
505		}
506		emus = append(emus, emu)
507	}
508	return emus
509}
510
511var re_memes = regexp.MustCompile("meme: ?([^\n]+)")
512var re_avatar = regexp.MustCompile("avatar: ?([^\n]+)")
513var re_banner = regexp.MustCompile("banner: ?([^\n]+)")
514var re_convoy = regexp.MustCompile("convoy: ?([^\n]+)")
515var re_retag = regexp.MustCompile("tags: ?([^\n]+)")
516var re_convalidate = regexp.MustCompile("^(https?|tag|data):")
517
518func memetize(honk *Honk) {
519	repl := func(x string) string {
520		name := x[5:]
521		if name[0] == ' ' {
522			name = name[1:]
523		}
524		fd, err := os.Open(dataDir + "/memes/" + name)
525		if err != nil {
526			ilog.Printf("no meme for %s", name)
527			return x
528		}
529		var peek [512]byte
530		n, _ := fd.Read(peek[:])
531		ct := http.DetectContentType(peek[:n])
532		fd.Close()
533
534		url := serverURL("/meme/%s", name)
535		fileid, err := savefile(name, name, url, ct, false, nil)
536		if err != nil {
537			elog.Printf("error saving meme: %s", err)
538			return x
539		}
540		d := &Donk{
541			FileID: fileid,
542			Name:   name,
543			Media:  ct,
544			URL:    url,
545			Local:  false,
546		}
547		honk.Donks = append(honk.Donks, d)
548		return ""
549	}
550	honk.Noise = re_memes.ReplaceAllStringFunc(honk.Noise, repl)
551}
552
553func recategorize(honk *Honk) {
554	repl := func(x string) string {
555		x = x[5:]
556		for _, t := range strings.Split(x, " ") {
557			if t == "" {
558				continue
559			}
560			if t[0] != '#' {
561				t = "#" + t
562			}
563			dlog.Printf("hashtag: %s", t)
564			honk.Onts = append(honk.Onts, t)
565		}
566		return ""
567	}
568	honk.Noise = re_retag.ReplaceAllStringFunc(honk.Noise, repl)
569}
570
571var re_quickmention = regexp.MustCompile("(^|[ \n])@[[:alnum:]_]+([ \n:;.,']|$)")
572
573func quickrename(s string, userid UserID) string {
574	nonstop := true
575	for nonstop {
576		nonstop = false
577		s = re_quickmention.ReplaceAllStringFunc(s, func(m string) string {
578			prefix := ""
579			if m[0] == ' ' || m[0] == '\n' {
580				prefix = m[:1]
581				m = m[1:]
582			}
583			prefix += "@"
584			m = m[1:]
585			tail := ""
586			if last := m[len(m)-1]; last == ' ' || last == '\n' ||
587				last == ':' || last == ';' ||
588				last == '.' || last == ',' || last == '\'' {
589				tail = m[len(m)-1:]
590				m = m[:len(m)-1]
591			}
592
593			xid := fullname(m, userid)
594
595			if xid != "" {
596				_, name := handles(xid)
597				if name != "" {
598					nonstop = true
599					m = name
600				}
601			}
602			return prefix + m + tail
603		})
604	}
605	return s
606}
607
608var shortnames = gencache.New(gencache.Options[UserID, map[string]string]{Fill: func(userid UserID) (map[string]string, bool) {
609	honkers := gethonkers(userid)
610	m := make(map[string]string)
611	for _, h := range honkers {
612		m[h.XID] = h.Name
613	}
614	return m, true
615}, Invalidator: &honkerinvalidator})
616
617func shortname(userid UserID, xid string) string {
618	m, ok := shortnames.Get(userid)
619	if ok {
620		return m[xid]
621	}
622	return ""
623}
624
625var fullnames = gencache.New(gencache.Options[UserID, map[string]string]{Fill: func(userid UserID) (map[string]string, bool) {
626	honkers := gethonkers(userid)
627	m := make(map[string]string)
628	for _, h := range honkers {
629		m[h.Name] = h.XID
630	}
631	return m, true
632}, Invalidator: &honkerinvalidator})
633
634func fullname(name string, userid UserID) string {
635	m, ok := fullnames.Get(userid)
636	if ok {
637		return m[name]
638	}
639	return ""
640}
641
642func attoreplacer(m string) string {
643	fill := `<span class="h-card"><a class="u-url mention" href="%s">%s</a></span>`
644	if strings.HasPrefix(m, "@https://") {
645		return fmt.Sprintf(fill, html.EscapeString(m[1:]), html.EscapeString(m))
646	}
647	where := gofish(m)
648	if where == "" {
649		return m
650	}
651	who := m[0 : 1+strings.IndexByte(m[1:], '@')]
652	return fmt.Sprintf(fill, html.EscapeString(where), html.EscapeString(who))
653}
654
655func ontoreplacer(h string) string {
656	return fmt.Sprintf(`<a class="mention hashtag" href="%s">%s</a>`,
657		serverURL("/o/%s", strings.ToLower(h[1:])), h)
658}
659
660var re_unurl = regexp.MustCompile("https://([^/]+).*/([^/]+)")
661var re_urlhost = regexp.MustCompile("https://([^/ #)]+)")
662
663func originate(u string) string {
664	m := re_urlhost.FindStringSubmatch(u)
665	if len(m) > 1 {
666		return m[1]
667	}
668	return ""
669}
670
671var allhandles = gencache.New(gencache.Options[string, string]{Fill: func(xid string) (string, bool) {
672	handle := getxonker(xid, "handle")
673	if handle == "" {
674		dlog.Printf("need to get a handle: %s", xid)
675		info, err := investigate(xid)
676		if err != nil {
677			m := re_unurl.FindStringSubmatch(xid)
678			if len(m) > 2 {
679				handle = m[2]
680			} else {
681				handle = xid
682			}
683		} else {
684			handle = info.Name
685		}
686	}
687	return handle, true
688}})
689
690// handle, handle@host
691func handles(xid string) (string, string) {
692	if xid == "" || xid == thewholeworld || strings.HasSuffix(xid, "/followers") {
693		return "", ""
694	}
695	handle, _ := allhandles.Get(xid)
696	if handle == xid {
697		return xid, xid
698	}
699	return handle, handle + "@" + originate(xid)
700}
701
702func butnottooloud(aud []string) {
703	for i, a := range aud {
704		if strings.HasSuffix(a, "/followers") {
705			aud[i] = ""
706		}
707	}
708}
709
710func loudandproud(aud []string) bool {
711	for _, a := range aud {
712		if a == thewholeworld {
713			return true
714		}
715	}
716	return false
717}
718
719func firstclass(honk *Honk) bool {
720	return honk.Audience[0] == thewholeworld
721}
722
723func oneofakind(a []string) []string {
724	seen := make(map[string]bool)
725	seen[""] = true
726	j := 0
727	for _, s := range a {
728		if !seen[s] {
729			seen[s] = true
730			a[j] = s
731			j++
732		}
733	}
734	return a[:j]
735}
736
737var ziggies = gencache.New(gencache.Options[UserID, *KeyInfo]{Fill: func(userid UserID) (*KeyInfo, bool) {
738	user, ok := somenumberedusers.Get(userid)
739	if !ok {
740		return nil, false
741	}
742	ki := new(KeyInfo)
743	ki.keyname = user.URL + "#key"
744	ki.seckey = user.SecKey
745	return ki, true
746}})
747
748func ziggy(userid UserID) *KeyInfo {
749	ki, _ := ziggies.Get(userid)
750	return ki
751}
752
753var zaggies = gencache.New(gencache.Options[string, httpsig.PublicKey]{Fill: func(keyname string) (httpsig.PublicKey, bool) {
754	data := getxonker(keyname, "pubkey")
755	if data == "" {
756		dlog.Printf("hitting the webs for missing pubkey: %s", keyname)
757		j, err := GetJunk(readyLuserOne, keyname)
758		if err != nil {
759			ilog.Printf("error getting %s pubkey: %s", keyname, err)
760			when := time.Now().UTC().Format(dbtimeformat)
761			stmtSaveXonker.Exec(keyname, "failed", "pubkey", when)
762			return httpsig.PublicKey{}, true
763		}
764		allinjest(originate(keyname), j)
765		data = getxonker(keyname, "pubkey")
766		if data == "" {
767			ilog.Printf("key not found after ingesting")
768			when := time.Now().UTC().Format(dbtimeformat)
769			stmtSaveXonker.Exec(keyname, "failed", "pubkey", when)
770			return httpsig.PublicKey{}, true
771		}
772	}
773	if data == "failed" {
774		ilog.Printf("lookup previously failed key %s", keyname)
775		return httpsig.PublicKey{}, true
776	}
777	_, key, err := httpsig.DecodeKey(data)
778	if err != nil {
779		ilog.Printf("error decoding %s pubkey: %s", keyname, err)
780		return key, true
781	}
782	return key, true
783}, Limit: 512})
784
785func zaggy(keyname string) (httpsig.PublicKey, error) {
786	key, _ := zaggies.Get(keyname)
787	return key, nil
788}
789
790func savingthrow(keyname string) {
791	when := time.Now().Add(-30 * time.Minute).UTC().Format(dbtimeformat)
792	stmtDeleteXonker.Exec(keyname, "pubkey", when)
793	zaggies.Clear(keyname)
794}
795
796func keymatch(keyname string, actor string) string {
797	origin := originate(actor)
798	if origin == originate(keyname) {
799		return origin
800	}
801	return ""
802}