Skip to content

Commit

Permalink
fix: change UDP code
Browse files Browse the repository at this point in the history
BREAKING CHANGE: The UDP code was changed in the multicodec table

The UDP code is now `273` instead of `17`. For the full discussion of this change
please see multiformats/multicodec#16.

Fixes #17.
  • Loading branch information
Stebalien committed Nov 28, 2018
1 parent 60251ad commit e8c3d7d
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ $ node
> addr.protos()
[
{code: 4, name: 'ip4', size: 32},
{code: 17, name: 'udp', size: 16}
{code: 273, name: 'udp', size: 16}
]

// gives you an object that is friendly with what Node.js core modules expect for addresses
Expand Down
4 changes: 2 additions & 2 deletions src/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Convert.toString = function convertToString (proto, buf) {
return ip.toString(buf)

case 6: // tcp
case 17: // udp
case 273: // udp
case 33: // dccp
case 132: // sctp
return buf2port(buf)
Expand All @@ -51,7 +51,7 @@ Convert.toBuffer = function convertToBuffer (proto, str) {
return ip2buf(new ipAddress.Address6(str))

case 6: // tcp
case 17: // udp
case 273: // udp
case 33: // dccp
case 132: // sctp
return port2buf(parseInt(str, 10))
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ Multiaddr.prototype.isThinWaistAddress = function isThinWaistAddress (addr) {
if (protos[0].code !== 4 && protos[0].code !== 41) {
return false
}
if (protos[1].code !== 6 && protos[1].code !== 17) {
if (protos[1].code !== 6 && protos[1].code !== 273) {
return false
}
return true
Expand Down
2 changes: 1 addition & 1 deletion src/protocols-table.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Protocols.V = V
Protocols.table = [
[4, 32, 'ip4'],
[6, 16, 'tcp'],
[17, 16, 'udp'],
[273, 16, 'udp'],
[33, 16, 'dccp'],
[41, 128, 'ip6'],
[54, V, 'dns4', 'resolvable'],
Expand Down
6 changes: 3 additions & 3 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ describe('requiring varint', () => {
describe('manipulation', () => {
it('basic', () => {
const udpAddrStr = '/ip4/127.0.0.1/udp/1234'
const udpAddrBuf = Buffer.from('047f0000011104d2', 'hex')
const udpAddrBuf = Buffer.from('047f000001910204d2', 'hex')
const udpAddr = multiaddr(udpAddrStr)

expect(udpAddr.toString()).to.equal(udpAddrStr)
expect(udpAddr.buffer).to.deep.equal(udpAddrBuf)

expect(udpAddr.protoCodes()).to.deep.equal([4, 17])
expect(udpAddr.protoCodes()).to.deep.equal([4, 273])
expect(udpAddr.protoNames()).to.deep.equal(['ip4', 'udp'])
expect(udpAddr.protos()).to.deep.equal([multiaddr.protocols.codes[4], multiaddr.protocols.codes[17]])
expect(udpAddr.protos()).to.deep.equal([multiaddr.protocols.codes[4], multiaddr.protocols.codes[273]])
expect(udpAddr.protos()[0] === multiaddr.protocols.codes[4]).to.equal(false)

const udpAddrBuf2 = udpAddr.encapsulate('/udp/5678')
Expand Down

0 comments on commit e8c3d7d

Please sign in to comment.