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
Browse files Browse the repository at this point in the history
Fixes #1853

License: MIT
Signed-off-by: Marcin Rataj <lidel@lidel.org>
  • Loading branch information
lidel committed Jan 30, 2019
1 parent bbe561b commit 95cc1c2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,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": "^1.6.2",
"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
24 changes: 16 additions & 8 deletions src/http/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
const series = require('async/series')
const Hapi = require('hapi')
const debug = require('debug')
const multiaddr = require('multiaddr')
const toUri = require('multiaddr-to-uri')
const toMultiaddr = require('uri-to-multiaddr')
const setHeader = require('hapi-set-header')
const once = require('once')

Expand All @@ -15,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 serverInfoToMultiaddr (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)
}

function HttpApi (repo, config, cliArgs) {
Expand Down Expand Up @@ -162,13 +171,12 @@ function HttpApi (repo, config, cliArgs) {
(cb) => {
const api = this.server.select('API')
const gateway = this.server.select('Gateway')
this.apiMultiaddr = multiaddr('/ip4/127.0.0.1/tcp/' + api.info.port)
api.info.ma = uriToMultiaddr(api.info.uri)
gateway.info.ma = uriToMultiaddr(gateway.info.uri)
api.info.ma = serverInfoToMultiaddr(api.info)
gateway.info.ma = serverInfoToMultiaddr(gateway.info)

this.node._print('API listening on %s', api.info.ma)
this.node._print('Gateway (read only) listening on %s', gateway.info.ma)
this.node._print('Web UI available at %s', api.info.uri + '/webui')
this.node._print('Web UI available at %s', toUri(api.info.ma) + '/webui')

// for the CLI to know the where abouts of the API
this.node._repo.apiAddr.set(api.info.ma, cb)
Expand Down

0 comments on commit 95cc1c2

Please sign in to comment.