Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CodeError dialing node using tcp #1980

Closed
threshold862543 opened this issue Aug 17, 2023 · 8 comments
Closed

CodeError dialing node using tcp #1980

threshold862543 opened this issue Aug 17, 2023 · 8 comments
Assignees
Labels
kind/bug A bug in existing code (including security flaws) P0 Critical: Tackled by core team ASAP

Comments

@threshold862543
Copy link

threshold862543 commented Aug 17, 2023

Version:
0.45.9

Platform:
5.15.0-33-generic #.34~20.04.1-Ubuntu (dialer)
5.15.0-78-generic #.85-Ubuntu (dialee)

Subsystem:
dialer

Severity:

High - The main functionality of the application does not work, API breakage, repo format breakage, etc.

Description:

Node A is dialing node B over the internet (not local) via tcp, using:
dial(multiaddr(<address>))
address is a string of the format:
'/dns4/<domain>/tcp/<port>/p2p/<peerid>'
the error output:

CodeError: CodeError: missing newline
    at DefaultUpgrader._encryptOutbound (file:///.../node_modules/libp2p/dist/src/upgrader.js:478:19)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async DefaultUpgrader.upgradeOutbound (file:///.../node_modules/libp2p/dist/src/upgrader.js:205:21)
    at async TCP.dial (file:///.../node_modules/@libp2p/tcp/dist/src/index.js:50:22)
    at async DefaultTransportManager.dial (file://.../node_modules/libp2p/dist/src/transport-manager.js:82:20)
    at async queue.add (file:///.../node_modules/libp2p/dist/src/connection-manager/dial-queue.js:333:42)
    at async file:///.../node_modules/p-queue/dist/index.js:118:36 {
  code: 'ERR_ENCRYPTION_FAILED',
  props: {}

Steps to reproduce the error:

Attempt to dial a node over the internet via tcp.
This error doesn't occur when dialing nodes at 127.0.0.1 on the same machine via tcp.

@threshold862543 threshold862543 added the need/triage Needs initial labeling and prioritization label Aug 17, 2023
@achingbrain
Copy link
Member

Are both nodes js-libp2p or is the remote running a different implementation?

@threshold862543
Copy link
Author

Both nodes are running the same version of js-libp2p.

@p-shahi
Copy link
Member

p-shahi commented Aug 18, 2023

v0.45.x is known to work and the interoperability tests for tcp are not failing in the interop test suite: https://github.com/libp2p/test-plans/actions/runs/5900727248/attempts/2#summary-16017106749

Can you share the code snippet?

@threshold862543
Copy link
Author

threshold862543 commented Aug 19, 2023

The libp2p node is initialized as follows:

import { Peerbit } from "peerbit"
import { webSockets } from '@libp2p/websockets'
import { all } from '@libp2p/websockets/filters'
import { mplex } from "@libp2p/mplex";
import { noise } from '@dao-xyz/libp2p-noise'

...
client = await Peerbit.create({
libp2p: {
	transports: [tcp(), webSockets({filter: all})],
	streamMuxers: [mplex()],
	connectionEncryption: [noise()],
	addresses: {
		listen: [
			'/ip4/127.0.0.1/tcp/9001',
			'/ip4/127.0.0.1/tcp/9002/ws'
		] 
	}
} 
})

Ports 9998 and 9999 are forwarded to 9001 and 9002 respectively via nginx proxy on the node being dialed as follows:

server {
        server_name peerchan.net;
        listen [::]:9998 ssl ipv6only=on;
        listen 9998 ssl;
        ssl_certificate /etc/letsencrypt/live/peerchan.net/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/peerchan.net/privkey.pem;
        ssl_trusted_certificate /etc/letsencrypt/live/peerchan.net/chain.pem;
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

        location / {
                proxy_pass http://127.0.0.1:9001;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }


}

server {
        server_name peerchan.net;
        listen [::]:9999 ssl ipv6only=on;
        listen 9999 ssl;
        ssl_certificate /etc/letsencrypt/live/peerchan.net/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/peerchan.net/privkey.pem;
        ssl_trusted_certificate /etc/letsencrypt/live/peerchan.net/chain.pem;
        ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;

        location / {
                proxy_pass http://127.0.0.1:9002;
                proxy_http_version 1.1;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "upgrade";
        }


}

Dialing the tcp node via
'/dns/peerchan.net/tcp/9998/p2p/<peerid>'
errors while
'/dns/peerchan.net/tcp/9999/wss/p2p/<peerid>'
successfully connects

@p-shahi p-shahi added kind/bug A bug in existing code (including security flaws) P0 Critical: Tackled by core team ASAP labels Aug 30, 2023
@maschad maschad moved this to 🛠️ Todo in js-libp2p Aug 31, 2023
@maschad maschad removed the need/triage Needs initial labeling and prioritization label Aug 31, 2023
@maschad
Copy link
Member

maschad commented Sep 1, 2023

There seems to be an issue during the encryption handshake during multi-stream select which suggest an invalid ssl_cert in this case but given you are using https://github.com/dao-xyz/js-libp2p-noise for encryption along with https://github.com/dao-xyz/peerbit 's fork of js-libp2p I would suggest you open an issue against either one of those repos to get further clarity as they may have made modifications to that are not within our codebase.

@maschad maschad closed this as completed Sep 1, 2023
@github-project-automation github-project-automation bot moved this from 🛠️ Todo to 🎉Done in js-libp2p Sep 1, 2023
@matisalimbene
Copy link

@achingbrain I’m getting this error but i’m trying to connect libp2p 1.2.1 to a go-ipfs node v0.4.18. Is this supposed to work or not because different implementation/old version?

@achingbrain
Copy link
Member

It is supposed to work, yes.

Can you please open a new issue with a way to reproduce the error you are seeing? Some runnable code or a link to a repository.

@matisalimbene
Copy link

matisalimbene commented Mar 15, 2024

@achingbrain thanks! and done: #2444

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug A bug in existing code (including security flaws) P0 Critical: Tackled by core team ASAP
Projects
Archived in project
Development

No branches or pull requests

5 participants