From db361bb5096270716bfcb5eee2675b34633b7dbb Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Mon, 7 Feb 2022 04:48:00 +0400 Subject: [PATCH] Prefix replaced by Suffix. Added NetworkType(). --- pkg/utils/dwelling.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkg/utils/dwelling.go b/pkg/utils/dwelling.go index 3547f93..5a9f6f6 100644 --- a/pkg/utils/dwelling.go +++ b/pkg/utils/dwelling.go @@ -4,11 +4,23 @@ import "strings" // MainSite returns homepage address depending on network used. func MainSite(host string) string { - if strings.HasPrefix(host, "i2p") { + if strings.HasSuffix(host, "i2p") { return "http://arav.i2p" - } else if strings.HasPrefix(host, "onion") { + } else if strings.HasSuffix(host, "onion") { return "http://.onion" } return "https://arav.top" } + +// NetworkType detects network based on host suffix, +// whether client connected from Tor, I2P or Clearnet. +func NetworkType(host string) string { + if strings.HasSuffix(host, "i2p") { + return "i2p" + } else if strings.HasSuffix(host, "onion") { + return "tor" + } else { + return "www" + } +}