Skip to content

Commit

Permalink
Merge pull request #23 from tonutils/test
Browse files Browse the repository at this point in the history
Print version + domain setup improvements
  • Loading branch information
xssnick authored Aug 1, 2024
2 parents 20be200 + 6f4d3c8 commit 1fb4a21
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
build
13 changes: 13 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.PHONY: all build

ver := $(shell git log -1 --pretty=format:"%h-%as")

build:
go build -ldflags "-w -s -X main.GitCommit=$(ver)" -o build/tonutils-reverse-proxy cmd/proxy/main.go

all:
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.GitCommit=$(ver)" -o build/tonutils-reverse-proxy-linux-amd64 cmd/proxy/main.go
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X main.GitCommit=$(ver)" -o build/tonutils-reverse-proxy-linux-arm64 cmd/proxy/main.go
GOOS=windows GOARCH=amd64 go build -ldflags="-s -w -X main.GitCommit=$(ver)" -o build/tonutils-reverse-proxy-windows-x64.exe cmd/proxy/main.go
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.GitCommit=$(ver)" -o build/tonutils-reverse-proxy-mac-amd64 cmd/proxy/main.go
GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X main.GitCommit=$(ver)" -o build/tonutils-reverse-proxy-mac-arm64 cmd/proxy/main.go
5 changes: 0 additions & 5 deletions build.sh

This file was deleted.

33 changes: 20 additions & 13 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"crypto/ed25519"
"encoding/base64"
"encoding/hex"
"encoding/json"
"flag"
"fmt"
Expand Down Expand Up @@ -42,6 +43,9 @@ var FlagDomain = flag.String("domain", "", "domain to configure")
var FlagDebug = flag.Bool("debug", false, "more logs")
var FlagTxURL = flag.Bool("tx-url", false, "show set domain record url instead of qr")

var GitCommit = "custom"
var Version = "v0.3.3"

type Handler struct {
h http.Handler
}
Expand All @@ -66,21 +70,20 @@ func (h Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {

log.Println("request:", request.Method, request.Host, request.RequestURI)

writer.Header().Set("Ton-Reverse-Proxy", "Tonutils Reverse Proxy v0.3.2")
writer.Header().Set("Ton-Reverse-Proxy", "Tonutils Reverse Proxy "+Version)
h.h.ServeHTTP(writer, request)
}

func main() {
flag.Parse()

log.Println("Tonutils Reverse Proxy", Version+", build: "+GitCommit)

cfg, err := loadConfig()
if err != nil {
panic("failed to load config: " + err.Error())
}

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

netCfg, err := liteclient.GetConfigFromUrl(context.Background(), cfg.NetworkConfigURL)
if err != nil {
log.Println("failed to download ton config:", err.Error(), "; we will take it from static cache")
Expand All @@ -92,7 +95,10 @@ func main() {
}

client := liteclient.NewConnectionPool()
// connect to testnet lite server

ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()

err = client.AddConnectionsFromConfig(ctx, netCfg)
if err != nil {
panic(err)
Expand Down Expand Up @@ -136,7 +142,7 @@ func main() {
if err != nil {
panic(err)
}
log.Println("Server's ADNL address is", addr+".adnl")
log.Println("Server's ADNL address is", addr+".adnl ("+hex.EncodeToString(s.Address())+")")

if *FlagDomain != "" {
setupDomain(client, *FlagDomain, s.Address())
Expand Down Expand Up @@ -228,9 +234,10 @@ func setupDomain(client *liteclient.ConnectionPool, domain string, adnlAddr []by
api := ton.NewAPIClient(client)

// get root dns address from network config
root, err := dns.RootContractAddr(api)
root, err := dns.GetRootContractAddr(ctx, api)
if err != nil {
panic(err)
log.Println("Failed to resolve root dns contract:", err)
return
}

resolver := dns.NewDNSClient(api, root)
Expand All @@ -245,7 +252,7 @@ func setupDomain(client *liteclient.ConnectionPool, domain string, adnlAddr []by
data := domainInfo.BuildSetSiteRecordPayload(adnlAddr, false).ToBOCWithFlags(false)
args := "?bin=" + base64.URLEncoding.EncodeToString(data) + "&amount=" + tlb.MustFromTON("0.02").Nano().String()

nftData, err := domainInfo.GetNFTData(context.Background())
nftData, err := domainInfo.GetNFTData(ctx)
if err != nil {
log.Println("Failed to get domain data", domain, ":", err)
return
Expand All @@ -261,8 +268,8 @@ func setupDomain(client *liteclient.ConnectionPool, domain string, adnlAddr []by
fmt.Println("Execute transaction from wallet:", nftData.OwnerAddress.String())
fmt.Println("When you've done, configuration will automatically proceed in ~10 seconds.")
for {
time.Sleep(5 * time.Second)
updated, err := resolve(resolver, domain, adnlAddr)
time.Sleep(2 * time.Second)
updated, err := resolve(ctx, resolver, domain, adnlAddr)
if err != nil {
continue
}
Expand All @@ -279,8 +286,8 @@ func setupDomain(client *liteclient.ConnectionPool, domain string, adnlAddr []by
fmt.Println("Domain", domain, "is already configured to use with current ADNL address. Everything is OK!")
}

func resolve(client *dns.Client, domain string, adnlAddr []byte) (bool, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
func resolve(ctx context.Context, client *dns.Client, domain string, adnlAddr []byte) (bool, error) {
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
defer cancel()

domainInfo, err := client.Resolve(ctx, domain)
Expand Down
8 changes: 0 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,8 @@ github.com/oasisprotocol/curve25519-voi v0.0.0-20220328075252-7dd334e3daae h1:7s
github.com/oasisprotocol/curve25519-voi v0.0.0-20220328075252-7dd334e3daae/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s=
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 h1:aQKxg3+2p+IFXXg97McgDGT5zcMrQoi0EICZs8Pgchs=
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3/go.mod h1:9/etS5gpQq9BJsJMWg1wpLbfuSnkm8dPF6FdW2JXVhA=
github.com/xssnick/tonutils-go v1.8.9-0.20240125180557-86af89e735af h1:gWcFk6S4bY1ypuVB+W4YTlaHYpOYgdlps86QQvRoU1E=
github.com/xssnick/tonutils-go v1.8.9-0.20240125180557-86af89e735af/go.mod h1:p1l1Bxdv9sz6x2jfbuGQUGJn6g5cqg7xsTp8rBHFoJY=
github.com/xssnick/tonutils-go v1.9.2 h1:70s1oqcJ4jOOmqjSik0TmZR05JySfk/PeVuPeXmr+ho=
github.com/xssnick/tonutils-go v1.9.2/go.mod h1:p1l1Bxdv9sz6x2jfbuGQUGJn6g5cqg7xsTp8rBHFoJY=
github.com/xssnick/tonutils-go v1.9.9-0.20240726185310-b76c122b8cd6 h1:po4uMNWZTLZxO0Xms4BEHB8TCar3gLFMUAGgmvDsN9E=
github.com/xssnick/tonutils-go v1.9.9-0.20240726185310-b76c122b8cd6/go.mod h1:p1l1Bxdv9sz6x2jfbuGQUGJn6g5cqg7xsTp8rBHFoJY=
github.com/xssnick/tonutils-go v1.9.9-0.20240729172752-0ce0d252a288 h1:nbTy2yUnRob4iCjiQcJ8gQVoc6rtqgIVNKMnl5AvhRo=
github.com/xssnick/tonutils-go v1.9.9-0.20240729172752-0ce0d252a288/go.mod h1:p1l1Bxdv9sz6x2jfbuGQUGJn6g5cqg7xsTp8rBHFoJY=
github.com/xssnick/tonutils-go v1.9.9 h1:J0hVJI4LNEFHqgRHzpWTjFuv/Ga89OqLRUc9gxmjCoc=
github.com/xssnick/tonutils-go v1.9.9/go.mod h1:p1l1Bxdv9sz6x2jfbuGQUGJn6g5cqg7xsTp8rBHFoJY=
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
Expand Down

0 comments on commit 1fb4a21

Please sign in to comment.