MCPcopy Create free account
hub / github.com/tailscale/tailscale / NewFileServer

Function NewFileServer

drive/driveimpl/fileserver.go:42–62  ·  view source on GitHub ↗

NewFileServer constructs a FileServer. The server attempts to listen at a random address on 127.0.0.1. The listen address is available via the Addr() method. The server has to be told about shares before it can serve them. This is accomplished either by calling SetShares(), or locking the shares w

()

Source from the content-addressed store, hash-verified

40// The server doesn't actually process requests until the Serve() method is
41// called.
42func NewFileServer() (*FileServer, error) {
43 // path := filepath.Join(os.TempDir(), fmt.Sprintf("%v.socket", uuid.New().String()))
44 // ln, err := safesocket.Listen(path)
45 // if err != nil {
46 // TODO(oxtoacart): actually get safesocket working in more environments (MacOS Sandboxed, Windows, ???)
47 ln, err := net.Listen("tcp", "127.0.0.1:0")
48 if err != nil {
49 return nil, fmt.Errorf("listen: %w", err)
50 }
51
52 secretToken, err := generateSecretToken()
53 if err != nil {
54 return nil, err
55 }
56
57 return &FileServer{
58 ln: ln,
59 secretToken: secretToken,
60 shareHandlers: make(map[string]http.Handler),
61 }, nil
62}
63
64// generateSecretToken generates a hex-encoded 256 bit secret.
65func generateSecretToken() (string, error) {

Callers 2

serveDriveFunction · 0.92
addRemoteMethod · 0.85

Calls 3

generateSecretTokenFunction · 0.85
ListenMethod · 0.65
ErrorfMethod · 0.65

Tested by 1

addRemoteMethod · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…