private void NotifyProtoHandler(ProtocolEnum protocolEnum, MessageBase msgBase)
 {
     if (_protoHandlers.ContainsKey(protocolEnum))
     {
         _protoHandlers[protocolEnum](msgBase);
     }
 }
示例#2
0
    public static MsgBase Decode(ProtocolEnum protocol, byte[] bytes, int offset, int count)
    {
        if (count <= 0)
        {
            Debug.LogError("协议解密出错,数据长度为0");
            return(null);
        }

        try
        {
            byte[] newBytes = new byte[count];
            Array.Copy(bytes, offset, newBytes, 0, count);
            string secret = ServerSocket.Secretkey;
            if (protocol == ProtocolEnum.MsgSecret)
            {
                secret = ServerSocket.PublicKey;
            }
            newBytes = AES.AESDecrypt(newBytes, secret);

            using (var memory = new MemoryStream(newBytes, 0, newBytes.Length))
            {
                Type t = System.Type.GetType(protocol.ToString());
                return((MsgBase)Serializer.NonGeneric.Deserialize(t, memory));
            }
        }
        catch (Exception ex)
        {
            Debug.LogError("协议解密出错:" + ex);
            return(null);
        }
    }
示例#3
0
 public Task <CreateListenerResponse> CreateListenerAsync(
     int port,
     ProtocolEnum protocol,
     string loadBalancerArn,
     string targetGroupArn,
     ActionTypeEnum actionTypeEnum,
     IEnumerable <Certificate> certificates = null,
     string sslPolicy = null,
     CancellationToken cancellationToken = default(CancellationToken))
 => _clientV2.CreateListenerAsync(
     new CreateListenerRequest()
 {
     Port            = port,
     Protocol        = protocol,
     LoadBalancerArn = loadBalancerArn,
     DefaultActions  = new List <Action>()
     {
         new Action()
         {
             TargetGroupArn = targetGroupArn,
             Type           = actionTypeEnum
         }
     },
     Certificates = certificates?.ToList(),
     SslPolicy    = sslPolicy
 }
     , cancellationToken).EnsureSuccessAsync();
示例#4
0
        /// <summary>
        /// 协议解密,以及反序列化
        /// </summary>
        /// <param name="protocol"></param>
        /// <param name="bytes"></param>
        /// <param name="offset"></param>
        /// <param name="count"></param>
        /// <returns></returns>
        public static MessageBase Decode(ProtocolEnum protocol, byte[] bytes, int offset, int count)
        {
            if (count <= 0)
            {
                Debug.LogError("协议解密出错,数据长度为0");
                return(null);
            }
            try
            {
                byte[] newBytes = new byte[count];
                Array.Copy(bytes, offset, newBytes, 0, count);
                string secret = ServerSocket.SecretKey;
                // 请求加密使用的是公钥加密
                if (protocol == ProtocolEnum.MessageSecret)
                {
                    secret = ServerSocket.PublicKey;
                }

                // 解密
                newBytes = AES.AESDecrypt(newBytes, secret);

                using (var memory = new MemoryStream(newBytes, 0, newBytes.Length))
                {
                    // 这里要求对应的协议类型类,要与协议枚举的名字一一对应(这里的类最好不要有命名空间包裹,若有,可能识别不到)
                    Type t = System.Type.GetType(protocol.ToString());
                    return((MessageBase)Serializer.NonGeneric.Deserialize(t, memory));
                }
            }
            catch (Exception ex)
            {
                Debug.LogError("协议解密出错 :" + ex);
                return(null);
            }
        }
 public static IEwkProtocol CreateIEwkProtocol(ProtocolEnum protocol_enum)
 {
     return(new EwkProtocol()
     {
         Protocol_Enum = protocol_enum,
     });
 }
示例#6
0
 public Task <CreateTargetGroupResponse> CreateTargetGroupAsync(
     string name,
     int port,
     ProtocolEnum protocol,
     string vpcId,
     TargetTypeEnum targetType,
     string healthCheckPath,
     int healthCheckIntervalSeconds,
     int healthyThresholdCount,
     int unhealthyThresholdCount,
     int healthCheckTimeoutSeconds,
     ProtocolEnum healthCheckProtocol,
     int?healthCheckPort,
     CancellationToken cancellationToken = default(CancellationToken))
 => _clientV2.CreateTargetGroupAsync(
     new CreateTargetGroupRequest()
 {
     Name                       = name,
     Port                       = port,
     Protocol                   = protocol,
     VpcId                      = vpcId,
     TargetType                 = targetType,
     HealthCheckPath            = healthCheckPath,
     HealthCheckIntervalSeconds = healthCheckIntervalSeconds,
     HealthyThresholdCount      = healthyThresholdCount,
     UnhealthyThresholdCount    = unhealthyThresholdCount,
     HealthCheckTimeoutSeconds  = healthCheckTimeoutSeconds,
     HealthCheckProtocol        = healthCheckProtocol,
     HealthCheckPort            = (healthCheckPort == null ? null : $"{healthCheckPort.Value}")
 }
     , cancellationToken).EnsureSuccessAsync();
示例#7
0
 public void SendMsg(ProtocolEnum protoId, object obj)
 {
     if (m_netProxy != null && m_netProxy.IsConnected)
     {
         m_netProxy.SendMsg(protoId, obj);
     }
 }
    /// <summary>
    /// 协议解密,以及反序列化
    /// </summary>
    /// <param name="protocol"></param>
    /// <param name="bytes"></param>
    /// <param name="offset"></param>
    /// <param name="count"></param>
    /// <returns></returns>
    public static MessageBase Decode(ProtocolEnum protocol, byte[] bytes, int offset, int count)
    {
        if (count <= 0)
        {
            Debug.LogError("协议解密出错,数据长度为0");
            return(null);
        }
        string secret = string.IsNullOrEmpty(NetManager.Instance.Secretkey) ? NetManager.Instance.PublicKey :
                        NetManager.Instance.Secretkey;

        try
        {
            byte[] newBytes = new byte[count];
            Array.Copy(bytes, offset, newBytes, 0, count);


            //// 解密
            newBytes = AES.AESDecrypt(newBytes, secret);

            using (var memory = new MemoryStream(newBytes, 0, newBytes.Length))
            {
                // 这里要求对应的协议类型类,要与协议枚举的名字一一对应
                Type t = System.Type.GetType(protocol.ToString());
                return((MessageBase)Serializer.NonGeneric.Deserialize(t, memory));
            }
        }
        catch (Exception ex)
        {
            Debug.LogError("协议解密出错 :" + ex);
            return(null);
        }
    }
 /// <summary>
 /// 执行协议的监听事件
 /// </summary>
 /// <param name="protocolEnum"></param>
 /// <param name="messageBase"></param>
 public void FirstProtocal(ProtocolEnum protocolEnum, MessageBase messageBase)
 {
     if (m_ProtocalListenerDic.ContainsKey(protocolEnum))
     {
         m_ProtocalListenerDic[protocolEnum](messageBase);
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SyslogServer" /> class.
 /// </summary>
 /// <param name="address">Specifies the IP address or hostname of the syslog server. (required).</param>
 /// <param name="isClusterAuditingEnabled">Specifies if Cluster audit logs should be sent to this syslog server. If &#39;true&#39;, Cluster audit logs are sent to the syslog server. (default) If &#39;false&#39;, Cluster audit logs are not sent to the syslog server. Either cluster audit logs or filer audit logs should be enabled..</param>
 /// <param name="isFilerAuditingEnabled">Specifies if filer audit logs should be sent to this syslog server. If &#39;true&#39;, filer audit logs are sent to the syslog server. (default) If &#39;false&#39;, filer audit logs are not sent to the syslog server. Either cluster audit logs or filer audit logs should be enabled..</param>
 /// <param name="name">Specifies a unique name for the syslog server on the Cluster..</param>
 /// <param name="port">Specifies the port where the syslog server listens. (required).</param>
 /// <param name="protocol">Specifies the protocol used to send the logs. Specifies the protocol used to communicate to a server. e.g., kUDP, kTCP.  &#39;kUDP&#39; indicates UDP protocol. &#39;kTCP&#39; indicates TCP protocol. (required).</param>
 public SyslogServer(string address = default(string), bool?isClusterAuditingEnabled = default(bool?), bool?isFilerAuditingEnabled = default(bool?), string name = default(string), int?port = default(int?), ProtocolEnum protocol = default(ProtocolEnum))
 {
     // to ensure "address" is required (not null)
     if (address == null)
     {
         throw new InvalidDataException("address is a required property for SyslogServer and cannot be null");
     }
     else
     {
         this.Address = address;
     }
     // to ensure "port" is required (not null)
     if (port == null)
     {
         throw new InvalidDataException("port is a required property for SyslogServer and cannot be null");
     }
     else
     {
         this.Port = port;
     }
     // to ensure "protocol" is required (not null)
     if (protocol == null)
     {
         throw new InvalidDataException("protocol is a required property for SyslogServer and cannot be null");
     }
     else
     {
         this.Protocol = protocol;
     }
     this.IsClusterAuditingEnabled = isClusterAuditingEnabled;
     this.IsFilerAuditingEnabled   = isFilerAuditingEnabled;
     this.Name = name;
 }
 public static IEwkProtocol CreateIEwkProtocol <T>(ProtocolEnum protocol_enum, T data)
 {
     return(new EwkProtocol <T>()
     {
         Protocol_Enum = protocol_enum,
         Data = data
     });
 }
示例#12
0
 public void FirstProto(ProtocolEnum protocolEnum, MsgBase msgBase)
 {
     Debug.Log(protocolEnum);
     if (m_ProtoDic.ContainsKey(protocolEnum))
     {
         m_ProtoDic[protocolEnum](msgBase);
     }
 }
示例#13
0
 public bool Equals(ProtocolEnum obj)
 {
     if ((object)obj == null)
     {
         return(false);
     }
     return(StringComparer.OrdinalIgnoreCase.Equals(this.Value, obj.Value));
 }
示例#14
0
 public void WriteFile(ProtocolEnum protocolEnum)
 {
     EnumParsed = protocolEnum;
     Writer     = new StringBuilder();
     EnumPath   = $@"{Directory.GetCurrentDirectory()}/Output/Enums/{EnumParsed.Name}.cs";
     CreateRepositories();
     CreateFile();
     GenerateClass();
 }
示例#15
0
        /// <summary>
        /// 创建协议
        /// </summary>
        /// <param name="pId">协议id</param>
        /// <param name="pData">协议体</param>
        /// <param name="pPoint">tcp的ipEndPoint(服务器用)</param>
        /// <returns></returns>
        public static ProtocolData MakeProtocol(ProtocolEnum pId, object pData, string pPoint = "")
        {
            ProtocolData protocolData = new ProtocolData();

            protocolData.MProtocolId = pId;
            protocolData.MData       = pData;
            protocolData.MIpEndPoint = pPoint;
            return(protocolData);
        }
示例#16
0
        public Type GetTypeByProtoId(ProtocolEnum penum)
        {
            Type type;

            if (m_protoDic.TryGetValue(penum, out type))
            {
                return(type);
            }
            return(null);
        }
示例#17
0
        /// <summary>
        /// 接收数据处理,根据信息解析协议,根据协议内容处理消息再下发到客户端
        /// </summary>
        /// <param name="clientSocket"></param>
        void OnReceiveData(ClientSocket clientSocket)
        {
            ByteArray readbuff = clientSocket.ReadBuff;

            byte[] bytes      = readbuff.Bytes;
            int    bodyLength = BitConverter.ToInt32(bytes, readbuff.ReadIdx);

            //判断接收到的信息长度是否小于包体长度+包体头长度,如果小于,代表我们的信息不全,大于代表信息全了(有可能有粘包存在)
            if (readbuff.Length < bodyLength + 4)
            {
                return;
            }

            //解析协议名
            ProtocolEnum proto = MsgBase.DecodeName(readbuff.Bytes);

            if (proto == ProtocolEnum.None)
            {
                Debug.LogError("OnReceiveData MsgBase.DecodeName  fail");
                CloseClient(clientSocket);
                return;
            }
            readbuff.ReadIdx += 4;
            //解析协议体
            int bodyCount = bodyLength - readbuff.Bytes[4] - 2;

            MsgBase msgBase = MsgBase.Decode(proto, readbuff.Bytes, bodyCount);

            if (msgBase == null)
            {
                Debug.LogError("{0}协议内容解析错误:" + proto.ToString());
                CloseClient(clientSocket);
                return;
            }
            //通过反射分发消息
            MethodInfo mi = typeof(MsgHandler).GetMethod(proto.ToString());

            object[] o = { clientSocket, msgBase };
            if (mi != null)
            {
                mi.Invoke(null, o);
            }
            else
            {
                Debug.LogError("OnReceiveData Invoke fail:" + proto.ToString());
            }

            readbuff.ReadIdx += bodyLength;
            readbuff.CheckAndMoveBytes();
            //继续读取消息 处理黏包
            if (readbuff.Length > 4)
            {
                OnReceiveData(clientSocket);
            }
        }
示例#18
0
        public void RegMsg(ProtocolEnum protoId, OnMsgHandle msgHandle)
        {
            List <OnMsgHandle> msgLst;

            if (!m_netMsgLst.TryGetValue(protoId, out msgLst))
            {
                msgLst = new List <OnMsgHandle>();
                m_netMsgLst.Add(protoId, msgLst);
            }
            msgLst.Add(msgHandle);
        }
示例#19
0
 public static void AddListener(ProtocolEnum protocolEnum, Callback <object> kHandler)
 {
     lock (mProtocolEventTable)
     {
         if (!mProtocolEventTable.ContainsKey(protocolEnum))
         {
             mProtocolEventTable.Add(protocolEnum, null);
         }
         mProtocolEventTable[protocolEnum] = (Callback <object>)mProtocolEventTable[protocolEnum] + kHandler;
     }
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="SyslogServer" /> class.
 /// </summary>
 /// <param name="address">Specifies the IP address or hostname of the syslog server. (required).</param>
 /// <param name="isClusterAuditingEnabled">Specifies if Cluster audit logs should be sent to this syslog server. If &#39;true&#39;, Cluster audit logs are sent to the syslog server. (default) If &#39;false&#39;, Cluster audit logs are not sent to the syslog server. Either cluster audit logs or filer audit logs should be enabled..</param>
 /// <param name="isFilerAuditingEnabled">Specifies if filer audit logs should be sent to this syslog server. If &#39;true&#39;, filer audit logs are sent to the syslog server. (default) If &#39;false&#39;, filer audit logs are not sent to the syslog server. Either cluster audit logs or filer audit logs should be enabled..</param>
 /// <param name="name">Specifies a unique name for the syslog server on the Cluster..</param>
 /// <param name="port">Specifies the port where the syslog server listens. (required).</param>
 /// <param name="protocol">Specifies the protocol used to send the logs. Specifies the protocol used to communicate to a server. e.g., kUDP, kTCP.  &#39;kUDP&#39; indicates UDP protocol. &#39;kTCP&#39; indicates TCP protocol. (required).</param>
 public SyslogServer(string address = default(string), bool?isClusterAuditingEnabled = default(bool?), bool?isFilerAuditingEnabled = default(bool?), string name = default(string), int?port = default(int?), ProtocolEnum protocol = default(ProtocolEnum))
 {
     this.Address = address;
     this.IsClusterAuditingEnabled = isClusterAuditingEnabled;
     this.IsFilerAuditingEnabled   = isFilerAuditingEnabled;
     this.Name     = name;
     this.Port     = port;
     this.Protocol = protocol;
     this.IsClusterAuditingEnabled = isClusterAuditingEnabled;
     this.IsFilerAuditingEnabled   = isFilerAuditingEnabled;
     this.Name = name;
 }
示例#21
0
        public void DispathMsg(ProtocolEnum protoId, object mdata)
        {
            List <OnMsgHandle> msgLst;

            if (!m_netMsgLst.TryGetValue(protoId, out msgLst))
            {
                Console.WriteLine("No Such A ProtoId{0} Registered", protoId);
                return;
            }
            foreach (var msg in msgLst)
            {
                msg(mdata);
            }
        }
示例#22
0
 /// <summary>
 /// 向服务器发送协议
 /// </summary>
 /// <param name="pId"></param>
 /// <param name="pBody"></param>
 public void SendMsg(ProtocolEnum pId, object pBody)
 {
     if (m_netProxy != null)
     {
         if (m_netProxy.IsConnected)
         {
             m_netProxy.SendMsg(pId, pBody);
         }
         else
         {
             Debug.Log("Client Has Closed");
         }
     }
 }
示例#23
0
 public static void RemoveListener(ProtocolEnum protocolEnum, Callback <object> kHandler)
 {
     lock (mProtocolEventTable)
     {
         if (mProtocolEventTable.ContainsKey(protocolEnum))
         {
             mProtocolEventTable[protocolEnum] = (Callback <object>)mProtocolEventTable[protocolEnum] - kHandler;
             if (mProtocolEventTable[protocolEnum] == null)
             {
                 mProtocolEventTable.Remove(protocolEnum);
             }
         }
     }
 }
示例#24
0
        public void UnRegMsg(ProtocolEnum protoId, OnMsgHandle msgHandle)
        {
            List <OnMsgHandle> msgLst;

            if (!m_netMsgLst.TryGetValue(protoId, out msgLst))
            {
                return;
            }

            msgLst.Remove(msgHandle);
            if (msgLst.Count <= 0)
            {
                m_netMsgLst.Remove(protoId);
            }
        }
示例#25
0
        public void DeletePortFromWhiteList(int port, ProtocolEnum protocol)
        {
            var protocolType = NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_UDP;

            switch (protocol)
            {
            case ProtocolEnum.TCP:
                protocolType = NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_TCP;
                break;

            default:
                protocolType = NET_FW_IP_PROTOCOL_.NET_FW_IP_PROTOCOL_UDP;
                break;
            }
            _mgr.LocalPolicy.CurrentProfile.GloballyOpenPorts.Remove(port, protocolType);
        }
示例#26
0
        public void SendMsg(string endPoint, ProtocolEnum protocolId, object data)
        {
            ServerClient client = GetSClient(endPoint);

            if (client != null)
            {
                try
                {
                    client.SendMsg(protocolId, data);
                }
                catch (Exception exp)
                {
                    ServerLog.Log(string.Format("Send To :{0}, Error:{1}", endPoint, exp.Message));
                }
            }
        }
示例#27
0
        public GrabResult GrabBanner(ProtocolEnum protocol, string serverAddr)
        {
            GrabResult result = null;

            switch (protocol)
            {
                case ProtocolEnum.HTTP:
                    result = GrapHTTP(serverAddr);
                    break;
                case ProtocolEnum.SSH:
                    break;
                case ProtocolEnum.FTP:
                    result = GrabFTP(serverAddr);
                    break;
                default:
                    break;
            }

            return result;
        }
示例#28
0
        public static void Invoke(ProtocolEnum protocolEnum, System.Object arg1)
        {
            try
            {
                Delegate kDelegate;
                if (mProtocolEventTable.TryGetValue(protocolEnum, out kDelegate))
                {
                    Callback <System.Object> kHandler = (Callback <System.Object>)kDelegate;

                    if (kHandler != null)
                    {
                        kHandler(arg1);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }
        }
示例#29
0
 private void InitProtocol(ProtocolEnum protocol)
 {
     try
     {
         if (protocol == ProtocolEnum.Http)
         {
             binding  = new WSHttpBinding(SecurityMode.None);
             endpoint = new EndpointAddress(Consts.HttpUrl());
         }
         if (protocol == ProtocolEnum.Tcp)
         {
             binding  = new NetTcpBinding(SecurityMode.None);
             endpoint = new EndpointAddress(Consts.TcpUrl());
         }
     }
     catch (Exception ex)
     {
         Logger.Log.Error(string.Format("{0}: {1}", nameof(InitProtocol), ex.Message));
     }
 }
示例#30
0
        /// <summary>
        /// 发送协议数据
        /// </summary>
        /// <param name="pid">协议id</param>
        /// <param name="pdata">协议体</param>
        public void SendMsg(ProtocolEnum pid, object pdata)
        {
            if (!CheckIsConnect)
            {
                return;
            }
            Type ptype = ProtocolMgr.MInstance.GetTypeByProtoId(pid);

            if (ptype == null)
            {
                Console.WriteLine("SendMsg-> No Such One Proto,Id:{0}", pid);
                return;
            }

            //消息构成:消息总长度+消息id+消息体

            //消息体
            MemoryStream pbodyStream = new MemoryStream();

            Serializer.NonGeneric.Serialize(pbodyStream, pdata);
            byte[] bodyBytes = pbodyStream.ToArray();
            //消息头长度
            int pheader = sizeof(int) * 2;
            //消息总长度
            int plength = bodyBytes.Length + pheader;

            using (MemoryStream pstream = new MemoryStream())
            {
                BinaryWriter bwriter = new BinaryWriter(pstream);
                bwriter.Write(plength);
                bwriter.Write((int)pid);
                bwriter.Write(bodyBytes);

                pstream.Position = 0;
                byte[] content = pstream.ToArray();
                m_client.GetStream().Write(content, 0, content.Length);
                m_client.GetStream().Flush();
            }

            pbodyStream.Close();
        }
示例#31
0
        public async Task <SA_Listener> CreatListener(
            string loadBalancerArn, string targetGroupArn,
            string strProtocol, int port, string certificateArn = "")
        {
            var actions = new List <Amazon.ElasticLoadBalancingV2.Model.Action>();
            var action  = new Amazon.ElasticLoadBalancingV2.Model.Action();

            action.Type           = ActionTypeEnum.Forward;
            action.TargetGroupArn = targetGroupArn;
            actions.Add(action);
            var protocol = new ProtocolEnum(strProtocol);
            var request  = new CreateListenerRequest
            {
                DefaultActions  = actions,
                Protocol        = protocol,
                Port            = port,
                LoadBalancerArn = loadBalancerArn,
            };

            if (!string.IsNullOrEmpty(certificateArn))
            {
                var certificate = new Certificate();
                certificate.CertificateArn = certificateArn;
                //certificate.IsDefault = true;
                request.Certificates = new List <Certificate>()
                {
                    certificate
                };
            }

            var response = await client.CreateListenerAsync(request);

            var listener = response.Listeners[0];

            return(ConvertListener(response.Listeners[0]));
        }