/// <summary> /// Constructor. /// </summary> public NodeContext(int nodeId, int processId, #if FEATURE_NAMED_PIPES_FULL_DUPLEX Stream nodePipe, #else AnonymousPipeServerStream clientToServerStream, AnonymousPipeServerStream serverToClientStream, #endif INodePacketFactory factory, NodeContextTerminateDelegate terminateDelegate) { _nodeId = nodeId; _processId = processId; #if FEATURE_NAMED_PIPES_FULL_DUPLEX _clientToServerStream = nodePipe; _serverToClientStream = nodePipe; #else _clientToServerStream = clientToServerStream; _serverToClientStream = serverToClientStream; #endif _packetFactory = factory; _headerByte = new byte[5]; // 1 for the packet type, 4 for the body length _smallReadBuffer = new byte[1000]; // 1000 was just an average seen on one profile run. _nodeTerminated = new ManualResetEvent(false); _terminateDelegate = terminateDelegate; _sharedReadBuffer = InterningBinaryReader.CreateSharedBuffer(); }
/// <summary> /// Instantiates an endpoint to act as a client /// </summary> /// <param name="pipeName">The name of the pipe to which we should connect.</param> internal void InternalConstruct(string pipeName) { ErrorUtilities.VerifyThrowArgumentLength(pipeName, nameof(pipeName)); _debugCommunications = (Environment.GetEnvironmentVariable("MSBUILDDEBUGCOMM") == "1"); _status = LinkStatus.Inactive; _asyncDataMonitor = new object(); _sharedReadBuffer = InterningBinaryReader.CreateSharedBuffer(); _packetStream = new MemoryStream(); _binaryWriter = new BinaryWriter(_packetStream); #if FEATURE_PIPE_SECURITY && FEATURE_NAMED_PIPE_SECURITY_CONSTRUCTOR if (!NativeMethodsShared.IsMono) { SecurityIdentifier identifier = WindowsIdentity.GetCurrent().Owner; PipeSecurity security = new PipeSecurity(); // Restrict access to just this account. We set the owner specifically here, and on the // pipe client side they will check the owner against this one - they must have identical // SIDs or the client will reject this server. This is used to avoid attacks where a // hacked server creates a less restricted pipe in an attempt to lure us into using it and // then sending build requests to the real pipe client (which is the MSBuild Build Manager.) PipeAccessRule rule = new PipeAccessRule(identifier, PipeAccessRights.ReadWrite, AccessControlType.Allow); security.AddAccessRule(rule); security.SetOwner(identifier); _pipeServer = new NamedPipeServerStream ( pipeName, PipeDirection.InOut, 1, // Only allow one connection at a time. PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, PipeBufferSize, // Default input buffer PipeBufferSize, // Default output buffer security, HandleInheritability.None ); } else #endif { _pipeServer = new NamedPipeServerStream ( pipeName, PipeDirection.InOut, 1, // Only allow one connection at a time. PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, PipeBufferSize, // Default input buffer PipeBufferSize // Default output buffer ); } }
/// <summary> /// Create a BinaryReader. It will either be an interning reader or standard binary reader /// depending on whether the interning reader is possible given the buffer and stream. /// </summary> internal static BinaryReader Create(Stream stream, SharedReadBuffer sharedBuffer) { Buffer buffer = (Buffer)sharedBuffer; if (buffer != null) { return(new InterningBinaryReader(stream, buffer, false)); } return(new InterningBinaryReader(stream, GetPooledBuffer(), true)); }
/// <summary> /// Create a BinaryReader. It will either be an interning reader or standard binary reader /// depending on whether the interning reader is possible given the buffer and stream. /// </summary> internal static BinaryReader Create(Stream stream, SharedReadBuffer sharedBuffer) { Buffer buffer = (Buffer)sharedBuffer; if (buffer == null) { buffer = new Buffer(); } return(new InterningBinaryReader(stream, buffer)); }
/// <summary> /// Instantiates an endpoint to act as a client /// </summary> /// <param name="pipeName">The name of the pipe to which we should connect.</param> internal void InternalConstruct(string pipeName) { ErrorUtilities.VerifyThrowArgumentLength(pipeName, nameof(pipeName)); _debugCommunications = (Environment.GetEnvironmentVariable("MSBUILDDEBUGCOMM") == "1"); _status = LinkStatus.Inactive; _asyncDataMonitor = new object(); _sharedReadBuffer = InterningBinaryReader.CreateSharedBuffer(); _pipeServer = NamedPipeUtil.CreateNamedPipeServer(pipeName, PipeBufferSize, PipeBufferSize); }
/// <summary> /// Constructor. /// </summary> public NodeContext(int nodeId, int processId, NamedPipeClientStream nodePipe, INodePacketFactory factory, NodeContextTerminateDelegate terminateDelegate) { _nodeId = nodeId; _processId = processId; _nodePipe = nodePipe; _packetFactory = factory; _headerByte = new byte[5]; // 1 for the packet type, 4 for the body length _smallReadBuffer = new byte[1000]; // 1000 was just an average seen on one profile run. _nodeTerminated = new ManualResetEvent(false); _terminateDelegate = terminateDelegate; _sharedReadBuffer = InterningBinaryReader.CreateSharedBuffer(); }
internal void InternalConstruct(string clientToServerPipeHandle, string serverToClientPipeHandle) { ErrorUtilities.VerifyThrowArgumentLength(clientToServerPipeHandle, "clientToServerPipeHandle"); ErrorUtilities.VerifyThrowArgumentLength(serverToClientPipeHandle, "serverToClientPipeHandle"); _debugCommunications = (Environment.GetEnvironmentVariable("MSBUILDDEBUGCOMM") == "1"); _status = LinkStatus.Inactive; _asyncDataMonitor = new object(); _sharedReadBuffer = InterningBinaryReader.CreateSharedBuffer(); _pipeClientToServer = new AnonymousPipeClientStream(PipeDirection.Out, clientToServerPipeHandle); _pipeServerToClient = new AnonymousPipeClientStream(PipeDirection.In, serverToClientPipeHandle); }
/// <summary> /// Constructor. /// </summary> public NodeContext(int nodeId, Process process, Stream nodePipe, INodePacketFactory factory, NodeContextTerminateDelegate terminateDelegate) { _nodeId = nodeId; _process = process; _clientToServerStream = nodePipe; _serverToClientStream = nodePipe; _packetFactory = factory; _headerByte = new byte[5]; // 1 for the packet type, 4 for the body length _readBufferMemoryStream = new MemoryStream(); _writeBufferMemoryStream = new MemoryStream(); _terminateDelegate = terminateDelegate; _sharedReadBuffer = InterningBinaryReader.CreateSharedBuffer(); }
/// <summary> /// Constructs a serializer from the specified stream, operating in the designated mode. /// </summary> public NodePacketReadTranslator(Stream packetStream, SharedReadBuffer buffer) { _packetStream = packetStream; _reader = InterningBinaryReader.Create(packetStream, buffer); }
/// <summary> /// Returns a read-only serializer. /// </summary> /// <returns>The serializer.</returns> static internal INodePacketTranslator GetReadTranslator(Stream stream, SharedReadBuffer buffer) { return(new NodePacketReadTranslator(stream, buffer)); }
/// <summary> /// Returns a read-only serializer. /// </summary> /// <returns>The serializer.</returns> static internal ITranslator GetReadTranslator(Stream stream, SharedReadBuffer buffer) { return(new BinaryReadTranslator(stream, buffer)); }
/// <summary> /// Instantiates an endpoint to act as a client /// </summary> /// <param name="pipeName">The name of the pipe to which we should connect.</param> internal void InternalConstruct(string pipeName) { ErrorUtilities.VerifyThrowArgumentLength(pipeName, "pipeName"); _debugCommunications = (Environment.GetEnvironmentVariable("MSBUILDDEBUGCOMM") == "1"); _status = LinkStatus.Inactive; _asyncDataMonitor = new object(); _sharedReadBuffer = InterningBinaryReader.CreateSharedBuffer(); SecurityIdentifier identifier = WindowsIdentity.GetCurrent().Owner; PipeSecurity security = new PipeSecurity(); // Restrict access to just this account. We set the owner specifically here, and on the // pipe client side they will check the owner against this one - they must have identical // SIDs or the client will reject this server. This is used to avoid attacks where a // hacked server creates a less restricted pipe in an attempt to lure us into using it and // then sending build requests to the real pipe client (which is the MSBuild Build Manager.) PipeAccessRule rule = new PipeAccessRule(identifier, PipeAccessRights.ReadWrite, AccessControlType.Allow); security.AddAccessRule(rule); security.SetOwner(identifier); _pipeServer = new NamedPipeServerStream ( pipeName, PipeDirection.InOut, 1, // Only allow one connection at a time. PipeTransmissionMode.Byte, PipeOptions.Asynchronous | PipeOptions.WriteThrough, PipeBufferSize, // Default input buffer PipeBufferSize, // Default output buffer security, HandleInheritability.None ); }
/// <summary> /// Create a BinaryReader. It will either be an interning reader or standard binary reader /// depending on whether the interning reader is possible given the buffer and stream. /// </summary> internal static BinaryReader Create(Stream stream, SharedReadBuffer sharedBuffer) { Buffer buffer = (Buffer)sharedBuffer; if (buffer == null) { buffer = new Buffer(); } return new InterningBinaryReader(stream, buffer); }