ipn/ipnlocal: always set Notify.FilesWaiting, set IncomingFiles non-nil when empty

pull/1715/head
Brad Fitzpatrick 3 years ago
parent b0af15ff5c
commit 20e7646b8d

@ -67,8 +67,17 @@ type Notify struct {
BackendLogID *string // public logtail id used by backend BackendLogID *string // public logtail id used by backend
PingResult *ipnstate.PingResult PingResult *ipnstate.PingResult
FilesWaiting *empty.Message `json:",omitempty"` // FilesWaiting if non-nil means that files are buffered in
IncomingFiles []PartialFile `json:",omitempty"` // the Tailscale daemon and ready for local transfer to the
// user's preferred storage location.
FilesWaiting *empty.Message `json:",omitempty"`
// IncomingFiles, if non-nil, specifies which files are in the
// process of being received. A nil IncomingFiles means this
// Notify should not update the state of file transfers. A non-nil
// but empty IncomingFiles means that no files are in the middle
// of being transferred.
IncomingFiles []PartialFile `json:",omitempty"`
// LocalTCPPort, if non-nil, informs the UI frontend which // LocalTCPPort, if non-nil, informs the UI frontend which
// (non-zero) localhost TCP port it's listening on. // (non-zero) localhost TCP port it's listening on.

@ -927,6 +927,7 @@ func (b *LocalBackend) readPoller() {
func (b *LocalBackend) send(n ipn.Notify) { func (b *LocalBackend) send(n ipn.Notify) {
b.mu.Lock() b.mu.Lock()
notifyFunc := b.notify notifyFunc := b.notify
apiSrv := b.peerAPIServer
b.mu.Unlock() b.mu.Unlock()
if notifyFunc == nil { if notifyFunc == nil {
@ -934,6 +935,10 @@ func (b *LocalBackend) send(n ipn.Notify) {
return return
} }
if apiSrv != nil && apiSrv.hasFilesWaiting() {
n.FilesWaiting = &empty.Message{}
}
n.Version = version.Long n.Version = version.Long
notifyFunc(n) notifyFunc(n)
} }
@ -949,9 +954,10 @@ func (b *LocalBackend) sendFileNotify() {
return return
} }
if apiSrv.hasFilesWaiting() { // Make sure we always set n.IncomingFiles non-nil so it gets encoded
n.FilesWaiting = &empty.Message{} // in JSON to clients. They distinguish between empty and non-nil
} // to know whether a Notify should be able about files.
n.IncomingFiles = make([]ipn.PartialFile, 0)
for f := range b.incomingFiles { for f := range b.incomingFiles {
n.IncomingFiles = append(n.IncomingFiles, f.PartialFile()) n.IncomingFiles = append(n.IncomingFiles, f.PartialFile())
} }

Loading…
Cancel
Save