From 350e62a10b2e2dc686ae2a1867978cc1b96839c3 Mon Sep 17 00:00:00 2001 From: Oleg Baranov Date: Fri, 24 Feb 2023 18:11:43 +0400 Subject: [PATCH] RLDP2 Support + core update --- cmd/proxy/main.go | 28 +++++++++++++++++++++++----- go.mod | 2 +- go.sum | 4 ++++ 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/cmd/proxy/main.go b/cmd/proxy/main.go index c85f813..2537a2e 100644 --- a/cmd/proxy/main.go +++ b/cmd/proxy/main.go @@ -79,7 +79,18 @@ func main() { panic(err) } - dhtClient, err := dht.NewClientFromConfig(ctx, netCfg) + _, dhtAdnlKey, err := ed25519.GenerateKey(nil) + if err != nil { + panic("failed to generate ed25519 key for dht: " + err.Error()) + } + + gateway := adnl.NewGateway(dhtAdnlKey) + err = gateway.StartClient() + if err != nil { + panic("failed to load network config: " + err.Error()) + } + + dhtClient, err := dht.NewClientFromConfig(ctx, gateway, netCfg) if err != nil { panic(err) } @@ -96,7 +107,8 @@ func main() { proxy := httputil.NewSingleHostReverseProxy(u) s := rldphttp.NewServer(ed25519.NewKeyFromSeed(cfg.PrivateKey), dhtClient, Handler{proxy}) - s.SetExternalIP(net.ParseIP(cfg.ExternalIP)) + println("IP", cfg.ExternalIP, net.ParseIP(cfg.ExternalIP).String()) + s.SetExternalIP(net.ParseIP(cfg.ExternalIP).To4()) addr, err := rldphttp.SerializeADNLAddress(s.Address()) if err != nil { @@ -200,8 +212,9 @@ func setupDomain(client *liteclient.ConnectionPool, domain string, adnlAddr []by return } - if !bytes.Equal(domainInfo.GetSiteRecord(), adnlAddr) { - data := domainInfo.BuildSetSiteRecordPayload(adnlAddr).ToBOCWithFlags(false) + record, isStorage := domainInfo.GetSiteRecord() + if isStorage || !bytes.Equal(record, adnlAddr) { + data := domainInfo.BuildSetSiteRecordPayload(adnlAddr, false).ToBOCWithFlags(false) args := "?bin=" + base64.URLEncoding.EncodeToString(data) + "&amount=" + tlb.MustFromTON("0.02").NanoTON().String() nftData, err := domainInfo.GetNFTData(context.Background()) @@ -242,5 +255,10 @@ func resolve(client *dns.Client, domain string, adnlAddr []byte) (bool, error) { return false, err } - return bytes.Equal(domainInfo.GetSiteRecord(), adnlAddr), nil + record, isStorage := domainInfo.GetSiteRecord() + if isStorage { + return false, nil + } + + return bytes.Equal(record, adnlAddr), nil } diff --git a/go.mod b/go.mod index 86d3308..656a1e5 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( github.com/mdp/qrterminal/v3 v3.0.0 github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 - github.com/xssnick/tonutils-go v1.5.1-0.20230131083811-f2432838f9cc + github.com/xssnick/tonutils-go v1.5.3-0.20230224103525-a740f2b2aa76 ) require ( diff --git a/go.sum b/go.sum index 5f7c534..c8725af 100644 --- a/go.sum +++ b/go.sum @@ -55,6 +55,10 @@ github.com/xssnick/tonutils-go v1.5.1-0.20230123133014-c4a895d57e23 h1:bJfFUtWMQ github.com/xssnick/tonutils-go v1.5.1-0.20230123133014-c4a895d57e23/go.mod h1:wH8ldhLueyfXW15r3MyaIq9YzA+8bzvL6UMU2BLp08g= github.com/xssnick/tonutils-go v1.5.1-0.20230131083811-f2432838f9cc h1:TEyycMu6wLBthFjeBeFvPfdQwfK3LdWnJkx5iYH1TgQ= github.com/xssnick/tonutils-go v1.5.1-0.20230131083811-f2432838f9cc/go.mod h1:wH8ldhLueyfXW15r3MyaIq9YzA+8bzvL6UMU2BLp08g= +github.com/xssnick/tonutils-go v1.5.3-0.20230220100828-dbce647061b4 h1:xptXTCkdt07WLQUct8tLrzwMWYCndvdcOjoy3sa22m4= +github.com/xssnick/tonutils-go v1.5.3-0.20230220100828-dbce647061b4/go.mod h1:wH8ldhLueyfXW15r3MyaIq9YzA+8bzvL6UMU2BLp08g= +github.com/xssnick/tonutils-go v1.5.3-0.20230224103525-a740f2b2aa76 h1:6W7QanatmrKV4JvoBndRC97VS8k4HKzB1io/RW3oMcM= +github.com/xssnick/tonutils-go v1.5.3-0.20230224103525-a740f2b2aa76/go.mod h1:wH8ldhLueyfXW15r3MyaIq9YzA+8bzvL6UMU2BLp08g= golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 h1:S25/rfnfsMVgORT4/J61MJ7rdyseOZOyvLIrZEZ7s6s= golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=