use shared inbox for delivery
Ted Unangst tedu@tedunangst.com
Tue, 16 Apr 2019 14:40:23 -0400
3 files changed,
43 insertions(+),
25 deletions(-)
M
activity.go
→
activity.go
@@ -265,27 +265,34 @@ }
} } -var boxofboxes = make(map[string]string) +type Box struct { + In string + Out string + Shared string +} + +var boxofboxes = make(map[string]*Box) var boxlock sync.Mutex -func getboxes(ident string) (string, string, error) { +func getboxes(ident string) (*Box, error) { boxlock.Lock() b, ok := boxofboxes[ident] boxlock.Unlock() if ok { - m := strings.Split(b, "\n") - return m[0], m[1], nil + return b, nil } j, err := GetJunk(ident) if err != nil { - return "", "", err + return nil, err } inbox, _ := jsongetstring(j, "inbox") outbox, _ := jsongetstring(j, "outbox") + sbox, _ := jsongetstring(j, "sharedInbox") + b = &Box { In: inbox, Out: outbox, Shared: sbox } boxlock.Lock() - boxofboxes[ident] = inbox + "\n" + outbox + boxofboxes[ident] = b boxlock.Unlock() - return inbox, outbox, err + return b, nil } func peeppeep() {@@ -296,13 +303,13 @@ if f.Flavor != "peep" {
continue } log.Printf("getting updates: %s", f.XID) - _, outbox, err := getboxes(f.XID) + box, err := getboxes(f.XID) if err != nil { log.Printf("error getting outbox: %s", err) continue } log.Printf("getting outbox") - j, err := GetJunk(outbox) + j, err := GetJunk(box.Out) if err != nil { log.Printf("err: %s", err) continue@@ -471,13 +478,13 @@
WriteJunk(os.Stdout, j) actor, _ := jsongetstring(req, "actor") - inbox, _, err := getboxes(actor) + box, err := getboxes(actor) if err != nil { log.Printf("can't get dub box: %s", err) return } keyname, key := ziggy(user.Name) - err = PostJunk(keyname, key, inbox, j) + err = PostJunk(keyname, key, box.In, j) if err != nil { log.Printf("can't rub a dub: %s", err) return@@ -495,14 +502,14 @@ j["to"] = xid
j["object"] = xid j["published"] = time.Now().UTC().Format(time.RFC3339) - inbox, _, err := getboxes(xid) + box, err := getboxes(xid) if err != nil { log.Printf("can't send follow: %s", err) return } WriteJunk(os.Stdout, j) keyname, key := ziggy(user.Name) - err = PostJunk(keyname, key, inbox, j) + err = PostJunk(keyname, key, box.In, j) if err != nil { log.Printf("failed to subsub: %s", err) }@@ -611,8 +618,12 @@ var buf bytes.Buffer
WriteJunk(&buf, jonk) msg := buf.Bytes() for _, f := range getdubs(user.ID) { - deliverate(0, user.Name, f.XID, msg) - delete(rcpts, f.XID) + box, _ := getboxes(f.XID) + if box != nil && box.Shared != "" { + rcpts["%" + box.Shared] = true + } else { + rcpts[f.XID] = true + } } for a := range rcpts { if !strings.HasSuffix(a, "/followers") {
M
deliverator.go
→
deliverator.go
@@ -56,13 +56,20 @@ }
func deliverate(goarounds int, username string, rcpt string, msg []byte) { keyname, key := ziggy(username) - inbox, _, err := getboxes(rcpt) - if err != nil { - log.Printf("error getting inbox %s: %s", rcpt, err) - sayitagain(goarounds+1, username, rcpt, msg) - return + var inbox string + // already did the box indirection + if rcpt[0] == '%' { + inbox = rcpt[1:] + } else { + box, err := getboxes(rcpt) + if err != nil { + log.Printf("error getting inbox %s: %s", rcpt, err) + sayitagain(goarounds+1, username, rcpt, msg) + return + } + inbox = box.In } - err = PostMsg(keyname, key, inbox, msg) + err := PostMsg(keyname, key, inbox, msg) if err != nil { log.Printf("failed to post json to %s: %s", inbox, err) sayitagain(goarounds+1, username, rcpt, msg)
M
honk.go
→
honk.go
@@ -227,7 +227,7 @@ return false
} func ping(user *WhatAbout, who string) { - inbox, _, err := getboxes(who) + box, err := getboxes(who) if err != nil { log.Printf("no inbox for ping: %s", err) return@@ -239,7 +239,7 @@ j["id"] = user.URL + "/ping/" + xfiltrate()
j["actor"] = user.URL j["to"] = who keyname, key := ziggy(user.Name) - err = PostJunk(keyname, key, inbox, j) + err = PostJunk(keyname, key, box.In, j) if err != nil { log.Printf("can't send ping: %s", err) return@@ -248,7 +248,7 @@ log.Printf("sent ping to %s: %s", who, j["id"])
} func pong(user *WhatAbout, who string, obj string) { - inbox, _, err := getboxes(who) + box, err := getboxes(who) if err != nil { log.Printf("no inbox for pong %s : %s", who, err) return@@ -261,7 +261,7 @@ j["actor"] = user.URL
j["to"] = who j["object"] = obj keyname, key := ziggy(user.Name) - err = PostJunk(keyname, key, inbox, j) + err = PostJunk(keyname, key, box.In, j) if err != nil { log.Printf("can't send pong: %s", err) return