private CallSlot doRequest(ClientEndPoint endpoint, RequestMsg request, CallOptions options) { long actualStartTimeTicks = Binding.StatTimeTicks; DateTime actualStartTimeUtc = DateTime.UtcNow; if (m_PriorDispatchTimeoutMs != options.DispatchTimeoutMs) { m_Client.SendTimeout = options.DispatchTimeoutMs; m_PriorDispatchTimeoutMs = options.DispatchTimeoutMs; } if (m_PriorTimeoutMs != options.TimeoutMs) { m_Client.ReceiveTimeout = options.TimeoutMs; m_PriorTimeoutMs = options.TimeoutMs; } putRequest(request); if (request.OneWay) { return(new CallSlot(endpoint, this, request, CallStatus.Dispatched, options.TimeoutMs)); } var response = getResponse(); return(new CallSlot(endpoint, this, actualStartTimeTicks, actualStartTimeUtc, request, response, options.TimeoutMs)); }
protected override ClientTransport AcquireClientTransportForCall(ClientEndPoint client, Protocol.RequestMsg request) { var tr = new InProcClientTransport(this, client.Node); tr.Start(); return(tr); }
protected override CallSlot DoSendRequest(ClientEndPoint endpoint, RequestMsg request, CallOptions options) { request.__setServerTransport(findServerTransport(endpoint)); //notice: no serialization because we are in the same address space ResponseMsg response; try { response = Glue.ServerHandleRequest(request); } catch (Exception e) { response = Glue.ServerHandleRequestFailure(request.RequestID, request.OneWay, e, request.BindingSpecificContext); } if (request.OneWay) { return(new CallSlot(endpoint, this, request, CallStatus.Dispatched, options.TimeoutMs)); } var result = new CallSlot(endpoint, this, request, CallStatus.ResponseOK); result.DeliverResponse(response); return(result); }
public RequestMsg ClientDispatchCall(ClientEndPoint endpoint, RequestMsg request) { request.Headers.Add(new TextInfoHeader { Text = "Moscow time is " + m_App.LocalizedTime.ToString(), Info = @"/\EH|/|H }|{|/|B!" }); return(request); }
protected override CallSlot DoSendRequest(ClientEndPoint endpoint, RequestMsg request, CallOptions options) { try { ensureClient(); return(sendRequest(endpoint, request, options)); } catch (Exception error) { var commError = error is SocketException || error is System.IO.IOException || (typeof(ProtocolException).IsAssignableFrom(error.GetType()) && ((ProtocolException)error).CloseChannel); Binding.WriteLog(LogSrc.Client, Log.MessageType.Error, StringConsts.GLUE_CLIENT_CALL_ERROR + (commError ? "Socket error." : string.Empty) + error.Message, from: "MpxClientTransport.SendRequest", exception: error); stat_Errors(); if (commError) { finClient(); } throw error; } }
public WSClient(ClientEndPoint c, ClientState cs) { clientWebSocket = new ClientWebSocket(); remoteEndPoint = c; clientState = cs; }
public void ClientDispatchedRequest(ClientEndPoint client, RequestMsg request, CallSlot callSlot) { if (client.Binding.OperationFlow == OperationFlow.Asynchronous) { m_Calls.Put(callSlot); } }
/// <summary> /// Initializes a new instance of the <see cref="CDNClient"/> class. /// </summary> /// <param name="cdnServer">The CDN server to connect to.</param> /// <param name="appticket">The appticket of the app this instance is for.</param> public CDNClient(ClientEndPoint cdnServer, byte[] appticket) { sessionKey = CryptoHelper.GenerateRandomBlock(32); webClient = new WebClient(); endPoint = cdnServer; appTicket = appticket; }
public RequestMsg ClientDispatchingRequest(ClientEndPoint client, RequestMsg request) { //Glue level inspectors foreach (var insp in ClientMsgInspectors.OrderedValues) { request = insp.ClientDispatchCall(client, request); } return(request); }
/// <summary> /// Initializes a new instance of the <see cref="CDNClient"/> class without an application ticket. /// </summary> /// <param name="cdnServer">The CDN server to connect to.</param> /// <param name="steamID">The SteamID of the current user.</param> /// <param name="depotID">Depot ID being requested.</param> public CDNClient(ClientEndPoint cdnServer, uint depotID, SteamID steamID) { sessionKey = CryptoHelper.GenerateRandomBlock(32); webClient = new WebClient(); endPoint = cdnServer; appTicket = null; this.steamID = steamID; this.depotID = depotID; }
private ServerTransport findServerTransport(ClientEndPoint client) { var srv = Glue.Servers.FirstOrDefault(s => s.Binding == this.Binding && Binding.AreNodesIdentical(client.Node, s.Node)); if (srv != null) { return(srv.Transport); } throw new ClientCallException(CallStatus.DispatchError, StringConsts.GLUE_NO_INPROC_MATCHING_SERVER_ENDPOINT_ERROR + client.Node.ToString()); }
private CallSlot sendRequest(ClientEndPoint endpoint, RequestMsg request, CallOptions options) { if (m_PriorDispatchTimeoutMs != options.DispatchTimeoutMs) { m_Client.Socket.SendTimeout = options.DispatchTimeoutMs; m_PriorDispatchTimeoutMs = options.DispatchTimeoutMs; } if (m_PriorTimeoutMs != options.TimeoutMs) { m_Client.Socket.ReceiveTimeout = options.TimeoutMs; m_PriorTimeoutMs = options.TimeoutMs; } var chunk = m_Client.GetSendChunk(); try { var frame = new WireFrame(WireFrame.SLIM_FORMAT, request.OneWay, request.RequestID); var size = serialize(chunk, frame, request); var wm = new WireMsg(chunk); Binding.DumpMsg(false, request, chunk.GetBuffer(), 0, (int)chunk.Position); if (size > Binding.MaxMsgSize) { Instrumentation.ClientSerializedOverMaxMsgSizeErrorEvent.Happened(Node); throw new MessageSizeException(size, Binding.MaxMsgSize, "sendRequest(" + request.RequestID + ")"); } m_Client.Send(wm); stat_MsgSent(); stat_BytesSent(wm.BufferUsedSize); } catch { stat_Errors(); throw; } finally { m_Client.ReleaseSendChunk(); } //regardless of (request.OneWay) we return callslot anyway return(new CallSlot(endpoint, this, request, CallStatus.Dispatched, options.TimeoutMs)); }
/// <summary> /// Fetches a server list from the given content server for the provided CellID. /// </summary> /// <param name="csServer">The server to request a server list from.</param> /// <param name="cellID">The CellID.</param> /// <returns>A list of content servers.</returns> public static List <ClientEndPoint> FetchServerList(ClientEndPoint csServer, int cellID) { int serversToRequest = 20; using (WebClient webClient = new WebClient()) { Uri request = new Uri(BuildCommand(csServer, "serverlist"), String.Format("{0}/{1}/", cellID, serversToRequest)); string serverList; try { serverList = webClient.DownloadString(request); } catch (WebException e) { Console.WriteLine("FetchServerList returned: {0}", e.Message); return(null); } KeyValue serverkv = KeyValue.LoadFromString(serverList); if (serverkv["deferred"].AsString() == "1") { return(null); } List <ClientEndPoint> endpoints = new List <ClientEndPoint>(); foreach (var child in serverkv.Children) { var node = child.Children.Where(x => x.Name == "host" || x.Name == "Host").First(); var typeNode = child.Children.Where(x => x.Name == "type").First(); var endpoint_string = node.Value.Split(':'); int port = 80; if (endpoint_string.Length > 1) { port = int.Parse(endpoint_string[1]); } endpoints.Add(new ClientEndPoint(endpoint_string[0], port, typeNode.AsString())); } return(endpoints); } }
public async Task<Response> Connect(string sessionKey) { if (sessionKey == null) { return new Response(); } var ipHostInfo = Dns.GetHostEntry("localhost"); var ipAddress = ipHostInfo.AddressList[0]; var endPoint = new IPEndPoint(ipAddress, 11000); localEndPoint = endPoint; var clientEndPoint = new ClientEndPoint { SessionKey = sessionKey, EndPoint = endPoint }; return await PutDataToRoute(Host + Resources.RouteSetEndPoint, clientEndPoint); }
public TCPClient(bool sim, int port, ClientEndPoint c, ClientState cs, IConnectionHandler ch, IPacketHandler ph) { readToken = new CancellationTokenSource(); socket = new Socket(SocketType.Stream, ProtocolType.Tcp); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, false); if (sim) { socket.Bind(new IPEndPoint(IPAddress.Any, port)); } connectionHandler = ch; packetHandler = ph; remoteEndPoint = c; clientState = cs; }
public async Task <Response> Connect(string sessionKey) { if (sessionKey == null) { return(new Response()); } var ipHostInfo = Dns.GetHostEntry("localhost"); var ipAddress = ipHostInfo.AddressList[0]; var endPoint = new IPEndPoint(ipAddress, 11000); localEndPoint = endPoint; var clientEndPoint = new ClientEndPoint { SessionKey = sessionKey, EndPoint = endPoint }; return(await PutDataToRoute(Host + Resources.RouteSetEndPoint, clientEndPoint)); }
public UDPClient(bool sim, int port, ClientEndPoint c, ClientState cs, IContextHandler cb) { // socket = new UdpClient(port); socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); // socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true); // socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true); // socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ExclusiveAddressUse, false); if (sim) { socket.Bind(new IPEndPoint(IPAddress.Any, port)); } else { socket.Bind(new IPEndPoint(IPAddress.Any, 1888)); } contextHandler = cb; remoteEndPoint = c; clientState = cs; }
protected override ClientTransport MakeNewClientTransport(ClientEndPoint client) { return(new MpxClientTransport(this, client.Node)); }
public void InstallServices(IServiceCollection services, IConfiguration configuration) { services.AddMvc(); services.AddCors(); var clientEndPoint = new ClientEndPoint(); configuration.Bind(nameof(clientEndPoint), clientEndPoint); services.AddSingleton <ClientEndPoint>(clientEndPoint); var authSkeleton = new AuthSkeleton(); configuration.Bind(nameof(authSkeleton), authSkeleton); services.AddSingleton <AuthSkeleton>(authSkeleton); var customerSkeleton = new CustomerSkeleton(); configuration.Bind(nameof(customerSkeleton), customerSkeleton); services.AddSingleton <CustomerSkeleton>(customerSkeleton); var dataKeys = new DataKeys(); configuration.Bind(nameof(dataKeys), dataKeys); services.AddSingleton <DataKeys>(dataKeys); var yamlSettings = new YamlSettings(); configuration.Bind(nameof(yamlSettings), yamlSettings); services.AddSingleton <YamlSettings>(yamlSettings); var jwtSettings = new JwtSettings(); configuration.Bind(nameof(jwtSettings), jwtSettings); services.AddSingleton <JwtSettings>(jwtSettings); var tokenValidationParameters = new TokenValidationParameters { ValidateIssuerSigningKey = true, IssuerSigningKey = new SymmetricSecurityKey(Encoding.ASCII.GetBytes(jwtSettings.Secret)), ValidateIssuer = false, ValidateAudience = false, RequireExpirationTime = false, ValidateLifetime = true }; services.AddSingleton(tokenValidationParameters); services.AddAuthentication(x => { x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultScheme = JwtBearerDefaults.AuthenticationScheme; x.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme; }) .AddJwtBearer(x => { x.SaveToken = true; x.TokenValidationParameters = tokenValidationParameters; }); services.AddSwaggerGen(x => { x.SwaggerDoc("v1", new OpenApiInfo { Title = "Customer API", Version = "v1" }); var security = new Dictionary <string, IEnumerable <string> > { { "Bearer", new string[0] } }; x.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { Description = "JWT Authorization header using the Bearer scheme", Name = "Authorization", In = ParameterLocation.Header, Type = SecuritySchemeType.ApiKey, Scheme = "Bearer" }); x.AddSecurityRequirement(new OpenApiSecurityRequirement() { { new OpenApiSecurityScheme { Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "Bearer" }, Scheme = "oauth2", Name = "Bearer", In = ParameterLocation.Header }, new List <string>() } }); }); }
public RequestMsg ClientDispatchingRequest(ClientEndPoint client, RequestMsg request) { //Glue level inspectors foreach(var insp in ClientMsgInspectors.OrderedValues) request = insp.ClientDispatchCall(client, request); return request; }
public void ClientDispatchedRequest(ClientEndPoint client, RequestMsg request, CallSlot callSlot) { if (client.Binding.OperationFlow == OperationFlow.Asynchronous) m_Calls.Put(callSlot); }
protected override ClientTransport MakeNewClientTransport(ClientEndPoint client) { return null; }
public void Send([FromBody] ClientEndPoint endPoint) { endPointSetter.SetEndPoint(endPoint.SessionKey, endPoint.EndPoint); }
static void RegisterClient(List<String> targetIP) { foreach (String ip in targetIP) { UdpClient sock = new UdpClient(); IPEndPoint iep = new IPEndPoint(IPAddress.Parse(ip), PORT); ClientEndPoint cep = new ClientEndPoint(); cep.Client = sock; cep.EndPoint = iep; _clients.Add(cep); } }
protected override ClientTransport MakeNewClientTransport(ClientEndPoint client) { return(null); }
protected override ClientTransport AcquireClientTransportForCall(ClientEndPoint client, Protocol.RequestMsg request) { var tr = new InProcClientTransport(this, client.Node); tr.Start(); return tr; }
public ClientCallStub(ClientEndPoint endPoint) { Assert(endPoint != null); _endPoint = endPoint; }
private static Uri BuildCommand(ClientEndPoint csServer, string command) { return new Uri(String.Format("http://{0}:{1}/{2}/", csServer.Host, csServer.Port.ToString(), command)); }
/// <summary> /// Points this <see cref="CDNClient"/> instance to another server. /// </summary> /// <param name="ep">The endpoint.</param> public void PointTo(ClientEndPoint ep) { endPoint = ep; }
/// <summary> /// Fetches a server list from the given content server for the provided CellID. /// </summary> /// <param name="csServer">The server to request a server list from.</param> /// <param name="cellID">The CellID.</param> /// <returns>A list of content servers.</returns> public static List<ClientEndPoint> FetchServerList(ClientEndPoint csServer, int cellID) { int serversToRequest = 20; using(WebClient webClient = new WebClient()) { Uri request = new Uri(BuildCommand(csServer, "serverlist"), String.Format("{0}/{1}/", cellID, serversToRequest)); string serverList; try { serverList = webClient.DownloadString(request); } catch (WebException e) { Console.WriteLine("FetchServerList returned: {0}", e.Message); return null; } KeyValue serverkv = KeyValue.LoadFromString(serverList); if (serverkv["deferred"].AsString() == "1") return null; List<ClientEndPoint> endpoints = new List<ClientEndPoint>(); foreach (var child in serverkv.Children) { var node = child.Children.Where(x => x.Name == "host" || x.Name == "Host").First(); var typeNode = child.Children.Where(x => x.Name == "type").First(); var endpoint_string = node.Value.Split(':'); int port = 80; if(endpoint_string.Length > 1) port = int.Parse(endpoint_string[1]); endpoints.Add(new ClientEndPoint(endpoint_string[0], port, typeNode.AsString())); } return endpoints; } }
private static Uri BuildCommand(ClientEndPoint csServer, string command) { return(new Uri(String.Format("http://{0}:{1}/{2}/", csServer.Host, csServer.Port.ToString(), command))); }
protected override ClientTransport MakeNewClientTransport(ClientEndPoint client) { return new MpxClientTransport(this, client.Node); }