update... work pending

This commit is contained in:
brent saner
2025-02-04 12:14:08 -05:00
parent 3b4d712722
commit 3c984a0636
39 changed files with 2122 additions and 597 deletions

View File

@@ -9,6 +9,16 @@ import (
"r00t2.io/clientinfo/server"
)
// Has48 returns true if this Tunnel has a /48 assigned.
func (t *Tunnel) Has48() (has48 bool) {
if t.Routed48 != nil {
has48 = true
}
return
}
/*
Update checks the current (or explicit) client IPv4 address, compares it against the Tunnel's configuration,
and updates itself on change.
@@ -20,10 +30,9 @@ func (t *Tunnel) Update() (updated bool, err error) {
var req *resty.Request
var targetIp net.IP
var respStrs []string
var newTun *Tunnel = new(Tunnel)
if t.tunCfg.ExplicitAddr != nil {
targetIp = *t.tunCfg.ExplicitAddr
if t.TunCfg.ExplicitAddr != nil {
targetIp = *t.TunCfg.ExplicitAddr
} else {
// Fetch the current client IP.
// Teeechnically we don't need to do this, as it by default uses client IP, but we wanna be as considerate as we can.
@@ -45,8 +54,8 @@ func (t *Tunnel) Update() (updated bool, err error) {
if !t.ClientIPv4.Equal(targetIp) {
// It's different, so update.
req = t.client.R()
req.SetBasicAuth(*t.tunCfg.Username, t.tunCfg.UpdateKey)
req.SetQueryParam(updateTidParam, fmt.Sprintf("%d", t.tunCfg.TunnelID))
req.SetBasicAuth(*t.TunCfg.Username, t.TunCfg.UpdateKey)
req.SetQueryParam(updateTidParam, fmt.Sprintf("%d", t.TunCfg.TunnelID))
req.SetQueryParam(updateIpParam, targetIp.To4().String())
if resp, err = req.Get(updateBaseUrl); err != nil {
@@ -59,20 +68,17 @@ func (t *Tunnel) Update() (updated bool, err error) {
respStrs = strings.Fields(resp.String())
if respStrs == nil || len(respStrs) == 0 {
// I... don't know what would result in this, but let's assume it succeeded.
if newTun, err = GetTunnel(t.tunCfg, t.client.Debug); err != nil {
return
}
updated = true
*t = *newTun
return
}
switch len(respStrs) {
case 1:
switch respStrs[0] {
case "abuse":
if respStrs[0] == "abuse" {
err = ErrHERateLimit
return
}
case 2:
switch respStrs[0] {
case "nochg":
// No update; existing value is the same
return
@@ -89,9 +95,7 @@ func (t *Tunnel) Update() (updated bool, err error) {
return
}
}
case 2:
}
}
return