filepizza icon indicating copy to clipboard operation
filepizza copied to clipboard

Want shorter URLs?

Open StoneCypher opened this issue 9 months ago • 2 comments

Hiya. Peer to peer WebRTC is an interest of mine, too.

I hate the beacons. They're stupidly long, and they don't conveniently fit into URLs.

So I wrote an extremely aggressive parser compressor for beacons, which gets them small enough to go into URLs in a reasonable way.

 

 

Heavy example

By example, here's Chrome 92's host beacon on Windows 10.

Original 1866 bytes, packed 337 bytes, URL encoded 577 characters

{"type":"offer","sdp":"v=0
o=- 1199580080461629164 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE 0
a=extmap-allow-mixed
a=msid-semantic: WMS
m=application 59267 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 73.162.196.213
a=candidate:2254048910 1 udp 2122262783 2601:645:8400:6c20:a0ed:463d:b3d9:2e5b 59265 typ host generation 0 network-id 2
a=candidate:794956039 1 udp 2122197247 2601:645:8400:6c20::a610 59266 typ host generation 0 network-id 3
a=candidate:1191081017 1 udp 2122129151 10.0.0.163 59267 typ host generation 0 network-id 1
a=candidate:3293969885 1 udp 2122063615 172.18.80.1 59268 typ host generation 0 network-id 4
a=candidate:3282507946 1 udp 2121998079 172.30.0.1 59269 typ host generation 0 network-id 5
a=candidate:3423470964 1 udp 2121932543 172.21.32.1 59270 typ host generation 0 network-id 6
a=candidate:2782917333 1 udp 1685921535 73.162.196.213 59267 typ srflx raddr 10.0.0.163 rport 59267 generation 0 network-id 1
a=candidate:3369726590 1 tcp 1518283007 2601:645:8400:6c20:a0ed:463d:b3d9:2e5b 9 typ host tcptype active generation 0 network-id 2
a=candidate:1642196471 1 tcp 1518217471 2601:645:8400:6c20::a610 9 typ host tcptype active generation 0 network-id 3
a=candidate:142444745 1 tcp 1518149375 10.0.0.163 9 typ host tcptype active generation 0 network-id 1
a=candidate:2329280813 1 tcp 1518083839 172.18.80.1 9 typ host tcptype active generation 0 network-id 4
a=candidate:2368005210 1 tcp 1518018303 172.30.0.1 9 typ host tcptype active generation 0 network-id 5
a=candidate:2190342532 1 tcp 1517952767 172.21.32.1 9 typ host tcptype active generation 0 network-id 6
a=ice-ufrag:h2zg
a=ice-pwd:rLDrcPyQHODnE5SBbDM0vAHf
a=fingerprint:sha-256 F2:7A:3A:54:09:D3:6B:62:39:A2:21:5E:87:92:12:90:7C:D9:9C:F6:CC:9B:A4:62:BD:99:59:18:88:F7:92:BD
a=setup:actpass
a=mid:0
a=sctp-port:5000
a=max-message-size:262144
"}

And here it is compressed and URL encoded:

K​A​S​Q​R​Q​I​w​q​w​U​A​A​H​A​x​Q​G​o​E​g​A​U​C​A​y​B​4​d​s​C​o​A​B​J​g​E​A​B​k​m​A​Y​A​K​I​A​h​c​A​N​k​Q​A​U​C​3​A​Y​g​L​w​D​N​A​m​w​D​o​A​2​p​V​o​N​m​C​S​X​A​B​l​A​B​E​w​B​g​A​M​i​y​A​p​Q​G​G​A​X​Q​H​4​A​M​Q​D​G​A​N​6​U​y​y​A​i​A​F​I​A​E​A​H​A​A​l​A​H​O​A​w​Q​A​p​S​O​A​G​E​A​t​A​H​A​A​4​z​A​A​-​A​H​8​X​A​H​+​4​B​w​B​A​9​w​B​6​A​C​M​z​G​y​D​A​8​M​w​H​A​C​C​F​A​g​4​A​P​4​A​X​A​E​4​g​g​F​8​c​M​I​V​n​T​A​I​I​A​F​U​A​X​4​B​d​o​I​A​f​c​o​A​Q​B​z​p​2​g​n​U​A​c​o​A​M​A​C​q​g​g​G​9​y​4​A​c​A​U​O​A​C​A​B​m​f​Y​H​y​g​g​C​9​y​q​g​c​P​K​g​B​c​V​Q​B​9​g​C​e​o​T​A​A​T​M​r​D​S​Z​0​q​n​T​A​A​c​A​A​m​+​A​8​D​M​L​1​C​I​w​r​g​A​J​j​h​b​g​E​M​A​I​d​s​A​D​v​r​1​S​Y​U​w​n​w​A​z​H​A​A​N​h​W​E​o​A​C​I​A​k​6​9​z​g​p​P​g​B​G​O​E​A​K​I​A​a​5​g​A​L​S​v​N​p​h​d​q​f​A​A​s​c​I​A​s​Q​A​S​A​A​n​X​l​e​4​z​C​w​E​+​A​F​Y​4​R​l​q​Q​B​P​u​i​v​N​Z​h​K​i​f​A​B​s​c​A​A​R​A​A​L​L​4​r​A​D​m​c​C​I​A​C​c​A​D​I​A​E​U​V​A​G​N​0​A​B​P​A​C​K​A​A​k​A​P​K​q​g​B​2​N​H​Z​A​G​U​A​E​L​x​V​U​A​W​Q​A​D​A​A​3​A​C​C​+​o​A​Z​n​B​a​Q​c​V​g​A​u​A​A​q​A​E​g​A​M​s​A​a​3​i​h​T​A​A​E​I​A​H​o​A​c​I​A​S​a​g​A​A​k​t​P​g​A​H​I​A​b​3​M​A​N​k​A​E​v​i​A​F​6​A​J​k​A​T​Q​G​i​O​B​C​c​L​A​F​g​A​P​C​B​g​D​Q​Q​A

 

 

Practical example

This is a more modern Chrome 120 host beacon from Windows 11, about 1/5 the size.

Original 488 bytes, packed 95 bytes, URL encoded 204 characters

{ "type": "offer", "sdp": "v=0
o=- 2567065588211027114 2 IN IP4 127.0.0.1
s=-
t=0 0
a=group:BUNDLE 0
a=extmap-allow-mixed
a=msid-semantic: WMS
m=application 9 UDP/DTLS/SCTP webrtc-datachannel
c=IN IP4 0.0.0.0
a=ice-ufrag:RgDu
a=ice-pwd:rZiEmiBHAHvzyVcAlraBu/kh
a=ice-options:trickle
a=fingerprint:sha-256 7B:86:40:3D:2E:56:D5:A4:EC:40:E5:AC:E8:93:53:BA:3A:BD:F8:65:61:40:D9:EA:59:B8:00:76:7D:51:20:03
a=setup:actpass
a=mid:0
a=sctp-port:5000
a=max-message-size:262144
" }

Which becomes

A​D​C​A​G​A​G​Q​G​I​A​K​B​g​C​x​A​W​A​T​g​G​I​F​U​C​B​Q​A​Q​B​E​A​U​g​A​g​B​w​A​S​m​A​E​g​A​K​Y​A​I​g​C​U​B​z​A​E​Q​F​d​g​A​C​V​A​L​Q​C​W​A​U​Q​C​2​A​g​E​I​A​J​A​I​K​S​A​b​g​C​8​A​n​g​D​U​A​x​t​I​A​2​q​A​I​b​i​O​A​e​g​D​W​A​C​2​A​A​q​A​C​Q​B​v​A​G​E​A​B​A​L​w​A​6​F​Q​F​W​A​J​Q​B​v​7​A​U​4​A​1​A​B​c​A​y​Q​D​K​A​F​0​A​X​A​C​9​A​B​8​A​p​j​r​2​A​J​s​A​V​w​C​a​A​B​3​A​c​g​C​+​A​I​r​c​4​A​C​w​A​P​D​U​A​N​B​A​A

StoneCypher avatar Mar 13 '25 13:03 StoneCypher

These sizes will come down a lot soon, when I start removing fields from the beacon and seeing what still works (obviously an optional, non-default change)

StoneCypher avatar Mar 13 '25 13:03 StoneCypher

Happy to accept a PR for this!

kern avatar Mar 31 '25 04:03 kern