ton-blockchain / ton

Main TON monorepo
Other
2.59k stars 712 forks source link

Access TON Site on TON Storage via TON Proxy #677

Open air3ijai opened 1 year ago

air3ijai commented 1 year ago

As a next step of the Publish TON Site stored on TON Storage #674 we are trying to access published site via TON Proxy.

When we follow Running an entry proxy

 rldp-http-proxy -p 8080 -c 3333 -C global.config.json -v 3
logs ``` [ 2][t 6][2023-04-23 10:10:59.321430414][TonlibClient.cpp:2716][!tonlibclient][&!config->ignore_cache_] Unknown LastBlockState: [Error : 0 : Unknown key] [ 3][t 6][2023-04-23 10:10:59.321468735][TonlibClient.cpp:2745][!tonlibclient] Use init block from USER config: (-1,8000000000000000,27747086):61192B72664CBCB06F8DA9F0282C8BDF0E2871E18FB457E0C7CCA6D502822BFE:378DB1CCF9C98C3944DE1C4F5CE6FEA4DCD7A26811B695F9019CCC3E7200E35B [ 3][t 6][2023-04-23 10:10:59.321653517][ExtClientLazy.cpp:101][!ExtClientLazy] Connecting to liteserver [164.68.101.206:52995] [ 1][t 0][2023-04-23 10:10:59.339615327][adnl-ext-connection.cpp:129][!outconn] Client got error [PosixError : Connection refused : 111 : Error on [fd:6]] [ 2][t 3][2023-04-23 10:10:59.340335915][DNSResolver.cpp:46][!tonlibclient] Sync error: [Error : 500 : LITE_SERVER_NETWORK(during check init block)] [ 2][t 1][2023-04-23 10:10:59.340358935][LastBlock.cpp:261][!LastBlock] Failed liteServer_getMasterchainInfo [Error : 500 : LITE_SERVER_NETWORK] [ 3][t 5][2023-04-23 10:11:04.341860111][ExtClientLazy.cpp:101][!ExtClientLazy] Connecting to liteserver [65.21.141.198:47160] [ 3][t 7][2023-04-23 10:11:05.139134504][LastBlock.cpp:327][!LastBlock] {"workchain":-1,"shard":-9223372036854775808,"seqno":27884997,"root_hash":"d/bCgPVpUydSnfD9QcaQEaHNOXgqFIboQNSBwHce4ns=","file_hash":"0QjCpdvlZ7s1vqgqpVzLDqSBBX/kMQLkYFy8pY7jZYY="} [ 3][t 1][2023-04-23 10:11:05.692003481][LastBlock.cpp:327][!LastBlock] {"workchain":-1,"shard":-9223372036854775808,"seqno":28038816,"root_hash":"j2JLj22/rW3notCHtA9SRhKtvYXLWY0D3u/hDh229Hg=","file_hash":"/tIfQg2ccoUkcP+rR40MyPugjC7FNgXXoHoTVS0vTHQ="} [ 3][t 7][2023-04-23 10:11:06.187787165][LastBlock.cpp:327][!LastBlock] {"workchain":-1,"shard":-9223372036854775808,"seqno":28188322,"root_hash":"NK/WPA4wC8ggEh3dysl8wpXwZPEnfOZ3o514923H4c8=","file_hash":"5U4XJcVOzuy6JYytp+rZxRCjjsJUUyEp8it9/HwEa9M="} [ 3][t 1][2023-04-23 10:11:06.699996482][LastBlock.cpp:327][!LastBlock] {"workchain":-1,"shard":-9223372036854775808,"seqno":28329533,"root_hash":"TefPjySrMM3afZTB1bCQ7PY2X8xKA1v40a1W7MN6VtE=","file_hash":"bnSYHuwfTi1zuSmjdBt0P6flkf8v0x+aAEiVlmpxdgw="} [ 3][t 1][2023-04-23 10:11:07.237225424][LastBlock.cpp:327][!LastBlock] {"workchain":-1,"shard":-9223372036854775808,"seqno":28415964,"root_hash":"f5HomGDtWuar9C2SIMGABd6DQQVqDLpzdauQIlgOLLk=","file_hash":"/0T/HOkV5qQUV2nMRthygdNB30jcuMQkFqZrHo5D9jA="} [ 3][t 1][2023-04-23 10:11:07.810182593][LastBlock.cpp:327][!LastBlock] {"workchain":-1,"shard":-9223372036854775808,"seqno":28523591,"root_hash":"u0JDiAgooELKC01PKPBSgnuGRj9nyA8MUB4sLH6dcTY=","file_hash":"Yey1f5k0HbssjdljSHmVHJrmpByNC22gzaFA+XeGQcM="} [ 3][t 5][2023-04-23 10:11:08.294749829][LastBlock.cpp:327][!LastBlock] {"workchain":-1,"shard":-9223372036854775808,"seqno":28654718,"root_hash":"rxC177LMIr5zgYMxDeYV/SupVMALhms6PZNW+LB8LVQ=","file_hash":"h11/wUH4d/SWPHmDrnmhptSDUc/BLz7gqO9b0ZdSj2U="} [ 3][t 5][2023-04-23 10:11:08.799185586][LastBlock.cpp:327][!LastBlock] {"workchain":-1,"shard":-9223372036854775808,"seqno":28804107,"root_hash":"S/Z4OLNxbfXJy17xB5/1UCBMFixO+iY2MjHh/hnDkYo=","file_hash":"UWDqymmza0Ffa66frEmqKn6eslNCJy+3AbywJlWPClI="} [ 3][t 7][2023-04-23 10:11:09.305019239][LastBlock.cpp:327][!LastBlock] {"workchain":-1,"shard":-9223372036854775808,"seqno":28959398,"root_hash":"EHr7EKNnXuM2QfrdrR/VmJagQqUJb2nLf4Z7VWbTyw0=","file_hash":"k20PcmvQ7Vmf/zLmF7HbA8xsppnM9/cqQF6A8nxHVqY="} [ 3][t 1][2023-04-23 10:11:09.423340969][LastBlock.cpp:327][!LastBlock] {"workchain":-1,"shard":-9223372036854775808,"seqno":28978989,"root_hash":"mUozPe07PPCdwTOzSaB214H6ySVXDI9yRq5D33Cz/BQ=","file_hash":"EreSJeEw+WhIuj/Ogw3oriuVRnpxRE4u6wtUwgowQYY="} [ 1][t 0][2023-04-23 10:12:58.278004018][TcpListener.cpp:62][!TcpListener[port:8080]] Accept [ 3][t 1][2023-04-23 10:12:58.278303191][ExtClientLazy.cpp:101][!ExtClientLazy] Connecting to liteserver [65.21.141.198:47160] [ 3][t 2][2023-04-23 10:12:58.675460521][rldp-http-proxy.cpp:557][!outboundreq] aborting http over rldp query: [Error : 0 : storage gateway is not set] ```
 curl -x 127.0.0.1:8080 http://just-for-test.ton -v
logs ``` * Trying 127.0.0.1:8080... * Connected to (nil) (127.0.0.1) port 8080 (#0) > GET http://just-for-test.ton/ HTTP/1.1 > Host: just-for-test.ton > User-Agent: curl/7.81.0 > Accept: */* > Proxy-Connection: Keep-Alive > * Mark bundle as not supporting multiuse < HTTP/1.1 502 Bad Gateway < Connection: keep-alive < Content-length: 0 < * Connection #0 to host (nil) left intact ```

What does this error mean in rldp-http-proxy logs - [Error : 0 : storage gateway is not set]?

  1. Should we run a local storage-daemon and specify its address?
  2. Should we specify any other, for example on a different node, running storage-daemon?

    We did a try with address on a different node and the result is the following

     rldp-http-proxy -p 8080 -c 3333 -C global.config.json -v 3 -S 'hNN+fuJUQkkPvOhzOZe5r45MSoBuJS1hFv10DT9p+/k='
    logs ``` [ 0][t 0][2023-04-23 10:25:12.821296815][Status.h:273] Unexpected Status [Error : 0 : Wrong length of adnl id] in file /build/c33p96i2ji7mi91ahrcbl5hk38srm67m-source/rldp-http-proxy/rldp-http-proxy.cpp at line 1736 [pid 3977] [time 1682245512] Signal: 6 ```

    We get hNN+fuJUQkkPvOhzOZe5r45MSoBuJS1hFv10DT9p+/k= from the storage-daemon log running on a different node

    logs ``` [ 3][t 1][2023-04-21 12:45:00.694509103][storage-daemon.cpp:183][!storage-daemon] Storage daemon ADNL id is hNN+fuJUQkkPvOhzOZe5r45MSoBuJS1hFv10DT9p+/k= ```
    1. If we should use storage-daemon hexadecimal and not user-friendly address, how can we get it from the running storage-daemon?
    2. How TON Proxy access TON Site hosted on TON Storage, does it have an embedded TON Storage support or it is intended to use an external one?
      TON Proxy --> TON Light Client (Resolve to ADNL) --> TON Storage
air3ijai commented 1 year ago

Similar result we get when follow steps from Running an entry proxy on a remote computer

Site http://just-for-test.ton is mentioned in the article TON Storage as an example of the TON Site stored on TON Storage - so, it should be somehow accessible via TON Proxy?

justdmitry commented 1 year ago

ADNL address strings are base32 encoded with some "fixes". Check here for C++ code or here for C# one.

Regarding TON sites hosted in storage - I found that client-side Tonutils-Proxy works nice, while proxy embedded into MyTonWallet Chrome extension does not understand storage-hosted sites yet.

air3ijai commented 1 year ago

Regarding TON sites hosted in storage - I found that client-side Tonutils-Proxy works nice

Just tried to use Tonutils-Proxy and http://foundation.ton works fine, but

  1. It is not clear if that site is hosted on TON Proxy or TON Storage
  2. To check where this site is hosted we have a separate issue - #676

And site http://just-for-test.ton doesn't work

RLDP Proxy Error: Get "http://just-for-test.ton/": failed to connect to site: failed to create downloader for storage bag of just-for-test.ton, err: failed to find storage nodes for this bag, err: no nodes found

Maybe just because no seeds found in the network?

while proxy embedded into MyTonWallet Chrome extension does not understand storage-hosted sites yet

You mean that it is just about the Proxy app endpoint used in that wallet?

And the same behaviour with the Public entry TON Proxies - site http://just-for-test.ton just a blank page.

With TON Run as well - http://just-for-test.ton.run, A timeout occurred Error code 524 from Cloudflare.

justdmitry commented 1 year ago

It is not clear if that site is hosted on TON Proxy or TON Storage

Dozen days ago when I was starting my own site - it was working from ADNL server, not storage. For 100% TONStorage site - check just-dmitry.ton - it will open via tonutils-proxy and will not open via ton proxies embedded into browser wallet plugins.

And site http://just-for-test.ton/ doesn't work

image

It IS stored in storage (due to "searching for bag id"), but my machine is failing to connect to specific storage node...

You mean that it is just about the Proxy app endpoint used in that wallet?

I asked in MyTonWallet support and they confirmed that proxy inside their plugin does not support storage-hosted sites yet.

And the same behaviour with the Public entry TON Proxies

I tried them with my site before trying tonutils-proxy and I think they also don't support storage-hosted sites yet, but I didn't ask anybody for confirmation.

air3ijai commented 1 year ago

Thanks, your site just-dmitry.ton works fine via tonutils-proxy

tonutils-proxy
2023/05/22 12:11:00 Fetching TON network config...
2023/05/22 12:11:01 Initialising DHT client...
2023/05/22 12:11:01 Initialising DNS resolver...
2023/05/22 12:11:01 Initialising RLDP transport layer...
2023/05/22 12:11:01 Starting proxy server on 127.0.0.1:8080
2023/05/22 12:12:03 OVER RLDP   GET   http://just-dmitry.ton/
2023/05/22 12:12:03 SEARCHING FOR BAG ID 9686aab427c3337928a33e3efdea0c3a9aefbc0922447b61402cde389f955885
2023/05/22 12:12:09 CONNECTING TO PEER 465013abd1de3f63a17027cd2471c353514d7ddd347b89fe27c369a08e2c8b64

And it also show a result of the nslookup - 9686aab427c3337928a33e3efdea0c3a9aefbc0922447b61402cde389f955885

air3ijai commented 1 year ago

Now, the latest question is to how to run local TON Proxy to access TON Storage hosted site, as it was mentioned in the initial post.

We did the following there

  1. Run TON Storage and noted its address
  2. Run TON Proxy and specified TON Storage address

    rldp-http-proxy \
      -p 8080 \
      -c 3333 \
      -C global.config.json \
      -S 'hNN+fuJUQkkPvOhzOZe5r45MSoBuJS1hFv10DT9p+/k=' \
      -v 3

    And we get the error

    [ 0][t 0][2023-04-23 10:25:12.821296815][Status.h:273] Unexpected Status [Error : 0 : Wrong length of adnl id] in file /build/c33p96i2ji7mi91ahrcbl5hk38srm67m-source/rldp-http-proxy/rldp-http-proxy.cpp at line 1736 [pid 3977] [time 1682245512] Signal: 6

Probably we should use something different here (-S) - how can we get that addresss from the running TON Storage instance?

justdmitry commented 1 year ago

Probably we should use something different here (-S) - how can we get that address from the running TON Storage instance?

I don't know how to get this result from running TON Storage instance, but I guess you need ADNL address as base32 encoded string with some "fixes", as I wrote earlier (C++ code here or C# code here).

Instead of your hNN+fuJUQkkPvOhzOZe5r45MSoBuJS1hFv10DT9p+/k= value try to use wcng7t64jkeesipxtuhgomxxgxy4tckqbxckllbc36xidj7nh57sqev string.

air3ijai commented 1 year ago

Now it is lightly better, at least proxy is running and accepting connections

rldp-http-proxy \
  -p 8080 \
  -c 3333 \
  -C global.config.json \
  -S 'wcng7t64jkeesipxtuhgomxxgxy4tckqbxckllbc36xidj7nh57sqev' \
  -v 3
Screenshot 2023-05-22 at 15 14 54

But anyway can't get site content

curl -x 127.0.0.1:8080 http://just-dmitry.ton -v
*   Trying 127.0.0.1:8080...
* Connected to (nil) (127.0.0.1) port 8080 (#0)
> GET http://just-dmitry.ton/ HTTP/1.1
> Host: just-dmitry.ton
> User-Agent: curl/7.81.0
> Accept: */*
> Proxy-Connection: Keep-Alive
> 
* Mark bundle as not supporting multiuse
< HTTP/1.1 504 Gateway Timeout
< Connection: keep-alive
< Content-length: 0
< 
* Connection #0 to host (nil) left intact
                 Light client (Get Site address and resolve address to ADNL)
               /
curl --> Proxy
               \
                 Storage (Get Site content by BagID)
air3ijai commented 1 year ago

And following the guide Running an entry proxy on a remote computer

rldp-http-proxy \
  -p 8080 \
  -a 1.1.1.1:4444 \
  -C global.config.json \
  -S wcng7t64jkeesipxtuhgomxxgxy4tckqbxckllbc36xidj7nh57sqev \
  -A vts3zj35elyhrwrpccfrior5cyrsf6tf3x7ydmyczore7ud5n57yky4 \
  -v 3

Same story - < HTTP/1.1 504 Gateway Timeout

And at the same time the following in the locally running TON Storage logs

[ 2][t 1][2023-05-22 12:52:48.539243553][adnl-peer.cpp:536][!localid] failed to answer query: [Error : 603 : dropping IN message from Hrq/USuokS/sM50dXHZr9seOuOgc1j/IDNiS5zoVges=: no callbacks for custom query. firstint=-613277815] [ 2][t 1][2023-05-22 12:52:48.540421312][adnl-peer.cpp:536][!localid] failed to answer query: [Error : 603 : dropping IN message from Zy3lO+kXg8bReIRYodHosRkX0y7v/A2YFl0SfoPre/w=: no callbacks for custom query. firstint=-613277815]

brianchul commented 1 year ago

you may need to check your firewall settings to allow ingress udp connection to connect rldp-http-proxy, which in your case is 4444

air3ijai commented 1 year ago

you may need to check your firewall settings to allow ingress udp connection to connect rldp-http-proxy, which in your case is 4444

I just checked Node Security Group and it allow TCP/UDP:4444 from 0.0.0.0/0 and I get same error as before.