forked from cwtch.im/ui
37 lines
803 B
Go
37 lines
803 B
Go
package characters
|
|
|
|
import (
|
|
"cwtch.im/ui/go/gobjects"
|
|
"cwtch.im/ui/go/the"
|
|
"git.openprivacy.ca/openprivacy/libricochet-go/log"
|
|
)
|
|
|
|
func PostmanPat(messages chan gobjects.Letter) {
|
|
postOffice := make(map[string]chan gobjects.Letter)
|
|
|
|
for {
|
|
m := <-messages
|
|
|
|
_, found := postOffice[m.To]
|
|
if !found {
|
|
postOffice[m.To] = make(chan gobjects.Letter, 100)
|
|
go andHisBlackAndWhiteCat(postOffice[m.To])
|
|
}
|
|
|
|
postOffice[m.To] <- m
|
|
}
|
|
}
|
|
|
|
func andHisBlackAndWhiteCat(incomingMessages chan gobjects.Letter) {
|
|
for {
|
|
m := <-incomingMessages
|
|
the.Peer.PeerWithOnion(m.To)
|
|
log.Debugf("sending message!")
|
|
ackID := new(the.AckId)
|
|
ackID.ID = m.MID
|
|
ackID.Ack = false
|
|
the.AcknowledgementIDs[m.To] = append(the.AcknowledgementIDs[m.To], ackID)
|
|
the.Peer.SendMessageToPeer(m.To, m.Message)
|
|
}
|
|
}
|