use shared inbox for delivery

This commit is contained in:
Ted Unangst 2019-04-16 14:40:23 -04:00
parent 8da5d74c31
commit 6ec4352d69
3 changed files with 43 additions and 25 deletions

View File

@ -265,27 +265,34 @@ func savexonk(x *Honk) {
}
}
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 @@ func peeppeep() {
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 @@ func rubadubdub(user *WhatAbout, req map[string]interface{}) {
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 @@ func subsub(user *WhatAbout, xid string) {
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 @@ func honkworldwide(user *WhatAbout, honk *Honk) {
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") {

View File

@ -56,13 +56,20 @@ func sayitagain(goarounds int, username string, rcpt string, msg []byte) {
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)

View File

@ -227,7 +227,7 @@ func crappola(j map[string]interface{}) bool {
}
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 @@ func ping(user *WhatAbout, who string) {
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 @@ func ping(user *WhatAbout, who string) {
}
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 @@ func pong(user *WhatAbout, who string, obj string) {
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