public void Write(BufRefStream dest) { Destination.Write(dest); Info.PublicKey.Write(dest); Info.PublicSigningKey.Write(dest); var cnt = (byte)Leases.Count; if (cnt > 16) { throw new OverflowException("Max 16 leases per I2PLeaseSet"); } var signfields = new List <BufLen>(); signfields.Add(new BufLen(Destination.ToByteArray())); signfields.Add(Info.PublicKey.Key); signfields.Add(Info.PublicSigningKey.Key); signfields.Add((BufLen)cnt); lock ( Leases ) { dest.Write((byte)Leases.Count); foreach (var lease in Leases) { var buf = lease.ToByteArray(); dest.Write(buf); signfields.Add(new BufLen(buf)); } } dest.Write(I2PSignature.DoSign(Info.PrivateSigningKey, signfields.ToArray())); }
public override void Write(BufRefStream dest) { dest.Write(BufUtils.Flip32B(3)); dest.Write((byte)MessageType); dest.Write(BitConverter.GetBytes(SessionId)); dest.Write((byte)SessionState); }
public void Write(BufRefStream dest) { Delivery.Write(dest); dest.Write((BufRefLen)(BufLen)CloveId); Expiration.Write(dest); dest.Write(0); dest.Write(0); dest.Write(0); }
public override void Write(BufRefStream dest) { base.Write(dest); if ((Flag & (byte)DeliveryFlags.Delay) != 0) { dest.Write(BufUtils.Flip32B(0)); } dest.Write((BufRefLen)Message.CreateHeader16.HeaderAndPayload); }
public void Write(BufRefStream dest) { if (SignedData == null) { throw new InvalidOperationException("No signed data available"); } dest.Write(SignedData); dest.Write(Hash); }
public override void Write(BufRefStream dest) { var header = new byte[10]; var writer = new BufRefLen(header); writer.WriteFlip16(SessionId); writer.WriteFlip32(MessageId); writer.WriteFlip32((uint)Payload.Length); dest.Write(header); dest.Write((BufRefLen)Payload); }
public void WriteMessage(BufRefStream dest, params I2PType[] fields) { var buf = new BufRefStream(); foreach (var field in fields) { field.Write(buf); } dest.Write(BufUtils.Flip32B((uint)buf.Length)); dest.Write((byte)MessageType); dest.Write(buf); }
public void Write(BufRefStream dest) { var buf = new BufRefStream(); foreach (var one in Mappings) { one.Key.Write(buf); buf.Write((byte)'='); one.Value.Write(buf); buf.Write((byte)';'); } dest.Write(BufUtils.Flip16B((ushort)buf.Length)); dest.Write(buf); }
private static ZipArchive GetRouterInfoFiles(BufLen data) { try { var reader = new BufRefLen(data); var header = new I2PSU3Header(reader); if (header.FileType != I2PSU3Header.SU3FileTypes.Zip) { throw new ArgumentException($"Unknown FileType in SU3: {header.FileType}"); } if (header.ContentType != I2PSU3Header.SU3ContentTypes.SeedData) { throw new ArgumentException($"Unknown ContentType in SU3: {header.ContentType}"); } // TODO: Verify signature var s = new BufRefStream(); s.Write(reader); return(new ZipArchive(s)); } catch (Exception ex) { Logging.Log(ex); } return(null); }
public override void Write(BufRefStream dest) { var header = new byte[3]; var writer = new BufRefLen(header); writer.WriteFlip16(SessionId); writer.Write8((byte)SessionState); dest.Write(header); }
public override void Write(BufRefStream dest) { var header = new byte[6]; var writer = new BufRefLen(header); writer.WriteFlip16(SessionId); writer.WriteFlip32(MessageId); dest.Write(header); }
public void Write(BufRefStream dest) { var l = (byte)Math.Min(255, Str.Length); var v = new byte[System.Text.Encoding.UTF8.GetMaxByteCount(l) + 1]; v[0] = l; var bytes = System.Text.Encoding.UTF8.GetBytes(Str, 0, l, v, 1); dest.Write(v, 0, bytes + 1); }
public Garlic(I2PDate expiration, IEnumerable <GarlicClove> cloves) { BufRefStream buf = new BufRefStream(); buf.Write((byte)cloves.Count()); foreach (var clove in cloves) { clove.Write(buf); } // Certificate buf.Write(new byte[] { 0, 0, 0 }); buf.Write((BufRefLen)BufUtils.Flip32BL(BufUtils.RandomUint())); expiration.Write(buf); Data = new BufLen(buf.ToArray()); ParseData(new BufRefLen(Data)); }
public void Write(BufRefStream dest) { Id.Write(dest); LastSeen.Write(dest); Created.Write(dest); dest.Write(BufUtils.RandomBytes(52)); // Reserved space var mapping = CreateMapping(); mapping.Write(dest); }
public override void Write(BufRefStream dest) { var header = new byte[15]; var writer = new BufRefLen(header); writer.WriteFlip16(SessionId); writer.WriteFlip32(MessageId); writer.Write8((byte)MessageStatus); writer.WriteFlip32(AvailableMessageSize); writer.WriteFlip32(ClientNonce); dest.Write(header); }
public void Write(BufRefStream dest) { // Routers MUST set this (expire) field to all zeros. As of release 0.9.12, // a non-zero expiration field is again recognized, however we must // wait several releases to use this field, until the vast majority // of the network recognizes it. // TODO: Hmmm? dest.Write(Cost); Expiration.Write(dest); TransportStyle.Write(dest); Options.Write(dest); }
public void Write(BufRefStream dest) { var dest2 = new BufRefStream(); Destination.Write(dest2); Map.Write(dest2); Date.Write(dest2); var dest2data = dest2.ToArray(); var sig = new I2PSignature(new BufRefLen(I2PSignature.DoSign(PrivateSigningKey, new BufLen(dest2data))), PrivateSigningKey.Certificate); dest.Write(dest2data); sig.Write(dest); }
public override void Write(BufRefStream dest) { var header = new byte[3]; var writer = new BufRefLen(header); writer.WriteFlip16(SessionId); writer.Write8((byte)Leases.Count); dest.Write(header); for (int i = 0; i < Leases.Count; ++i) { Leases[i].Write(dest); } }
public override void Write( BufRefStream dest ) { var buf = new byte[3]; var writer = new BufRefLen( buf ); writer.WriteFlip16( SessionId ); writer.Write8( (byte)Leases.Count ); dest.Write( buf ); for ( int i = 0; i < Leases.Count; ++i ) { Leases[i].TunnelGw.Write( dest ); Leases[i].TunnelId.Write( dest ); } new I2PDate( DateTime.UtcNow.AddMinutes( 9 ) ).Write( dest ); }
public override void Write(BufRefStream dest) { var header = new byte[7]; var writer = new BufRefLen(header); writer.WriteFlip16(SessionId); writer.WriteFlip32(RequestId); writer.Write8((byte)ResultCode); dest.Write(header); if (ResultCode == HostLookupResults.Success) { Destination.Write(dest); } }
public virtual void Write(BufRefStream dest) { byte flag = Flag; if (SessionKey != null) { flag |= (byte)DeliveryFlags.Encrypted; } if (Delay != 0) { flag |= (byte)DeliveryFlags.Delay; } dest.Write(flag); if (SessionKey != null) { SessionKey.Write(dest); } }
public override void Write(BufRefStream dest) { dest.Write(BitConverter.GetBytes(SessionId)); var dummy = new I2PSigningPrivateKey(new I2PCertificate()); dummy.Write(dest); //Info.PrivateSigningKey.Write( dest ); Info.PrivateKey.Write(dest); Leases.Write(dest); /* * var ar = dest.ToArray(); * int ix = 22; * var pivk = new I2PPrivateKey( ar, ref ix ); * ix = 665; * var refpubk = new I2PPublicKey( ar, ref ix ); * var diff = ( new I2PPublicKey( pivk ) ).Key.Subtract( refpubk.Key ); * var ok = diff.CompareTo( BigInteger.Zero ) == 0; */ }
public void Write(BufRefStream dest) { // Not including options var headersize = 4 * 4 + 1 + NACKs.Count * 4 + 1 + 2 + 2; // Options var optionssize = (Flags & PacketFlags.FROM_INCLUDED) != 0 ? From.Size : 0; optionssize += (Flags & PacketFlags.SIGNATURE_INCLUDED) != 0 ? From.SigningPublicKey.Certificate.SignatureLength : 0; optionssize += (Flags & PacketFlags.MAX_PACKET_SIZE_INCLUDED) != 0 ? 2 : 0; optionssize += (Flags & PacketFlags.DELAY_REQUESTED) != 0 ? 2 : 0; var header = new BufLen(new byte[headersize + optionssize]); var writer = new BufRefLen(header); writer.WriteFlip32(SendStreamId); writer.WriteFlip32(ReceiveStreamId); writer.WriteFlip32(SequenceNumber); writer.WriteFlip32(AckTrhough); writer.Write8((byte)NACKs.Count); foreach (var nak in NACKs) { writer.WriteFlip32(nak); } writer.Write8(ResendDelay); writer.WriteFlip16((ushort)Flags); writer.WriteFlip16((ushort)optionssize); // Options order // DELAY_REQUESTED // FROM_INCLUDED if ((Flags & PacketFlags.FROM_INCLUDED) != 0) { writer.Write(From.ToByteArray()); } // MAX_PACKET_SIZE_INCLUDED if ((Flags & PacketFlags.MAX_PACKET_SIZE_INCLUDED) != 0) { writer.WriteFlip16(MTU); } // OFFLINE_SIGNATURE // SIGNATURE_INCLUDED if ((Flags & PacketFlags.SIGNATURE_INCLUDED) != 0) { writer.Write(I2PSignature.DoSign(SigningKey, header)); } #if DEBUG if (writer.Length != 0) { throw new InvalidOperationException("StreamingPacket Write buffer size error"); } #endif dest.Write((BufRefLen)header); dest.Write((BufRefLen)Payload); }
public void Write( BufRefStream dest ) { dest.Write( BufUtils.Flip64B( DateMilliseconds ) ); }
public override void Write(BufRefStream dest) { dest.Write((BufRefLen)BufUtils.Flip16BL(SessionId)); }
public void Write(BufRefStream dest) { dest.Write((BufRefLen)Hash); }
public override void Write(BufRefStream dest) { dest.Write(BufUtils.Flip16B(SessionId)); Config.Write(dest); }
public void Write(BufRefStream dest) { dest.Write(BitConverter.GetBytes(Id)); }
public void Write(BufRefStream dest) { dest.Write(Data); }
public void Write(BufRefStream dest) { dest.Write(ToByteArray()); }