Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
R
re6stnet
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
2
Issues
2
List
Boards
Labels
Milestones
Merge Requests
4
Merge Requests
4
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
re6stnet
Commits
eee67f4e
Commit
eee67f4e
authored
Jul 25, 2012
by
Guillaume Bury
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Blacklist is now a sql table
parent
44eab543
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
9 deletions
+22
-9
db.py
db.py
+20
-6
tunnel.py
tunnel.py
+2
-3
No files found.
db.py
View file @
eee67f4e
...
...
@@ -28,6 +28,11 @@ class PeerManager:
utils
.
log
(
'Preparing peers database...'
,
4
)
try
:
self
.
_db
.
execute
(
"UPDATE peers SET used = 0"
)
self
.
_db
.
execute
(
"""CREATE TABLE IF NOT EXISTS blacklist (
prefix TEXT PRIMARY KEY,
flag INTEGER NOT NULL)"""
)
self
.
_db
.
execute
(
"""CREATE INDEX IF NOT EXISTS
blacklist_flag ON blacklist(flag)"""
)
except
sqlite3
.
OperationalError
,
e
:
if
e
.
args
[
0
]
==
'no such table: peers'
:
raise
RuntimeError
...
...
@@ -35,13 +40,22 @@ class PeerManager:
self
.
next_refresh
=
time
.
time
()
def
reset_blacklist
(
self
):
self
.
_blacklist
=
[(
self
.
_prefix
)]
def
clear_blacklist
(
self
,
flag
):
utils
.
log
(
'Clearing blacklist from flag %u'
%
(
flag
,),
3
)
self
.
_db
.
execute
(
"DELETE FROM blacklist WHERE flag = ?"
,
(
flag
,))
utils
.
log
(
'Blacklist cleared'
,
5
)
def
blacklist
(
self
,
prefix
):
def
blacklist
(
self
,
prefix
,
flag
):
utils
.
log
(
'Blacklisting %s'
%
(
prefix
,),
4
)
self
.
_db
.
execute
(
"DELETE FROM peers WHERE prefix = ?"
,
(
prefix
,))
self
.
_blacklist
=
list
(
set
(
self
.
_blacklist
+
[(
prefix
,)]))
self
.
_db
.
execute
(
"INSERT OR REPLACE INTO blacklist VALUES (?,?)"
,
(
prefix
,
flag
))
utils
.
log
(
'%s blacklisted'
%
(
prefix
,),
5
)
def
whitelist
(
self
,
prefix
):
utils
.
log
(
'Unblacklisting %s'
%
(
prefix
,),
4
)
self
.
_db
.
execute
(
"DELETE FROM blacklist WHERE prefix = ?"
,
(
prefix
,))
utils
.
log
(
'%s whitelisted'
%
(
prefix
,),
5
)
def
refresh
(
self
):
utils
.
log
(
'Refreshing the peers DB...'
,
2
)
...
...
@@ -74,8 +88,8 @@ class PeerManager:
(
str
(
len
(
new_peer_list
)
-
self
.
_db_size
),))
self
.
_db
.
executemany
(
"""INSERT OR IGNORE INTO peers (prefix, address)
VALUES (?,?)"""
,
new_peer_list
)
self
.
_db
.
execute
many
(
"DELETE FROM peers WHERE prefix = ?"
,
self
.
_blacklist
)
self
.
_db
.
execute
(
"""DELETE FROM peers WHERE prefix IN
(SELECT prefix FROM blacklist)"""
)
utils
.
log
(
'DB populated'
,
3
)
utils
.
log
(
'New peers : %s'
%
', '
.
join
(
map
(
str
,
new_peer_list
)),
5
)
...
...
tunnel.py
View file @
eee67f4e
...
...
@@ -78,7 +78,6 @@ class TunnelManager:
self
.
_network
=
network
self
.
_net_len
=
len
(
network
)
self
.
_iface_list
=
iface_list
self
.
__indirect_connect
=
[]
self
.
free_interface_set
=
set
((
'client1'
,
'client2'
,
'client3'
,
'client4'
,
'client5'
,
'client6'
,
'client7'
,
'client8'
,
'client9'
,
...
...
@@ -150,7 +149,7 @@ class TunnelManager:
def
_countRoutes
(
self
):
utils
.
log
(
'Starting to count the routes on each interface...'
,
3
)
self
.
_
indirect_connect
=
[]
self
.
_
peer_db
.
clear_blacklist
(
0
)
for
iface
in
self
.
_iface_to_prefix
.
keys
():
self
.
_connection_dict
[
self
.
_iface_to_prefix
[
iface
]].
routes
=
0
f
=
open
(
'/proc/net/ipv6_route'
,
'r'
)
...
...
@@ -170,7 +169,7 @@ class TunnelManager:
prefix
=
ip
[
self
.
_net_len
:
subnet_size
]
utils
.
log
(
'A route to %s has been discovered on the LAN'
%
(
prefix
,),
3
)
self
.
_peer_db
.
blacklist
(
prefix
)
self
.
_peer_db
.
blacklist
(
prefix
,
0
)
utils
.
log
(
"Routes have been counted"
,
3
)
for
p
in
self
.
_connection_dict
.
keys
():
...
...
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