Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ip cache time configable #708

Merged
merged 1 commit into from
May 25, 2023
Merged

feat: ip cache time configable #708

merged 1 commit into from
May 25, 2023

Conversation

feranwq
Copy link
Contributor

@feranwq feranwq commented May 23, 2023

What does this PR do?

#706

Motivation

可配置 IP 缓存次数,增加本地IP 检查频率, 且不会被服务商限流

Additional Notes

@feranwq feranwq force-pushed the master branch 3 times, most recently from 8c32d38 to cde1c10 Compare May 24, 2023 15:02
util/ip_cache.go Outdated
@@ -13,10 +20,14 @@ func (d *IpCache) Check(newAddr string) bool {
if newAddr == "" {
return true
}
IPCacheTimes, err := strconv.Atoi(os.Getenv(IPCacheTimesENV))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IPCacheTimes获取可以放在28行的if里面

main.go Outdated
@@ -26,6 +26,9 @@ var listen = flag.String("l", ":9876", "监听地址")
// 更新频率(秒)
var every = flag.Int("f", 300, "同步间隔时间(秒)")

// 缓存次数
var ipCacheTimes = flag.Int("t", 6, "IP缓存次数")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不用简写t。换个类似noweb的单词

README.md Outdated
@@ -59,10 +59,10 @@
docker run -d --name ddns-go --restart=always --net=host -v /opt/ddns-go:/root ghcr.io/jeessy2/ddns-go
```

- [可选] 支持启动带参数 `-l`监听地址 `-f`间隔时间(秒)
- [可选] 支持启动带参数 `-l`监听地址 `-f`间隔时间(秒) `-t`缓存触发更新次数
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

缓存触发更新次数 这个不好理解,想个更加容易理解的,如:间隔多少次与服务商比对?或想下有没有更好的

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

好的,我看下一起改下

@feranwq feranwq force-pushed the master branch 4 times, most recently from 35fb976 to f5f55ae Compare May 24, 2023 15:35
@feranwq
Copy link
Contributor Author

feranwq commented May 24, 2023

@jeessy2 已更新, flag 改为 -cacheTimes , 说明没改, 下面举例说了一下用法, 默认示例里不再体现此参数

@jeessy2
Copy link
Owner

jeessy2 commented May 25, 2023

@jeessy2 已更新, flag 改为 -cacheTimes , 说明没改, 下面举例说了一下用法, 默认示例里不再体现此参数

缓存触发更新次数 这个有点拗口,想个啥名称好点

@feranwq
Copy link
Contributor Author

feranwq commented May 25, 2023

@jeessy2 已更新, flag 改为 -cacheTimes , 说明没改, 下面举例说了一下用法, 默认示例里不再体现此参数

缓存触发更新次数 这个有点拗口,想个啥名称好点

间隔N次与服务商比对 怎么样

@jeessy2
Copy link
Owner

jeessy2 commented May 25, 2023

@jeessy2 已更新, flag 改为 -cacheTimes , 说明没改, 下面举例说了一下用法, 默认示例里不再体现此参数

缓存触发更新次数 这个有点拗口,想个啥名称好点

间隔N次与服务商比对 怎么样

可以

@feranwq
Copy link
Contributor Author

feranwq commented May 25, 2023

@jeessy2 done

Copy link
Owner

@jeessy2 jeessy2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @feranwq

@jeessy2 jeessy2 merged commit d69bbe6 into jeessy2:master May 25, 2023
@jeessy2
Copy link
Owner

jeessy2 commented May 25, 2023

还有一个转换问题,比如:输入的6,实际等待了5次,感觉有点不对呢

@feranwq
Copy link
Contributor Author

feranwq commented May 25, 2023

我试下,逻辑跟之前应该是没区别的

@jeessy2
Copy link
Owner

jeessy2 commented May 25, 2023

我试下,逻辑跟之前应该是没区别的

以前没暴露给用户看,所以不存在这个问题。现在让用户设置了,我设置的6,怎么间隔了5次

@feranwq
Copy link
Contributor Author

feranwq commented May 25, 2023

@jeessy2 去服务商比对也算作一次,所以实际间隔次数确实需要加一
ip_cache.go里

d.Times = IPCacheTimes + 1

这样可以达到预期效果,你看如何

@jeessy2
Copy link
Owner

jeessy2 commented May 25, 2023

-cacheTimes间隔N次与服务商比对
看文字的话,应该是间隔的次数,设置6次,间隔应该也是6次
以前默认的5次,所以初始化应该是5次,间隔也是5次

Copy link
Owner

@jeessy2 jeessy2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我觉得应该这么改?

@@ -15,8 +22,12 @@ func (d *IpCache) Check(newAddr string) bool {
}
// 地址改变 或 达到剩余次数
if d.Addr != newAddr || d.Times <= 1 {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该为d.Times <= 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这样改虽然实际执行是正确的,log显示不友好, 例如设置为 3 次
2023/05/26 00:07:27 IPv6未改变,将等待 2 次后与DNS服务商进行比对
2023/05/26 00:07:32 IPv6未改变,将等待 1 次后与DNS服务商进行比对
2023/05/26 00:07:37 IPv6未改变,将等待 0 次后与DNS服务商进行比对

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那按你的来,默认5次

@@ -26,6 +26,9 @@ var listen = flag.String("l", ":9876", "监听地址")
// 更新频率(秒)
var every = flag.Int("f", 300, "同步间隔时间(秒)")

// 缓存次数
var ipCacheTimes = flag.Int("cacheTimes", 6, "间隔N次与服务商比对")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

默认5次

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants