skycoin / dmsg

dmsg
7 stars 17 forks source link

Dmsgweb handle multiple tcp connections correctly #270

Open 0pcom opened 5 months ago

0pcom commented 5 months ago

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 commented 5 months ago

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