This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactory: async with multiaddr conn
- Loading branch information
1 parent
20358d3
commit 382b37a
Showing
16 changed files
with
389 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,4 @@ | ||
docs | ||
node_modules | ||
package-lock.json | ||
yarn.lock | ||
|
||
# Logs | ||
logs | ||
*.log | ||
npm-debug.log* | ||
|
||
# Runtime data | ||
pids | ||
*.pid | ||
*.seed | ||
|
||
# Directory for instrumented libs generated by jscoverage/JSCover | ||
lib-cov | ||
|
||
# Coverage directory used by tools like istanbul | ||
coverage | ||
.nyc_output | ||
|
||
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) | ||
.grunt | ||
|
||
# node-waf configuration | ||
.lock-wscript | ||
|
||
# Compiled binary addons (http://nodejs.org/api/addons.html) | ||
build/Release | ||
|
||
# Dependency directory | ||
node_modules | ||
|
||
# Optional npm cache directory | ||
.npm | ||
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
# Vim editor swap files | ||
*.swp | ||
|
||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict' | ||
|
||
// p2p multi-address code | ||
exports.CODE_P2P = 421 | ||
exports.CODE_CIRCUIT = 290 | ||
|
||
// Time to wait for a connection to close gracefully before destroying it manually | ||
exports.CLOSE_TIMEOUT = 2000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
const multiaddr = require('multiaddr') | ||
const { Address4, Address6 } = require('ip-address') | ||
|
||
module.exports = (ip, port) => { | ||
if (typeof ip !== 'string') { | ||
throw new Error('invalid ip') | ||
} | ||
|
||
port = parseInt(port) | ||
|
||
if (isNaN(port)) { | ||
throw new Error('invalid port') | ||
} | ||
|
||
if (new Address4(ip).isValid()) { | ||
return multiaddr(`/ip4/${ip}/tcp/${port}`) | ||
} | ||
|
||
const ip6 = new Address6(ip) | ||
|
||
if (ip6.isValid()) { | ||
return ip6.is4() | ||
? multiaddr(`/ip4/${ip6.to4().correctForm()}/tcp/${port}`) | ||
: multiaddr(`/ip6/${ip}/tcp/${port}`) | ||
} | ||
|
||
throw new Error('invalid ip') | ||
} |
Oops, something went wrong.