Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
sakia
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab 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
clients
python
sakia
Commits
bc696127
Commit
bc696127
authored
9 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Fix network spam
parent
c3b797e0
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sakia/core/net/network.py
+37
-15
37 additions, 15 deletions
src/sakia/core/net/network.py
with
37 additions
and
15 deletions
src/sakia/core/net/network.py
+
37
−
15
View file @
bc696127
...
...
@@ -5,6 +5,7 @@ Created on 24 févr. 2015
"""
from
.node
import
Node
from
...tools.exceptions
import
InvalidNodeCurrency
from
...tools.decorators
import
asyncify
import
logging
import
aiohttp
import
time
...
...
@@ -44,6 +45,7 @@ class Network(QObject):
self
.
_block_found
=
self
.
current_blockUID
self
.
_timer
=
QTimer
()
self
.
_client_session
=
session
self
.
_discovery_stack
=
[]
@classmethod
def
create
(
cls
,
node
):
...
...
@@ -332,8 +334,10 @@ class Network(QObject):
node
=
self
.
nodes
[
index
]
return
self
.
_root_nodes
.
index
(
node
)
def
refresh_once
(
self
):
@asyncify
async
def
refresh_once
(
self
):
for
node
in
self
.
_nodes
:
await
asyncio
.
sleep
(
1
)
node
.
refresh
(
manual
=
True
)
async
def
discover_network
(
self
):
...
...
@@ -343,6 +347,7 @@ class Network(QObject):
"""
self
.
_must_crawl
=
True
first_loop
=
True
asyncio
.
ensure_future
(
self
.
pop_discovery_stack
())
while
self
.
continue_crawling
():
for
node
in
self
.
nodes
:
if
self
.
continue_crawling
():
...
...
@@ -354,9 +359,15 @@ class Network(QObject):
logging
.
debug
(
"
End of network discovery
"
)
def
handle_new_node
(
self
,
peer
):
key
=
VerifyingKey
(
peer
.
pubkey
)
if
key
.
verify_document
(
peer
):
async
def
pop_discovery_stack
(
self
):
"""
Handle poping of nodes in discovery stack
:return:
"""
while
self
.
continue_crawling
():
try
:
await
asyncio
.
sleep
(
1
)
peer
=
self
.
_discovery_stack
.
pop
()
pubkeys
=
[
n
.
pubkey
for
n
in
self
.
nodes
]
if
peer
.
pubkey
not
in
pubkeys
:
logging
.
debug
(
"
New node found : {0}
"
.
format
(
peer
.
pubkey
[:
5
]))
...
...
@@ -370,7 +381,18 @@ class Network(QObject):
else
:
node
=
[
n
for
n
in
self
.
nodes
if
n
.
pubkey
==
peer
.
pubkey
][
0
]
if
node
.
peer
.
blockUID
.
number
<
peer
.
blockUID
.
number
:
logging
.
debug
(
"
Update node : {0}
"
.
format
(
peer
.
pubkey
[:
5
]))
node
.
peer
=
peer
except
IndexError
:
await
asyncio
.
sleep
(
2
)
def
handle_new_node
(
self
,
peer
):
key
=
VerifyingKey
(
peer
.
pubkey
)
if
key
.
verify_document
(
peer
):
if
len
(
self
.
_discovery_stack
)
<
1000
\
and
peer
.
signatures
[
0
]
not
in
[
p
.
signatures
[
0
]
for
p
in
self
.
_discovery_stack
]:
logging
.
debug
(
"
Stacking new peer document : {0}
"
.
format
(
peer
.
pubkey
))
self
.
_discovery_stack
.
append
(
peer
)
else
:
logging
.
debug
(
"
Wrong document received : {0}
"
.
format
(
peer
.
signed_raw
()))
...
...
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