Beispiel #1
0
        public static Cell ReadFrom(Stream stream, int protocolVersion)
        {
            using (var reader = new BEBinaryReader(stream))
            {
                var circuitId = (protocolVersion >= 4)
                    ? (uint)reader.ReadUInt32()
                    : (uint)reader.ReadUInt16();

                var command = (CommandType)reader.ReadByte();
                var cell    = CreateFromCommand(circuitId, command);
                cell.ReadPayload(reader);

                return(cell);
            }
        }
Beispiel #2
0
        protected override void ReadPayload(BinaryReader reader)
        {
            var payload = reader.ReadBytes(MaxPayloadSize);

            using var preader = new BEBinaryReader(new MemoryStream(payload));
            Timestamp         = DateTimeOffset.FromUnixTimeSeconds(preader.ReadUInt32());
            MyIPAddress       = preader.ReadIPAddress();
            var numOfAddresses = preader.ReadByte();

            for (var i = 0; i < numOfAddresses; i++)
            {
                var remote = preader.ReadIPAddress();
                if (remote != null)
                {
                    OtherIPs.Add(remote);
                }
                else
                {
                    break;
                }
            }
        }