use shared inbox for delivery
This commit is contained in:
parent
8da5d74c31
commit
6ec4352d69
41
activity.go
41
activity.go
|
@ -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
|
var boxlock sync.Mutex
|
||||||
|
|
||||||
func getboxes(ident string) (string, string, error) {
|
func getboxes(ident string) (*Box, error) {
|
||||||
boxlock.Lock()
|
boxlock.Lock()
|
||||||
b, ok := boxofboxes[ident]
|
b, ok := boxofboxes[ident]
|
||||||
boxlock.Unlock()
|
boxlock.Unlock()
|
||||||
if ok {
|
if ok {
|
||||||
m := strings.Split(b, "\n")
|
return b, nil
|
||||||
return m[0], m[1], nil
|
|
||||||
}
|
}
|
||||||
j, err := GetJunk(ident)
|
j, err := GetJunk(ident)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", "", err
|
return nil, err
|
||||||
}
|
}
|
||||||
inbox, _ := jsongetstring(j, "inbox")
|
inbox, _ := jsongetstring(j, "inbox")
|
||||||
outbox, _ := jsongetstring(j, "outbox")
|
outbox, _ := jsongetstring(j, "outbox")
|
||||||
|
sbox, _ := jsongetstring(j, "sharedInbox")
|
||||||
|
b = &Box { In: inbox, Out: outbox, Shared: sbox }
|
||||||
boxlock.Lock()
|
boxlock.Lock()
|
||||||
boxofboxes[ident] = inbox + "\n" + outbox
|
boxofboxes[ident] = b
|
||||||
boxlock.Unlock()
|
boxlock.Unlock()
|
||||||
return inbox, outbox, err
|
return b, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func peeppeep() {
|
func peeppeep() {
|
||||||
|
@ -296,13 +303,13 @@ func peeppeep() {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Printf("getting updates: %s", f.XID)
|
log.Printf("getting updates: %s", f.XID)
|
||||||
_, outbox, err := getboxes(f.XID)
|
box, err := getboxes(f.XID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error getting outbox: %s", err)
|
log.Printf("error getting outbox: %s", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Printf("getting outbox")
|
log.Printf("getting outbox")
|
||||||
j, err := GetJunk(outbox)
|
j, err := GetJunk(box.Out)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("err: %s", err)
|
log.Printf("err: %s", err)
|
||||||
continue
|
continue
|
||||||
|
@ -471,13 +478,13 @@ func rubadubdub(user *WhatAbout, req map[string]interface{}) {
|
||||||
WriteJunk(os.Stdout, j)
|
WriteJunk(os.Stdout, j)
|
||||||
|
|
||||||
actor, _ := jsongetstring(req, "actor")
|
actor, _ := jsongetstring(req, "actor")
|
||||||
inbox, _, err := getboxes(actor)
|
box, err := getboxes(actor)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("can't get dub box: %s", err)
|
log.Printf("can't get dub box: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
keyname, key := ziggy(user.Name)
|
keyname, key := ziggy(user.Name)
|
||||||
err = PostJunk(keyname, key, inbox, j)
|
err = PostJunk(keyname, key, box.In, j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("can't rub a dub: %s", err)
|
log.Printf("can't rub a dub: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -495,14 +502,14 @@ func subsub(user *WhatAbout, xid string) {
|
||||||
j["object"] = xid
|
j["object"] = xid
|
||||||
j["published"] = time.Now().UTC().Format(time.RFC3339)
|
j["published"] = time.Now().UTC().Format(time.RFC3339)
|
||||||
|
|
||||||
inbox, _, err := getboxes(xid)
|
box, err := getboxes(xid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("can't send follow: %s", err)
|
log.Printf("can't send follow: %s", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
WriteJunk(os.Stdout, j)
|
WriteJunk(os.Stdout, j)
|
||||||
keyname, key := ziggy(user.Name)
|
keyname, key := ziggy(user.Name)
|
||||||
err = PostJunk(keyname, key, inbox, j)
|
err = PostJunk(keyname, key, box.In, j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to subsub: %s", err)
|
log.Printf("failed to subsub: %s", err)
|
||||||
}
|
}
|
||||||
|
@ -611,8 +618,12 @@ func honkworldwide(user *WhatAbout, honk *Honk) {
|
||||||
WriteJunk(&buf, jonk)
|
WriteJunk(&buf, jonk)
|
||||||
msg := buf.Bytes()
|
msg := buf.Bytes()
|
||||||
for _, f := range getdubs(user.ID) {
|
for _, f := range getdubs(user.ID) {
|
||||||
deliverate(0, user.Name, f.XID, msg)
|
box, _ := getboxes(f.XID)
|
||||||
delete(rcpts, f.XID)
|
if box != nil && box.Shared != "" {
|
||||||
|
rcpts["%" + box.Shared] = true
|
||||||
|
} else {
|
||||||
|
rcpts[f.XID] = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for a := range rcpts {
|
for a := range rcpts {
|
||||||
if !strings.HasSuffix(a, "/followers") {
|
if !strings.HasSuffix(a, "/followers") {
|
||||||
|
|
|
@ -56,13 +56,20 @@ func sayitagain(goarounds int, username string, rcpt string, msg []byte) {
|
||||||
|
|
||||||
func deliverate(goarounds int, username string, rcpt string, msg []byte) {
|
func deliverate(goarounds int, username string, rcpt string, msg []byte) {
|
||||||
keyname, key := ziggy(username)
|
keyname, key := ziggy(username)
|
||||||
inbox, _, err := getboxes(rcpt)
|
var inbox string
|
||||||
|
// already did the box indirection
|
||||||
|
if rcpt[0] == '%' {
|
||||||
|
inbox = rcpt[1:]
|
||||||
|
} else {
|
||||||
|
box, err := getboxes(rcpt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("error getting inbox %s: %s", rcpt, err)
|
log.Printf("error getting inbox %s: %s", rcpt, err)
|
||||||
sayitagain(goarounds+1, username, rcpt, msg)
|
sayitagain(goarounds+1, username, rcpt, msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = PostMsg(keyname, key, inbox, msg)
|
inbox = box.In
|
||||||
|
}
|
||||||
|
err := PostMsg(keyname, key, inbox, msg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("failed to post json to %s: %s", inbox, err)
|
log.Printf("failed to post json to %s: %s", inbox, err)
|
||||||
sayitagain(goarounds+1, username, rcpt, msg)
|
sayitagain(goarounds+1, username, rcpt, msg)
|
||||||
|
|
8
honk.go
8
honk.go
|
@ -227,7 +227,7 @@ func crappola(j map[string]interface{}) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func ping(user *WhatAbout, who string) {
|
func ping(user *WhatAbout, who string) {
|
||||||
inbox, _, err := getboxes(who)
|
box, err := getboxes(who)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("no inbox for ping: %s", err)
|
log.Printf("no inbox for ping: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -239,7 +239,7 @@ func ping(user *WhatAbout, who string) {
|
||||||
j["actor"] = user.URL
|
j["actor"] = user.URL
|
||||||
j["to"] = who
|
j["to"] = who
|
||||||
keyname, key := ziggy(user.Name)
|
keyname, key := ziggy(user.Name)
|
||||||
err = PostJunk(keyname, key, inbox, j)
|
err = PostJunk(keyname, key, box.In, j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("can't send ping: %s", err)
|
log.Printf("can't send ping: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -248,7 +248,7 @@ func ping(user *WhatAbout, who string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func pong(user *WhatAbout, who string, obj string) {
|
func pong(user *WhatAbout, who string, obj string) {
|
||||||
inbox, _, err := getboxes(who)
|
box, err := getboxes(who)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("no inbox for pong %s : %s", who, err)
|
log.Printf("no inbox for pong %s : %s", who, err)
|
||||||
return
|
return
|
||||||
|
@ -261,7 +261,7 @@ func pong(user *WhatAbout, who string, obj string) {
|
||||||
j["to"] = who
|
j["to"] = who
|
||||||
j["object"] = obj
|
j["object"] = obj
|
||||||
keyname, key := ziggy(user.Name)
|
keyname, key := ziggy(user.Name)
|
||||||
err = PostJunk(keyname, key, inbox, j)
|
err = PostJunk(keyname, key, box.In, j)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("can't send pong: %s", err)
|
log.Printf("can't send pong: %s", err)
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in New Issue