diff options
| author | Brad Fitzpatrick <bradfitz@tailscale.com> | 2021-11-30 08:47:52 -0800 |
|---|---|---|
| committer | Brad Fitzpatrick <brad@danga.com> | 2021-11-30 11:47:27 -0800 |
| commit | 3181bbb8e4aea869a67c19cea6877bc9a6c4467d (patch) | |
| tree | d704a40682d1915064ad43e394ccfefb89f1a99f /cmd | |
| parent | 46a9782322e969af26f6fe9d191599354077dd02 (diff) | |
| download | tailscale-3181bbb8e4aea869a67c19cea6877bc9a6c4467d.tar.xz tailscale-3181bbb8e4aea869a67c19cea6877bc9a6c4467d.zip | |
cmd/tailscale: make file cp send files via tailscaled localapi
So Taildrop sends work even if the local tailscaled is running in
netstack mode, as it often is on Synology, etc.
Updates #2179 (which is primarily about receiving, but both important)
Change-Id: I9bd1afdc8d25717e0ab6802c7cf2f5e0bd89a3b2
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/tailscale/cli/file.go | 28 |
1 files changed, 8 insertions, 20 deletions
diff --git a/cmd/tailscale/cli/file.go b/cmd/tailscale/cli/file.go index 9f42c1d04..775c44933 100644 --- a/cmd/tailscale/cli/file.go +++ b/cmd/tailscale/cli/file.go @@ -11,11 +11,9 @@ import ( "flag" "fmt" "io" - "io/ioutil" "log" "mime" "net/http" - "net/url" "os" "path/filepath" "strconv" @@ -30,6 +28,7 @@ import ( "tailscale.com/client/tailscale/apitype" "tailscale.com/ipn" "tailscale.com/net/tsaddr" + "tailscale.com/tailcfg" "tailscale.com/version" ) @@ -96,7 +95,7 @@ func runCp(ctx context.Context, args []string) error { return err } - peerAPIBase, isOffline, err := discoverPeerAPIBase(ctx, ip) + stableID, isOffline, err := getTargetStableID(ctx, ip) if err != nil { return fmt.Errorf("can't send to %s: %v", target, err) } @@ -154,32 +153,21 @@ func runCp(ctx context.Context, args []string) error { } } - dstURL := peerAPIBase + "/v0/put/" + url.PathEscape(name) - req, err := http.NewRequestWithContext(ctx, "PUT", dstURL, fileContents) - if err != nil { - return err - } - req.ContentLength = contentLength if cpArgs.verbose { - log.Printf("sending to %v ...", dstURL) + log.Printf("sending %q to %v/%v/%v ...", name, target, ip, stableID) } - res, err := http.DefaultClient.Do(req) + err := tailscale.PushFile(ctx, stableID, contentLength, name, fileContents) if err != nil { return err } - if res.StatusCode == 200 { - io.Copy(ioutil.Discard, res.Body) - res.Body.Close() - continue + if cpArgs.verbose { + log.Printf("sent %q", name) } - io.Copy(Stdout, res.Body) - res.Body.Close() - return errors.New(res.Status) } return nil } -func discoverPeerAPIBase(ctx context.Context, ipStr string) (base string, isOffline bool, err error) { +func getTargetStableID(ctx context.Context, ipStr string) (id tailcfg.StableNodeID, isOffline bool, err error) { ip, err := netaddr.ParseIP(ipStr) if err != nil { return "", false, err @@ -195,7 +183,7 @@ func discoverPeerAPIBase(ctx context.Context, ipStr string) (base string, isOffl continue } isOffline = n.Online != nil && !*n.Online - return ft.PeerAPIURL, isOffline, nil + return n.StableID, isOffline, nil } } return "", false, fileTargetErrorDetail(ctx, ip) |
