Skip to content

Commit

Permalink
Merge pull request #73 from multiformats/fix/72
Browse files Browse the repository at this point in the history
fix UDP code
  • Loading branch information
victorb authored Nov 28, 2018
2 parents 60251ad + 627978c commit 59d3663
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 10 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
8 changes: 4 additions & 4 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 Expand Up @@ -514,7 +514,7 @@ describe('helpers', () => {

it('throws on missing transport', () => {
expect(
() => multiaddr.fromNodeAddress({address: '0.0.0.0'})
() => multiaddr.fromNodeAddress({ address: '0.0.0.0' })
).to.throw(
/requires transport protocol/
)
Expand Down
2 changes: 1 addition & 1 deletion test/protocols.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('protocols', () => {

it('else', () => {
expect(
() => protocols({hi: 34})
() => protocols({ hi: 34 })
).to.throw(
/invalid protocol id type/
)
Expand Down

0 comments on commit 59d3663

Please sign in to comment.