Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Status-Bot
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Freifunk Hochstift
Status-Bot
Commits
ac4c4194
Commit
ac4c4194
authored
9 years ago
by
Maximilian Wilhelm
Browse files
Options
Downloads
Patches
Plain Diff
Add message cache and use it for "Peers updated:" messages.
Signed-off-by:
Maximilian Wilhelm
<
max@rfc2324.org
>
parent
7206851a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
modules/ffpb.py
+28
-4
28 additions, 4 deletions
modules/ffpb.py
with
28 additions
and
4 deletions
modules/ffpb.py
+
28
−
4
View file @
ac4c4194
...
...
@@ -40,12 +40,14 @@ __batcave = None
ffpb_resolver
=
dns
.
resolver
.
Resolver
()
ffpb_resolver
.
nameservers
=
[
'
10.132.251.53
'
]
msg_cache
=
{}
msg_cache_time
=
10
class
MsgHandler
(
SocketServer
.
BaseRequestHandler
):
"""
Reads line from TCP stream and forwards it to configured IRC channels.
"""
def
handle
(
self
):
data
=
self
.
request
.
recv
(
2048
).
strip
()
msg
=
str
(
self
.
request
.
recv
(
2048
).
strip
()
)
sender
=
self
.
resolve_name
(
self
.
client_address
[
0
])
bot
=
self
.
server
.
bot
...
...
@@ -55,15 +57,28 @@ class MsgHandler(SocketServer.BaseRequestHandler):
target
=
bot
.
config
.
core
.
owner
if
bot
.
config
.
has_section
(
'
ffpb
'
):
is_public
=
data
.
lstrip
().
startswith
(
"
PUBLIC:
"
)
is_public
=
msg
.
lstrip
().
startswith
(
"
PUBLIC:
"
)
if
is_public
and
not
bot
.
config
.
ffpb
.
msg_target_public
is
None
:
data
=
data
[
7
:].
lstrip
()
msg
=
msg
[
7
:].
lstrip
()
target
=
bot
.
config
.
ffpb
.
msg_target_public
elif
not
bot
.
config
.
ffpb
.
msg_target
is
None
:
target
=
bot
.
config
.
ffpb
.
msg_target
bot
.
msg
(
target
,
"
[{0}] {1}
"
.
format
(
sender
,
str
(
data
)))
# Try to aggregate peer updates and print them in batch
if
msg
.
startswith
(
"
Peers updated:
"
):
if
msg
not
in
msg_cache
:
msg_cache
[
msg
]
=
{
'
time
'
:
time
.
time
(),
'
nodes
'
:
[]
}
# Save message in message cache, will be delivered later
msg_cache
[
msg
][
'
nodes
'
].
append
(
sender
)
return
bot
.
msg
(
target
,
"
[{0}] {1}
"
.
format
(
sender
,
msg
))
def
resolve_name
(
self
,
ipaddr
):
"""
...
...
@@ -565,6 +580,15 @@ def ffpb_updatepeers(bot):
bot
.
msg
(
bot
.
config
.
ffpb
.
msg_target
,
response
)
@willie.module.interval
(
15
)
def
ffpb_print_cached_messages
(
bot
):
for
msg
,
m_info
in
msg_cache
.
items
():
if
time
.
time
()
-
m_info
[
'
time
'
]
>
msg_cache_time
:
sender
=
"
,
"
.
join
(
sorted
(
m_info
[
'
nodes
'
]))
bot
.
msg
(
bot
.
config
.
ffpb
.
msg_target
,
"
[{0}] {1}
"
.
format
(
sender
,
msg
))
del
msg_cache
[
msg
]
def
ffpb_fetch_stats
(
bot
,
url
,
memoryid
):
"""
Fetch a ffmap-style nodes.json from the given URL and
store it in the bot
'
s memory.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment