Skip to content

Commit 737b3ea

Browse files
authored
fix: parameterise max message size in SDP messages (#2681)
Do not hard code the `max-message-size` SDP directive, instead reuse the `MAX_MESSAGE_SIZE` constant.
1 parent 2265e59 commit 737b3ea

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

packages/transport-webrtc/src/private-to-public/sdp.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { type Multiaddr } from '@multiformats/multiaddr'
22
import { bases, digest } from 'multiformats/basics'
33
import { inappropriateMultiaddr, invalidArgument, invalidFingerprint, unsupportedHashAlgorithmCode } from '../error.js'
4+
import { MAX_MESSAGE_SIZE } from '../stream.js'
45
import { CERTHASH_CODE } from './transport.js'
56
import type { LoggerOptions } from '@libp2p/interface'
67
import type { MultihashDigest } from 'multiformats/hashes/interface'
@@ -42,6 +43,7 @@ export function getFingerprintFromSdp (sdp: string): string | undefined {
4243
const searchResult = sdp.match(fingerprintRegex)
4344
return searchResult?.groups?.fingerprint
4445
}
46+
4547
/**
4648
* Get base2 | identity decoders
4749
*/
@@ -127,7 +129,7 @@ a=ice-ufrag:${ufrag}
127129
a=ice-pwd:${ufrag}
128130
a=fingerprint:${CERTFP}
129131
a=sctp-port:5000
130-
a=max-message-size:16384
132+
a=max-message-size:${MAX_MESSAGE_SIZE}
131133
a=candidate:1467250027 1 UDP 1467250027 ${host} ${port} typ host\r\n`
132134
}
133135

packages/transport-webrtc/test/sdp.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { multiaddr } from '@multiformats/multiaddr'
22
import { expect } from 'aegir/chai'
33
import * as underTest from '../src/private-to-public/sdp.js'
4+
import { MAX_MESSAGE_SIZE } from '../src/stream.js'
45

56
const sampleMultiAddr = multiaddr('/ip4/0.0.0.0/udp/56093/webrtc/certhash/uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ')
67
const sampleCerthash = 'uEiByaEfNSLBexWBNFZy_QB1vAKEj7JAXDizRs4_SnTflsQ'
@@ -17,7 +18,7 @@ a=ice-ufrag:MyUserFragment
1718
a=ice-pwd:MyUserFragment
1819
a=fingerprint:SHA-256 72:68:47:CD:48:B0:5E:C5:60:4D:15:9C:BF:40:1D:6F:00:A1:23:EC:90:17:0E:2C:D1:B3:8F:D2:9D:37:E5:B1
1920
a=sctp-port:5000
20-
a=max-message-size:16384
21+
a=max-message-size:${MAX_MESSAGE_SIZE}
2122
a=candidate:1467250027 1 UDP 1467250027 0.0.0.0 56093 typ host`
2223

2324
describe('SDP', () => {
@@ -72,7 +73,7 @@ a=ice-ufrag:someotheruserfragmentstring
7273
a=ice-pwd:someotheruserfragmentstring
7374
a=fingerprint:SHA-256 72:68:47:CD:48:B0:5E:C5:60:4D:15:9C:BF:40:1D:6F:00:A1:23:EC:90:17:0E:2C:D1:B3:8F:D2:9D:37:E5:B1
7475
a=sctp-port:5000
75-
a=max-message-size:16384
76+
a=max-message-size:${MAX_MESSAGE_SIZE}
7677
a=candidate:1467250027 1 UDP 1467250027 0.0.0.0 56093 typ host`
7778

7879
expect(result.sdp).to.equal(expected)

0 commit comments

Comments
 (0)