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
3133818c
Commit
3133818c
authored
9 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
Check peer document signatures ( # 411 )
parent
d5c4e139
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/sakia/core/net/network.py
+19
-15
19 additions, 15 deletions
src/sakia/core/net/network.py
src/sakia/core/net/node.py
+4
-5
4 additions, 5 deletions
src/sakia/core/net/node.py
with
23 additions
and
20 deletions
src/sakia/core/net/network.py
+
19
−
15
View file @
3133818c
...
@@ -10,6 +10,7 @@ import aiohttp
...
@@ -10,6 +10,7 @@ import aiohttp
import
time
import
time
import
asyncio
import
asyncio
from
duniterpy.documents
import
Peer
,
Block
,
BlockUID
,
MalformedDocumentError
from
duniterpy.documents
import
Peer
,
Block
,
BlockUID
,
MalformedDocumentError
from
duniterpy.key
import
VerifyingKey
from
PyQt5.QtCore
import
pyqtSignal
,
pyqtSlot
,
QObject
,
QTimer
from
PyQt5.QtCore
import
pyqtSignal
,
pyqtSlot
,
QObject
,
QTimer
from
collections
import
Counter
from
collections
import
Counter
...
@@ -353,22 +354,25 @@ class Network(QObject):
...
@@ -353,22 +354,25 @@ class Network(QObject):
logging
.
debug
(
"
End of network discovery
"
)
logging
.
debug
(
"
End of network discovery
"
)
@pyqtSlot
(
Peer
,
str
)
def
handle_new_node
(
self
,
peer
):
def
handle_new_node
(
self
,
peer
,
pubkey
):
key
=
VerifyingKey
(
peer
.
pubkey
)
if
key
.
verify_document
(
peer
):
pubkeys
=
[
n
.
pubkey
for
n
in
self
.
nodes
]
pubkeys
=
[
n
.
pubkey
for
n
in
self
.
nodes
]
if
peer
.
pubkey
not
in
pubkeys
:
if
peer
.
pubkey
not
in
pubkeys
:
logging
.
debug
(
"
New node found : {0}
"
.
format
(
peer
.
pubkey
[:
5
]))
logging
.
debug
(
"
New node found : {0}
"
.
format
(
peer
.
pubkey
[:
5
]))
try
:
try
:
node
=
Node
.
from_peer
(
self
.
currency
,
peer
,
pubkey
,
self
.
session
)
node
=
Node
.
from_peer
(
self
.
currency
,
peer
,
self
.
session
)
node
.
refresh
(
manual
=
True
)
node
.
refresh
(
manual
=
True
)
self
.
add_node
(
node
)
self
.
add_node
(
node
)
self
.
nodes_changed
.
emit
()
self
.
nodes_changed
.
emit
()
except
InvalidNodeCurrency
as
e
:
except
InvalidNodeCurrency
as
e
:
logging
.
debug
(
str
(
e
))
logging
.
debug
(
str
(
e
))
else
:
else
:
node
=
[
n
for
n
in
self
.
nodes
if
n
.
pubkey
==
pubkey
][
0
]
node
=
[
n
for
n
in
self
.
nodes
if
n
.
pubkey
==
peer
.
pubkey
][
0
]
if
node
.
peer
.
blockUID
.
number
<
peer
.
blockUID
.
number
:
if
node
.
peer
.
blockUID
.
number
<
peer
.
blockUID
.
number
:
node
.
peer
=
peer
node
.
peer
=
peer
else
:
logging
.
debug
(
"
Wrong document received : {0}
"
.
format
(
peer
.
signed_raw
()))
@pyqtSlot
()
@pyqtSlot
()
def
handle_identity_change
(
self
):
def
handle_identity_change
(
self
):
...
...
This diff is collapsed.
Click to expand it.
src/sakia/core/net/node.py
+
4
−
5
View file @
3133818c
...
@@ -43,7 +43,7 @@ class Node(QObject):
...
@@ -43,7 +43,7 @@ class Node(QObject):
changed
=
pyqtSignal
()
changed
=
pyqtSignal
()
error
=
pyqtSignal
()
error
=
pyqtSignal
()
identity_changed
=
pyqtSignal
()
identity_changed
=
pyqtSignal
()
neighbour_found
=
pyqtSignal
(
Peer
,
str
)
neighbour_found
=
pyqtSignal
(
Peer
)
def
__init__
(
self
,
peer
,
uid
,
pubkey
,
block
,
def
__init__
(
self
,
peer
,
uid
,
pubkey
,
block
,
state
,
last_change
,
last_merkle
,
state
,
last_change
,
last_merkle
,
...
@@ -105,7 +105,7 @@ class Node(QObject):
...
@@ -105,7 +105,7 @@ class Node(QObject):
return
node
return
node
@classmethod
@classmethod
def
from_peer
(
cls
,
currency
,
peer
,
pubkey
,
session
):
def
from_peer
(
cls
,
currency
,
peer
,
session
):
"""
"""
Factory method to get a node from a peer document.
Factory method to get a node from a peer document.
...
@@ -119,7 +119,7 @@ class Node(QObject):
...
@@ -119,7 +119,7 @@ class Node(QObject):
if
peer
.
currency
!=
currency
:
if
peer
.
currency
!=
currency
:
raise
InvalidNodeCurrency
(
peer
.
currency
,
currency
)
raise
InvalidNodeCurrency
(
peer
.
currency
,
currency
)
node
=
cls
(
peer
,
""
,
pubkey
,
None
,
node
=
cls
(
peer
,
""
,
peer
.
pubkey
,
None
,
Node
.
OFFLINE
,
time
.
time
(),
Node
.
OFFLINE
,
time
.
time
(),
{
'
root
'
:
""
,
'
leaves
'
:
[]},
{
'
root
'
:
""
,
'
leaves
'
:
[]},
""
,
""
,
0
,
session
)
""
,
""
,
0
,
session
)
...
@@ -626,8 +626,7 @@ class Node(QObject):
...
@@ -626,8 +626,7 @@ class Node(QObject):
str_doc
=
"
{0}{1}
\n
"
.
format
(
peer_data
[
'
raw
'
],
str_doc
=
"
{0}{1}
\n
"
.
format
(
peer_data
[
'
raw
'
],
peer_data
[
'
signature
'
])
peer_data
[
'
signature
'
])
peer_doc
=
Peer
.
from_signed_raw
(
str_doc
)
peer_doc
=
Peer
.
from_signed_raw
(
str_doc
)
pubkey
=
peer_data
[
'
pubkey
'
]
self
.
neighbour_found
.
emit
(
peer_doc
)
self
.
neighbour_found
.
emit
(
peer_doc
,
pubkey
)
except
MalformedDocumentError
as
e
:
except
MalformedDocumentError
as
e
:
logging
.
debug
(
str
(
e
))
logging
.
debug
(
str
(
e
))
else
:
else
:
...
...
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