Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Method Transport#filter() doesn't matches unix sockets #132

Closed
rumkin opened this issue May 25, 2020 · 2 comments · Fixed by #229
Closed

Method Transport#filter() doesn't matches unix sockets #132

rumkin opened this issue May 25, 2020 · 2 comments · Fixed by #229
Labels
exp/novice Someone with a little familiarity can pick up kind/bug A bug in existing code (including security flaws) P2 Medium: Good to have, but can wait until someone steps up released status/ready Ready to be worked

Comments

@rumkin
Copy link

rumkin commented May 25, 2020

According to the source code, TCP transport method Transport#filter() relies on mafmt's TCP matcher function (mafmt /src/index.js:18) which doesn't match unix sockets: src/index.js:135. So it's impossible to listen unix sockets. And attempts to provide unix path to Transport fails:

import path from 'path'

import Libp2p from 'libp2p'
import Tcp from 'libp2p-tcp'
import Mplex from 'libp2p-mplex'
import PeerId from 'peer-id'
import PeerInfo from 'peer-info'
import Plaintext from 'libp2p/src/insecure/plaintext.js'



const serverPeer = await PeerId.create()
const serverInfo = new PeerInfo(serverPeer)

serverInfo.multiaddrs.add(
  path.join('/unix', path.resolve('unix.sock'))
)

const node = await Libp2p.create({
    peerInfo: serverInfo,
    modules: {
      transport: [Tcp],
      connEncryption: [Plaintext],
      streamMuxer: [Mplex],
    },
})

The code throws ERR_NO_VALID_ADDRESSES. I'm not sure if it the TCP or mafmt package error. I'm not sure if it the TCP or mafmt package error, but while it's hard to understand which protocol is unix port listening I think it relates to this package.

@jacobheun jacobheun added kind/bug A bug in existing code (including security flaws) exp/novice Someone with a little familiarity can pick up P2 Medium: Good to have, but can wait until someone steps up status/ready Ready to be worked labels Jun 1, 2020
@jacobheun
Copy link
Contributor

Filter needs to be updated here to check for tcp and unix multiaddrs. Unix could be added to the mafmt module, but that's probably unnecessary right now since we only support a single structure to the address (/unix/<path>).

achingbrain pushed a commit that referenced this issue Sep 14, 2022
This PR adds the functionality to handle UNIX domain sockets.

* This works with plain `/unix` multiaddresses but is unable to handle p2p encapsulated addresses (`/unix/.../p2p/...`) due to ambiguity. Because of this it causes errors when attempting to use `/unix` addresses in js-libp2p because it appends the `/p2p` address.
* On Windows this uses named pipes instead.

Despite the fact that it does not work with `/unix` addresses in js-libp2p directly, this still remains useful and is needed in other projects like [js-libp2p-daemon](https://github.com/libp2p/js-libp2p-daemon).

Refs #132.

Co-authored-by: saul <saul@organicdesign.nz>
github-actions bot pushed a commit that referenced this issue Sep 14, 2022
## [3.1.0](v3.0.8...v3.1.0) (2022-09-14)

### Features

* Unix domain sockets ([#208](#208)) ([223f79b](223f79b)), closes [#132](#132)
github-actions bot pushed a commit that referenced this issue Nov 17, 2022
## [6.0.2](v6.0.1...v6.0.2) (2022-11-17)

### Bug Fixes

* update metric names to follow prometheus naming guide ([#228](#228)) ([24c5b37](24c5b37))

### Trivial Changes

* add test for filtering unix socket address ([#229](#229)) ([efcfbb2](efcfbb2)), closes [#132](#132)
@github-actions
Copy link

🎉 This issue has been resolved in version 6.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
exp/novice Someone with a little familiarity can pick up kind/bug A bug in existing code (including security flaws) P2 Medium: Good to have, but can wait until someone steps up released status/ready Ready to be worked
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants