/// <summary> /// Expected to be called when TaskHostTask is done with host of the given context. /// </summary> internal void DisconnectFromHost(HandshakeOptions hostContext) { ErrorUtilities.VerifyThrow(_nodeIdToPacketFactory.ContainsKey((int)hostContext) && _nodeIdToPacketHandler.ContainsKey((int)hostContext), "Why are we trying to disconnect from a context that we already disconnected from? Did we call DisconnectFromHost twice?"); _nodeIdToPacketFactory.Remove((int)hostContext); _nodeIdToPacketHandler.Remove((int)hostContext); }
/// <summary> /// Make sure a node in the requested context exists. /// </summary> internal bool AcquireAndSetUpHost(HandshakeOptions hostContext, INodePacketFactory factory, INodePacketHandler handler, TaskHostConfiguration configuration) { NodeContext context; bool nodeCreationSucceeded; if (!_nodeContexts.TryGetValue(hostContext, out context)) { nodeCreationSucceeded = CreateNode(hostContext, factory, handler, configuration); } else { // node already exists, so "creation" automatically succeeded nodeCreationSucceeded = true; } if (nodeCreationSucceeded) { context = _nodeContexts[hostContext]; _nodeIdToPacketFactory[(int)hostContext] = factory; _nodeIdToPacketHandler[(int)hostContext] = handler; // Configure the node. context.SendData(configuration); return(true); } return(false); }
public Handshake(PeerHash local, PeerHash remote, FileHash hash, HandshakeOptions options) { this.local = local; this.remote = remote; this.hash = hash; this.options = options; }
/// <summary> /// Instantiates a new MSBuild or MSBuildTaskHost process acting as a child node. /// </summary> internal bool CreateNode(HandshakeOptions hostContext, INodePacketFactory factory, INodePacketHandler handler, TaskHostConfiguration configuration) { ErrorUtilities.VerifyThrowArgumentNull(factory, "factory"); ErrorUtilities.VerifyThrow(!_nodeIdToPacketFactory.ContainsKey((int)hostContext), "We should not already have a factory for this context! Did we forget to call DisconnectFromHost somewhere?"); if (AvailableNodes == 0) { ErrorUtilities.ThrowInternalError("All allowable nodes already created ({0}).", _nodeContexts.Count); return(false); } // Start the new process. We pass in a node mode with a node number of 2, to indicate that we // want to start up an MSBuild task host node. string commandLineArgs = $" /nologo /nodemode:2 /nodereuse:{ComponentHost.BuildParameters.EnableNodeReuse} "; string msbuildLocation = GetMSBuildLocationFromHostContext(hostContext); // we couldn't even figure out the location we're trying to launch ... just go ahead and fail. if (msbuildLocation == null) { return(false); } CommunicationsUtilities.Trace("For a host context of {0}, spawning executable from {1}.", hostContext.ToString(), msbuildLocation ?? "MSBuild.exe"); // Make it here. NodeContext context = GetNode ( msbuildLocation, commandLineArgs, (int)hostContext, this, CommunicationsUtilities.GetHostHandshake(hostContext), CommunicationsUtilities.GetClientHandshake(hostContext), NodeContextTerminated ); if (null != context) { _nodeContexts[hostContext] = context; // Start the asynchronous read. context.BeginAsyncPacketRead(); _activeNodes.Add((int)hostContext); _noNodesActiveEvent.Reset(); return(true); } return(false); }
private void LogErrorUnableToCreateTaskHost(HandshakeOptions requiredContext, string runtime, string architecture, NodeFailedToLaunchException e) { string msbuildLocation = NodeProviderOutOfProcTaskHost.GetMSBuildLocationFromHostContext(requiredContext) ?? // We don't know the path -- probably we're trying to get a 64-bit assembly on a // 32-bit machine. At least give them the exe name to look for, though ... ((requiredContext & HandshakeOptions.CLR2) == HandshakeOptions.CLR2 ? "MSBuildTaskHost.exe" : "MSBuild.exe"); if (e == null) { _taskLoggingContext.LogError(new BuildEventFileInfo(_taskLocation), "TaskHostAcquireFailed", _taskType.Type.Name, runtime, architecture, msbuildLocation); } else { _taskLoggingContext.LogError(new BuildEventFileInfo(_taskLocation), "TaskHostNodeFailedToLaunch", _taskType.Type.Name, runtime, architecture, msbuildLocation, e.ErrorCode, e.Message); } }
internal Handshake(HandshakeOptions nodeType) { // We currently use 6 bits of this 32-bit integer. Very old builds will instantly reject any handshake that does not start with F5 or 06; slightly old builds always lead with 00. // This indicates in the first byte that we are a modern build. options = (int)nodeType | (((int)CommunicationsUtilities.handshakeVersion) << 24); string handshakeSalt = Environment.GetEnvironmentVariable("MSBUILDNODEHANDSHAKESALT"); string toolsDirectory = (nodeType & HandshakeOptions.X64) == HandshakeOptions.X64 ? BuildEnvironmentHelper.Instance.MSBuildToolsDirectory64 : BuildEnvironmentHelper.Instance.MSBuildToolsDirectory32; salt = CommunicationsUtilities.GetHandshakeHashCode(handshakeSalt + toolsDirectory); Version fileVersion = new Version(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion); fileVersionMajor = fileVersion.Major; fileVersionMinor = fileVersion.Minor; fileVersionBuild = fileVersion.Build; fileVersionPrivate = fileVersion.Revision; sessionId = Process.GetCurrentProcess().SessionId; }
/// <summary> /// Add the task host context to this handshake, to make sure that task hosts with different contexts /// will have different handshakes. Shift it into the upper 32-bits to avoid running into the /// session ID. The connection may be salted to allow MSBuild to only connect to nodes that come from the same /// test environment. /// </summary> /// <param name="hostContext">TaskHostContext</param> /// <returns>Base Handshake</returns> private static long GetBaseHandshakeForContext(HandshakeOptions hostContext) { string salt = Environment.GetEnvironmentVariable("MSBUILDNODEHANDSHAKESALT") + BuildEnvironmentHelper.Instance.MSBuildToolsDirectory32; long nodeHandshakeSalt = GetHandshakeHashCode(salt); Trace("MSBUILDNODEHANDSHAKESALT=\"{0}\", msbuildDirectory=\"{1}\", hostContext={2}, FileVersionHash={3}", Environment.GetEnvironmentVariable("MSBUILDNODEHANDSHAKESALT"), BuildEnvironmentHelper.Instance.MSBuildToolsDirectory32, hostContext, FileVersionHash); //FileVersionHash (32 bits) is shifted 8 bits to avoid session ID collision //hostContext (4 bits) is shifted just after the FileVersionHash //nodeHandshakeSalt (32 bits) is shifted just after hostContext //the most significant byte (leftmost 8 bits) will get zero'd out to avoid connecting to older builds. //| masked out | nodeHandshakeSalt | hostContext | fileVersionHash | SessionID // 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 long baseHandshake = (nodeHandshakeSalt << 44) | ((long)hostContext << 40) | ((long)FileVersionHash << 8); return(baseHandshake); }
/// <summary> /// Magic number sent by the host to the client during the handshake. /// Derived from the binary timestamp to avoid mixing binary versions. /// </summary> internal static long GetHostHandshake(HandshakeOptions nodeType) { string salt = Environment.GetEnvironmentVariable("MSBUILDNODEHANDSHAKESALT"); string toolsDirectory = (nodeType & HandshakeOptions.X64) == HandshakeOptions.X64 ? BuildEnvironmentHelper.Instance.MSBuildToolsDirectory64 : BuildEnvironmentHelper.Instance.MSBuildToolsDirectory32; int nodeHandshakeSalt = GetHandshakeHashCode(salt + toolsDirectory); Trace("MSBUILDNODEHANDSHAKESALT=\"{0}\", msbuildDirectory=\"{1}\", nodeType={2}, FileVersionHash={3}", salt, toolsDirectory, nodeType, FileVersionHash); //FileVersionHash (32 bits) is shifted 8 bits to avoid session ID collision //nodeType (4 bits) is shifted just after the FileVersionHash //nodeHandshakeSalt (32 bits) is shifted just after hostContext //the most significant byte (leftmost 8 bits) will get zero'd out to avoid connecting to older builds. //| masked out | nodeHandshakeSalt | hostContext | fileVersionHash | SessionID // 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 long baseHandshake = ((long)nodeHandshakeSalt << 44) | ((long)nodeType << 40) | ((long)FileVersionHash << 8); return(GenerateHostHandshakeFromBase(baseHandshake)); }
/// <summary> /// Magic number sent by the host to the client during the handshake. /// Derived from the binary timestamp to avoid mixing binary versions. /// </summary> internal static long GetHostHandshake(HandshakeOptions nodeType) { string salt = Environment.GetEnvironmentVariable("MSBUILDNODEHANDSHAKESALT"); string toolsDirectory = (nodeType & HandshakeOptions.X64) == HandshakeOptions.X64 ? BuildEnvironmentHelper.Instance.MSBuildToolsDirectory64 : BuildEnvironmentHelper.Instance.MSBuildToolsDirectory32; int nodeHandshakeSalt = GetHandshakeHashCode(salt + toolsDirectory); Trace("MSBUILDNODEHANDSHAKESALT=\"{0}\", msbuildDirectory=\"{1}\", nodeType={2}, FileVersionHash={3}", salt, toolsDirectory, nodeType, FileVersionHash); // FileVersionHash (32 bits) is shifted 8 bits to avoid session ID collision // HandshakeOptions (5 bits) is shifted just after the FileVersionHash // remaining bits of nodeHandshakeSalt (32 bits truncated to 11) are shifted next // nodeHandshakeSalt | HandshakeOptions | fileVersionHash | SessionID // 0000 0000 0000 0000 000 0 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 unchecked { ulong baseHandshake = ((ulong)(uint)nodeHandshakeSalt << 45) | ((ulong)(uint)nodeType << 40) | ((ulong)(uint)FileVersionHash << 8); return(GenerateHostHandshakeFromBase((long)baseHandshake)); } }
private void HandleHandshakeMessage(NetworkIncomingMessage message) { HandshakeKey decryptor = keys.Remote.Clone(); NetworkIncomingMessage decrypted = decryptor.Decrypt(message); int size = HandshakeMessage.GetSize(decrypted); PeerHash peer = HandshakeMessage.GetPeer(decrypted); HandshakeOptions options = HandshakeMessage.GetOptions(decrypted); Handshake handshake = new Handshake(context.Peer, peer, context.Hash, options); message.Acknowledge(size); keys.Remote.Acknowledge(size); NetworkConnection other = connection.StartEncryption(keys); hooks.CallHandshakeCompleted(other, handshake); context.OnHandshake(other, handshake); }
/// <summary> /// Returns true if a task host exists that can service the requested runtime and architecture /// values, and false otherwise. /// </summary> internal static bool DoesTaskHostExist(string runtime, string architecture) { if (runtime != null) { runtime = runtime.Trim(); } if (architecture != null) { architecture = architecture.Trim(); } if (!XMakeAttributes.IsValidMSBuildRuntimeValue(runtime)) { ErrorUtilities.ThrowArgument("InvalidTaskHostFactoryParameter", runtime, "Runtime", XMakeAttributes.MSBuildRuntimeValues.clr2, XMakeAttributes.MSBuildRuntimeValues.clr4, XMakeAttributes.MSBuildRuntimeValues.currentRuntime, XMakeAttributes.MSBuildRuntimeValues.any); } if (!XMakeAttributes.IsValidMSBuildArchitectureValue(architecture)) { ErrorUtilities.ThrowArgument("InvalidTaskHostFactoryParameter", architecture, "Architecture", XMakeAttributes.MSBuildArchitectureValues.x86, XMakeAttributes.MSBuildArchitectureValues.x64, XMakeAttributes.MSBuildArchitectureValues.currentArchitecture, XMakeAttributes.MSBuildArchitectureValues.any); } runtime = XMakeAttributes.GetExplicitMSBuildRuntime(runtime); architecture = XMakeAttributes.GetExplicitMSBuildArchitecture(architecture); IDictionary <string, string> parameters = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); parameters.Add(XMakeAttributes.runtime, runtime); parameters.Add(XMakeAttributes.architecture, architecture); HandshakeOptions desiredContext = CommunicationsUtilities.GetHandshakeOptions(taskHost: true, taskHostParameters: parameters); string taskHostLocation = NodeProviderOutOfProcTaskHost.GetMSBuildLocationFromHostContext(desiredContext); if (taskHostLocation != null && FileUtilities.FileExistsNoThrow(taskHostLocation)) { return(true); } return(false); }
/// <summary> /// Given the appropriate information, return the equivalent HandshakeOptions. /// </summary> internal static HandshakeOptions GetHandshakeOptions(bool taskHost, bool is64Bit = false, int clrVersion = 0, bool nodeReuse = false, bool lowPriority = false, IDictionary <string, string> taskHostParameters = null) { HandshakeOptions context = taskHost ? HandshakeOptions.TaskHost : HandshakeOptions.None; // We don't know about the TaskHost. Figure it out. if (taskHost && clrVersion == 0) { // Take the current TaskHost context if (taskHostParameters == null) { clrVersion = typeof(bool).GetTypeInfo().Assembly.GetName().Version.Major; is64Bit = XMakeAttributes.GetCurrentMSBuildArchitecture().Equals(XMakeAttributes.MSBuildArchitectureValues.x64); } else { ErrorUtilities.VerifyThrow(taskHostParameters.ContainsKey(XMakeAttributes.runtime), "Should always have an explicit runtime when we call this method."); ErrorUtilities.VerifyThrow(taskHostParameters.ContainsKey(XMakeAttributes.architecture), "Should always have an explicit architecture when we call this method."); clrVersion = taskHostParameters[XMakeAttributes.runtime].Equals(XMakeAttributes.MSBuildRuntimeValues.clr4, StringComparison.OrdinalIgnoreCase) ? 4 : 2; is64Bit = taskHostParameters[XMakeAttributes.architecture].Equals(XMakeAttributes.MSBuildArchitectureValues.x64); } } if (is64Bit) { context |= HandshakeOptions.X64; } if (clrVersion == 2) { context |= HandshakeOptions.CLR2; } if (nodeReuse) { context |= HandshakeOptions.NodeReuse; } if (lowPriority) { context |= HandshakeOptions.LowPriority; } return(context); }
internal bool CreateNode(HandshakeOptions hostContext, INodePacketFactory factory, INodePacketHandler handler, TaskHostConfiguration configuration) { ErrorUtilities.VerifyThrowArgumentNull(factory, nameof(factory)); ErrorUtilities.VerifyThrow(!_nodeIdToPacketFactory.ContainsKey((int)hostContext), "We should not already have a factory for this context! Did we forget to call DisconnectFromHost somewhere?"); if (AvailableNodes <= 0) { ErrorUtilities.ThrowInternalError("All allowable nodes already created ({0}).", _nodeContexts.Count); return(false); } // Start the new process. We pass in a node mode with a node number of 2, to indicate that we // want to start up an MSBuild task host node. string commandLineArgs = $" /nologo /nodemode:2 /nodereuse:{ComponentHost.BuildParameters.EnableNodeReuse} /low:{ComponentHost.BuildParameters.LowPriority} "; string msbuildLocation = GetMSBuildLocationFromHostContext(hostContext); // we couldn't even figure out the location we're trying to launch ... just go ahead and fail. if (msbuildLocation == null) { return(false); } CommunicationsUtilities.Trace("For a host context of {0}, spawning executable from {1}.", hostContext.ToString(), msbuildLocation ?? "MSBuild.exe"); // There is always one task host per host context so we always create just 1 one task host node here. int nodeId = (int)hostContext; IList <NodeContext> nodeContexts = GetNodes( msbuildLocation, commandLineArgs, nodeId, this, new Handshake(hostContext), NodeContextCreated, NodeContextTerminated, 1); return(nodeContexts.Count == 1); }
/// <summary> /// Given a TaskHostContext, returns the name of the executable we should be searching for. /// </summary> internal static string GetTaskHostNameFromHostContext(HandshakeOptions hostContext) { ErrorUtilities.VerifyThrowInternalErrorUnreachable((hostContext & HandshakeOptions.TaskHost) == HandshakeOptions.TaskHost); if ((hostContext & HandshakeOptions.CLR2) == HandshakeOptions.CLR2) { return(TaskHostNameForClr2TaskHost); } else { if (s_msbuildName == null) { s_msbuildName = Environment.GetEnvironmentVariable("MSBUILD_EXE_NAME"); if (s_msbuildName == null) { s_msbuildName = "MSBuild.exe"; } } return(s_msbuildName); } }
internal Handshake(HandshakeOptions nodeType) { const int handshakeVersion = (int)CommunicationsUtilities.handshakeVersion; // We currently use 7 bits of this 32-bit integer. Very old builds will instantly reject any handshake that does not start with F5 or 06; slightly old builds always lead with 00. // This indicates in the first byte that we are a modern build. options = (int)nodeType | (handshakeVersion << 24); CommunicationsUtilities.Trace("Building handshake for node type {0}, (version {1}): options {2}.", nodeType, handshakeVersion, options); string handshakeSalt = Environment.GetEnvironmentVariable("MSBUILDNODEHANDSHAKESALT"); CommunicationsUtilities.Trace("Handshake salt is " + handshakeSalt); string toolsDirectory = BuildEnvironmentHelper.Instance.MSBuildToolsDirectoryRoot; CommunicationsUtilities.Trace("Tools directory root is " + toolsDirectory); salt = CommunicationsUtilities.GetHashCode(handshakeSalt + toolsDirectory); Version fileVersion = new Version(FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).FileVersion); fileVersionMajor = fileVersion.Major; fileVersionMinor = fileVersion.Minor; fileVersionBuild = fileVersion.Build; fileVersionPrivate = fileVersion.Revision; sessionId = Process.GetCurrentProcess().SessionId; }
/// <summary> /// Sends data to the specified node. /// </summary> /// <param name="hostContext">The node to which data shall be sent.</param> /// <param name="packet">The packet to send.</param> public void SendData(HandshakeOptions hostContext, INodePacket packet) { ErrorUtilities.VerifyThrow(_nodeContexts.ContainsKey(hostContext), "Invalid host context specified: {0}.", hostContext.ToString()); SendData(_nodeContexts[hostContext], packet); }
public ServiceConf(Config conf, XmlElement self) { Name = self.GetAttribute("Name"); string attr; // SocketOptions attr = self.GetAttribute("NoDelay"); if (attr.Length > 0) { SocketOptions.NoDelay = bool.Parse(attr); } attr = self.GetAttribute("SendBuffer"); if (attr.Length > 0) { SocketOptions.SendBuffer = int.Parse(attr); } attr = self.GetAttribute("ReceiveBuffer"); if (attr.Length > 0) { SocketOptions.ReceiveBuffer = int.Parse(attr); } attr = self.GetAttribute("InputBufferSize"); if (attr.Length > 0) { SocketOptions.InputBufferSize = int.Parse(attr); } attr = self.GetAttribute("InputBufferMaxProtocolSize"); if (attr.Length > 0) { SocketOptions.InputBufferMaxProtocolSize = int.Parse(attr); } attr = self.GetAttribute("OutputBufferMaxSize"); if (attr.Length > 0) { SocketOptions.OutputBufferMaxSize = int.Parse(attr); } attr = self.GetAttribute("Backlog"); if (attr.Length > 0) { SocketOptions.Backlog = int.Parse(attr); } attr = self.GetAttribute("SocketLogLevel"); if (attr.Length > 0) { SocketOptions.SocketLogLevel = NLog.LogLevel.FromString(attr); } // HandshakeOptions attr = self.GetAttribute("DhGroups"); if (attr.Length > 0) { HandshakeOptions.DhGroups = new HashSet <int>(); foreach (string dg in attr.Split(',')) { string dgtmp = dg.Trim(); if (dgtmp.Length == 0) { continue; } HandshakeOptions.AddDhGroup(int.Parse(dgtmp)); } } attr = self.GetAttribute("SecureIp"); if (attr.Length > 0) { HandshakeOptions.SecureIp = System.Net.IPAddress.Parse(attr).GetAddressBytes(); } attr = self.GetAttribute("S2cNeedCompress"); if (attr.Length > 0) { HandshakeOptions.S2cNeedCompress = bool.Parse(attr); } attr = self.GetAttribute("C2sNeedCompress"); if (attr.Length > 0) { HandshakeOptions.C2sNeedCompress = bool.Parse(attr); } attr = self.GetAttribute("DhGroup"); if (attr.Length > 0) { HandshakeOptions.DhGroup = byte.Parse(attr); } if (string.IsNullOrEmpty(Name)) { conf.DefaultServiceConf = this; } else if (!conf.ServiceConfMap.TryAdd(Name, this)) { throw new Exception($"Duplicate ServiceConf '{Name}'"); } // connection creator options XmlNodeList childNodes = self.ChildNodes; foreach (XmlNode node in childNodes) { if (XmlNodeType.Element != node.NodeType) { continue; } XmlElement e = (XmlElement)node; switch (e.Name) { case "Acceptor": AddAcceptor(new Acceptor(e)); break; case "Connector": AddConnector(Connector.Create(e)); break; default: throw new Exception("unknown node name: " + e.Name); } } }
public bool Execute() { // log that we are about to spawn the task host string runtime = _taskHostParameters[XMakeAttributes.runtime]; string architecture = _taskHostParameters[XMakeAttributes.architecture]; _taskLoggingContext.LogComment(MessageImportance.Low, "ExecutingTaskInTaskHost", _taskType.Type.Name, _taskType.Assembly.AssemblyLocation, runtime, architecture); // set up the node lock (_taskHostLock) { _taskHostProvider = (NodeProviderOutOfProcTaskHost)_buildComponentHost.GetComponent(BuildComponentType.OutOfProcTaskHostNodeProvider); ErrorUtilities.VerifyThrowInternalNull(_taskHostProvider, "taskHostProvider"); } TaskHostConfiguration hostConfiguration = new TaskHostConfiguration ( _buildComponentHost.BuildParameters.NodeId, NativeMethodsShared.GetCurrentDirectory(), CommunicationsUtilities.GetEnvironmentVariables(), _buildComponentHost.BuildParameters.Culture, _buildComponentHost.BuildParameters.UICulture, #if FEATURE_APPDOMAIN _appDomainSetup, #endif BuildEngine.LineNumberOfTaskNode, BuildEngine.ColumnNumberOfTaskNode, BuildEngine.ProjectFileOfTaskNode, BuildEngine.ContinueOnError, _taskType.Type.FullName, AssemblyUtilities.GetAssemblyLocation(_taskType.Type.GetTypeInfo().Assembly), _buildComponentHost.BuildParameters.LogTaskInputs, _setParameters, new Dictionary <string, string>(_buildComponentHost.BuildParameters.GlobalProperties), _taskLoggingContext.GetWarningsAsErrors(), _taskLoggingContext.GetWarningsAsMessages() ); try { lock (_taskHostLock) { _requiredContext = CommunicationsUtilities.GetHandshakeOptions(taskHost: true, taskHostParameters: _taskHostParameters); _connectedToTaskHost = _taskHostProvider.AcquireAndSetUpHost(_requiredContext, this, this, hostConfiguration); } if (_connectedToTaskHost) { try { bool taskFinished = false; while (!taskFinished) { _packetReceivedEvent.WaitOne(); INodePacket packet = null; // Handle the packet that's coming in while (_receivedPackets.TryDequeue(out packet)) { if (packet != null) { HandlePacket(packet, out taskFinished); } } } } finally { lock (_taskHostLock) { _taskHostProvider.DisconnectFromHost(_requiredContext); _connectedToTaskHost = false; } } } else { LogErrorUnableToCreateTaskHost(_requiredContext, runtime, architecture, null); } } catch (BuildAbortedException) { LogErrorUnableToCreateTaskHost(_requiredContext, runtime, architecture, null); } catch (NodeFailedToLaunchException e) { LogErrorUnableToCreateTaskHost(_requiredContext, runtime, architecture, e); } return(_taskExecutionSucceeded); }
public HandshakeNegotiatorPassiveInstance(PeerHash peer, FileHashCollection hashes, HandshakeOptions options) { this.hashes = hashes; this.peer = peer; this.options = options; }
public HandshakeMessage(PeerHash peer, FileHash hash, HandshakeOptions options) { this.peer = peer; this.hash = hash; this.options = options; }
public HandshakeNegotiatorActiveInstance(PeerHash peer, FileHash hash, HandshakeOptions options) { this.hash = hash; this.peer = peer; this.options = options; }
/// <summary> /// Magic number sent by the client to the host during the handshake. /// Munged version of the host handshake. /// </summary> internal static long GetClientHandshake(HandshakeOptions hostContext) { return(~GetHostHandshake(hostContext)); }
/// <summary> /// Given a TaskHostContext, return the appropriate location of the /// executable (MSBuild or MSBuildTaskHost) that we wish to use, or null /// if that location cannot be resolved. /// </summary> internal static string GetMSBuildLocationFromHostContext(HandshakeOptions hostContext) { string toolName = GetTaskHostNameFromHostContext(hostContext); string toolPath; s_baseTaskHostPath = BuildEnvironmentHelper.Instance.MSBuildToolsDirectory32; s_baseTaskHostPath64 = BuildEnvironmentHelper.Instance.MSBuildToolsDirectory64; ErrorUtilities.VerifyThrowInternalErrorUnreachable((hostContext & HandshakeOptions.TaskHost) == HandshakeOptions.TaskHost); if ((hostContext & HandshakeOptions.X64) == HandshakeOptions.X64 && (hostContext & HandshakeOptions.CLR2) == HandshakeOptions.CLR2) { if (s_pathToX64Clr2 == null) { s_pathToX64Clr2 = Environment.GetEnvironmentVariable("MSBUILDTASKHOSTLOCATION64"); if (s_pathToX64Clr2 == null || !FileUtilities.FileExistsNoThrow(Path.Combine(s_pathToX64Clr2, toolName))) { s_pathToX64Clr2 = s_baseTaskHostPath64; } } toolPath = s_pathToX64Clr2; } else if ((hostContext & HandshakeOptions.CLR2) == HandshakeOptions.CLR2) { if (s_pathToX32Clr2 == null) { s_pathToX32Clr2 = Environment.GetEnvironmentVariable("MSBUILDTASKHOSTLOCATION"); if (s_pathToX32Clr2 == null || !FileUtilities.FileExistsNoThrow(Path.Combine(s_pathToX32Clr2, toolName))) { s_pathToX32Clr2 = s_baseTaskHostPath; } } toolPath = s_pathToX32Clr2; } else if ((hostContext & HandshakeOptions.X64) == HandshakeOptions.X64) { if (s_pathToX64Clr4 == null) { s_pathToX64Clr4 = s_baseTaskHostPath64; } toolPath = s_pathToX64Clr4; } else { if (s_pathToX32Clr4 == null) { s_pathToX32Clr4 = s_baseTaskHostPath; } toolPath = s_pathToX32Clr4; } if (toolName != null && toolPath != null) { return(Path.Combine(toolPath, toolName)); } return(null); }