ipn/ipnlocal: run peerapi even if Taildrop storage not configured
Change-Id: I77f9ecbe4617d01d13aa1127fa59c83f2aa3e1b8 Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
This commit is contained in:
parent
44d0c1ab06
commit
43983a4a3b
|
@ -1284,7 +1284,7 @@ func (b *LocalBackend) send(n ipn.Notify) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if apiSrv != nil && apiSrv.hasFilesWaiting() {
|
if apiSrv.hasFilesWaiting() {
|
||||||
n.FilesWaiting = &empty.Message{}
|
n.FilesWaiting = &empty.Message{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2118,7 +2118,7 @@ func (b *LocalBackend) fileRootLocked(uid tailcfg.UserID) string {
|
||||||
}
|
}
|
||||||
varRoot := b.TailscaleVarRoot()
|
varRoot := b.TailscaleVarRoot()
|
||||||
if varRoot == "" {
|
if varRoot == "" {
|
||||||
b.logf("peerapi disabled; no state directory")
|
b.logf("Taildrop disabled; no state directory")
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
baseDir := fmt.Sprintf("%s-uid-%d",
|
baseDir := fmt.Sprintf("%s-uid-%d",
|
||||||
|
@ -2126,7 +2126,7 @@ func (b *LocalBackend) fileRootLocked(uid tailcfg.UserID) string {
|
||||||
uid)
|
uid)
|
||||||
dir := filepath.Join(varRoot, "files", baseDir)
|
dir := filepath.Join(varRoot, "files", baseDir)
|
||||||
if err := os.MkdirAll(dir, 0700); err != nil {
|
if err := os.MkdirAll(dir, 0700); err != nil {
|
||||||
b.logf("peerapi disabled; error making directory: %v", err)
|
b.logf("Taildrop disabled; error making directory: %v", err)
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
return dir
|
return dir
|
||||||
|
@ -2189,7 +2189,7 @@ func (b *LocalBackend) initPeerAPIListener() {
|
||||||
|
|
||||||
fileRoot := b.fileRootLocked(selfNode.User)
|
fileRoot := b.fileRootLocked(selfNode.User)
|
||||||
if fileRoot == "" {
|
if fileRoot == "" {
|
||||||
return
|
b.logf("peerapi starting without Taildrop directory configured")
|
||||||
}
|
}
|
||||||
|
|
||||||
ps := &peerAPIServer{
|
ps := &peerAPIServer{
|
||||||
|
@ -2783,9 +2783,6 @@ func (b *LocalBackend) WaitingFiles() ([]apitype.WaitingFile, error) {
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
apiSrv := b.peerAPIServer
|
apiSrv := b.peerAPIServer
|
||||||
b.mu.Unlock()
|
b.mu.Unlock()
|
||||||
if apiSrv == nil {
|
|
||||||
return nil, errors.New("peerapi disabled")
|
|
||||||
}
|
|
||||||
return apiSrv.WaitingFiles()
|
return apiSrv.WaitingFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2793,9 +2790,6 @@ func (b *LocalBackend) DeleteFile(name string) error {
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
apiSrv := b.peerAPIServer
|
apiSrv := b.peerAPIServer
|
||||||
b.mu.Unlock()
|
b.mu.Unlock()
|
||||||
if apiSrv == nil {
|
|
||||||
return errors.New("peerapi disabled")
|
|
||||||
}
|
|
||||||
return apiSrv.DeleteFile(name)
|
return apiSrv.DeleteFile(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2803,9 +2797,6 @@ func (b *LocalBackend) OpenFile(name string) (rc io.ReadCloser, size int64, err
|
||||||
b.mu.Lock()
|
b.mu.Lock()
|
||||||
apiSrv := b.peerAPIServer
|
apiSrv := b.peerAPIServer
|
||||||
b.mu.Unlock()
|
b.mu.Unlock()
|
||||||
if apiSrv == nil {
|
|
||||||
return nil, 0, errors.New("peerapi disabled")
|
|
||||||
}
|
|
||||||
return apiSrv.OpenFile(name)
|
return apiSrv.OpenFile(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,7 @@ var initListenConfig func(*net.ListenConfig, netaddr.IP, *interfaces.State, stri
|
||||||
|
|
||||||
type peerAPIServer struct {
|
type peerAPIServer struct {
|
||||||
b *LocalBackend
|
b *LocalBackend
|
||||||
rootDir string
|
rootDir string // empty means file receiving unavailable
|
||||||
selfNode *tailcfg.Node
|
selfNode *tailcfg.Node
|
||||||
knownEmpty syncs.AtomicBool
|
knownEmpty syncs.AtomicBool
|
||||||
resolver *resolver.Resolver
|
resolver *resolver.Resolver
|
||||||
|
@ -76,6 +76,10 @@ const (
|
||||||
deletedSuffix = ".deleted"
|
deletedSuffix = ".deleted"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func (s *peerAPIServer) canReceiveFiles() bool {
|
||||||
|
return s != nil && s.rootDir != ""
|
||||||
|
}
|
||||||
|
|
||||||
func validFilenameRune(r rune) bool {
|
func validFilenameRune(r rune) bool {
|
||||||
switch r {
|
switch r {
|
||||||
case '/':
|
case '/':
|
||||||
|
@ -122,7 +126,7 @@ func (s *peerAPIServer) diskPath(baseName string) (fullPath string, ok bool) {
|
||||||
// hasFilesWaiting reports whether any files are buffered in the
|
// hasFilesWaiting reports whether any files are buffered in the
|
||||||
// tailscaled daemon storage.
|
// tailscaled daemon storage.
|
||||||
func (s *peerAPIServer) hasFilesWaiting() bool {
|
func (s *peerAPIServer) hasFilesWaiting() bool {
|
||||||
if s.rootDir == "" || s.directFileMode {
|
if s == nil || s.rootDir == "" || s.directFileMode {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if s.knownEmpty.Get() {
|
if s.knownEmpty.Get() {
|
||||||
|
@ -182,8 +186,11 @@ func (s *peerAPIServer) hasFilesWaiting() bool {
|
||||||
// As a side effect, it also does any lazy deletion of files as
|
// As a side effect, it also does any lazy deletion of files as
|
||||||
// required by Windows.
|
// required by Windows.
|
||||||
func (s *peerAPIServer) WaitingFiles() (ret []apitype.WaitingFile, err error) {
|
func (s *peerAPIServer) WaitingFiles() (ret []apitype.WaitingFile, err error) {
|
||||||
|
if s == nil {
|
||||||
|
return nil, errNilPeerAPIServer
|
||||||
|
}
|
||||||
if s.rootDir == "" {
|
if s.rootDir == "" {
|
||||||
return nil, errors.New("peerapi disabled; no storage configured")
|
return nil, errNoTaildrop
|
||||||
}
|
}
|
||||||
if s.directFileMode {
|
if s.directFileMode {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
|
@ -247,6 +254,11 @@ func (s *peerAPIServer) WaitingFiles() (ret []apitype.WaitingFile, err error) {
|
||||||
return ret, nil
|
return ret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
errNilPeerAPIServer = errors.New("peerapi unavailable; not listening")
|
||||||
|
errNoTaildrop = errors.New("Taildrop disabled; no storage directory")
|
||||||
|
)
|
||||||
|
|
||||||
// tryDeleteAgain tries to delete path (and path+deletedSuffix) after
|
// tryDeleteAgain tries to delete path (and path+deletedSuffix) after
|
||||||
// it failed earlier. This happens on Windows when various anti-virus
|
// it failed earlier. This happens on Windows when various anti-virus
|
||||||
// tools hook into filesystem operations and have the file open still
|
// tools hook into filesystem operations and have the file open still
|
||||||
|
@ -262,8 +274,11 @@ func tryDeleteAgain(fullPath string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *peerAPIServer) DeleteFile(baseName string) error {
|
func (s *peerAPIServer) DeleteFile(baseName string) error {
|
||||||
|
if s == nil {
|
||||||
|
return errNilPeerAPIServer
|
||||||
|
}
|
||||||
if s.rootDir == "" {
|
if s.rootDir == "" {
|
||||||
return errors.New("peerapi disabled; no storage configured")
|
return errNoTaildrop
|
||||||
}
|
}
|
||||||
if s.directFileMode {
|
if s.directFileMode {
|
||||||
return errors.New("deletes not allowed in direct mode")
|
return errors.New("deletes not allowed in direct mode")
|
||||||
|
@ -328,8 +343,11 @@ func touchFile(path string) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *peerAPIServer) OpenFile(baseName string) (rc io.ReadCloser, size int64, err error) {
|
func (s *peerAPIServer) OpenFile(baseName string) (rc io.ReadCloser, size int64, err error) {
|
||||||
|
if s == nil {
|
||||||
|
return nil, 0, errNilPeerAPIServer
|
||||||
|
}
|
||||||
if s.rootDir == "" {
|
if s.rootDir == "" {
|
||||||
return nil, 0, errors.New("peerapi disabled; no storage configured")
|
return nil, 0, errNoTaildrop
|
||||||
}
|
}
|
||||||
if s.directFileMode {
|
if s.directFileMode {
|
||||||
return nil, 0, errors.New("opens not allowed in direct mode")
|
return nil, 0, errors.New("opens not allowed in direct mode")
|
||||||
|
@ -607,7 +625,7 @@ func (h *peerAPIHandler) handlePeerPut(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if h.ps.rootDir == "" {
|
if h.ps.rootDir == "" {
|
||||||
http.Error(w, "no rootdir", http.StatusInternalServerError)
|
http.Error(w, errNoTaildrop.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
rawPath := r.URL.EscapedPath()
|
rawPath := r.URL.EscapedPath()
|
||||||
|
|
|
@ -179,7 +179,7 @@ func TestHandlePeerAPI(t *testing.T) {
|
||||||
req: httptest.NewRequest("PUT", "/v0/put/foo", nil),
|
req: httptest.NewRequest("PUT", "/v0/put/foo", nil),
|
||||||
checks: checks(
|
checks: checks(
|
||||||
httpStatus(http.StatusInternalServerError),
|
httpStatus(http.StatusInternalServerError),
|
||||||
bodyContains("no rootdir"),
|
bodyContains("Taildrop disabled; no storage directory"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue