コード例 #1
0
        public RpcAnswer RpcCall(Combinator combinator, params string[] expectedAnswers)
        {
            Trace.TraceInformation("#Send plain: {0}", combinator);

            var pm = new PlainMessage(0, combinator);

            var transport = new TcpTransport(_connection.PacketNumber++, pm.Serialize());

            byte[] responseb = _connection.ExchangeWithServer(transport.Serialize());

            TcpTransport answer;
            using (var ms = new MemoryStream(responseb))
                answer = new TcpTransport(ms);
            uint constructor = PlainMessage.ExtractConstructor(answer.Payload);

            new Crc32();

            foreach (string item in expectedAnswers)
            {
                uint crc32 = Crc32.Compute(Encoding.UTF8.GetBytes(item));
                if (crc32 == constructor)
                {
                    var resultCombinator = new PlainMessage(answer.Payload, item.Split(' ').Last().Trim()).Combinator;
                    Trace.TraceInformation("#Recieve plain: {0}", resultCombinator);
                    return new RpcAnswer(resultCombinator);
                }
            }
            throw new ArgumentException("unexpected answer");
        }
コード例 #2
0
ファイル: Provider.cs プロジェクト: Fedorm/core-master
        private IEnumerable<Combinator> Exchange(Combinator combinator)
        {
            _session.Salt = _settings.NonceNewNonceXor;
            var oc = new SessionContainer(_session.SessionId, combinator);

            EncryptedMessage encMessage = _session.PrepareRpcCall(oc);
            var call = new TcpTransport(_connection.PacketNumber++, encMessage.Serialize());

            _connection.Write(call.Serialize());
            Trace.TraceInformation("#Send: {0}", combinator);

            var buffer = _connection.Read();
            if (buffer.Length == 0)
                throw new DecodeException("Response is empty");

            var result = new List<Combinator>();// ReSharper disable once LoopCanBeConvertedToQuery
            foreach (SessionContainer container in ProcessInputBuffer(buffer))
            {
                Combinator c = Unwrap(container.Combinator, container.SessionId, _session.SessionId, combinator.Descriptor.type);
                if (c != null)
                    result.Add(c);
            }
            return result;
        }