feat: implement NTCP2 protocol, native TCP transport, and live I2P interop
This commit is contained in:
1 parent
dff69dfac6
commit
e6d1c464dd
12 files changed
+2557
-2
No files matched your search
@@ -0,0 +1,125 @@
|
||||
// Generated using `moon info`, DON'T EDIT IT
|
||||
package "experiments/moon_i2p/ntcp2"
|
||||
|
||||
import {
|
||||
"experiments/moon_i2p/common",
|
||||
"experiments/moon_i2p/crypto",
|
||||
"experiments/moon_i2p/encoding",
|
||||
"experiments/moon_i2p/i2np",
|
||||
"experiments/moon_i2p/noise",
|
||||
"moonbitlang/core/debug",
|
||||
}
|
||||
|
||||
// Values
|
||||
pub fn decode_blocks(Bytes) -> Array[Ntcp2Block] raise Ntcp2Error
|
||||
|
||||
pub fn decode_i2np_block(Bytes) -> (@i2np.ShortHeader, @i2np.I2npPayload) raise Ntcp2Error
|
||||
|
||||
pub fn derive_siphash_params(Bytes, Bytes) -> SipHashParams
|
||||
|
||||
pub fn encode_blocks(Array[Ntcp2Block]) -> Bytes raise Ntcp2Error
|
||||
|
||||
pub fn i2np_block(UInt32, UInt32, @i2np.I2npPayload) -> Ntcp2Block raise Ntcp2Error
|
||||
|
||||
pub fn router_info_block(@common.RouterInfo, flood? : Bool) -> Ntcp2Block raise Ntcp2Error
|
||||
|
||||
// Errors
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub suberror Ntcp2Error {
|
||||
Crypto(@crypto.CryptoError)
|
||||
Noise(@noise.NoiseError)
|
||||
Encoding(@encoding.EncodingError)
|
||||
Common(@common.CommonError)
|
||||
I2np(@i2np.I2npError)
|
||||
InvalidState(String)
|
||||
InvalidFormat(String)
|
||||
InvalidLength(String)
|
||||
}
|
||||
|
||||
// Types and methods
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) enum Ntcp2Block {
|
||||
DateTime(UInt32)
|
||||
Options(Bytes)
|
||||
RouterInfo(flood_flag~ : Byte, router_info~ : Bytes)
|
||||
I2np(Bytes)
|
||||
Termination(valid_frames_received~ : UInt64, reason~ : Byte, additional_data~ : Bytes)
|
||||
Padding(Bytes)
|
||||
Unknown(Byte, Bytes)
|
||||
}
|
||||
pub fn Ntcp2Block::encode(Self, @encoding.Writer) -> Unit raise Ntcp2Error
|
||||
|
||||
pub struct Ntcp2DataSession {
|
||||
send_cipher : @noise.CipherState
|
||||
recv_cipher : @noise.CipherState
|
||||
send_mask : @noise.SipHashLengthMask
|
||||
recv_mask : @noise.SipHashLengthMask
|
||||
handshake_hash : Bytes
|
||||
remote_static : Bytes
|
||||
}
|
||||
pub fn Ntcp2DataSession::decrypt_frame(Self, Bytes) -> Array[Ntcp2Block] raise Ntcp2Error
|
||||
pub fn Ntcp2DataSession::decrypt_frame_body(Self, Bytes) -> Array[Ntcp2Block] raise Ntcp2Error
|
||||
pub fn Ntcp2DataSession::encrypt_frame(Self, Array[Ntcp2Block]) -> Bytes raise Ntcp2Error
|
||||
pub fn Ntcp2DataSession::handshake_hash(Self) -> Bytes
|
||||
pub fn Ntcp2DataSession::remote_static(Self) -> Bytes
|
||||
pub fn Ntcp2DataSession::unmask_frame_length(Self, Bytes) -> Int32 raise Ntcp2Error
|
||||
|
||||
pub struct Ntcp2Handshake {
|
||||
sym : @noise.SymmetricState
|
||||
initiator : Bool
|
||||
local_static : @noise.KeyPair
|
||||
mut local_ephemeral : @noise.KeyPair?
|
||||
mut remote_static : Bytes?
|
||||
mut remote_ephemeral : Bytes?
|
||||
responder_hash : Bytes
|
||||
published_iv : Bytes
|
||||
mut msg2_iv : Bytes
|
||||
mut m3p2_len : Int32
|
||||
mut step : Int32
|
||||
}
|
||||
pub fn Ntcp2Handshake::finish_read_session_created(Self, Bytes) -> Unit raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::finish_read_session_request(Self, Bytes) -> Unit raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::into_data_session(Self) -> Ntcp2DataSession raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::m3p2_len(Self) -> Int32
|
||||
pub fn Ntcp2Handshake::new_initiator(@noise.KeyPair, Bytes, Bytes, Bytes) -> Self raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::new_responder(@noise.KeyPair, Bytes, Bytes) -> Self raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::read_session_confirmed(Self, Bytes) -> Array[Ntcp2Block] raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::read_session_created(Self, Bytes) -> SessionCreatedOptions raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::read_session_created_head(Self, Bytes) -> SessionCreatedOptions raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::read_session_request(Self, Bytes) -> SessionRequestOptions raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::read_session_request_head(Self, Bytes) -> SessionRequestOptions raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::set_ephemeral(Self, @noise.KeyPair) -> Unit
|
||||
pub fn Ntcp2Handshake::write_session_confirmed(Self, Array[Ntcp2Block]) -> Bytes raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::write_session_created(Self, UInt32, padding? : Bytes) -> Bytes raise Ntcp2Error
|
||||
pub fn Ntcp2Handshake::write_session_request(Self, Int32, UInt32, padding? : Bytes, network_id? : Byte) -> Bytes raise Ntcp2Error
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) struct SessionCreatedOptions {
|
||||
pad_len : UInt32
|
||||
timestamp_sec : UInt32
|
||||
}
|
||||
pub fn SessionCreatedOptions::decode(Bytes) -> Self raise Ntcp2Error
|
||||
pub fn SessionCreatedOptions::encode(Self) -> Bytes
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) struct SessionRequestOptions {
|
||||
network_id : Byte
|
||||
version : Byte
|
||||
pad_len : UInt32
|
||||
m3p2_len : UInt32
|
||||
timestamp_sec : UInt32
|
||||
}
|
||||
pub fn SessionRequestOptions::decode(Bytes) -> Self raise Ntcp2Error
|
||||
pub fn SessionRequestOptions::encode(Self) -> Bytes
|
||||
|
||||
#derive(Eq, @debug.Debug)
|
||||
pub(all) struct SipHashParams {
|
||||
key_ab : Bytes
|
||||
iv_ab : Bytes
|
||||
key_ba : Bytes
|
||||
iv_ba : Bytes
|
||||
}
|
||||
|
||||
// Type aliases
|
||||
|
||||
// Traits
|
||||
Reference in new issue
Block a user