Skip to content

Commit 59cc938

Browse files
committedJan 11, 2023
Explicit external ip support
1 parent 0b5eaef commit 59cc938

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed
 

‎cmd/proxy/main.go

+23-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"github.com/mdp/qrterminal/v3"
1212
"github.com/sigurn/crc16"
13+
"github.com/xssnick/tonutils-go/adnl"
1314
"github.com/xssnick/tonutils-go/adnl/dht"
1415
rldphttp "github.com/xssnick/tonutils-go/adnl/rldp/http"
1516
"github.com/xssnick/tonutils-go/liteclient"
@@ -18,6 +19,7 @@ import (
1819
"github.com/xssnick/tonutils-go/ton/dns"
1920
"io"
2021
"log"
22+
"net"
2123
"net/http"
2224
"net/http/httputil"
2325
"net/url"
@@ -27,13 +29,14 @@ import (
2729

2830
type Config struct {
2931
ProxyPass string `json:"proxy_pass"`
30-
ForwardTo string `json:"forward_to"`
3132
PrivateKey []byte `json:"private_key"`
32-
IP string `json:"address"`
33+
ExternalIP string `json:"external_ip"`
34+
ListenIP string `json:"listen_ip"`
3335
Port uint16 `json:"port"`
3436
}
3537

3638
var FlagDomain = flag.String("domain", "", "domain to configure")
39+
var FlagDebug = flag.Bool("debug", false, "more logs")
3740

3841
type Handler struct {
3942
h http.Handler
@@ -49,7 +52,7 @@ func (h Handler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
4952

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

52-
writer.Header().Set("Ton-Reverse-Proxy", "TonUtils Reverse Proxy v0.0.2")
55+
writer.Header().Set("Ton-Reverse-Proxy", "TonUtils Reverse Proxy v0.0.4")
5356
h.h.ServeHTTP(writer, request)
5457
}
5558

@@ -86,8 +89,14 @@ func main() {
8689
panic(err)
8790
}
8891

92+
if *FlagDebug == false {
93+
adnl.Logger = func(v ...any) {}
94+
// rldphttp.Logger = func(v ...any) {}
95+
}
96+
8997
proxy := httputil.NewSingleHostReverseProxy(u)
9098
s := rldphttp.NewServer(ed25519.NewKeyFromSeed(cfg.PrivateKey), dhtClient, Handler{proxy})
99+
s.SetExternalIP(net.ParseIP(cfg.ExternalIP))
91100

92101
addr, err := rldphttp.SerializeADNLAddress(s.Address())
93102
if err != nil {
@@ -100,7 +109,7 @@ func main() {
100109
}
101110

102111
log.Println("Starting server on", addr+".adnl")
103-
if err = s.ListenAndServe(fmt.Sprintf("%s:%d", cfg.IP, cfg.Port)); err != nil {
112+
if err = s.ListenAndServe(fmt.Sprintf("%s:%d", cfg.ListenIP, cfg.Port)); err != nil {
104113
panic(err)
105114
}
106115
}
@@ -141,13 +150,14 @@ func loadConfig() (*Config, error) {
141150
}
142151
cfg.PrivateKey = srvKey.Seed()
143152

144-
cfg.IP, err = getPublicIP()
153+
cfg.ExternalIP, err = getPublicIP()
145154
if err != nil {
146155
return nil, err
147156
}
157+
cfg.ListenIP = "0.0.0.0"
148158

149159
// generate consistent port
150-
cfg.Port = 9000 + (crc16.Checksum([]byte(cfg.IP), crc16.MakeTable(crc16.CRC16_XMODEM)) % 5000)
160+
cfg.Port = 9000 + (crc16.Checksum([]byte(cfg.ExternalIP), crc16.MakeTable(crc16.CRC16_XMODEM)) % 5000)
151161

152162
cfg.ProxyPass = "http://127.0.0.1:80/"
153163

@@ -194,8 +204,15 @@ func setupDomain(client *liteclient.ConnectionPool, domain string, adnlAddr []by
194204
data := domainInfo.BuildSetSiteRecordPayload(adnlAddr).ToBOCWithFlags(false)
195205
args := "?bin=" + base64.URLEncoding.EncodeToString(data) + "&amount=" + tlb.MustFromTON("0.02").NanoTON().String()
196206

207+
nftData, err := domainInfo.GetNFTData(context.Background())
208+
if err != nil {
209+
log.Println("Failed to get domain data", domain, ":", err)
210+
return
211+
}
212+
197213
qrterminal.GenerateHalfBlock("ton://transfer/"+domainInfo.GetNFTAddress().String()+args, qrterminal.L, os.Stdout)
198214
fmt.Println("Execute this transaction from the domain owner's wallet to setup site records.")
215+
fmt.Println("Execute transaction from wallet:", nftData.OwnerAddress.String())
199216
fmt.Println("When you've done, configuration will automatically proceed in ~10 seconds.")
200217
for {
201218
time.Sleep(5 * time.Second)

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.19
55
require (
66
github.com/mdp/qrterminal/v3 v3.0.0
77
github.com/sigurn/crc16 v0.0.0-20211026045750-20ab5afb07e3
8-
github.com/xssnick/tonutils-go v1.4.1-0.20230109130346-b0cd607f9ab5
8+
github.com/xssnick/tonutils-go v1.4.1-0.20230111070238-84e56fb29fc5
99
)
1010

1111
require (

‎go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ github.com/xssnick/tonutils-go v1.4.1-0.20230109125855-ce4e62c44be4 h1:ihkJUII8d
4545
github.com/xssnick/tonutils-go v1.4.1-0.20230109125855-ce4e62c44be4/go.mod h1:wH8ldhLueyfXW15r3MyaIq9YzA+8bzvL6UMU2BLp08g=
4646
github.com/xssnick/tonutils-go v1.4.1-0.20230109130346-b0cd607f9ab5 h1:BkYqyX87xkZ1MmlP5SGV42lSnewJPrB2WCArPDzaVCI=
4747
github.com/xssnick/tonutils-go v1.4.1-0.20230109130346-b0cd607f9ab5/go.mod h1:wH8ldhLueyfXW15r3MyaIq9YzA+8bzvL6UMU2BLp08g=
48+
github.com/xssnick/tonutils-go v1.4.1-0.20230111063410-3fe2a189cd60 h1:Tc9Lm9G3VGjIb29/tjKk2tgwlSFBIvnwpgGaMF6B+4U=
49+
github.com/xssnick/tonutils-go v1.4.1-0.20230111063410-3fe2a189cd60/go.mod h1:wH8ldhLueyfXW15r3MyaIq9YzA+8bzvL6UMU2BLp08g=
50+
github.com/xssnick/tonutils-go v1.4.1-0.20230111065721-26547c5ebc1e h1:V09j1fNm1pWsdULpeTic2r16nqH00A41kBlzjurc/UA=
51+
github.com/xssnick/tonutils-go v1.4.1-0.20230111065721-26547c5ebc1e/go.mod h1:wH8ldhLueyfXW15r3MyaIq9YzA+8bzvL6UMU2BLp08g=
52+
github.com/xssnick/tonutils-go v1.4.1-0.20230111070238-84e56fb29fc5 h1:21bO7IXo0gjG5HwkMg6VqbOMUzwP7C4eMeMFACjGuVw=
53+
github.com/xssnick/tonutils-go v1.4.1-0.20230111070238-84e56fb29fc5/go.mod h1:wH8ldhLueyfXW15r3MyaIq9YzA+8bzvL6UMU2BLp08g=
4854
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064 h1:S25/rfnfsMVgORT4/J61MJ7rdyseOZOyvLIrZEZ7s6s=
4955
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
5056
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=

0 commit comments

Comments
 (0)