Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
rpcproxy
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
rpcproxy
Commits
572b8a73
Commit
572b8a73
authored
Dec 29, 2025
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update file watcher
parent
1ae4f985
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
122 additions
and
33 deletions
+122
-33
main.go
main.go
+122
-33
No files found.
main.go
View file @
572b8a73
...
...
@@ -695,19 +695,21 @@ func compilePattern(p string) *regexp.Regexp {
}
func
startWhitelistWatcher
(
path
string
)
{
// Start fsnotify watcher
go
func
()
{
watcher
,
err
:=
fsnotify
.
NewWatcher
()
if
err
!=
nil
{
log
.
Printf
(
"create whitelist watcher error: %v"
,
err
)
return
}
defer
watcher
.
Close
()
dir
:=
filepath
.
Dir
(
path
)
if
err
:=
watcher
.
Add
(
dir
);
err
!=
nil
{
log
.
Printf
(
"add whitelist watch dir error: %v"
,
err
)
watcher
.
Close
()
return
}
go
func
()
{
defer
watcher
.
Close
()
for
{
select
{
case
ev
,
ok
:=
<-
watcher
.
Events
:
...
...
@@ -739,6 +741,34 @@ func startWhitelistWatcher(path string) {
}
}
}()
// Start Polling as fallback for Docker mounts
go
func
()
{
ticker
:=
time
.
NewTicker
(
10
*
time
.
Second
)
defer
ticker
.
Stop
()
var
lastModTime
time
.
Time
if
info
,
err
:=
os
.
Stat
(
path
);
err
==
nil
{
lastModTime
=
info
.
ModTime
()
}
for
range
ticker
.
C
{
info
,
err
:=
os
.
Stat
(
path
)
if
err
!=
nil
{
continue
}
// Check if modified
if
!
info
.
ModTime
()
.
Equal
(
lastModTime
)
{
lastModTime
=
info
.
ModTime
()
exact
,
pats
:=
loadWhitelist
(
path
)
whitelistMu
.
Lock
()
whitelist
=
exact
whitelistPatterns
=
pats
whitelistMu
.
Unlock
()
log
.
Printf
(
"whitelist reloaded (%d exact, %d patterns) due to polling change"
,
len
(
exact
),
len
(
pats
))
}
}
}()
}
// ===== IP Blacklist helper functions (dynamic reload) =====
...
...
@@ -820,19 +850,21 @@ func isIPBlacklisted(v string) bool {
}
func
startIPBlacklistWatcher
(
path
string
)
{
// Start fsnotify watcher
go
func
()
{
watcher
,
err
:=
fsnotify
.
NewWatcher
()
if
err
!=
nil
{
log
.
Printf
(
"create ip blacklist watcher error: %v"
,
err
)
return
}
defer
watcher
.
Close
()
dir
:=
filepath
.
Dir
(
path
)
if
err
:=
watcher
.
Add
(
dir
);
err
!=
nil
{
log
.
Printf
(
"add ip blacklist watch dir error: %v"
,
err
)
watcher
.
Close
()
return
}
go
func
()
{
defer
watcher
.
Close
()
for
{
select
{
case
ev
,
ok
:=
<-
watcher
.
Events
:
...
...
@@ -864,6 +896,34 @@ func startIPBlacklistWatcher(path string) {
}
}
}()
// Start Polling as fallback for Docker mounts
go
func
()
{
ticker
:=
time
.
NewTicker
(
10
*
time
.
Second
)
defer
ticker
.
Stop
()
var
lastModTime
time
.
Time
if
info
,
err
:=
os
.
Stat
(
path
);
err
==
nil
{
lastModTime
=
info
.
ModTime
()
}
for
range
ticker
.
C
{
info
,
err
:=
os
.
Stat
(
path
)
if
err
!=
nil
{
continue
}
// Check if modified
if
!
info
.
ModTime
()
.
Equal
(
lastModTime
)
{
lastModTime
=
info
.
ModTime
()
exact
,
pats
:=
loadIPBlacklist
(
path
)
ipBlacklistMu
.
Lock
()
ipBlacklist
=
exact
ipBlacklistPatterns
=
pats
ipBlacklistMu
.
Unlock
()
log
.
Printf
(
"ip blacklist reloaded (%d exact, %d patterns) due to polling change"
,
len
(
exact
),
len
(
pats
))
}
}
}()
}
// ===== Local Address Blacklist helper functions =====
...
...
@@ -896,19 +956,21 @@ func isLocalBlacklisted(addr string) bool {
}
func
startLocalBlacklistWatcher
(
path
string
)
{
// Start fsnotify watcher
go
func
()
{
watcher
,
err
:=
fsnotify
.
NewWatcher
()
if
err
!=
nil
{
log
.
Printf
(
"create local blacklist watcher error: %v"
,
err
)
return
}
defer
watcher
.
Close
()
dir
:=
filepath
.
Dir
(
path
)
if
err
:=
watcher
.
Add
(
dir
);
err
!=
nil
{
log
.
Printf
(
"add local blacklist watch dir error: %v"
,
err
)
watcher
.
Close
()
return
}
go
func
()
{
defer
watcher
.
Close
()
for
{
select
{
case
ev
,
ok
:=
<-
watcher
.
Events
:
...
...
@@ -938,6 +1000,33 @@ func startLocalBlacklistWatcher(path string) {
}
}
}()
// Start Polling as fallback for Docker mounts
go
func
()
{
ticker
:=
time
.
NewTicker
(
10
*
time
.
Second
)
defer
ticker
.
Stop
()
var
lastModTime
time
.
Time
if
info
,
err
:=
os
.
Stat
(
path
);
err
==
nil
{
lastModTime
=
info
.
ModTime
()
}
for
range
ticker
.
C
{
info
,
err
:=
os
.
Stat
(
path
)
if
err
!=
nil
{
continue
}
// Check if modified
if
!
info
.
ModTime
()
.
Equal
(
lastModTime
)
{
lastModTime
=
info
.
ModTime
()
bl
:=
loadLocalBlacklist
(
path
)
localBlacklistMu
.
Lock
()
localBlacklist
=
bl
localBlacklistMu
.
Unlock
()
log
.
Printf
(
"local blacklist reloaded (%d entries) due to polling change"
,
len
(
bl
))
}
}
}()
}
// ===== Ban List helper functions =====
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment