mirror of
https://github.com/matrix-org/sliding-sync.git
synced 2025-03-10 13:37:11 +00:00
Bunch of comments
This commit is contained in:
parent
3e8f270b09
commit
06b7d91b08
@ -9,6 +9,7 @@ import (
|
|||||||
// The channel which has V2* payloads
|
// The channel which has V2* payloads
|
||||||
const ChanV2 = "v2ch"
|
const ChanV2 = "v2ch"
|
||||||
|
|
||||||
|
// V2Listener describes the messages that sync v2 pollers will publish.
|
||||||
type V2Listener interface {
|
type V2Listener interface {
|
||||||
Initialise(p *V2Initialise)
|
Initialise(p *V2Initialise)
|
||||||
Accumulate(p *V2Accumulate)
|
Accumulate(p *V2Accumulate)
|
||||||
|
@ -3,6 +3,7 @@ package pubsub
|
|||||||
// The channel which has V3* payloads
|
// The channel which has V3* payloads
|
||||||
const ChanV3 = "v3ch"
|
const ChanV3 = "v3ch"
|
||||||
|
|
||||||
|
// V3Listener describes the messages that incoming sliding sync requests will publish.
|
||||||
type V3Listener interface {
|
type V3Listener interface {
|
||||||
EnsurePolling(p *V3EnsurePolling)
|
EnsurePolling(p *V3EnsurePolling)
|
||||||
}
|
}
|
||||||
|
@ -7,14 +7,25 @@ import (
|
|||||||
"github.com/matrix-org/sliding-sync/pubsub"
|
"github.com/matrix-org/sliding-sync/pubsub"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// pendingInfo tracks the status of a poller that we are (or previously were) waiting
|
||||||
|
// to start.
|
||||||
type pendingInfo struct {
|
type pendingInfo struct {
|
||||||
|
// done is set to true when we confirm that this poller has started polling.
|
||||||
done bool
|
done bool
|
||||||
ch chan struct{}
|
// ch is a dummy channel which never receives any data. A call to
|
||||||
|
// EnsurePoller.OnInitialSyncComplete will close the channel (unblocking any
|
||||||
|
// EnsurePoller.EnsurePolling calls which are waiting on it) and then set the ch
|
||||||
|
// field to nil.
|
||||||
|
ch chan struct{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EnsurePoller is a gadget used by the sliding sync request handler to ensure that
|
||||||
|
// we are running a v2 poller for a given device.
|
||||||
type EnsurePoller struct {
|
type EnsurePoller struct {
|
||||||
chanName string
|
chanName string
|
||||||
mu *sync.Mutex
|
// mu guards reads and writes to pendingPolls.
|
||||||
|
mu *sync.Mutex
|
||||||
|
// pendingPolls tracks the status of pollers that we are waiting to start.
|
||||||
pendingPolls map[sync2.PollerID]pendingInfo
|
pendingPolls map[sync2.PollerID]pendingInfo
|
||||||
notifier pubsub.Notifier
|
notifier pubsub.Notifier
|
||||||
}
|
}
|
||||||
@ -33,6 +44,11 @@ func NewEnsurePoller(notifier pubsub.Notifier) *EnsurePoller {
|
|||||||
func (p *EnsurePoller) EnsurePolling(pid sync2.PollerID, tokenHash string) {
|
func (p *EnsurePoller) EnsurePolling(pid sync2.PollerID, tokenHash string) {
|
||||||
p.mu.Lock()
|
p.mu.Lock()
|
||||||
// do we need to wait?
|
// do we need to wait?
|
||||||
|
// TODO: this lookup is based on (user, device) pair. If the same user logs in on
|
||||||
|
// another device, we will wait for the poller to make an initial sync. We could do
|
||||||
|
// better here by using the data we've accumulated for the first device. However
|
||||||
|
// that wouldn't include any to-device messages, so encrypted messages would be
|
||||||
|
// undecrypted.
|
||||||
if p.pendingPolls[pid].done {
|
if p.pendingPolls[pid].done {
|
||||||
p.mu.Unlock()
|
p.mu.Unlock()
|
||||||
return
|
return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user