Skip to content

Commit

Permalink
chore: ip6
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed May 16, 2024
1 parent 8e5260d commit f503663
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
9 changes: 3 additions & 6 deletions packages/transport-webtransport/.aegir.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@ export default {
return {
goLibp2p,
env: {
GO_LIBP2P_ADDR_IP4: goLibp2p.ip4,
GO_LIBP2P_ADDR_IP6: goLibp2p.ip6,
DISABLE_IPV6: process.env.DISABLE_IPV6
GO_LIBP2P_ADDR: goLibp2p.multiaddr
}
}
},
Expand All @@ -34,7 +32,7 @@ async function createGoLibp2p () {
const deferred = pDefer()
const proc = execa(p2pd(), [
`-listen=${apiAddr.toString()}`,
'-hostAddrs=/ip4/127.0.0.1/udp/0/quic-v1/webtransport,/ip6/::1/udp/0/quic-v1/webtransport',
'-hostAddrs=/ip4/127.0.0.1/udp/0/quic-v1/webtransport',
'-noise=true',
'-dhtServer',
'-relay',
Expand Down Expand Up @@ -62,8 +60,7 @@ async function createGoLibp2p () {
return {
apiAddr,
peerId: id.peerId.toString(),
ip4: id.addrs.map(ma => ma.encapsulate(`/p2p/${id.peerId}`).toString()).filter(ma => ma.startsWith('/ip4')).pop(),
ip6: id.addrs.map(ma => ma.encapsulate(`/p2p/${id.peerId}`).toString()).filter(ma => ma.startsWith('/ip6')).pop(),
multiaddr: id.addrs.map(ma => ma.encapsulate(`/p2p/${id.peerId}`).toString()).pop(),
proc
}
}
39 changes: 12 additions & 27 deletions packages/transport-webtransport/test/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ describe('libp2p-webtransport', () => {
})

it('webtransport connects to go-libp2p', async () => {
if (process.env.GO_LIBP2P_ADDR_IP4 == null) {
throw new Error('GO_LIBP2P_ADDR_IP4 not found')
if (process.env.GO_LIBP2P_ADDR == null) {
throw new Error('GO_LIBP2P_ADDR not found')
}

const maStr: string = process.env.GO_LIBP2P_ADDR_IP4
const maStr: string = process.env.GO_LIBP2P_ADDR
const ma = multiaddr(maStr)

// Ping many times
Expand All @@ -56,11 +56,11 @@ describe('libp2p-webtransport', () => {
})

it('fails to connect without certhashes', async () => {
if (process.env.GO_LIBP2P_ADDR_IP4 == null) {
throw new Error('GO_LIBP2P_ADDR_IP4 not found')
if (process.env.GO_LIBP2P_ADDR == null) {
throw new Error('GO_LIBP2P_ADDR not found')
}

const maStr: string = process.env.GO_LIBP2P_ADDR_IP4
const maStr: string = process.env.GO_LIBP2P_ADDR
const maStrNoCerthash: string = maStr.split('/certhash')[0]
const maStrP2p = maStr.split('/p2p/')[1]
const ma = multiaddr(maStrNoCerthash + '/p2p/' + maStrP2p)
Expand All @@ -70,11 +70,11 @@ describe('libp2p-webtransport', () => {
})

it('fails to connect due to an aborted signal', async () => {
if (process.env.GO_LIBP2P_ADDR_IP4 == null) {
throw new Error('GO_LIBP2P_ADDR_IP4 not found')
if (process.env.GO_LIBP2P_ADDR == null) {
throw new Error('GO_LIBP2P_ADDR not found')
}

const maStr: string = process.env.GO_LIBP2P_ADDR_IP4
const maStr: string = process.env.GO_LIBP2P_ADDR
const ma = multiaddr(maStr)

const controller = new AbortController()
Expand All @@ -86,28 +86,13 @@ describe('libp2p-webtransport', () => {
expect(err.toString()).to.contain('aborted')
})

it('connects to ipv6 addresses', async function () {
if (process.env.DISABLE_IPV6 === 'true') {
return this.skip()
}
if (process.env.GO_LIBP2P_ADDR_IP6 == null) {
throw new Error('GO_LIBP2P_ADDR_IP6 not found')
}

const ma = multiaddr(process.env.GO_LIBP2P_ADDR_IP6)

// the address is unreachable but we can parse it correctly
const stream = await node.dialProtocol(ma, '/ipfs/ping/1.0.0')
await stream.close()
})

it('closes writes of streams after they have sunk a source', async () => {
// This is the behavior of stream muxers: (see mplex, yamux and compliance tests: https://github.com/libp2p/js-libp2p/blob/main/packages/interface-compliance-tests/src/stream-muxer/close-test.ts)
if (process.env.GO_LIBP2P_ADDR_IP4 == null) {
throw new Error('GO_LIBP2P_ADDR_IP4 not found')
if (process.env.GO_LIBP2P_ADDR == null) {
throw new Error('GO_LIBP2P_ADDR not found')
}

const maStr: string = process.env.GO_LIBP2P_ADDR_IP4
const maStr: string = process.env.GO_LIBP2P_ADDR
const ma = multiaddr(maStr)

const data = [
Expand Down

0 comments on commit f503663

Please sign in to comment.