From 518d4b433563ac1b438467d163eb8d6fc18385f9 Mon Sep 17 00:00:00 2001 From: Christian Ditaputratama Date: Fri, 6 Sep 2024 00:08:59 +0700 Subject: [PATCH] feat: Added IPv6 nodes support (alpha) #84 This commit accept IPv6 nodes submission. When user submit new public node, the server will check IP addresses from given hostname. If host IP addresses doesn't have IPv4, it will be recorded as "IPv6 only" node. Probers that support IPv6 may add `IPV6_CAPABLE=true` to the `.env` file. Please note that this feature still experimental and may not being merged to the main branch. --- .env.example | 1 + cmd/client/probe.go | 36 +++++++++++++++-------- frontend/src/routes/add-node/+page.svelte | 2 +- internal/config/app.go | 2 ++ internal/database/schema.go | 18 +++++++++++- internal/handler/response.go | 3 +- internal/monero/monero.go | 20 +++++++++---- internal/monero/report.go | 6 +++- 8 files changed, 67 insertions(+), 21 deletions(-) diff --git a/.env.example b/.env.example index d37fbd6..c279942 100644 --- a/.env.example +++ b/.env.example @@ -8,6 +8,7 @@ SERVER_ENDPOINT="http://127.0.0.1:18901" API_KEY= ACCEPT_TOR=false TOR_SOCKS="127.0.0.1:9050" +IPV6_CAPABLE=false # Server Config # ############# diff --git a/cmd/client/probe.go b/cmd/client/probe.go index 0794bd5..c79d787 100644 --- a/cmd/client/probe.go +++ b/cmd/client/probe.go @@ -36,20 +36,22 @@ func (err errProber) Error() string { } type proberClient struct { - endpoint string // server endpoint - apiKey string // prober api key - acceptTor bool // accept tor - torSOCKS string // IP:Port of tor socks - message string // message to include when reporting back to server + endpoint string // server endpoint + apiKey string // prober api key + acceptTor bool // accept tor + torSOCKS string // IP:Port of tor socks + acceptIPv6 bool // accept ipv6 + message string // message to include when reporting back to server } func newProber() *proberClient { cfg := config.AppCfg() return &proberClient{ - endpoint: cfg.ServerEndpoint, - apiKey: cfg.APIKey, - acceptTor: cfg.AcceptTor, - torSOCKS: cfg.TorSOCKS, + endpoint: cfg.ServerEndpoint, + apiKey: cfg.APIKey, + acceptTor: cfg.AcceptTor, + torSOCKS: cfg.TorSOCKS, + acceptIPv6: cfg.IPv6Capable, } } @@ -85,6 +87,10 @@ func (p *proberClient) SetAcceptTor(acceptTor bool) { p.acceptTor = acceptTor } +func (p *proberClient) SetAcceptIPv6(acceptIPv6 bool) { + p.acceptIPv6 = acceptIPv6 +} + // Fetch a new job from the server, fetches node info, and sends it to the server func (p *proberClient) Run() error { if err := p.validateConfig(); err != nil { @@ -121,20 +127,26 @@ func (p *proberClient) validateConfig() error { // Get monero node info to fetch from the server func (p *proberClient) fetchJob() (monero.Node, error) { - queryParams := "" + acceptTor := 0 if p.acceptTor { - queryParams = "?accept_tor=1" + acceptTor = 1 + } + + acceptIPv6 := 0 + if p.acceptIPv6 { + acceptIPv6 = 1 } var node monero.Node - uri := fmt.Sprintf("%s/api/v1/job%s", p.endpoint, queryParams) + uri := fmt.Sprintf("%s/api/v1/job?accept_tor=%d&accept_ipv6=%d", p.endpoint, acceptTor, acceptIPv6) slog.Info(fmt.Sprintf("[PROBE] Getting node from %s", uri)) req, err := http.NewRequest(http.MethodGet, uri, nil) if err != nil { return node, err } + req.Header.Add(monero.ProberAPIKey, p.apiKey) req.Header.Set("User-Agent", RPCUserAgent) diff --git a/frontend/src/routes/add-node/+page.svelte b/frontend/src/routes/add-node/+page.svelte index c7901dd..4565f97 100644 --- a/frontend/src/routes/add-node/+page.svelte +++ b/frontend/src/routes/add-node/+page.svelte @@ -42,7 +42,7 @@
-

Enter your Monero node information below (IPv4 host only):

+

Enter your Monero node information below (IPv6 host check is experimental):

0 { where = "WHERE " + strings.Join(wq, " AND ")