/// <summary>Creates a new IncomingResponse Frame</summary> /// <param name="communicator">The communicator to use when initializing the stream.</param> /// <param name="protocol">The Ice protocol of this frame.</param> /// <param name="payload">The frame data as an array segment.</param> public IncomingResponseFrame(Communicator communicator, Protocol protocol, ArraySegment <byte> payload) { _communicator = communicator; Protocol = protocol; byte replyStatus = payload[0]; if (replyStatus > 7) { throw new InvalidDataException( $"received {Protocol.GetName()} response frame with unknown reply status `{replyStatus}'"); } ReplyStatus = (ReplyStatus)replyStatus; Payload = payload; if (ReplyStatus == ReplyStatus.UserException || ReplyStatus == ReplyStatus.OK) { int size; (size, Encoding) = InputStream.ReadEncapsulationHeader(Protocol.GetEncoding(), Payload.AsSpan(1)); if (Protocol == Protocol.Ice1 && size + 4 + 1 != Payload.Count) // 4 = size length with 1.1 encoding { throw new InvalidDataException($"invalid response encapsulation size: `{size}'"); } // TODO: ice2 } else { Encoding = Protocol.GetEncoding(); } }
/// <summary>Creates a new IncomingResponse Frame</summary> /// <param name="communicator">The communicator to use when initializing the stream.</param> /// <param name="payload">The frame data as an array segment.</param> public IncomingResponseFrame(Communicator communicator, ArraySegment <byte> payload) { _communicator = communicator; byte replyStatus = payload[0]; if (replyStatus > 7) { throw new InvalidDataException( $"received ice1 response frame with unknown reply status `{replyStatus}'"); } ReplyStatus = (ReplyStatus)replyStatus; Payload = payload; if (ReplyStatus == ReplyStatus.UserException || ReplyStatus == ReplyStatus.OK) { int size; (size, Encoding) = InputStream.ReadEncapsulationHeader(Ice1Definitions.Encoding, Payload.AsSpan(1)); if (size + 4 + 1 != Payload.Count) // 4 = size length with 1.1 encoding { throw new InvalidDataException($"invalid response encapsulation size: `{size}'"); } } else { Encoding = Ice1Definitions.Encoding; } }
public SocksReply(ReplyStatus status, IPAddress address, ushort port) { address.ThrowIfNull <IPAddress>("address"); this.Status = status; this.ATyp = (address.AddressFamily == AddressFamily.InterNetworkV6) ? S22.Xmpp.Extensions.Socks5.ATyp.IPv6 : S22.Xmpp.Extensions.Socks5.ATyp.IPv4; this.Address = address; this.Port = port; }
/// <summary> /// Initializes a new instance of the SocksReply class. /// </summary> /// <param name="status">The status of the response.</param> /// <param name="address">The server bound IP address.</param> /// <param name="port">The server bound port.</param> /// <exception cref="ArgumentNullException">The address parameter /// is null.</exception> public SocksReply(ReplyStatus status, IPAddress address, ushort port) { Status = status; ATyp = address.AddressFamily == AddressFamily.InterNetworkV6 ? ATyp.IPv6 : ATyp.IPv4; Address = address; Port = port; }
/** * Serialized value of the enum. * Is apparently much more performant than ToString. */ public static string Serialized(this ReplyStatus status) { return(status switch { ReplyStatus.Ok => "ok", ReplyStatus.Error => "error", ReplyStatus.Timeout => "timeout", _ => throw new ArgumentOutOfRangeException(nameof(status), status, null) });
internal void Trigger(ReplyStatus status) { _channel.Trigger(new Message( @event: _refEvent, payload: new Dictionary <string, object> { { "status", status.Serialized() } } )); }
internal ReplyContent CreatReplyContent(ReplyStatus status, ReplyMethodName methodName, string content) { ReplyContent replyModel = new ReplyContent() { ReplyStatus = status, ReplyMethodName = methodName, Content = content }; return(replyModel); }
/// <summary> /// Initializes a new instance of the SocksReply class. /// </summary> /// <param name="status">The status of the response.</param> /// <param name="domain">The server bound fully-qualified domain /// name.</param> /// <param name="port">The server bound port.</param> /// <exception cref="ArgumentNullException">The domain parameter /// is null.</exception> /// <exception cref="ArgumentException">The length of the domain string /// exceeds 255 characters.</exception> public SocksReply(ReplyStatus status, string domain, ushort port) { if (domain.Length > 255) { throw new ArgumentException("The length of the domain string must " + "not exceed 255 characters."); } Status = status; ATyp = ATyp.Domain; Address = domain; Port = port; }
public SocksReply(ReplyStatus status, string domain, ushort port) { domain.ThrowIfNull <string>("domain"); if (domain.Length > 0xff) { throw new ArgumentException("The length of the domain string must not exceed 255 characters."); } this.Status = status; this.ATyp = S22.Xmpp.Extensions.Socks5.ATyp.Domain; this.Address = domain; this.Port = port; }
/// <summary>Creates a new outgoing response frame with the given reply status and payload.</summary> /// <param name="current">The current parameter holds decoded header data and other information about the /// request for which this method creates a response.</param> /// <param name="replyStatus">The reply status.</param> /// <param name="payload">The payload for this response frame.</param> // TODO: add parameter such as "bool assumeOwnership" once we add memory pooling. public OutgoingResponseFrame(Current current, ReplyStatus replyStatus, ArraySegment <byte> payload) : this(current) { WriteByte((byte)replyStatus); if (payload.Count == 0 && (replyStatus == ReplyStatus.OK || replyStatus == ReplyStatus.UserException)) { WriteEmptyEncapsulation(current.Encoding); } else { WritePayload(payload); } }
public Push Receive(ReplyStatus status, Action <Reply> callback) { if (HasReceived(status) && _receivedResp.HasValue) { callback(_receivedResp.Value); } if (!_recHooks.TryGetValue(status, out var callbacks)) { callbacks = new List <Action <Reply> >(); _recHooks[status] = callbacks; } callbacks.Add(callback); return(this); }
internal Task DeSubscribe(String connectionId, string groupName) { ReplyStatus status = ReplyStatus.Error; ClientInfo client = _List.Where(x => x.ClientId == connectionId).FirstOrDefault(); ClientInfo group = _List.Where(x => x.ConnectionType == ConnectionType.Group && x.ClientToken == groupName).FirstOrDefault(); if (group != null) { group.Clients.Remove(client); if (group.Clients.Count == 0) { _List.Remove(group); } status = ReplyStatus.Success; } return(ReplyAsync(connectionId, status, ReplyMethodName.DeSubscribe, groupName)); }
/// <summary> /// 向目的 IP 发送本机上线信息。 /// </summary> /// <param name="iPAddress">目标主机的 IP 地址,当填写 IPAddress.Broadcast 时即为广播。</param> /// <param name="replyStatus">广播状态字:请使用 ReplyStatus 枚举类型。</param> /// <param name="onlineStatus">在线状态字:请使用 OnlineStatus 结构体。</param> public static void OnlineMessageSend(IPAddress iPAddress, ReplyStatus replyStatus, string onlineStatus) { /// 上线状态信息由以下部分组成: /// 【本机活动的IP地址】 + 【分隔符“英文逗号 , ”】 + 【上下线状态字 UP 或 DP 】 + 【本用户17位UID】+ 【广播状态字】 + 【本用户名】 string re = ""; if (replyStatus == ReplyStatus.NeedReply) { re = "1"; } else { re = "0"; } string carrier = HostInfo.IPv4Address.ToString() + onlineStatus.ToString() + CommonFoundations.HostUID + re + CommonFoundations.HostName; UDPMessageSender(iPAddress, carrier); }
private bool CurrentlyProccessing(ReplyStatus r) { switch (r) { case ReplyStatus.Success: case ReplyStatus.Pending: case ReplyStatus.Rejected: case ReplyStatus.Expired: return(false); case ReplyStatus.ApprovedBySupplier: case ReplyStatus.ConfirmedByCustomer: case ReplyStatus.AgreedWithASupplier: case ReplyStatus.WaitingForPayment: return(true); } return(false); }
public static SocksReply Deserialize(byte[] buffer) { SocksReply reply; buffer.ThrowIfNull <byte[]>("buffer"); using (MemoryStream stream = new MemoryStream(buffer)) { using (BinaryReader reader = new BinaryReader(stream)) { if (reader.ReadByte() != 5) { throw new SerializationException("Invalid SOCKS5 reply."); } ReplyStatus status = (ReplyStatus)reader.ReadByte(); reader.ReadByte(); S22.Xmpp.Extensions.Socks5.ATyp typ = (S22.Xmpp.Extensions.Socks5.ATyp)reader.ReadByte(); IPAddress address = null; string domain = null; switch (typ) { case S22.Xmpp.Extensions.Socks5.ATyp.IPv4: case S22.Xmpp.Extensions.Socks5.ATyp.IPv6: address = new IPAddress(reader.ReadBytes((typ == S22.Xmpp.Extensions.Socks5.ATyp.IPv4) ? 4 : 0x10)); break; case S22.Xmpp.Extensions.Socks5.ATyp.Domain: { byte count = reader.ReadByte(); domain = Encoding.ASCII.GetString(reader.ReadBytes(count)); break; } } ushort port = reader.ReadUInt16(true); if (typ == S22.Xmpp.Extensions.Socks5.ATyp.Domain) { return(new SocksReply(status, domain, port)); } reply = new SocksReply(status, address, port); } } return(reply); }
/// <summary> /// Deserializes a new instance of the SocksReply class from the /// specified byte array. /// </summary> /// <param name="buffer">An array of bytes to deserialize a new instance /// of the SocksReply class from.</param> /// <returns>An initialized instance of the SocksReply class.</returns> /// <exception cref="ArgumentNullException">The buffer parameter is /// null.</exception> /// <exception cref="SerializationException">The specified buffer does /// not contain a valid SOCKS5 reply message.</exception> public static SocksReply Deserialize(byte[] buffer) { buffer.ThrowIfNull("buffer"); using (var ms = new MemoryStream(buffer)) { using (BinaryReader r = new BinaryReader(ms)) { if (r.ReadByte() != version) { throw new SerializationException("Invalid SOCKS5 reply."); } ReplyStatus status = (ReplyStatus)r.ReadByte(); // Skip reserved octet. r.ReadByte(); ATyp atyp = (ATyp)r.ReadByte(); IPAddress addr = null; string domain = null; switch (atyp) { case ATyp.IPv4: case ATyp.IPv6: addr = new IPAddress(r.ReadBytes(atyp == ATyp.IPv4 ? 4 : 16)); break; case ATyp.Domain: byte len = r.ReadByte(); domain = Encoding.ASCII.GetString(r.ReadBytes(len)); break; } ushort port = r.ReadUInt16(true); if (atyp == ATyp.Domain) { return(new SocksReply(status, domain, port)); } return(new SocksReply(status, addr, port)); } } }
internal static void ShouldBe <T>(this Reply <T> reply, ReplyStatus status) => reply.Status.ShouldBe(status, reply.Error.Print());
/// <summary> /// Sends the specified SOCKS5 reply to the connected client. /// </summary> /// <param name="status">The status code of the reply.</param> /// <param name="address">The address sent as part of the reply.</param> /// <param name="port">The port sent as part of the reply.</param> /// <exception cref="ArgumentNullException">The domain parameter is /// null.</exception> /// <exception cref="ObjectDisposedException">The object has been /// disposed.</exception> public async Task Reply(ReplyStatus status, IPAddress address, ushort port) { await Reply(new SocksReply(status, address, port)); }
/// <summary> /// Sends the specified SOCKS5 reply to the connected client. /// </summary> /// <param name="status">The status code of the reply.</param> /// <param name="domain">The domain sent as part of the reply.</param> /// <param name="port">The port sent as part of the reply.</param> /// <exception cref="ArgumentNullException">The domain parameter is /// null.</exception> /// <exception cref="ObjectDisposedException">The object has been /// disposed.</exception> public async Task Reply(ReplyStatus status, string domain, ushort port) { await Reply(new SocksReply(status, domain, port)); }
/// <summary> /// Initializes a new instance of the SocksReply class. /// </summary> /// <param name="status">The status of the response.</param> /// <param name="domain">The server bound fully-qualified domain /// name.</param> /// <param name="port">The server bound port.</param> /// <exception cref="ArgumentNullException">The domain parameter /// is null.</exception> /// <exception cref="ArgumentException">The length of the domain string /// exceeds 255 characters.</exception> public SocksReply(ReplyStatus status, string domain, ushort port) { domain.ThrowIfNull("domain"); if (domain.Length > 255) { throw new ArgumentException("The length of the domain string must " + "not exceed 255 characters."); } Status = status; ATyp = ATyp.Domain; Address = domain; Port = port; }
/// <summary> /// Initializes a new instance of the SocksReply class. /// </summary> /// <param name="status">The status of the response.</param> /// <param name="address">The server bound IP address.</param> /// <param name="port">The server bound port.</param> /// <exception cref="ArgumentNullException">The address parameter /// is null.</exception> public SocksReply(ReplyStatus status, IPAddress address, ushort port) { address.ThrowIfNull("address"); Status = status; ATyp = address.AddressFamily == AddressFamily.InterNetworkV6 ? ATyp.IPv6 : ATyp.IPv4; Address = address; Port = port; }
/// <summary> /// Sends the specified SOCKS5 reply to the connected client. /// </summary> /// <param name="status">The status code of the reply.</param> /// <param name="address">The address sent as part of the reply.</param> /// <param name="port">The port sent as part of the reply.</param> /// <exception cref="ArgumentNullException">The domain parameter is /// null.</exception> /// <exception cref="ObjectDisposedException">The object has been /// disposed.</exception> public void Reply(ReplyStatus status, IPAddress address, ushort port) { Reply(new SocksReply(status, address, port)); }
internal Task ReplyAsync(string ClientId, ReplyStatus status, ReplyMethodName methodName, string content) { string replyContent = PublicMethod.JsonSerialize <ReplyContent>(CreatReplyContent(status, methodName, content)); return(hub.Clients.Client(ClientId).SendAsync("Reply", replyContent)); }
/// <summary> /// Sends the specified SOCKS5 reply to the connected client. /// </summary> /// <param name="status">The status code of the reply.</param> /// <param name="domain">The domain sent as part of the reply.</param> /// <param name="port">The port sent as part of the reply.</param> /// <exception cref="ArgumentNullException">The domain parameter is /// null.</exception> /// <exception cref="ObjectDisposedException">The object has been /// disposed.</exception> public void Reply(ReplyStatus status, string domain, ushort port) { Reply(new SocksReply(status, domain, port)); }
public CommandFailedException(ReplyStatus status) { Status = status; }
public DcopReply(DcopFunction fun, int id) { status = ReplyStatus.Pending; replyId = id; replyType = fun.ReturnValue; }
private bool HasReceived(ReplyStatus status) { return(_receivedResp?.ReplyStatus == status); }
public Reply(ReplyStatus status, string message) { this.ReplyStatus = status; this.Message = message; }
/// <summary>Creates a response frame that represents "failure" and contains an exception.</summary> /// <param name="current">The current parameter holds decoded header data and other information about the /// request for which this constructor creates a response.</param> /// <param name="exception">The exception to store into the frame's payload.</param> public OutgoingResponseFrame(Current current, RemoteException exception) : this(current) { if (exception is RequestFailedException requestFailedException) { if (requestFailedException is DispatchException dispatchException) { // TODO: the null checks are necessary due to the way we unmarshal the exception through reflection. if (dispatchException.Id.Name == null || dispatchException.Id.Name.Length == 0) { dispatchException.Id = current.Id; } if (dispatchException.Facet == null || dispatchException.Facet.Length == 0) { dispatchException.Facet = current.Facet; } if (dispatchException.Operation == null || dispatchException.Operation.Length == 0) { dispatchException.Operation = current.Operation; } ReplyStatus replyStatus = default; if (dispatchException is ObjectNotExistException) { replyStatus = ReplyStatus.ObjectNotExistException; } else if (dispatchException is OperationNotExistException) { replyStatus = ReplyStatus.OperationNotExistException; } else { Debug.Assert(false); } WriteByte((byte)replyStatus); dispatchException.Id.IceWrite(this); // For compatibility with the old FacetPath. if (dispatchException.Facet == null || dispatchException.Facet.Length == 0) { WriteStringSeq(Array.Empty <string>()); } else { WriteStringSeq(new string[] { dispatchException.Facet }); } WriteString(dispatchException.Operation); } else { WriteByte((byte)ReplyStatus.UnknownLocalException); if (requestFailedException.IceMessage.Length > 0) { WriteString(requestFailedException.IceMessage); } else { WriteString(requestFailedException.ToString()); } } } else { WriteByte((byte)ReplyStatus.UserException); StartEncapsulation(current.Encoding, FormatType.SlicedFormat); WriteException(exception); EndEncapsulation(); } }
public OwnsLeaveRequirement(ReplyStatus status) { Status = status; }
internal IncomingResponseFrame(ReplyStatus replyStatus, InputStream inputStream) { InputStream = inputStream; ReplyStatus = replyStatus; }
public Reply(ReplyStatus status, TResult result, ErrorMessageList error) { Status = status; Error = error; Result = result; }