From f339bc9c3c5a0fd76448b4e1d9be8a73f51b0bae Mon Sep 17 00:00:00 2001 From: Christian Ditaputratama Date: Thu, 7 Nov 2024 20:52:38 +0700 Subject: [PATCH] feat: Added remote nodes i2p filter #148 --- internal/handler/views/remote_nodes.templ | 2 +- internal/handler/views/remote_nodes_templ.go | 2 +- internal/monero/monero.go | 14 +++++++++----- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/internal/handler/views/remote_nodes.templ b/internal/handler/views/remote_nodes.templ index 38fe71c..54eaec0 100644 --- a/internal/handler/views/remote_nodes.templ +++ b/internal/handler/views/remote_nodes.templ @@ -11,7 +11,7 @@ import ( ) var nettypes = []string{"mainnet", "stagenet", "testnet"} -var protocols = []string{"tor", "http", "https"} +var protocols = []string{"tor", "i2p", "http", "https"} type nodeStatus struct { Code int diff --git a/internal/handler/views/remote_nodes_templ.go b/internal/handler/views/remote_nodes_templ.go index a4812d2..47bbb17 100644 --- a/internal/handler/views/remote_nodes_templ.go +++ b/internal/handler/views/remote_nodes_templ.go @@ -19,7 +19,7 @@ import ( ) var nettypes = []string{"mainnet", "stagenet", "testnet"} -var protocols = []string{"tor", "http", "https"} +var protocols = []string{"tor", "i2p", "http", "https"} type nodeStatus struct { Code int diff --git a/internal/monero/monero.go b/internal/monero/monero.go index 200a2d8..30da41f 100644 --- a/internal/monero/monero.go +++ b/internal/monero/monero.go @@ -99,13 +99,17 @@ func (q *QueryNodes) toSQL() (args []interface{}, where string) { wq = append(wq, "nettype = ?") args = append(args, q.Nettype) } - if q.Protocol != "any" && slices.Contains([]string{"tor", "http", "https"}, q.Protocol) { - if q.Protocol == "tor" { + if q.Protocol != "any" && slices.Contains([]string{"tor", "i2p", "http", "https"}, q.Protocol) { + switch q.Protocol { + case "i2p": + wq = append(wq, "is_i2p = ?") + args = append(args, 1) + case "tor": wq = append(wq, "is_tor = ?") args = append(args, 1) - } else { - wq = append(wq, "(protocol = ? AND is_tor = ?)") - args = append(args, q.Protocol, 0) + default: + wq = append(wq, "(protocol = ? AND is_tor = ? AND is_i2p = ?)") + args = append(args, q.Protocol, 0, 0) } } if q.CC != "any" {