This repository has been archived on 2021-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
ui/go/characters/postmanpat.go

37 lines
803 B
Go
Raw Permalink Normal View History

2018-11-22 00:01:17 +00:00
package characters
import (
2018-11-28 22:14:02 +00:00
"cwtch.im/ui/go/gobjects"
"cwtch.im/ui/go/the"
"git.openprivacy.ca/openprivacy/libricochet-go/log"
2018-11-22 00:01:17 +00:00
)
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
2019-01-21 21:17:51 +00:00
the.Peer.PeerWithOnion(m.To)
log.Debugf("sending message!")
2019-02-11 21:05:01 +00:00
ackID := new(the.AckId)
ackID.ID = m.MID
ackID.Ack = false
the.AcknowledgementIDs[m.To] = append(the.AcknowledgementIDs[m.To], ackID)
2019-02-04 22:22:58 +00:00
the.Peer.SendMessageToPeer(m.To, m.Message)
2018-11-22 00:01:17 +00:00
}
}