AoS URLs
AoS uses urls like "aos://1124169524:43887" to encode the ip and port of a server. This is a guide on how to parse them.
Parsing Algorithm
- strip protocol prefix (e.g. "aos://" -> "1124169524:43887")
- search for colon (e.g. ":" -> "1124169524" ":" "43887")
- if none found
- port is default port (32887)
- if found
- split at colon (e.g. ":" -> "1124169524" ":" "43887")
- port is second part
- continue with first part
- if none found
- search for dot (e.g. "." -> none found in "1124169524")
- if at least one (or better, exactly four) found (e.g. "192.168.1.1")
- URL is IP
- if none found
- URL is an integer address, parse it as explained here
- if at least one (or better, exactly four) found (e.g. "192.168.1.1")
Decoding integer addresses
The integer address is a 32-bit integer that represents the IP address. The IP address is encoded in big-endian. It can be decoded by using the following algorithm:
- to get the four IP parts:
- apply bitwise AND with 255 (e.g., "1124169524" & 255 -> 52)
- right-shift the URL by 8 bits and then apply bitwise AND with 255 (e.g., ("1124169524" >> 8) & 255 -> 119)
- right-shift the URL by 16 bits and then apply bitwise AND with 255 (e.g., ("1124169524" >> 16) & 255 -> 1)
- right-shift the URL by 24 bits and apply bitwise AND with 255 (e.g., ("1124169524" >> 24) & 255 -> 67)
- the four IP parts are 52, 119, 1, 67
- join the parts with dots (e.g. "52.119.1.67")
Example JS code:
let ip = ${url & 255}.${(url >> 8) & 255}.${(url >> 16) & 255}.${(url >> 24) & 255}