Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
DuniterPy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
clients
python
DuniterPy
Commits
4ad9109e
Commit
4ad9109e
authored
5 years ago
by
Moul
Committed by
Vincent Texier
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
[enh]
#58
: Use generate_ws2p_endpoint() helper in examples
- Remove comments
parent
acf4c062
No related branches found
No related tags found
2 merge requests
!94
Merge dev into master for release 0.56.0
,
!84
#58: WS2P support
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
examples/listen_ws2p.py
+9
-7
9 additions, 7 deletions
examples/listen_ws2p.py
examples/request_ws2p.py
+9
-6
9 additions, 6 deletions
examples/request_ws2p.py
with
18 additions
and
13 deletions
examples/listen_ws2p.py
+
9
−
7
View file @
4ad9109e
...
...
@@ -9,7 +9,7 @@ from jsonschema import ValidationError
from
duniterpy.key
import
SigningKey
from
duniterpy.helpers.ws2p
import
handshake
from
duniterpy.helpers.ws2p
import
handshake
,
generate_ws2p_endpoint
from
duniterpy.api.client
import
Client
# CONFIG #######################################
...
...
@@ -17,10 +17,7 @@ from duniterpy.api.client import Client
# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
# Here we use the WS2P API (WS2P [UUID] [DOMAIN] [PORT] [PATH])
# You can find the UUID of a node with the /network/ws2p/heads BMA API request,
# using the UUID of the HEAD with step 0
# or in your node user interface in the network view in the WS2PID column
WS2P_ENDPOINT
=
"
WS2P 96675302 g1-test.duniter.org 443
"
BMAS_ENDPOINT
=
"
BMAS g1-test.duniter.org 443
"
CURRENCY
=
"
g1-test
"
...
...
@@ -38,7 +35,12 @@ async def main():
signing_key
=
SigningKey
.
from_credentials
(
salt
,
password
)
# Create Client from endpoint string in Duniter format
client
=
Client
(
WS2P_ENDPOINT
)
try
:
ws2p_endpoint
=
await
generate_ws2p_endpoint
(
BMAS_ENDPOINT
)
except
ValueError
as
e
:
print
(
e
)
return
client
=
Client
(
ws2p_endpoint
)
try
:
# Create a Web Socket connection
...
...
@@ -73,7 +75,7 @@ async def main():
except
(
aiohttp
.
WSServerHandshakeError
,
ValueError
)
as
e
:
print
(
"
Websocket handshake {0} : {1}
"
.
format
(
type
(
e
).
__name__
,
str
(
e
)))
except
(
aiohttp
.
ClientError
,
gaierror
,
TimeoutError
)
as
e
:
print
(
"
{0} : {1}
"
.
format
(
str
(
e
),
WS2P_ENDPOINT
))
print
(
"
{0} : {1}
"
.
format
(
str
(
e
),
ws2p_endpoint
.
inline
()
))
except
jsonschema
.
ValidationError
as
e
:
print
(
"
{:}:{:}
"
.
format
(
str
(
e
.
__class__
.
__name__
),
str
(
e
)))
...
...
This diff is collapsed.
Click to expand it.
examples/request_ws2p.py
+
9
−
6
View file @
4ad9109e
...
...
@@ -12,7 +12,7 @@ from typing import Any
from
duniterpy.tools
import
get_ws2p_challenge
from
duniterpy.key
import
SigningKey
from
duniterpy.helpers.ws2p
import
handshake
from
duniterpy.helpers.ws2p
import
handshake
,
generate_ws2p_endpoint
from
duniterpy.api.ws2p
import
requests
from
duniterpy.api.client
import
Client
,
WSConnection
...
...
@@ -21,9 +21,7 @@ from duniterpy.api.client import Client, WSConnection
# You can either use a complete defined endpoint : [NAME_OF_THE_API] [DOMAIN] [IPv4] [IPv6] [PORT] [PATH]
# or the simple definition : [NAME_OF_THE_API] [DOMAIN] [PORT] [PATH]
# Here we use the WS2P API (WS2P [UUID] [DOMAIN] [PORT] [PATH])
# You can find the UUID of a node with the /network/ws2p/heads BMA API request
# or in your node user interface in the network view in the WS2PID column
WS2P_ENDPOINT
=
"
WS2P 96675302 g1-test.duniter.org 443
"
BMAS_ENDPOINT
=
"
BMAS g1-test.duniter.org 443
"
CURRENCY
=
"
g1-test
"
...
...
@@ -86,7 +84,12 @@ async def main():
signing_key
=
SigningKey
.
from_credentials
(
salt
,
password
)
# Create Client from endpoint string in Duniter format
client
=
Client
(
WS2P_ENDPOINT
)
try
:
ws2p_endpoint
=
await
generate_ws2p_endpoint
(
BMAS_ENDPOINT
)
except
ValueError
as
e
:
print
(
e
)
return
client
=
Client
(
ws2p_endpoint
)
try
:
# Create a Web Socket connection
...
...
@@ -152,7 +155,7 @@ async def main():
except
(
aiohttp
.
WSServerHandshakeError
,
ValueError
)
as
e
:
print
(
"
Websocket handshake {0} : {1}
"
.
format
(
type
(
e
).
__name__
,
str
(
e
)))
except
(
aiohttp
.
ClientError
,
gaierror
,
TimeoutError
)
as
e
:
print
(
"
{0} : {1}
"
.
format
(
str
(
e
),
WS2P_ENDPOINT
))
print
(
"
{0} : {1}
"
.
format
(
str
(
e
),
ws2p_endpoint
.
inline
()
))
except
jsonschema
.
ValidationError
as
e
:
print
(
"
{:}:{:}
"
.
format
(
str
(
e
.
__class__
.
__name__
),
str
(
e
)))
...
...
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