rc4

fun rc4(secret: ByteArray, streamKey: Sha1Hash, outgoing: Boolean): MseEncryption

Build the RC4 handshake encryption context for one connection, given the DH shared secret, the stream key (v1 info-hash), and whether this peer is the one that initiated the connection (outgoing).

Mirrors init_pe_rc4_handler(secret, stream_key, outgoing) in bt_peer_connection.cpp:

  • outgoing peer: encrypt with keyA, decrypt with keyB

  • incoming peer: encrypt with keyB, decrypt with keyA

so that one side's outgoing stream is the other side's incoming stream.