Add logging to test_server, fix it

This commit is contained in:
Pedro Ferreira 2017-07-31 23:17:59 +02:00
parent 14291ed863
commit 00fc46890e
2 changed files with 25 additions and 16 deletions

View File

@ -75,11 +75,11 @@ logger.setLevel(logging.DEBUG)
logger.addHandler(ch)
server_pub_key = b64decode(config['public'][:-8])
# server_prv_key = b64decode(config['private'][:-8])
# sign = SigningKey(server_prv_key[:32])
server_prv_key = b64decode(config['private'][:-8])
sign = SigningKey(server_prv_key[:32])
loop = get_event_loop()
packet_stream = PSClient('127.0.0.1', 8008, SigningKey.generate(), server_pub_key, loop=loop)
packet_stream = PSClient('127.0.0.1', 8008, sign, server_pub_key, loop=loop)
packet_stream.connect()
api.add_connection(packet_stream)

View File

@ -1,8 +1,10 @@
import logging
import os
from asyncio import get_event_loop
from asyncio import get_event_loop, ensure_future
from base64 import b64decode
import yaml
from colorlog import ColoredFormatter
from nacl.signing import SigningKey
from ssb.packet_stream import PSServer
@ -12,18 +14,25 @@ with open(os.path.expanduser('~/.ssb/secret')) as f:
config = yaml.load(f)
async def on_connect(server):
server.write('JSON', {
"name": ["createHistoryStream"],
"args": [{
"id": "@/Odg52x38pt7OivNnxK1Lm+H/+x6yV4DhMeXHBQRYc0=.ed25519",
"seq": 9,
"live": True,
"keys": False
}],
"type": "source"}, req=1)
print(await server.read())
server.write('JSON', {})
async def on_connect():
loop.create_task(ensure_future(packet_stream))
# create console handler and set level to debug
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
# create formatter
formatter = ColoredFormatter('%(log_color)s%(levelname)s%(reset)s:%(bold_white)s%(name)s%(reset)s - '
'%(cyan)s%(message)s%(reset)s')
# add formatter to ch
ch.setFormatter(formatter)
# add ch to logger
logger = logging.getLogger('packet_stream')
logger.setLevel(logging.DEBUG)
logger.addHandler(ch)
loop = get_event_loop()