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
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
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
Yohann D'Anello
re6stnet
Commits
4fc87945
Commit
4fc87945
authored
Aug 14, 2012
by
Ulysse Beaugnon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Populate has been removed
parent
ab232120
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
39 deletions
+11
-39
TODO
TODO
+3
-5
re6st-registry
re6st-registry
+0
-16
re6st/db.py
re6st/db.py
+8
-18
No files found.
TODO
View file @
4fc87945
...
...
@@ -2,14 +2,12 @@ Bug :
possible bug in the upnp refresh, when refreshing after a too long time
To be done :
Choose
peer DB size.
Choose the number of peer we ask to the server
Choose
the db size and who peers are deleted
find out who to have an automatic recovery without declare
Test the package
remove some peers if their is too much in addpeer
check the ips attributed
remove populate
remove unused methodes from the registry
remove decalre
how do we make sure that none inject some false packets ?
how do we make sur that noone is declaring too much false nodes ?
...
...
re6st-registry
View file @
4fc87945
...
...
@@ -234,21 +234,5 @@ class main(object):
%
(
utils
.
ipFromBin
(
client_ip
),
utils
.
ipFromBin
(
self
.
network
.
ljust
(
128
,
'0'
))))
return
False
def
getPeerList
(
self
,
handler
,
n
):
assert
0
<
n
<
1000
client_address
,
_
,
_
,
_
=
handler
.
client_address
client_ip
=
utils
.
binFromIp
(
client_address
)
if
client_ip
.
startswith
(
self
.
network
):
if
time
.
time
()
>
self
.
last_refresh
+
self
.
refresh_interval
:
print
"refreshing peers for dead ones"
self
.
db
.
execute
(
"DELETE FROM peers WHERE ( date + ? ) <= CAST (strftime('%s', 'now') AS INTEGER)"
,
(
self
.
time_out
,))
self
.
last_refesh
=
time
.
time
()
print
"sending peers"
return
self
.
db
.
execute
(
"SELECT prefix, address FROM peers ORDER BY random() LIMIT ?"
,
(
n
,)).
fetchall
()
else
:
logging
.
warning
(
"Unauthorized connection from %s which does not start with %s"
%
(
utils
.
ipFromBin
(
client_ip
),
utils
.
ipFromBin
(
self
.
network
.
ljust
(
128
,
'0'
))))
raise
RuntimeError
if
__name__
==
"__main__"
:
main
()
re6st/db.py
View file @
4fc87945
...
...
@@ -74,10 +74,12 @@ class PeerManager:
logging
.
info
(
'Refreshing the peers DB...'
)
try
:
self
.
_declare
()
self
.
_populate
()
logging
.
info
(
'DB refreshed'
)
self
.
next_refresh
=
time
.
time
()
+
self
.
_refresh_time
return
True
except
socket
.
error
,
e
:
logging
.
info
(
'Connection to server failed, re-bootstraping'
)
try
:
self
.
_bootstrap
()
except
socket
.
error
,
e
:
logging
.
debug
(
'socket.error : %s'
%
e
)
logging
.
info
(
'Connection to server failed, retrying in 30s'
)
...
...
@@ -92,23 +94,8 @@ class PeerManager:
else
:
logging
.
warning
(
"Warning : couldn't send ip, unknown external config"
)
def
_populate
(
self
):
logging
.
info
(
'Populating the peers DB...'
)
new_peer_list
=
self
.
_proxy
.
getPeerList
(
self
.
_db_size
)
with
self
.
_db
:
self
.
_db
.
execute
(
"""DELETE FROM peers WHERE used <= 0 ORDER BY used,
RANDOM() LIMIT MAX(0, ? + (SELECT COUNT(*)
FROM peers WHERE used <= 0))"""
,
(
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
(
"""DELETE FROM peers WHERE prefix IN
(SELECT prefix FROM blacklist.flag)"""
)
logging
.
info
(
'DB populated'
)
logging
.
trace
(
'New peers : %s'
%
(
', '
.
join
(
map
(
str
,
new_peer_list
)),))
def
getUnusedPeers
(
self
,
peer_count
):
for
populate
in
self
.
refresh
,
self
.
_bootstrap
,
bool
:
for
populate
in
self
.
_bootstrap
,
bool
:
peer_list
=
self
.
_db
.
execute
(
"""SELECT prefix, address FROM peers WHERE used
<= 0 ORDER BY used DESC,RANDOM() LIMIT ?"""
,
(
peer_count
,)).
fetchall
()
...
...
@@ -196,6 +183,9 @@ class PeerManager:
if
int
(
self
.
_db
.
execute
(
"""SELECT COUNT(*) FROM blacklist.flag WHERE prefix = ?"""
,
(
peer
[
0
],)).
next
()[
0
])
>
0
:
logging
.
info
(
'Peer is blacklisted'
)
return
False
self
.
_db
.
execute
(
"""DELETE FROM peers WHERE used <= 0 ORDER BY used,
RANDOM() LIMIT MAX(0, (SELECT COUNT(*) FROM peers
WHERE used <= 0) - ?)"""
,
str
(
self
.
_db_size
))
self
.
_db
.
execute
(
"INSERT INTO peers (prefix, address) VALUES (?,?)"
,
peer
)
logging
.
debug
(
'Peer added'
)
return
True
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