Пример #1
0
        private void OnRecvErrorX(IPEndPoint ipinfo, DHTErrorMessage msg)
        {
            if (msg == null)
            {
                return;
            }

            fLogger.WriteDebug("DHT error receive: {0} / {1}", msg.ErrCode, msg.ErrText);
        }
Пример #2
0
        public static DHTMessage ParseBuffer(byte[] buffer)
        {
            if (buffer == null || buffer.Length == 0 || buffer[0] != 'd')
            {
                return(null);
            }

            var data = fParser.Parse <BDictionary>(buffer);

            var bsY = data.Get <BString>("y");

            if (bsY == null)
            {
                return(null);
            }

            string      strMsgType = bsY.ToString();
            MessageType msgType    = DHTMessage.GetMessageType(strMsgType);

            DHTMessage result;

            switch (msgType)
            {
            case MessageType.Response:
                result = new DHTResponseMessage(msgType, QueryType.None, data);
                break;

            case MessageType.Query:
                result = new DHTQueryMessage(msgType, QueryType.None, data);
                break;

            case MessageType.Error:
                result = new DHTErrorMessage(msgType, QueryType.None, data);
                break;

            default:
                result = new DHTMessage(msgType, QueryType.None, data);
                break;
            }

            result.Parse();
            return(result);
        }