Skip to content

Commit 1fb4a21

Browse files
authored
Merge pull request #23 from tonutils/test
Print version + domain setup improvements
2 parents 20be200 + 6f4d3c8 commit 1fb4a21

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
.idea
2+
build

Makefile

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.PHONY: all build
2+
3+
ver := $(shell git log -1 --pretty=format:"%h-%as")
4+
5+
build:
6+
go build -ldflags "-w -s -X main.GitCommit=$(ver)" -o build/tonutils-reverse-proxy cmd/proxy/main.go
7+
8+
all:
9+
GOOS=linux GOARCH=amd64 go build -ldflags="-s -w -X main.GitCommit=$(ver)" -o build/tonutils-reverse-proxy-linux-amd64 cmd/proxy/main.go
10+
GOOS=linux GOARCH=arm64 go build -ldflags="-s -w -X main.GitCommit=$(ver)" -o build/tonutils-reverse-proxy-linux-arm64 cmd/proxy/main.go
11+
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
12+
GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w -X main.GitCommit=$(ver)" -o build/tonutils-reverse-proxy-mac-amd64 cmd/proxy/main.go
13+
GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w -X main.GitCommit=$(ver)" -o build/tonutils-reverse-proxy-mac-arm64 cmd/proxy/main.go

build.sh

-5
This file was deleted.

cmd/proxy/main.go

+20-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"context"
66
"crypto/ed25519"
77
"encoding/base64"
8+
"encoding/hex"
89
"encoding/json"
910
"flag"
1011
"fmt"
@@ -42,6 +43,9 @@ var FlagDomain = flag.String("domain", "", "domain to configure")
4243
var FlagDebug = flag.Bool("debug", false, "more logs")
4344
var FlagTxURL = flag.Bool("tx-url", false, "show set domain record url instead of qr")
4445

46+
var GitCommit = "custom"
47+
var Version = "v0.3.3"
48+
4549
type Handler struct {
4650
h http.Handler
4751
}
@@ -66,21 +70,20 @@ func (h Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
6670

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

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

7377
func main() {
7478
flag.Parse()
7579

80+
log.Println("Tonutils Reverse Proxy", Version+", build: "+GitCommit)
81+
7682
cfg, err := loadConfig()
7783
if err != nil {
7884
panic("failed to load config: " + err.Error())
7985
}
8086

81-
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
82-
defer cancel()
83-
8487
netCfg, err := liteclient.GetConfigFromUrl(context.Background(), cfg.NetworkConfigURL)
8588
if err != nil {
8689
log.Println("failed to download ton config:", err.Error(), "; we will take it from static cache")
@@ -92,7 +95,10 @@ func main() {
9295
}
9396

9497
client := liteclient.NewConnectionPool()
95-
// connect to testnet lite server
98+
99+
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
100+
defer cancel()
101+
96102
err = client.AddConnectionsFromConfig(ctx, netCfg)
97103
if err != nil {
98104
panic(err)
@@ -136,7 +142,7 @@ func main() {
136142
if err != nil {
137143
panic(err)
138144
}
139-
log.Println("Server's ADNL address is", addr+".adnl")
145+
log.Println("Server's ADNL address is", addr+".adnl ("+hex.EncodeToString(s.Address())+")")
140146

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

230236
// get root dns address from network config
231-
root, err := dns.RootContractAddr(api)
237+
root, err := dns.GetRootContractAddr(ctx, api)
232238
if err != nil {
233-
panic(err)
239+
log.Println("Failed to resolve root dns contract:", err)
240+
return
234241
}
235242

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

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

282-
func resolve(client *dns.Client, domain string, adnlAddr []byte) (bool, error) {
283-
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
289+
func resolve(ctx context.Context, client *dns.Client, domain string, adnlAddr []byte) (bool, error) {
290+
ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
284291
defer cancel()
285292

286293
domainInfo, err := client.Resolve(ctx, domain)

go.sum

-8
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,8 @@ github.com/oasisprotocol/curve25519-voi v0.0.0-20220328075252-7dd334e3daae h1:7s
77
github.com/oasisprotocol/curve25519-voi v0.0.0-20220328075252-7dd334e3daae/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s=
88
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3 h1:aQKxg3+2p+IFXXg97McgDGT5zcMrQoi0EICZs8Pgchs=
99
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3/go.mod h1:9/etS5gpQq9BJsJMWg1wpLbfuSnkm8dPF6FdW2JXVhA=
10-
github.com/xssnick/tonutils-go v1.8.9-0.20240125180557-86af89e735af h1:gWcFk6S4bY1ypuVB+W4YTlaHYpOYgdlps86QQvRoU1E=
11-
github.com/xssnick/tonutils-go v1.8.9-0.20240125180557-86af89e735af/go.mod h1:p1l1Bxdv9sz6x2jfbuGQUGJn6g5cqg7xsTp8rBHFoJY=
12-
github.com/xssnick/tonutils-go v1.9.2 h1:70s1oqcJ4jOOmqjSik0TmZR05JySfk/PeVuPeXmr+ho=
13-
github.com/xssnick/tonutils-go v1.9.2/go.mod h1:p1l1Bxdv9sz6x2jfbuGQUGJn6g5cqg7xsTp8rBHFoJY=
14-
github.com/xssnick/tonutils-go v1.9.9-0.20240726185310-b76c122b8cd6 h1:po4uMNWZTLZxO0Xms4BEHB8TCar3gLFMUAGgmvDsN9E=
15-
github.com/xssnick/tonutils-go v1.9.9-0.20240726185310-b76c122b8cd6/go.mod h1:p1l1Bxdv9sz6x2jfbuGQUGJn6g5cqg7xsTp8rBHFoJY=
1610
github.com/xssnick/tonutils-go v1.9.9-0.20240729172752-0ce0d252a288 h1:nbTy2yUnRob4iCjiQcJ8gQVoc6rtqgIVNKMnl5AvhRo=
1711
github.com/xssnick/tonutils-go v1.9.9-0.20240729172752-0ce0d252a288/go.mod h1:p1l1Bxdv9sz6x2jfbuGQUGJn6g5cqg7xsTp8rBHFoJY=
18-
github.com/xssnick/tonutils-go v1.9.9 h1:J0hVJI4LNEFHqgRHzpWTjFuv/Ga89OqLRUc9gxmjCoc=
19-
github.com/xssnick/tonutils-go v1.9.9/go.mod h1:p1l1Bxdv9sz6x2jfbuGQUGJn6g5cqg7xsTp8rBHFoJY=
2012
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
2113
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
2214
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

0 commit comments

Comments
 (0)