mirror of
https://github.com/tailscale/tailscale.git
synced 2026-02-11 02:31:20 +01:00
This file was never truly necessary and has never actually been used in the history of Tailscale's open source releases. A Brief History of AUTHORS files --- The AUTHORS file was a pattern developed at Google, originally for Chromium, then adopted by Go and a bunch of other projects. The problem was that Chromium originally had a copyright line only recognizing Google as the copyright holder. Because Google (and most open source projects) do not require copyright assignemnt for contributions, each contributor maintains their copyright. Some large corporate contributors then tried to add their own name to the copyright line in the LICENSE file or in file headers. This quickly becomes unwieldy, and puts a tremendous burden on anyone building on top of Chromium, since the license requires that they keep all copyright lines intact. The compromise was to create an AUTHORS file that would list all of the copyright holders. The LICENSE file and source file headers would then include that list by reference, listing the copyright holder as "The Chromium Authors". This also become cumbersome to simply keep the file up to date with a high rate of new contributors. Plus it's not always obvious who the copyright holder is. Sometimes it is the individual making the contribution, but many times it may be their employer. There is no way for the proejct maintainer to know. Eventually, Google changed their policy to no longer recommend trying to keep the AUTHORS file up to date proactively, and instead to only add to it when requested: https://opensource.google/docs/releasing/authors. They are also clear that: > Adding contributors to the AUTHORS file is entirely within the > project's discretion and has no implications for copyright ownership. It was primarily added to appease a small number of large contributors that insisted that they be recognized as copyright holders (which was entirely their right to do). But it's not truly necessary, and not even the most accurate way of identifying contributors and/or copyright holders. In practice, we've never added anyone to our AUTHORS file. It only lists Tailscale, so it's not really serving any purpose. It also causes confusion because Tailscalars put the "Tailscale Inc & AUTHORS" header in other open source repos which don't actually have an AUTHORS file, so it's ambiguous what that means. Instead, we just acknowledge that the contributors to Tailscale (whoever they are) are copyright holders for their individual contributions. We also have the benefit of using the DCO (developercertificate.org) which provides some additional certification of their right to make the contribution. The source file changes were purely mechanical with: git ls-files | xargs sed -i -e 's/\(Tailscale Inc &\) AUTHORS/\1 contributors/g' Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <will@tailscale.com>
175 lines
4.8 KiB
Go
175 lines
4.8 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
||
// SPDX-License-Identifier: BSD-3-Clause
|
||
|
||
package taildrop
|
||
|
||
import (
|
||
"context"
|
||
"errors"
|
||
"io"
|
||
"io/fs"
|
||
"os"
|
||
"runtime"
|
||
"sort"
|
||
"time"
|
||
|
||
"tailscale.com/client/tailscale/apitype"
|
||
"tailscale.com/util/backoff"
|
||
"tailscale.com/util/set"
|
||
)
|
||
|
||
// HasFilesWaiting reports whether any files are buffered in [Handler.Dir].
|
||
// This always returns false when [Handler.DirectFileMode] is false.
|
||
func (m *manager) HasFilesWaiting() bool {
|
||
if m == nil || m.opts.fileOps == nil || m.opts.DirectFileMode {
|
||
return false
|
||
}
|
||
|
||
// Optimization: this is usually empty, so avoid opening
|
||
// the directory and checking. We can't cache the actual
|
||
// has-files-or-not values as the macOS/iOS client might
|
||
// in the future use+delete the files directly. So only
|
||
// keep this negative cache.
|
||
total := m.totalReceived.Load()
|
||
if total == m.emptySince.Load() {
|
||
return false
|
||
}
|
||
|
||
files, err := m.opts.fileOps.ListFiles()
|
||
if err != nil {
|
||
return false
|
||
}
|
||
|
||
// Build a set of filenames present in Dir
|
||
fileSet := set.Of(files...)
|
||
|
||
for _, filename := range files {
|
||
if isPartialOrDeleted(filename) {
|
||
continue
|
||
}
|
||
if fileSet.Contains(filename + deletedSuffix) {
|
||
continue // already handled
|
||
}
|
||
// Found at least one downloadable file
|
||
return true
|
||
}
|
||
|
||
// No waiting files → update negative‑result cache
|
||
m.emptySince.Store(total)
|
||
return false
|
||
}
|
||
|
||
// WaitingFiles returns the list of files that have been sent by a
|
||
// peer that are waiting in [Handler.Dir].
|
||
// This always returns nil when [Handler.DirectFileMode] is false.
|
||
func (m *manager) WaitingFiles() ([]apitype.WaitingFile, error) {
|
||
if m == nil || m.opts.fileOps == nil {
|
||
return nil, ErrNoTaildrop
|
||
}
|
||
if m.opts.DirectFileMode {
|
||
return nil, nil
|
||
}
|
||
names, err := m.opts.fileOps.ListFiles()
|
||
if err != nil {
|
||
return nil, redactError(err)
|
||
}
|
||
var ret []apitype.WaitingFile
|
||
for _, name := range names {
|
||
if isPartialOrDeleted(name) {
|
||
continue
|
||
}
|
||
// A corresponding .deleted marker means the file was already handled.
|
||
if _, err := m.opts.fileOps.Stat(name + deletedSuffix); err == nil {
|
||
continue
|
||
}
|
||
fi, err := m.opts.fileOps.Stat(name)
|
||
if err != nil {
|
||
continue
|
||
}
|
||
ret = append(ret, apitype.WaitingFile{
|
||
Name: name,
|
||
Size: fi.Size(),
|
||
})
|
||
}
|
||
sort.Slice(ret, func(i, j int) bool { return ret[i].Name < ret[j].Name })
|
||
return ret, nil
|
||
}
|
||
|
||
// DeleteFile deletes a file of the given baseName from [Handler.Dir].
|
||
// This method is only allowed when [Handler.DirectFileMode] is false.
|
||
func (m *manager) DeleteFile(baseName string) error {
|
||
if m == nil || m.opts.fileOps == nil {
|
||
return ErrNoTaildrop
|
||
}
|
||
if m.opts.DirectFileMode {
|
||
return errors.New("deletes not allowed in direct mode")
|
||
}
|
||
|
||
var bo *backoff.Backoff
|
||
logf := m.opts.Logf
|
||
t0 := m.opts.Clock.Now()
|
||
for {
|
||
err := m.opts.fileOps.Remove(baseName)
|
||
if err != nil && !os.IsNotExist(err) {
|
||
err = redactError(err)
|
||
// Put a retry loop around deletes on Windows.
|
||
//
|
||
// Windows file descriptor closes are effectively asynchronous,
|
||
// as a bunch of hooks run on/after close,
|
||
// and we can't necessarily delete the file for a while after close,
|
||
// as we need to wait for everybody to be done with it.
|
||
// On Windows, unlike Unix, a file can't be deleted if it's open anywhere.
|
||
// So try a few times but ultimately just leave a "foo.jpg.deleted"
|
||
// marker file to note that it's deleted and we clean it up later.
|
||
if runtime.GOOS == "windows" {
|
||
if bo == nil {
|
||
bo = backoff.NewBackoff("delete-retry", logf, 1*time.Second)
|
||
}
|
||
if m.opts.Clock.Since(t0) < 5*time.Second {
|
||
bo.BackOff(context.Background(), err)
|
||
continue
|
||
}
|
||
if err := m.touchFile(baseName + deletedSuffix); err != nil {
|
||
logf("peerapi: failed to leave deleted marker: %v", err)
|
||
}
|
||
m.deleter.Insert(baseName + deletedSuffix)
|
||
}
|
||
logf("peerapi: failed to DeleteFile: %v", err)
|
||
return err
|
||
}
|
||
return nil
|
||
}
|
||
}
|
||
|
||
func (m *manager) touchFile(name string) error {
|
||
wc, _, err := m.opts.fileOps.OpenWriter(name /* offset= */, 0, 0666)
|
||
if err != nil {
|
||
return redactError(err)
|
||
}
|
||
return wc.Close()
|
||
}
|
||
|
||
// OpenFile opens a file of the given baseName from [Handler.Dir].
|
||
// This method is only allowed when [Handler.DirectFileMode] is false.
|
||
func (m *manager) OpenFile(baseName string) (rc io.ReadCloser, size int64, err error) {
|
||
if m == nil || m.opts.fileOps == nil {
|
||
return nil, 0, ErrNoTaildrop
|
||
}
|
||
if m.opts.DirectFileMode {
|
||
return nil, 0, errors.New("opens not allowed in direct mode")
|
||
}
|
||
if _, err := m.opts.fileOps.Stat(baseName + deletedSuffix); err == nil {
|
||
return nil, 0, redactError(&fs.PathError{Op: "open", Path: baseName, Err: fs.ErrNotExist})
|
||
}
|
||
f, err := m.opts.fileOps.OpenReader(baseName)
|
||
if err != nil {
|
||
return nil, 0, redactError(err)
|
||
}
|
||
fi, err := m.opts.fileOps.Stat(baseName)
|
||
if err != nil {
|
||
f.Close()
|
||
return nil, 0, redactError(err)
|
||
}
|
||
return f, fi.Size(), nil
|
||
}
|