From aebc6c8981eba23bc21d609a1f0870c78ac4a227 Mon Sep 17 00:00:00 2001 From: Ted Unangst Date: Tue, 22 Oct 2019 13:06:43 -0400 Subject: [PATCH] more robust shortcut.. return hash of long xid instead of tail. sometimes the suffix is common to many activities. noticed by micropub. --- activity.go | 2 ++ fun.go | 28 ++++++++++++++++------------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/activity.go b/activity.go index 5f2095e..4eeea45 100644 --- a/activity.go +++ b/activity.go @@ -1176,6 +1176,8 @@ func honkworldwide(user *WhatAbout, honk *Honk) { jonk.Write(&buf) msg := buf.Bytes() + log.Printf("obj for transmission: %s", msg) + rcpts := make(map[string]bool) for _, a := range honk.Audience { if a == thewholeworld || a == user.URL || strings.HasSuffix(a, "/followers") { diff --git a/fun.go b/fun.go index 3f88a6b..cb0f1b4 100644 --- a/fun.go +++ b/fun.go @@ -18,8 +18,10 @@ package main import ( "crypto/rand" "crypto/rsa" + "crypto/sha512" "fmt" "html/template" + "io" "log" "net/http" "os" @@ -230,25 +232,27 @@ func translate(honk *Honk, redoimages bool) { } } -func shortxid(xid string) string { - idx := strings.LastIndexByte(xid, '/') - if idx == -1 { - return xid - } - return xid[idx+1:] -} - -func xfiltrate() string { +func xcelerate(b []byte) string { letters := "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz1234567891234567891234" - var b [18]byte - rand.Read(b[:]) for i, c := range b { b[i] = letters[c&63] } - s := string(b[:]) + s := string(b) return s } +func shortxid(xid string) string { + h := sha512.New512_256() + io.WriteString(h, xid) + return xcelerate(h.Sum(nil)[:20]) +} + +func xfiltrate() string { + var b [18]byte + rand.Read(b[:]) + return xcelerate(b[:]) +} + var re_hashes = regexp.MustCompile(`(?:^| )#[[:alnum:]][[:alnum:]_-]*`) func ontologies(s string) []string {