Skip to content

Commit

Permalink
RLDP2 Support + core update
Browse files Browse the repository at this point in the history
  • Loading branch information
xssnick committed Feb 24, 2023
1 parent e6593eb commit 350e62a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
28 changes: 23 additions & 5 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 350e62a

Please sign in to comment.