def client(): io = SansIORW(encoding="utf-8") yield from io.write_struct("B", 5) yield from io.write_struct("BB", 1, 0) version, auth_method = yield from io.read_struct("BB") assert (version, auth_method) == (5, 0) yield from io.write_struct("4B", 5, 1, 0, 1) yield from io.write_struct("4sH", b"\x00" * 4, 666) version, command, zero, address_type = yield from io.read_struct("4B") assert (version, command, zero, address_type) == (5, 1, 0, 1) raise RuntimeError("connection failed")
def server(): io = SansIORW(encoding="utf-8") version, one, auth_method = yield from io.read_struct("BBB") assert (version, one, auth_method) == (5, 1, 0) yield from io.write_struct("BB", 5, 0) version, command, zero, address_type = yield from io.read_struct("4B") assert (version, command, zero, address_type) == (5, 1, 0, 1) ipv4, port = yield from io.read_struct("4sH") assert (ipv4, port) == (b"\x7f\x00\x00\x01", 666) yield from io.write_struct("4B", 6, 0, 0, 0) yield from io.passthrough()
def client(): io = SansIORW(encoding="utf-8") yield from io.write_struct("B", 5) yield from io.write_struct("BB", 1, 2) version, auth_method = yield from io.read_struct("BB") assert (version, auth_method) == (5, 2) yield from io.write_struct("B", 1) yield from io.write_pascal_string("yoba") yield from io.write_pascal_string("foo1") auth_version, retcode = yield from io.read_struct("BB") assert (auth_version, retcode) == (1, 1) yield from io.passthrough()
def client(): io = SansIORW(encoding="utf-8") yield from io.write_struct("B", 5) yield from io.write_struct("BB", 1, 0) version, auth_method = yield from io.read_struct("BB") assert (version, auth_method) == (5, 0) yield from io.write_struct("4B", 5, 1, 0, 4) yield from io.write_struct("16sH", b"\x00" * 16, 666) version, command, zero, address_type = yield from io.read_struct("4B") assert (version, command, zero, address_type) == (5, 0, 0, 1) ipv4, port = yield from io.read_struct("4sH") assert (ipv4, port) == (b"\x00" * 4, 0) yield from io.passthrough()
def server(): io = SansIORW(encoding="utf-8") version, one, auth_method = yield from io.read_struct("BBB") assert (version, one, auth_method) == (5, 1, 0) yield from io.write_struct("BB", 5, 0) version, command, zero, address_type = yield from io.read_struct("4B") assert (version, command, zero, address_type) == (5, 1, 0, 3) domain = yield from io.read_pascal_string() port = yield from io.read_struct("H") assert (domain, port) == ("python.org", 666) yield from io.write_struct("4B", 5, 0, 0, 1) yield from io.write(b"\x00" * 4) yield from io.write_struct("H", 0) yield from io.passthrough()
def server(): io = SansIORW(encoding="utf-8") version, one, auth_method = yield from io.read_struct("BBB") assert version == 5 assert one == 1 assert auth_method == 2 yield from io.write_struct("BB", 5, 2) auth_version = yield from io.read_struct("B") assert auth_version == 1 username = yield from io.read_pascal_string() password = yield from io.read_pascal_string() assert username == "yoba" assert password == "foo" yield from io.write_struct("BB", 1, 1) yield from io.passthrough()
def client(): io = SansIORW(encoding="utf-8") yield from io.write_struct("B", 5) yield from io.write_struct("BB", 1, 2) version, auth_method = yield from io.read_struct("BB") assert (version, auth_method) == (5, 2) yield from io.write_struct("B", 0) yield from io.passthrough()
def server(): io = SansIORW(encoding="utf-8") version, one, auth_method = yield from io.read_struct("BBB") assert version == 5 assert one == 1 assert auth_method == 0 yield from io.write_struct("BB", 5, 1) yield from io.passthrough()
def client(): io = SansIORW(encoding="utf-8") yield from io.write_struct("BBH4s", 4, 1, 123, b"\x7f\x00\x00\x01") yield from io.write_c_string("yoba") prefix, code, port, ipv4 = yield from io.read_struct("BBH4s") assert prefix == 0 assert code == 0x5a assert port == 0 assert ipv4 == b"\x00" * 4 yield from io.passthrough()
def client(): io = SansIORW(encoding="utf-8") yield from io.write_struct("BBH4s", 4, 1, 123, b"\x7f\x00\x00\x01") yield from io.write_c_string("yoba") prefix, code, port, ipv4 = yield from io.read_struct("BBH4s") assert prefix == 0 assert code == 0x5b assert port == 0 assert ipv4 == b"\x00" * 4 raise RuntimeError("connection failed")
def server(): io = SansIORW(encoding="utf-8") version, command, port, ipv4 = yield from io.read_struct("BBH4s") assert version == 4 assert command == 1 assert port == 123 assert ipv4 == b"\x7f\x00\x00\x01" user_id = yield from io.read_c_string() assert user_id == "yoba" yield from io.connect(ipv4, port) yield from io.write_struct("BBH4s", 0, 0x5a, 666, b"\x00" * 4) yield from io.passthrough()
def server(): io = SansIORW(encoding="utf-8") version, command, port, ipv4 = yield from io.read_struct("BBH4s") assert version == 4 assert command == 1 assert port == 123 assert ipv4 == b"\x00\x00\x00\xff" user_id = yield from io.read_c_string() assert user_id == "" host = yield from io.read_c_string() assert host == "python.org" yield from io.connect(host, port) yield from io.write_struct("BBH4s", 0, 0x5a, 0, b"\x00" * 4) yield from io.passthrough()