Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ĞMixer-py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
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
Pascal Engélibert
ĞMixer-py
Commits
bb91e7d8
Commit
bb91e7d8
authored
5 years ago
by
Pascal Engélibert
Browse files
Options
Downloads
Patches
Plain Diff
Server uses WoT for checking peers
parent
696c75db
No related branches found
No related tags found
No related merge requests found
Pipeline
#5777
passed
5 years ago
Stage: deploy
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
server.py
+7
-2
7 additions, 2 deletions
server.py
utils.py
+41
-2
41 additions, 2 deletions
utils.py
with
48 additions
and
4 deletions
server.py
+
7
−
2
View file @
bb91e7d8
...
@@ -28,6 +28,7 @@ import duniterpy.api.bma as bma
...
@@ -28,6 +28,7 @@ import duniterpy.api.bma as bma
from
duniterpy.api.client
import
Client
from
duniterpy.api.client
import
Client
from
duniterpy.key
import
SigningKey
,
PublicKey
from
duniterpy.key
import
SigningKey
,
PublicKey
import
utils
import
utils
import
nest_asyncio
"""
"""
Used terms:
Used terms:
...
@@ -201,6 +202,7 @@ def read_config(cdir, conf_overwrite={}):
...
@@ -201,6 +202,7 @@ def read_config(cdir, conf_overwrite={}):
conf
[
"
mix
"
].
setdefault
(
"
mix_min_txs
"
,
MIX_MIN_TXS
)
conf
[
"
mix
"
].
setdefault
(
"
mix_min_txs
"
,
MIX_MIN_TXS
)
conf
[
"
mix
"
].
setdefault
(
"
mix_req_age_max
"
,
MIX_REQ_AGE_MAX
)
conf
[
"
mix
"
].
setdefault
(
"
mix_req_age_max
"
,
MIX_REQ_AGE_MAX
)
conf
.
setdefault
(
"
idty
"
,
{})
conf
.
setdefault
(
"
idty
"
,
{})
conf
[
"
idty
"
].
setdefault
(
"
needed
"
,
True
)
conf
[
"
idty
"
].
setdefault
(
"
sig
"
,
""
)
conf
[
"
idty
"
].
setdefault
(
"
sig
"
,
""
)
conf
[
"
idty
"
].
setdefault
(
"
pubkey
"
,
""
)
conf
[
"
idty
"
].
setdefault
(
"
pubkey
"
,
""
)
...
@@ -585,6 +587,7 @@ class ClientThread(Thread):
...
@@ -585,6 +587,7 @@ class ClientThread(Thread):
new_peer
=
utils
.
Peer
(
self
.
conf
,
data
[
"
info
"
])
new_peer
=
utils
.
Peer
(
self
.
conf
,
data
[
"
info
"
])
except
Exception
as
e
:
except
Exception
as
e
:
print
(
"
Peer detection: info:
"
+
str
(
e
))
print
(
"
Peer detection: info:
"
+
str
(
e
))
continue
new_peers
.
setdefault
(
new_peer
.
hash
,
[])
new_peers
.
setdefault
(
new_peer
.
hash
,
[])
new_peers
[
new_peer
.
hash
].
append
(
new_peer
)
new_peers
[
new_peer
.
hash
].
append
(
new_peer
)
...
@@ -601,7 +604,7 @@ class ClientThread(Thread):
...
@@ -601,7 +604,7 @@ class ClientThread(Thread):
answered
+=
1
answered
+=
1
except
(
ConnectionRefusedError
,
socks
.
GeneralProxyError
,
socket
.
gaierror
,
socket
.
timeout
):
except
(
ConnectionRefusedError
,
socks
.
GeneralProxyError
,
socket
.
gaierror
,
socket
.
timeout
):
utils
.
logprint
(
"
Peer detection: Network error:
"
+
peer
.
to_human_str
(),
utils
.
LOG_WARN
)
utils
.
logprint
(
"
Peer detection: Network error:
"
+
peer
.
to_human_str
(),
utils
.
LOG_WARN
)
# Choose the more recent peer infos
# Choose the more recent peer infos
added_peers
=
False
added_peers
=
False
...
@@ -714,7 +717,9 @@ class ClientThread(Thread):
...
@@ -714,7 +717,9 @@ class ClientThread(Thread):
utils
.
logprint
(
"
All BMA endpoints down: cannot mix!
"
,
utils
.
LOG_ERROR
)
utils
.
logprint
(
"
All BMA endpoints down: cannot mix!
"
,
utils
.
LOG_ERROR
)
def
run
(
self
):
def
run
(
self
):
asyncio
.
new_event_loop
().
run_until_complete
(
self
.
start_client
())
loop
=
asyncio
.
new_event_loop
()
nest_asyncio
.
apply
(
loop
)
loop
.
run_until_complete
(
self
.
start_client
())
async
def
start_client
(
self
):
async
def
start_client
(
self
):
t
=
time
.
time
()
t
=
time
.
time
()
...
...
This diff is collapsed.
Click to expand it.
utils.py
+
41
−
2
View file @
bb91e7d8
...
@@ -17,12 +17,15 @@
...
@@ -17,12 +17,15 @@
along with ĞMixer-py. If not, see <https://www.gnu.org/licenses/>.
along with ĞMixer-py. If not, see <https://www.gnu.org/licenses/>.
"""
"""
import
sys
,
os
,
re
,
socket
,
time
,
secrets
,
hashlib
,
base64
import
sys
,
os
,
re
,
socket
,
time
,
secrets
,
hashlib
,
base64
,
asyncio
import
socks
import
socks
import
ubjson
import
ubjson
import
libnacl.sign
import
libnacl.sign
import
plyvel
import
plyvel
from
duniterpy.key
import
SigningKey
,
PublicKey
from
duniterpy.key
import
SigningKey
,
PublicKey
import
duniterpy.api.bma
as
bma
from
duniterpy.api.client
import
Client
from
duniterpy.api.errors
import
DuniterError
import
silkaj.money
,
silkaj
.
tx
import
silkaj.money
,
silkaj
.
tx
VERSION
=
"
0.2.0
"
VERSION
=
"
0.2.0
"
...
@@ -121,6 +124,11 @@ def getargv(arg:str, default:str="", n:int=1, args:list=sys.argv) -> str:
...
@@ -121,6 +124,11 @@ def getargv(arg:str, default:str="", n:int=1, args:list=sys.argv) -> str:
else
:
else
:
return
default
return
default
def
run_async
(
coro
):
try
:
return
asyncio
.
get_event_loop
().
run_until_complete
(
coro
)
except
RuntimeError
:
return
asyncio
.
new_event_loop
().
run_until_complete
(
coro
)
#-------- ĞMixer
#-------- ĞMixer
...
@@ -137,6 +145,8 @@ class Peer:
...
@@ -137,6 +145,8 @@ class Peer:
# TODO tests
# TODO tests
assert
data
[
"
currency
"
]
==
conf
[
"
currency
"
]
,
"
Not the same currency
"
assert
data
[
"
currency
"
]
==
conf
[
"
currency
"
]
,
"
Not the same currency
"
if
conf
[
"
idty
"
][
"
needed
"
]:
assert
run_async
(
check_idty
(
conf
[
"
client
"
][
"
bma_hosts
"
],
data
[
"
idty
"
]))
self
.
doctype
=
data
[
"
doctype
"
]
self
.
doctype
=
data
[
"
doctype
"
]
self
.
docver
=
data
[
"
docver
"
]
self
.
docver
=
data
[
"
docver
"
]
...
@@ -170,7 +180,10 @@ class Peer:
...
@@ -170,7 +180,10 @@ class Peer:
"
raw
"
:
raw
"
raw
"
:
raw
}
}
raw
=
ubjson
.
dumpb
(
data
)
raw
=
ubjson
.
dumpb
(
data
)
return
Peer
(
conf
,
raw
)
try
:
return
Peer
(
conf
,
raw
)
except
AssertionError
:
return
None
def
load_peers
(
conf
:
dict
,
db_peers
:
plyvel
.
DB
,
peers
:
dict
):
def
load_peers
(
conf
:
dict
,
db_peers
:
plyvel
.
DB
,
peers
:
dict
):
for
_
,
data
in
db_peers
:
for
_
,
data
in
db_peers
:
...
@@ -181,6 +194,32 @@ def save_peers(db_peers:plyvel.DB, peers:dict):
...
@@ -181,6 +194,32 @@ def save_peers(db_peers:plyvel.DB, peers:dict):
for
peer
in
peers
:
for
peer
in
peers
:
db_peers
.
put
(
peers
[
peer
].
hash
,
peers
[
peer
].
raw
)
db_peers
.
put
(
peers
[
peer
].
hash
,
peers
[
peer
].
raw
)
async
def
bma_client
(
bma_endpoints
:
list
):
client
=
None
for
bma_endpoint
in
bma_endpoints
:
client
=
Client
(
"
BMAS
"
+
bma_endpoint
)
try
:
await
client
(
bma
.
node
.
summary
)
break
except
:
logprint
(
"
BMA down:
"
+
bma_endpoint
,
utils
.
LOG_WARN
)
await
client
.
close
()
client
=
None
return
client
#async def check_idty(client:Client, pubkey:str):
# print( await client(bma.wot.lookup, pubkey))
async
def
check_idty
(
bma_endpoints
:
list
,
pubkey
:
str
):
client
=
await
bma_client
(
bma_endpoints
)
try
:
result
=
await
client
(
bma
.
wot
.
requirements
,
pubkey
)
except
DuniterError
:
result
=
{}
finally
:
await
client
.
close
()
return
"
identities
"
in
result
and
len
(
result
[
"
identities
"
])
>
0
and
result
[
"
identities
"
][
0
][
"
pubkey
"
]
==
pubkey
and
result
[
"
identities
"
][
0
][
"
membershipExpiresIn
"
]
>
0
async
def
send_transaction
(
sender_keys
:
SigningKey
,
receiver_pubkey
:
str
,
amount
:
int
,
comment
:
str
):
async
def
send_transaction
(
sender_keys
:
SigningKey
,
receiver_pubkey
:
str
,
amount
:
int
,
comment
:
str
):
#sender_amount = silkaj.money.get_amount_from_pubkey(sender_keys.pubkey)[0]
#sender_amount = silkaj.money.get_amount_from_pubkey(sender_keys.pubkey)[0]
#assert sender_amount >= amount, "not enough money"
#assert sender_amount >= amount, "not enough money"
...
...
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