Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: ipv6 multiaddr in stdout (#1854)
Browse files Browse the repository at this point in the history
Fixes #1853 

License: MIT
Signed-off-by: Marcin Rataj <[email protected]>
  • Loading branch information
lidel authored and Alan Shaw committed Feb 11, 2019
1 parent e30600b commit 35fd541
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
"mime-types": "^2.1.21",
"mkdirp": "~0.5.1",
"multiaddr": "^6.0.0",
"multiaddr-to-uri": "^4.0.0",
"multiaddr-to-uri": "^4.0.1",
"multibase": "~0.6.0",
"multihashes": "~0.4.14",
"multihashing-async": "~0.5.1",
Expand Down Expand Up @@ -175,6 +175,7 @@
"tar-stream": "^2.0.0",
"temp": "~0.9.0",
"update-notifier": "^2.5.0",
"uri-to-multiaddr": "^3.0.1",
"varint": "^5.0.0",
"yargs": "^12.0.5",
"yargs-promise": "^1.1.0"
Expand Down
22 changes: 16 additions & 6 deletions src/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ const Pino = require('hapi-pino')
const debug = require('debug')
const multiaddr = require('multiaddr')
const promisify = require('promisify-es6')
const toUri = require('multiaddr-to-uri')
const toMultiaddr = require('uri-to-multiaddr')

const IPFS = require('../core')
const WStar = require('libp2p-webrtc-star')
Expand All @@ -14,9 +16,17 @@ const WS = require('libp2p-websockets')
const Bootstrap = require('libp2p-bootstrap')
const errorHandler = require('./error-handler')

function uriToMultiaddr (uri) {
const ipPort = uri.split('/')[2].split(':')
return `/ip4/${ipPort[0]}/tcp/${ipPort[1]}`
function hapiInfoToMultiaddr (info) {
let hostname = info.host
let uri = info.uri
// ipv6 fix
if (hostname.includes(':') && !hostname.startsWith('[')) {
// hapi 16 produces invalid URI for ipv6
// we fix it here by restoring missing square brackets
hostname = `[${hostname}]`
uri = uri.replace(`://${info.host}`, `://${hostname}`)
}
return toMultiaddr(uri)
}

class HttpApi {
Expand Down Expand Up @@ -82,7 +92,7 @@ class HttpApi {
const apiAddr = config.Addresses.API.split('/')
const apiServer = await this._createApiServer(apiAddr[2], apiAddr[4], ipfs)
await apiServer.start()
apiServer.info.ma = uriToMultiaddr(apiServer.info.uri)
apiServer.info.ma = hapiInfoToMultiaddr(apiServer.info)
this._apiServer = apiServer

// for the CLI to know the where abouts of the API
Expand All @@ -91,12 +101,12 @@ class HttpApi {
const gatewayAddr = config.Addresses.Gateway.split('/')
const gatewayServer = await this._createGatewayServer(gatewayAddr[2], gatewayAddr[4], ipfs)
await gatewayServer.start()
gatewayServer.info.ma = uriToMultiaddr(gatewayServer.info.uri)
gatewayServer.info.ma = hapiInfoToMultiaddr(gatewayServer.info)
this._gatewayServer = gatewayServer

ipfs._print('API listening on %s', apiServer.info.ma)
ipfs._print('Gateway (read only) listening on %s', gatewayServer.info.ma)
ipfs._print('Web UI available at %s', apiServer.info.uri + '/webui')
ipfs._print('Web UI available at %s', toUri(apiServer.info.ma) + '/webui')
this._log('started')
return this
}
Expand Down

0 comments on commit 35fd541

Please sign in to comment.