Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1020)

Unified Diff: logdog/client/butler/streamserver/namedPipe_windows.go

Issue 2737603003: Butler stream servers can generate client address. (Closed)
Patch Set: better Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: logdog/client/butler/streamserver/namedPipe_windows.go
diff --git a/logdog/client/butler/streamserver/namedPipe_windows.go b/logdog/client/butler/streamserver/namedPipe_windows.go
index e848d56cdb0ddc087513b483eaad61cce32d3c67..d1245541fe9b8a16c5f6d506780eb121c6b96dba 100644
--- a/logdog/client/butler/streamserver/namedPipe_windows.go
+++ b/logdog/client/butler/streamserver/namedPipe_windows.go
@@ -7,19 +7,40 @@ package streamserver
import (
"net"
+ "github.com/luci/luci-go/common/errors"
log "github.com/luci/luci-go/common/logging"
+
"golang.org/x/net/context"
npipe "gopkg.in/natefinch/npipe.v2"
)
+// localNamedPipePrefix is the prefix that can be applied to a named pipe in
+// order to bind it exclusively to the local system.
+const localNamedPipePrefix = `\\.\pipe\`
+
+// maxWindowsNamedPipeLength is the maximum length of a Windows named pipe.
+const maxWindowsNamedPipeLength = 256
+
// NewNamedPipeServer instantiates a new Windows named pipe server instance.
-func NewNamedPipeServer(ctx context.Context, address string) StreamServer {
- ctx = log.SetField(ctx, "address", address)
+func NewNamedPipeServer(ctx context.Context, name string) (StreamServer, error) {
+ switch l := len(name); {
+ case l == 0:
+ return nil, errors.New("cannot have empty name")
+ case l > maxWindowsNamedPipeLength:
+ return nil, errors.Reason("name exceeds maximum length %(max)d").
+ D("name", name).
+ D("max", maxWindowsNamedPipeLength).
+ Err()
+ }
+
+ name = localNamedPipePrefix + name
nodir 2017/03/06 22:29:44 this may be more than maxWindowsNamedPipeLength?
dnj 2017/03/06 22:39:30 This is fine - the name length is about the pipe n
+ ctx = log.SetField(ctx, "name", name)
return &listenerStreamServer{
Context: ctx,
+ address: "net.pipe:" + name,
gen: func() (net.Listener, error) {
log.Debugf(ctx, "Creating Windows server socket Listener.")
- return npipe.Listen(address)
+ return npipe.Listen(name)
},
- }
+ }, nil
}
« no previous file with comments | « logdog/client/butler/streamserver/namedPipe_posix_test.go ('k') | logdog/client/butler/streamserver/namedPipe_windows_test.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698