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
18f5271c
Commit
18f5271c
authored
Jan 06, 2026
by
vicotor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add ipbanlist watcher
parent
1be0814d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
0 deletions
+48
-0
main.go
main.go
+48
-0
No files found.
main.go
View file @
18f5271c
...
@@ -190,6 +190,7 @@ func main() {
...
@@ -190,6 +190,7 @@ func main() {
}
}
banList
=
loadBanList
(
banListFile
)
banList
=
loadBanList
(
banListFile
)
log
.
Printf
(
"loaded ban list entries: %d"
,
len
(
banList
))
log
.
Printf
(
"loaded ban list entries: %d"
,
len
(
banList
))
startIpBanListWatcher
(
banListFile
)
// Load Local Address Blacklist
// Load Local Address Blacklist
localBlacklistFile
=
os
.
Getenv
(
"LOCAL_BLACKLIST_FILE"
)
localBlacklistFile
=
os
.
Getenv
(
"LOCAL_BLACKLIST_FILE"
)
...
@@ -1029,6 +1030,53 @@ func startLocalBlacklistWatcher(path string) {
...
@@ -1029,6 +1030,53 @@ func startLocalBlacklistWatcher(path string) {
}()
}()
}
}
func
startIpBanListWatcher
(
path
string
)
{
// Start fsnotify watcher
go
func
()
{
watcher
,
err
:=
fsnotify
.
NewWatcher
()
if
err
!=
nil
{
log
.
Printf
(
"create ip banlist watcher error: %v"
,
err
)
return
}
defer
watcher
.
Close
()
dir
:=
filepath
.
Dir
(
path
)
if
err
:=
watcher
.
Add
(
dir
);
err
!=
nil
{
log
.
Printf
(
"add ip banlist watch dir error: %v"
,
err
)
return
}
for
{
select
{
case
ev
,
ok
:=
<-
watcher
.
Events
:
if
!
ok
{
return
}
if
ev
.
Name
==
path
{
if
ev
.
Op
&
(
fsnotify
.
Write
|
fsnotify
.
Create
|
fsnotify
.
Rename
)
!=
0
{
bl
:=
loadBanList
(
path
)
banListMu
.
Lock
()
banList
=
bl
banListMu
.
Unlock
()
log
.
Printf
(
"ip banlist reloaded (%d entries) due to event: %s"
,
len
(
bl
),
ev
.
Op
.
String
())
}
if
ev
.
Op
&
fsnotify
.
Remove
!=
0
{
banListMu
.
Lock
()
banList
=
map
[
string
]
struct
{}{}
banListMu
.
Unlock
()
log
.
Printf
(
"ip banlist file removed, cleared entries"
)
}
}
case
err
,
ok
:=
<-
watcher
.
Errors
:
if
!
ok
{
return
}
log
.
Printf
(
"ip banlist watcher error: %v"
,
err
)
}
}
}()
}
// ===== Ban List helper functions =====
// ===== Ban List helper functions =====
func
loadBanList
(
path
string
)
map
[
string
]
struct
{}
{
func
loadBanList
(
path
string
)
map
[
string
]
struct
{}
{
result
:=
make
(
map
[
string
]
struct
{})
result
:=
make
(
map
[
string
]
struct
{})
...
...
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