public void MergeFrom(PeerConfig other) { if (other == null) { return; } if (other.PeerId != 0) { PeerId = other.PeerId; } if (other.WebPort != 0) { WebPort = other.WebPort; } if (other.rpcEndpoint_ != null) { if (rpcEndpoint_ == null) { rpcEndpoint_ = new global::PeerEndpoint(); } RpcEndpoint.MergeFrom(other.RpcEndpoint); } metaNodes_.Add(other.metaNodes_); _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); }
public IRpcClientTransport Connect(RpcEndpoint endpoint, RpcTransportSecurity transport_security) { string hostname = string.IsNullOrEmpty(endpoint.NetworkAddress) ? "127.0.0.1" : endpoint.NetworkAddress; int port = int.Parse(endpoint.Endpoint); return(new RpcTcpClientTransport(hostname, port, transport_security)); }
/// <summary> /// Connect the client to a RPC endpoint. /// </summary> /// <param name="endpoint">The endpoint for RPC server.</param> /// <param name="security_quality_of_service">The security quality of service for the connection.</param> public void Connect(RpcEndpoint endpoint, SecurityQualityOfService security_quality_of_service) { if (Connected) { throw new InvalidOperationException("RPC client is already connected."); } if (endpoint == null) { throw new ArgumentNullException("Must specify an endpoint", nameof(endpoint)); } try { _transport = RpcClientTransportFactory.ConnectEndpoint(endpoint, security_quality_of_service); _transport.Bind(InterfaceId, InterfaceVersion, NdrNativeUtils.DCE_TransferSyntax, new Version(2, 0)); } catch { // Disconnect transport on any exception. _transport?.Disconnect(); _transport = null; throw; } }
public JsonRpcUrl(string scheme, string host, int port, RpcEndpoint rpcEndpoint, string[] enabledModules) { Scheme = scheme; Host = host; Port = port; RpcEndpoint = rpcEndpoint; EnabledModules = enabledModules; }
/// <summary> /// Connect a client transport from an endpoint. /// </summary> /// <param name="endpoint">The RPC endpoint.</param> /// <param name="security_quality_of_service">The security quality of service for the connection.</param> /// <returns>The connected client transport.</returns> /// <exception cref="ArgumentException">Thrown if protocol sequence unsupported.</exception> /// <exception cref="Exception">Other exceptions depending on the connection.</exception> public static IRpcClientTransport ConnectEndpoint(RpcEndpoint endpoint, SecurityQualityOfService security_quality_of_service) { if (!_factories.ContainsKey(endpoint.ProtocolSequence)) { throw new ArgumentException($"Unsupported protocol sequence {endpoint.ProtocolSequence}", nameof(endpoint)); } return(_factories[endpoint.ProtocolSequence].Connect(endpoint, security_quality_of_service)); }
/// <summary> /// Connect a client transport from an endpoint. /// </summary> /// <param name="endpoint">The RPC endpoint.</param> /// <param name="transport_security">The transport security for the connection.</param> /// <returns>The connected client transport.</returns> /// <exception cref="ArgumentException">Thrown if protocol sequence unsupported.</exception> /// <exception cref="Exception">Other exceptions depending on the connection.</exception> public static IRpcClientTransport ConnectEndpoint(RpcEndpoint endpoint, RpcTransportSecurity transport_security) { if (!_factories.ContainsKey(endpoint.ProtocolSequence)) { throw new ArgumentException($"Unsupported protocol sequence {endpoint.ProtocolSequence}", nameof(endpoint)); } return(_factories[endpoint.ProtocolSequence].Connect(endpoint, transport_security)); }
public JsonRpcUrl(string scheme, string host, int port, RpcEndpoint rpcEndpoint, bool isAuthenticated, string[] enabledModules) { Scheme = scheme; Host = host; Port = port; RpcEndpoint = rpcEndpoint; EnabledModules = new HashSet <string>(enabledModules, StringComparer.InvariantCultureIgnoreCase); IsAuthenticated = isAuthenticated; }
public ResolvedMethodInfo( string moduleType, MethodInfo methodInfo, bool readOnly, RpcEndpoint availability) { ModuleType = moduleType; MethodInfo = methodInfo; ReadOnly = readOnly; Availability = availability; }
public void RpcCallTest() { var client = new RpcEndpoint(); var server = new RpcEndpoint(); client.OnDataOut += (data, offset, length) => server.ReceiveData(data, offset, length, null); var service = new TestRpcService(); server.RegisterRpcHandler(service); client.GetRpcInterface <ITestRpcService>().Test(42); Assert.AreEqual(42, service.Result); }
public static JsonRpcUrl Parse(string packedUrlValue) { if (packedUrlValue == null) { throw new ArgumentNullException(nameof(packedUrlValue)); } string[] parts = packedUrlValue.Split('|'); if (parts.Length != 3) { throw new FormatException("Packed url value must contain 3 parts delimited by '|'"); } string url = parts[0]; if (!Uri.TryCreate(url, UriKind.Absolute, out Uri? uri) || (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps) || uri.Segments.Count() > 1 || uri.Port == 0) { throw new FormatException("First part must be a valid url with the format: scheme://host:port"); } string[] endpointValues = parts[1].Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); if (endpointValues.Length == 0) { throw new FormatException("Second part must contain at least one valid endpoint value delimited by ';'"); } RpcEndpoint endpoint = RpcEndpoint.None; foreach (string endpointValue in endpointValues) { if (Enum.TryParse(endpointValue, ignoreCase: true, out RpcEndpoint parsedEndpoint) && (parsedEndpoint == RpcEndpoint.Http || parsedEndpoint == RpcEndpoint.Ws)) { endpoint |= parsedEndpoint; } } if (endpoint == RpcEndpoint.None) { throw new FormatException($"Second part must contain at least one valid endpoint value (http, https, ws, wss)"); } string[] enabledModules = parts[2].Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); if (enabledModules.Length == 0) { throw new FormatException("Third part must contain at least one module delimited by ';'"); } return(new JsonRpcUrl(uri.Scheme, uri.Host, uri.Port, endpoint, enabledModules)); }
public JsonRpcSocketsClient( string clientName, ISocketHandler handler, RpcEndpoint endpointType, IJsonRpcProcessor jsonRpcProcessor, IJsonRpcService jsonRpcService, IJsonRpcLocalStats jsonRpcLocalStats, IJsonSerializer jsonSerializer, JsonRpcUrl?url = null) : base(clientName, handler, jsonSerializer) { _jsonRpcProcessor = jsonRpcProcessor; _jsonRpcService = jsonRpcService; _jsonRpcLocalStats = jsonRpcLocalStats; _jsonRpcContext = new JsonRpcContext(endpointType, this, url); }
/// <summary> /// Connect the client to a RPC endpoint. /// </summary> /// <param name="string_binding">The binding string for the RPC server.</param> /// <param name="transport_security">The transport security for the connection.</param> public void Connect(string string_binding, RpcTransportSecurity transport_security) { var endpoint = new RpcEndpoint(InterfaceId, InterfaceVersion, string_binding, false); if (string.IsNullOrEmpty(endpoint.ProtocolSequence)) { throw new ArgumentException("Binding string must contain a protocol sequence."); } if (string.IsNullOrEmpty(endpoint.Endpoint)) { endpoint = LookupEndpoint(string_binding); } Connect(endpoint, transport_security); }
public override int GetHashCode() { int hash = 1; if (PeerId != 0) { hash ^= PeerId.GetHashCode(); } if (WebPort != 0) { hash ^= WebPort.GetHashCode(); } if (rpcEndpoint_ != null) { hash ^= RpcEndpoint.GetHashCode(); } hash ^= metaNodes_.GetHashCode(); if (_unknownFields != null) { hash ^= _unknownFields.GetHashCode(); } return(hash); }
public void Connect(RpcEndpoint endpoint, SecurityQualityOfService security_quality_of_service) { Connect(endpoint, new RpcTransportSecurity(security_quality_of_service)); }
public IRpcClientTransport Connect(RpcEndpoint endpoint, SecurityQualityOfService security_quality_of_service) { return(new RpcNamedPipeClientTransport(endpoint.EndpointPath, security_quality_of_service)); }
public void Parse_success(string packedUrlValue, string expectedScheme, string expectedHost, int expectedPort, RpcEndpoint expectedRpcEndpoint, string[] expectedEnabledModules) { JsonRpcUrl url = JsonRpcUrl.Parse(packedUrlValue); Assert.AreEqual(expectedScheme, url.Scheme); Assert.AreEqual(expectedHost, url.Host); Assert.AreEqual(expectedPort, url.Port); Assert.AreEqual(expectedRpcEndpoint, url.RpcEndpoint); CollectionAssert.AreEqual(expectedEnabledModules, url.EnabledModules); }
private static HyperVEndPoint GetEndpoint(RpcEndpoint endpoint) { return(new HyperVEndPoint(Guid.Parse(endpoint.Endpoint), ResolveVmId(endpoint.NetworkAddress))); }
public IRpcClientTransport Connect(RpcEndpoint endpoint, RpcTransportSecurity transport_security) { return(new RpcHyperVClientTransport(GetEndpoint(endpoint), transport_security)); }
public static JsonRpcUrl Parse(string packedUrlValue) { if (packedUrlValue == null) { throw new ArgumentNullException(nameof(packedUrlValue)); } string[] parts = packedUrlValue.Split('|'); if (parts.Length != 3 && parts.Length != 4) { throw new FormatException("Packed url value must contain 3 or 4 parts delimited by '|'"); } string url = parts[0]; if (!Uri.TryCreate(url, UriKind.Absolute, out Uri? uri) || (uri.Scheme != Uri.UriSchemeHttp && uri.Scheme != Uri.UriSchemeHttps) || uri.Segments.Count() > 1 || uri.Port == 0) { throw new FormatException("First part must be a valid url with the format: scheme://host:port"); } string[] endpointValues = parts[1].Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); if (endpointValues.Length == 0) { throw new FormatException("Second part must contain at least one valid endpoint value delimited by ';'"); } RpcEndpoint endpoint = RpcEndpoint.None; foreach (string endpointValue in endpointValues) { if (FastEnum.TryParse(endpointValue, ignoreCase: true, out RpcEndpoint parsedEndpoint) && (parsedEndpoint == RpcEndpoint.Http || parsedEndpoint == RpcEndpoint.Ws)) { endpoint |= parsedEndpoint; } } if (endpoint == RpcEndpoint.None) { throw new FormatException($"Second part must contain at least one valid endpoint value (http, https, ws, wss)"); } string[] enabledModules = parts[2].Split(';', StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries); if (enabledModules.Length == 0) { throw new FormatException("Third part must contain at least one module delimited by ';'"); } bool isAuthenticated = enabledModules.Any(m => m.ToLower() == "engine"); // Check if authentication disabled for this url if (parts.Length == 4) { if (parts[3] != "no-auth") { throw new FormatException("Fourth part should be \"no-auth\""); } isAuthenticated = false; } JsonRpcUrl result = new (uri.Scheme, uri.Host, uri.Port, endpoint, isAuthenticated, enabledModules); return(result); }
public ModuleResolution Check(string methodName, RpcEndpoint rpcEndpoint) { return(_provider.Check(methodName, rpcEndpoint)); }
public static IRpcClientTransport ConnectEndpoint(RpcEndpoint endpoint, SecurityQualityOfService security_quality_of_service) { return(ConnectEndpoint(endpoint, new RpcTransportSecurity(security_quality_of_service))); }
public IRpcClientTransport Connect(RpcEndpoint endpoint, RpcTransportSecurity transport_security) { return(new RpcNamedPipeClientTransport(endpoint.EndpointPath, transport_security)); }
public IRpcClientTransport Connect(RpcEndpoint endpoint, RpcTransportSecurity transport_security) { return(new RpcAlpcClientTransport(endpoint.EndpointPath, transport_security.SecurityQualityOfService)); }