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
decfaf5b
Commit
decfaf5b
authored
9 years ago
by
inso
Browse files
Options
Downloads
Patches
Plain Diff
First experimentation
parent
226ea666
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/sakia/core/net/node.py
+31
-10
31 additions, 10 deletions
src/sakia/core/net/node.py
with
31 additions
and
10 deletions
src/sakia/core/net/node.py
+
31
−
10
View file @
decfaf5b
...
@@ -10,11 +10,13 @@ from ...tools.decorators import asyncify
...
@@ -10,11 +10,13 @@ from ...tools.decorators import asyncify
from
ucoinpy.api
import
bma
as
bma
from
ucoinpy.api
import
bma
as
bma
from
ucoinpy.api.bma
import
ConnectionHandler
from
ucoinpy.api.bma
import
ConnectionHandler
import
asyncio
from
aiohttp.errors
import
ClientError
,
DisconnectedError
,
TimeoutError
,
\
from
aiohttp.errors
import
ClientError
,
Disconnected
Error
WSClientDisconnectedError
,
WSServerHandshakeError
,
ClientResponse
Error
import
logging
import
logging
import
time
import
time
import
jsonschema
import
jsonschema
import
asyncio
import
aiohttp
from
socket
import
gaierror
from
socket
import
gaierror
from
PyQt5.QtCore
import
QObject
,
pyqtSignal
from
PyQt5.QtCore
import
QObject
,
pyqtSignal
...
@@ -281,7 +283,7 @@ class Node(QObject):
...
@@ -281,7 +283,7 @@ class Node(QObject):
Refresh all data of this node
Refresh all data of this node
:param bool manual: True if the refresh was manually initiated
:param bool manual: True if the refresh was manually initiated
"""
"""
self
.
refresh
_block
()
asyncio
.
ensure_future
(
self
.
connect_current
_block
()
)
self
.
refresh_peers
()
self
.
refresh_peers
()
if
self
.
_refresh_counter
%
20
==
0
or
manual
:
if
self
.
_refresh_counter
%
20
==
0
or
manual
:
...
@@ -292,6 +294,25 @@ class Node(QObject):
...
@@ -292,6 +294,25 @@ class Node(QObject):
else
:
else
:
self
.
_refresh_counter
+=
1
self
.
_refresh_counter
+=
1
async
def
connect_current_block
(
self
):
try
:
conn_handler
=
self
.
endpoint
.
conn_handler
()
async
with
bma
.
websocket
.
Block
(
conn_handler
).
connect
()
as
ws
:
async
for
msg
in
ws
:
if
msg
.
tp
==
aiohttp
.
MsgType
.
text
:
pass
elif
msg
.
tp
==
aiohttp
.
MsgType
.
closed
:
break
elif
msg
.
tp
==
aiohttp
.
MsgType
.
error
:
break
else
:
pass
except
(
WSServerHandshakeError
,
WSClientDisconnectedError
)
as
e
:
logging
.
debug
(
"
Websocket error : {0}
"
.
format
(
str
(
e
)))
except
ClientResponseError
as
e
:
logging
.
debug
(
"
Client response error : {0}
"
.
format
(
str
(
e
)))
@asyncify
@asyncify
async
def
refresh_block
(
self
):
async
def
refresh_block
(
self
):
"""
"""
...
@@ -318,7 +339,7 @@ class Node(QObject):
...
@@ -318,7 +339,7 @@ class Node(QObject):
logging
.
debug
(
"
Error in previous block reply : {0}
"
.
format
(
self
.
pubkey
))
logging
.
debug
(
"
Error in previous block reply : {0}
"
.
format
(
self
.
pubkey
))
logging
.
debug
(
str
(
e
))
logging
.
debug
(
str
(
e
))
self
.
changed
.
emit
()
self
.
changed
.
emit
()
except
(
ClientError
,
gaierror
,
asyncio
.
TimeoutError
,
DisconnectedError
)
as
e
:
except
(
ClientError
,
gaierror
,
TimeoutError
,
DisconnectedError
)
as
e
:
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
except
jsonschema
.
ValidationError
:
except
jsonschema
.
ValidationError
:
...
@@ -338,7 +359,7 @@ class Node(QObject):
...
@@ -338,7 +359,7 @@ class Node(QObject):
logging
.
debug
(
"
Error in block reply : {0}
"
.
format
(
self
.
pubkey
))
logging
.
debug
(
"
Error in block reply : {0}
"
.
format
(
self
.
pubkey
))
logging
.
debug
(
str
(
e
))
logging
.
debug
(
str
(
e
))
self
.
changed
.
emit
()
self
.
changed
.
emit
()
except
(
ClientError
,
gaierror
,
asyncio
.
TimeoutError
,
DisconnectedError
)
as
e
:
except
(
ClientError
,
gaierror
,
TimeoutError
,
DisconnectedError
)
as
e
:
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
except
jsonschema
.
ValidationError
:
except
jsonschema
.
ValidationError
:
...
@@ -371,7 +392,7 @@ class Node(QObject):
...
@@ -371,7 +392,7 @@ class Node(QObject):
logging
.
debug
(
"
Error in peering reply : {0}
"
.
format
(
str
(
e
)))
logging
.
debug
(
"
Error in peering reply : {0}
"
.
format
(
str
(
e
)))
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
self
.
changed
.
emit
()
self
.
changed
.
emit
()
except
(
ClientError
,
gaierror
,
asyncio
.
TimeoutError
,
DisconnectedError
)
as
e
:
except
(
ClientError
,
gaierror
,
TimeoutError
,
DisconnectedError
)
as
e
:
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
except
jsonschema
.
ValidationError
:
except
jsonschema
.
ValidationError
:
...
@@ -398,7 +419,7 @@ class Node(QObject):
...
@@ -398,7 +419,7 @@ class Node(QObject):
logging
.
debug
(
"
Error in summary : {0}
"
.
format
(
e
))
logging
.
debug
(
"
Error in summary : {0}
"
.
format
(
e
))
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
self
.
changed
.
emit
()
self
.
changed
.
emit
()
except
(
ClientError
,
gaierror
,
asyncio
.
TimeoutError
,
DisconnectedError
)
as
e
:
except
(
ClientError
,
gaierror
,
TimeoutError
,
DisconnectedError
)
as
e
:
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
except
jsonschema
.
ValidationError
:
except
jsonschema
.
ValidationError
:
...
@@ -433,7 +454,7 @@ class Node(QObject):
...
@@ -433,7 +454,7 @@ class Node(QObject):
logging
.
debug
(
"
error in uid reply : {0}
"
.
format
(
self
.
pubkey
))
logging
.
debug
(
"
error in uid reply : {0}
"
.
format
(
self
.
pubkey
))
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
self
.
identity_changed
.
emit
()
self
.
identity_changed
.
emit
()
except
(
ClientError
,
gaierror
,
asyncio
.
TimeoutError
,
DisconnectedError
)
as
e
:
except
(
ClientError
,
gaierror
,
TimeoutError
,
DisconnectedError
)
as
e
:
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
except
jsonschema
.
ValidationError
:
except
jsonschema
.
ValidationError
:
...
@@ -469,7 +490,7 @@ class Node(QObject):
...
@@ -469,7 +490,7 @@ class Node(QObject):
leaf
=
leaf_hash
))
leaf
=
leaf_hash
))
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
self
.
changed
.
emit
()
self
.
changed
.
emit
()
except
(
ClientError
,
gaierror
,
asyncio
.
TimeoutError
,
DisconnectedError
)
as
e
:
except
(
ClientError
,
gaierror
,
TimeoutError
,
DisconnectedError
)
as
e
:
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
except
jsonschema
.
ValidationError
:
except
jsonschema
.
ValidationError
:
...
@@ -481,7 +502,7 @@ class Node(QObject):
...
@@ -481,7 +502,7 @@ class Node(QObject):
logging
.
debug
(
"
Error in peers reply
"
)
logging
.
debug
(
"
Error in peers reply
"
)
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
self
.
changed
.
emit
()
self
.
changed
.
emit
()
except
(
ClientError
,
gaierror
,
asyncio
.
TimeoutError
,
DisconnectedError
)
as
e
:
except
(
ClientError
,
gaierror
,
TimeoutError
,
DisconnectedError
)
as
e
:
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
logging
.
debug
(
"
{0} : {1}
"
.
format
(
str
(
e
),
self
.
pubkey
))
self
.
state
=
Node
.
OFFLINE
self
.
state
=
Node
.
OFFLINE
except
jsonschema
.
ValidationError
:
except
jsonschema
.
ValidationError
:
...
...
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