diff options
author | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2019-02-04 00:02:39 -1000 |
---|---|---|
committer | cel <cel@f/6sQ6d2CMxRUhLpspgGIulDxDCwYD7DzFzPNr7u5AU=.ed25519> | 2019-02-04 00:12:55 -1000 |
commit | be9a1da05281cc6c1c3569d2822ba8ff6e611c7b (patch) | |
tree | d84ce14818e799383c29186ad5ff0f975ed68dd2 /lib/util.js | |
parent | 54f2f24d48151bdcd501bcc58bb8934e9cef08a4 (diff) | |
download | patchfoo-be9a1da05281cc6c1c3569d2822ba8ff6e611c7b.tar.gz patchfoo-be9a1da05281cc6c1c3569d2822ba8ff6e611c7b.zip |
Show addresses more compactly
Handle missing port
Diffstat (limited to 'lib/util.js')
-rw-r--r-- | lib/util.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/util.js b/lib/util.js index 4fdbc24..731cc82 100644 --- a/lib/util.js +++ b/lib/util.js @@ -266,3 +266,15 @@ u.truncate = function (str, len) { str = String(str) return str.length > len ? str.substr(0, len) + '...' : str } + +u.extractHostPort = function (id, addr) { + var i = addr.lastIndexOf(':' + id) + if (i > -1 && addr.length === i + id.length + 1) { + return addr.substr(0, i) + } + var m = /^(?:net|onion):([^~;]*(?::[0-9]*)?)~shs:([0-9a-zA-Z/=+]{44})$/.exec(addr) + if (m && id === '@' + m[2] + '.ed25519') { + return m[1] + } + return addr +} |