commit 8cda711e33c0b9b08a506626f4c2b641ed04dfd8
parent 923aed5e17e207cf64cd70a506c471023bc767c7
Author: n0tr1v <n0tr1v@protonmail.com>
Date: Sun, 18 Dec 2022 14:40:21 -0800
cleanup
Diffstat:
1 file changed, 16 insertions(+), 11 deletions(-)
diff --git a/pkg/web/web.go b/pkg/web/web.go
@@ -298,6 +298,21 @@ func Start(host string, port int) {
}
}
+func extractGlobalCircuitIdentifier(m string) int64 {
+ // You can compute the global circuit identifier using the following formula given the IPv6 address "fc00:dead:beef:4dad::AABB:CCDD":
+ // global_circuit_id = (0xAA << 24) + (0xBB << 16) + (0xCC << 8) + 0xDD;
+ s1 := strings.Split(m, "::")[1]
+ s2 := strings.Split(s1, ":")
+ aabb := fmt.Sprintf("%04s", s2[0])
+ ccdd := fmt.Sprintf("%04s", s2[1])
+ aa, _ := strconv.ParseInt(aabb[0:2], 16, 64)
+ bb, _ := strconv.ParseInt(aabb[2:4], 16, 64)
+ cc, _ := strconv.ParseInt(ccdd[0:2], 16, 64)
+ dd, _ := strconv.ParseInt(ccdd[2:4], 16, 64)
+ globalCircuitID := (aa << 24) + (bb << 16) + (cc << 8) + dd
+ return globalCircuitID
+}
+
func prodServer(e *echo.Echo) {
rate := limiter.Rate{Period: 5 * time.Second, Limit: 25}
store := memory.NewStore()
@@ -313,17 +328,7 @@ func prodServer(e *echo.Echo) {
}
m := haproxyRgx.FindStringSubmatch(string(buf))
if len(m) == 2 {
- // You can compute the global circuit identifier using the following formula given the IPv6 address "fc00:dead:beef:4dad::AABB:CCDD":
- // global_circuit_id = (0xAA << 24) + (0xBB << 16) + (0xCC << 8) + 0xDD;
- s1 := strings.Split(m[1], "::")[1]
- s2 := strings.Split(s1, ":")
- aabb := fmt.Sprintf("%04s", s2[0])
- ccdd := fmt.Sprintf("%04s", s2[1])
- aa, _ := strconv.ParseInt(aabb[0:2], 16, 64)
- bb, _ := strconv.ParseInt(aabb[2:4], 16, 64)
- cc, _ := strconv.ParseInt(ccdd[0:2], 16, 64)
- dd, _ := strconv.ParseInt(ccdd[2:4], 16, 64)
- globalCircuitID := (aa << 24) + (bb << 16) + (cc << 8) + dd
+ globalCircuitID := extractGlobalCircuitIdentifier(m[1])
config.ConnMap.Set(conn, globalCircuitID)
limiterCtx, _ := limiterInstance.Get(context.Background(), utils.FormatInt64(globalCircuitID))