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

Dmsgweb handle multiple tcp connections correctly #270

Merged
merged 24 commits into from
Jan 30, 2025
Merged

Conversation

0pcom
Copy link
Collaborator

@0pcom 0pcom commented Jun 30, 2024

Testing

serve hello world via tcp on port 8000

$ go run examples/tcp/tcp.go :8000

serve hello world via tcp on port 8002

$ go run examples/tcp/tcp.go :8002

(optional sanity check) test the tcp proxy

$ go run examples/tcp-proxy/tcp-proxy.go 8000 8003
2024/06/30 12:46:22 TCP proxy started: Listening on port 8003 and forwarding to port 8000

use ncat to access the tcp server via the proxy

$ ncat 127.0.0.1 8003
Hello, World!

then, stop the terminal running tcp-proxy.

Now, test proxying via dmsg web srv

$ go run cmd/dmsg/dmsg.go web srv -c true,true -d 8000,8002 -l 8000,8002
[2024-06-29T19:53:53.287147917-05:00] INFO [dmsgwebsrv]: dmsg client pk: 02f62747c244ce91e9d1672da55950dbad1847352ceaeebb091bc1d2f40dd8f55b
[2024-06-29T19:53:53.287174994-05:00] DEBUG disc.NewHTTP [dmsgwebsrv]: Created HTTP client. addr="http://dmsgd.skywire.dev"
[2024-06-29T19:53:53.287241569-05:00] DEBUG [dmsg_client]: Discovering dmsg servers...
[2024-06-29T19:53:53.592221737-05:00] DEBUG [dmsg_client]: Dialing session... remote_pk=03717576ada5b1744e395c66c2bb11cea73b0e23d0dcd54422139b1a7f12e962c4
[2024-06-29T19:53:54.128915092-05:00] DEBUG [dmsg_client]: Serving session. remote_pk=03717576ada5b1744e395c66c2bb11cea73b0e23d0dcd54422139b1a7f12e962c4

Those ports are now served over dmsg

COPY THE CLIENT PK

use dmsgweb we can put them back on other localhost ports so that we can access with netcat

Keep in mind that the logic for a simgle instance is different from multiple instances, so test these separately

one:

go run cmd/dmsg/dmsg.go web -t <dmsg-web-srv-pk>:8000 -p 8003 -c true

two:

go run cmd/dmsg/dmsg.go web -t <dmsg-web-srv-pk>:8000,<dmsg-web-srv-pk>:8002 -p 8003,8004 -c true,true

Now attempt to access them via ncat (desired output shown below)

$ ncat 127.0.0.1 8003
Hello, World!
$ ncat 127.0.0.1 8004
Hello, World!

@mrpalide
Copy link
Contributor

mrpalide commented Jul 3, 2024

I get this error on test one:

[2024-07-03T11:35:58.089356979Z] INFO [dmsgwebsrv]: Error during copy: read tcp 127.0.0.1:56900->127.0.0.1:8000: use of closed network connection
[2024-07-03T11:35:58.089403212Z] INFO [dmsgwebsrv]: Error during copy: readfrom tcp 127.0.0.1:56900->127.0.0.1:8000: EOF

Have same error on test two, also second proxy never run there:

mohammed@workstation:~$ ncat 127.0.0.1 8004
Ncat: Connection refused.

Just first reverse proxy tcp server running, and 8004 never serving, based on logs.

[2024-07-03T11:38:38.038530211Z] DEBUG [dmsgweb]: Dmsg network ready.
[2024-07-03T11:38:38.038625645Z] DEBUG [dmsgweb]: proxyTCPConn(0)
[2024-07-03T11:38:38.038616644Z] DEBUG [dmsg_client]: Serving session. remote_pk=02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
2024/07/03 11:38:38 Serving TCP on 127.0.0.1:8003

@0pcom
Copy link
Collaborator Author

0pcom commented Jan 24, 2025

@mrpalide I'm encountering inexplicable errors and would appreciate your insights / help here.

I've updated the examples implementation, it should be easier to look at & work with

Testing

  1. create a keypair:
skywire cli config gen-keys | tee dmsgwebsrv.key
  1. run example hello world tcp server
go run examples/tcp/tcp.go :8000
  1. Test server directly (sanity check)
$ ncat 127.0.0.1 8000
Hello, World!
  1. start the example tcp proxy
go run examples/tcp-proxy/tcp-proxy.go 8000 8004
  1. test the example tcp proxy
$ ncat 127.0.0.1 8004
Hello, World!
  1. start the example tcp->dmsg proxy
go run examples/tcp-proxy-dmsg/tcp-proxy-dmsg.go  -d 8000 -l 8000 -s $(tail -n1 dmsgwebsrv.key)
  1. start the example dmsg->tcp reverse proxy
go run examples/tcp-reverse-proxy-dmsg/tcp-reverse-proxy-dmsg.go  -t $(head -n1 dmsgwebsrv.key):8000 -p 8003
  1. test
$ ncat 127.0.0.1 8003

...

I see logging on all three terminal windows.

$ go run examples/tcp/tcp.go :8000
2025/01/23 18:50:38 TCP server started on port :8000
2025/01/23 18:50:43 Handling Connection

The logging prints on the hello world server when something connects.

On the proxy to dmsg:

$ go run examples/tcp-proxy-dmsg/tcp-proxy-dmsg.go  -d 8000 -l 8000 -s $(tail -n1 dmsgwebsrv.key)
[2025-01-23T18:56:07.775147772-06:00] INFO [dmsgwebsrv]: dmsg client pk: 03f45df9890955214bbfe2e06487741489266a60c487365989b9723680b45e0f6e
[2025-01-23T18:56:07.775174379-06:00] DEBUG disc.NewHTTP [dmsgwebsrv]: Created HTTP client. addr="http://dmsgd.skywire.skycoin.com"
[2025-01-23T18:56:07.775230466-06:00] DEBUG [dmsg_client]: Discovering dmsg servers...
[2025-01-23T18:56:08.043227251-06:00] DEBUG [dmsg_client]: Dialing session... remote_pk=0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7
[2025-01-23T18:56:08.330902484-06:00] DEBUG [dmsg_client]: Serving session. remote_pk=0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7
[2025-01-23T18:56:18.636745034-06:00] INFO [dmsgwebsrv]: Error copying from dmsg to local: readfrom tcp 127.0.0.1:43196->127.0.0.1:8000: EOF

On the reverse proxy:

$  go run examples/tcp-reverse-proxy-dmsg/tcp-reverse-proxy-dmsg.go  -t $(head -n1 dmsgwebsrv.key):8000 -p 8003
[2025-01-23T18:56:10.804182164-06:00] INFO [dmsgweb]: dmsg client pk: 03f662f5d8d5a4d63c9b47aa0f55f788668e0c3396a309d5caf8f2b7299d2825ac
[2025-01-23T18:56:10.804214787-06:00] INFO [dmsgweb]: dmsg address to dial: 03f45df9890955214bbfe2e06487741489266a60c487365989b9723680b45e0f6e:8000
[2025-01-23T18:56:10.804281012-06:00] DEBUG disc.NewHTTP [dmsgweb]: Created HTTP client. addr="http://dmsgd.skywire.skycoin.com"
[2025-01-23T18:56:10.804329523-06:00] DEBUG [dmsgweb]: Connecting to dmsg network... dmsg_disc="http://dmsgd.skywire.skycoin.com" public_key="03f662f5d8d5a4d63c9b47aa0f55f788668e0c3396a309d5caf8f2b7299d2825ac"
[2025-01-23T18:56:10.804373239-06:00] DEBUG [dmsg_client]: Discovering dmsg servers...
[2025-01-23T18:56:11.074260758-06:00] DEBUG [dmsg_client]: Dialing session... remote_pk=0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7
[2025-01-23T18:56:11.365586493-06:00] DEBUG [dmsg_client]: Serving session. remote_pk=0326978f5a53aff537dbb47fed58b1f123af3b00132d365f1309a14db4168dcff7
[2025-01-23T18:56:11.36561911-06:00] DEBUG [dmsgweb]: Dmsg network ready.
2025/01/23 18:56:11 Serving TCP on 127.0.0.1:8003
2025/01/23 18:56:18 Error copying data from dmsg client: readfrom tcp 127.0.0.1:8003->127.0.0.1:39670: write tcp 127.0.0.1:8003->127.0.0.1:39670: use of closed network connection
2025/01/23 18:56:18 Error copying data to dmsg client: writeto tcp 127.0.0.1:8003->127.0.0.1:39670: read tcp 127.0.0.1:8003->127.0.0.1:39670: use of closed network connection

Nothing prints back from ncat in the other terminal window.

The code is basically the same between the tcp->dmsg proxy and the tcp->tcp proxy. There is something really subtle I'm missing here.

@mrpalide
Copy link
Contributor

I tested, and everything work well. Here are screenshots after run ncat 127.0.0.1 8003:

tcp server:
image

tcd->dmsg:
image

dmsg-tcp (reverse):
image

and ncat 127.0.0.1 8003 output:
image

Note: I tested them on local dmsg-disc and dmsg-server.

@mrpalide
Copy link
Contributor

As test, I just run this simple server, https://hub.docker.com/r/nginxdemos/hello/ , and test reverse proxy on it, and it works as well as! Great job Moses.

Full logs:
reverse-proxy-test-full.log

Screenshot:
image

Copy link
Contributor

@mrpalide mrpalide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work. Just needs handle CI issues on linter and formatting issue.

@0pcom
Copy link
Collaborator Author

0pcom commented Jan 26, 2025

The examples worked, since I updated them. I didn't get to update my comment here.

The issue now is with dmsgweb itself. I'm not able to connect to anything, I keep getting errors that the entry is not found in discovery when the key is in the discovery. It might be erroneous proxy configuration, I'm really not sure... annoying because this was working before as non-multiplexed

[2025-01-25T20:46:20.418822784-06:00] WARN [dmsgweb]: Failed to dial dmsg address 036a70e6956061778e1883e928c1236189db14dfd446df23d83e45c321b330c91f port 80 error="dmsg error 100 - entry is not found in discovery"
2025/01/26 03:36:12 [ERR] yamux: keepalive failed: i/o deadline reached
[2025-01-26T03:36:12.485002003-06:00] WARN [dmsg_client]: Stopped accepting streams. error="keepalive timeout" session=0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13
[2025-01-26T03:36:12.485181503-06:00] DEBUG [dmsg_client]: Session stopped. error="failed to serve dialed session to 0371ab4bcff7b121f4b91f6856d6740c6f9dc1fe716977850aeb5d84378b300a13: keepalive timeout"
[2025-01-26T03:36:12.487710297-06:00] ERROR [dmsgweb]: Failed to perform request. endpoint="http://dmsgd.skywire.skycoin.com/dmsg-discovery/entry/" error="Post "http://dmsgd.skywire.skycoin.com/dmsg-discovery/entry/": invalid host address: Invalid public key"
[2025-01-26T03:36:12.487754501-06:00] WARN EntityCommon.delSession [dmsg_client]: Callback returned non-nil error. error="Post "http://dmsgd.skywire.skycoin.com/dmsg-discovery/entry/": invalid host address: Invalid public key"
[2025-01-26T03:36:12.487789869-06:00] DEBUG [dmsg_client]: Dialing session... remote_pk=02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd
[2025-01-26T03:36:17.848748907-06:00] ERROR [dmsgweb]: Failed to perform request. endpoint="http://dmsgd.skywire.skycoin.com/dmsg-discovery/entry/" error="Post "http://dmsgd.skywire.skycoin.com/dmsg-discovery/entry/": invalid host address: Invalid public key"
[2025-01-26T03:36:17.848799167-06:00] WARN EntityCommon.setSession [dmsg_client]: Callback returned non-nil error. error="Post "http://dmsgd.skywire.skycoin.com/dmsg-discovery/entry/": invalid host address: Invalid public key"
[2025-01-26T03:36:17.848858772-06:00] DEBUG [dmsg_client]: Serving session. remote_pk=02a2d4c346dabd165fd555dfdba4a7f4d18786fe7e055e562397cd5102bdd7f8dd

@0pcom 0pcom merged commit 770537a into skycoin:develop Jan 30, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants