Document serverUp protocol
serverUp uses hex spaghetti to send and receive a short sequence of packets, to see whether a server is online. The packet format is now annotated for easier cross-reference with minetest source.
This commit is contained in:
parent
e49da8f1b9
commit
a2b47ff52b
23
server.py
23
server.py
@ -142,14 +142,37 @@ def serverUp(info):
|
|||||||
sock = socket.socket(info[0], info[1], info[2])
|
sock = socket.socket(info[0], info[1], info[2])
|
||||||
sock.settimeout(3)
|
sock.settimeout(3)
|
||||||
sock.connect(info[4])
|
sock.connect(info[4])
|
||||||
|
# send packet of type ORIGINAL, with no data
|
||||||
|
# this should prompt the server to assign us a peer id
|
||||||
|
# [0] u32 protocol_id (PROTOCOL_ID)
|
||||||
|
# [4] session_t sender_peer_id (PEER_ID_INEXISTENT)
|
||||||
|
# [6] u8 channel
|
||||||
|
# [7] u8 type (PACKET_TYPE_ORIGINAL)
|
||||||
buf = b"\x4f\x45\x74\x03\x00\x00\x00\x01"
|
buf = b"\x4f\x45\x74\x03\x00\x00\x00\x01"
|
||||||
sock.send(buf)
|
sock.send(buf)
|
||||||
start = time.time()
|
start = time.time()
|
||||||
|
# receive reliable packet of type CONTROL, subtype SET_PEER_ID,
|
||||||
|
# with our assigned peer id as data
|
||||||
|
# [0] u32 protocol_id (PROTOCOL_ID)
|
||||||
|
# [4] session_t sender_peer_id
|
||||||
|
# [6] u8 channel
|
||||||
|
# [7] u8 type (PACKET_TYPE_RELIABLE)
|
||||||
|
# [8] u16 seqnum
|
||||||
|
# [10] u8 type (PACKET_TYPE_CONTROL)
|
||||||
|
# [11] u8 controltype (CONTROLTYPE_SET_PEER_ID)
|
||||||
|
# [12] session_t peer_id_new
|
||||||
data = sock.recv(1024)
|
data = sock.recv(1024)
|
||||||
end = time.time()
|
end = time.time()
|
||||||
if not data:
|
if not data:
|
||||||
return False
|
return False
|
||||||
peer_id = data[12:14]
|
peer_id = data[12:14]
|
||||||
|
# send packet of type CONTROL, subtype DISCO,
|
||||||
|
# to cleanly close our server connection
|
||||||
|
# [0] u32 protocol_id (PROTOCOL_ID)
|
||||||
|
# [4] session_t sender_peer_id
|
||||||
|
# [6] u8 channel
|
||||||
|
# [7] u8 type (PACKET_TYPE_CONTROL)
|
||||||
|
# [8] u8 controltype (CONTROLTYPE_DISCO)
|
||||||
buf = b"\x4f\x45\x74\x03" + peer_id + b"\x00\x00\x03"
|
buf = b"\x4f\x45\x74\x03" + peer_id + b"\x00\x00\x03"
|
||||||
sock.send(buf)
|
sock.send(buf)
|
||||||
sock.close()
|
sock.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user