SHA256
back32hash 5591: готово к тестам
Вроде как всё готово к тестам.
This commit is contained in:
@@ -1,11 +1,24 @@
|
||||
#!/usr/bin/env python3
|
||||
import argparse, asyncio, base64, hashlib, json, os, random, struct, sys, time, uuid
|
||||
from pathlib import Path
|
||||
import re
|
||||
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
|
||||
from websockets.asyncio.client import connect
|
||||
|
||||
ZERO32 = bytes(32)
|
||||
FRAME_CODE_V1=1; TEXT_TYPE=1; TEXT_POST=10; VERSION=1
|
||||
def shine_protocol_namespace():
|
||||
here = Path(__file__).resolve()
|
||||
for parent in here.parents:
|
||||
cfg = parent / 'shine-UI' / 'js' / 'services' / 'protocol-tags.js'
|
||||
if cfg.exists():
|
||||
m = re.search(r"SHINE_PROTOCOL_NAMESPACE\s*=\s*['\"]([^'\"]+)['\"]", cfg.read_text(encoding='utf-8'))
|
||||
if m:
|
||||
return m.group(1)
|
||||
raise RuntimeError('Не найден shine-UI/js/services/protocol-tags.js с SHINE_PROTOCOL_NAMESPACE')
|
||||
|
||||
SHINE_PROTOCOL_NAMESPACE = shine_protocol_namespace()
|
||||
|
||||
|
||||
def atomic_json(path, obj):
|
||||
path=Path(path); path.parent.mkdir(parents=True, exist_ok=True)
|
||||
@@ -54,9 +67,9 @@ def post_body(line_code, prev_line_num, prev_line_hash, this_line_num, text):
|
||||
if len(tb)>65535: raise ValueError('post text too long')
|
||||
return struct.pack('>ii32siH',line_code,prev_line_num,prev_line_hash,this_line_num,len(tb))+tb
|
||||
|
||||
def frame(prev_hash, block_num, body, ts=None):
|
||||
ts=int(time.time()) if ts is None else int(ts); size=56+len(body)
|
||||
return struct.pack('>H32siiqHHH',FRAME_CODE_V1,prev_hash,size,block_num,ts,TEXT_TYPE,TEXT_POST,VERSION)+body
|
||||
def frame(prev_hash, back32_hash, block_num, body, ts=None):
|
||||
ts=int(time.time()) if ts is None else int(ts); size=88+len(body)
|
||||
return struct.pack('>H32s32siiqHHH',FRAME_CODE_V1,prev_hash,back32_hash,size,block_num,ts,TEXT_TYPE,TEXT_POST,VERSION)+body
|
||||
|
||||
def h32(b): return hashlib.sha256(b).digest()
|
||||
def hx(b): return b.hex()
|
||||
@@ -139,7 +152,7 @@ async def publish_one(cfg,st,items):
|
||||
else: print('Queue exhausted. Nothing to publish.'); return False
|
||||
text=items[idx]['text'].strip(); block_num=int(st['last_block_number'])+1; prev_hash=bytes.fromhex(st['last_block_hash']); this_line=int(st['last_line_number'])+1
|
||||
body=post_body(int(cfg['channel_root_block_number']),int(st['last_line_number']),bytes.fromhex(st['last_line_hash']),this_line,text)
|
||||
fr=frame(prev_hash,block_num,body); block_hash=h32(fr); tags=[('App','test5590'),('c',cfg['channel_name'].strip().lower())]
|
||||
back32_hash=ZERO32 if block_num<32 else bytes.fromhex((await block(cfg,block_num-32))[0]); fr=frame(prev_hash,back32_hash,block_num,body); block_hash=h32(fr); tags=[('App',SHINE_PROTOCOL_NAMESPACE),('c',cfg['channel_name'].strip().lower())]
|
||||
raw=data_item(read_key(cfg['key_file']),tags,fr)
|
||||
nextidx=idx+1
|
||||
p={'queue_index':idx,'next_index_after':nextidx,'block_number':block_num,'block_hash':hx(block_hash),'previous_block_number':st['last_block_number'],'previous_block_hash':st['last_block_hash'],'this_line_number':this_line,'data_item_b64':base64.b64encode(raw).decode()}
|
||||
|
||||
Reference in New Issue
Block a user