Comments (5)
The code has been added to the protocol table but convert.js
likely needs to be updated to handle the conversion. Adding some tests for various onion addresses and fixing the conversion code where needed would be the best path forward. Happy to review a PR if you'd be up for submitting one! :)
from js-multiaddr.
Hi Jacob, thanks for the feedback. I changed the convert.js file to handle the onion and onion3 cases using the str2buf(str)
function, but I really don't know if this is correct. I'm still getting an error: in bufferToTuples
the size of the address that you get from
let size = sizeForAddr(p, buf.slice(i + n))
is not correct. I suppose I'm doing something wrong, but I'm kinda lost now.
from js-multiaddr.
I'm not very familiar with onion addresses but looking at the go implementation there will need to be more in depth parsing of the string than just using str2buf
. You can look at how go is doing the onion and onion3 transcoding, https://github.com/multiformats/go-multiaddr/blob/0460aad0fe51f7aa64d3a3c17854dc25368f7ca2/transcoders.go#L128-L213. The string needs to be split by :
to determine the port.
It would also be good to leverage the same bad and good onion addresses from the go test suite when testing here.
from js-multiaddr.
Ok, I added the following to converter.js:
const base32 = require('hi-base32')
function onion2buf(str) {
const addr = str.split(':')
if (addr.length !== 2) {
throw new Error('failed to parse onion addr: ' + addr + ' does not contain a port number')
}
if (addr[0].length !== 16) {
throw new Error('failed to parse onion addr: ' + addr[0] + ' not a Tor onion address.')
}
const buf = Buffer.from(base32.decode.asBytes(addr[0].toUpperCase()))
const size = Buffer.from(varint.encode(buf.length))
//onion port number
const port = parseInt(addr[1], 10);
if (port < 1 || port > 65536) {
throw new Error("Port number is not in range(1, 65536)")
}
const portBuf = port2buf(port)
return Buffer.concat([buf, portBuf])
}
I checked it against the python implementation and it gives the same result. I still have to understand your code 100%, but I think the general direction is correct. I'll finish up with the onion3 protocol and submit a pull in the next days.
from js-multiaddr.
Released in 6.1.0
from js-multiaddr.
Related Issues (20)
- Add a static method `isValid` HOT 2
- Adding types to DefinitelyTyped HOT 3
- Export Multiaddr to allow type checking HOT 2
- Export types HOT 2
- DeprecationWarning: Custom inspection function on Objects via .inspect() is deprecated HOT 1
- Current ipv6 implementation doesn't account for interface HOT 3
- Add tls to protocoltables
- Compile problem when using latest multiaddr in a browser app HOT 1
- No documentation for getPeerId() HOT 3
- Replace Multiaddr class with an interface HOT 1
- Outdated README.md HOT 1
- The automated release is failing 🚨
- Transitive dependency on `node-fetch` HOT 1
- Add /webrtc and /certhash HOT 2
- [ERR_MODULE_NOT_FOUND]: Cannot find package 'dns' imported from /Users/javaspeak/workspace3/symbiont/permanent_node/server/node_modules/@multiformats/multiaddr/dist/src/resolvers/dns.js HOT 1
- Drop is-ip dependency with alternative IP parsing fn HOT 2
- Reference to non-existent js file from ts HOT 4
- bug: new kubo/ipfs/libp2p protocols break JS ecosystem HOT 2
- getPeerId can return an unexpected peer id HOT 1
- Respect `.../ipfs/...` when it is passed? HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from js-multiaddr.