mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-04-07 10:56:49 +00:00
debug
This commit is contained in:
parent
956a39a6c1
commit
43023fb620
53
ws_client.py
53
ws_client.py
@ -1,7 +1,8 @@
|
||||
from __future__ import print_function
|
||||
|
||||
import json
|
||||
import sys
|
||||
import json
|
||||
from os.path import join
|
||||
|
||||
from twisted.internet.task import react
|
||||
from twisted.internet.defer import inlineCallbacks, Deferred
|
||||
@ -11,13 +12,15 @@ from autobahn.twisted.websocket import (
|
||||
WebSocketClientFactory,
|
||||
)
|
||||
|
||||
from allmydata.client import read_config
|
||||
|
||||
|
||||
class TahoeLogProtocol(WebSocketClientProtocol):
|
||||
"""
|
||||
"""
|
||||
|
||||
def onOpen(self):
|
||||
pass#print("connected")
|
||||
self.factory.on_open.callback(self)
|
||||
|
||||
def onMessage(self, payload, isBinary):
|
||||
if False:
|
||||
@ -30,33 +33,49 @@ class TahoeLogProtocol(WebSocketClientProtocol):
|
||||
sys.stdout.flush()
|
||||
|
||||
def onClose(self, *args):
|
||||
print("bye", args)
|
||||
if not self.factory.on_open.called:
|
||||
self.factory.on_open.errback(
|
||||
RuntimError("Failed: {}".format(args))
|
||||
)
|
||||
self.factory.on_close.callback(self)
|
||||
|
||||
|
||||
@inlineCallbacks
|
||||
def main(reactor):
|
||||
|
||||
with open("testgrid/alice/private/api_auth_token", "r") as f:
|
||||
#with open("alice/private/api_auth_token", "r") as f:
|
||||
token = f.read().strip()
|
||||
from twisted.python import log
|
||||
log.startLogging(sys.stdout)
|
||||
|
||||
tahoe_dir = "testgrid/alice"
|
||||
cfg = read_config(tahoe_dir, "portnum")
|
||||
|
||||
token = cfg.get_private_config("api_auth_token").strip()
|
||||
webport = cfg.get_config("node", "web.port")
|
||||
if webport.startswith("tcp:"):
|
||||
port = webport.split(':')[1]
|
||||
else:
|
||||
port = webport
|
||||
|
||||
factory = WebSocketClientFactory(
|
||||
url=u"ws://127.0.0.1:8890/logs_v1",
|
||||
url=u"ws://127.0.0.1:{}/logs_v1".format(port),
|
||||
headers={
|
||||
"Authorization": "tahoe-lafs {}".format(token),
|
||||
}
|
||||
)
|
||||
factory.on_open = Deferred()
|
||||
factory.on_close = Deferred()
|
||||
|
||||
factory.protocol = TahoeLogProtocol
|
||||
port = yield reactor.connectTCP("127.0.0.1", 8890, factory)
|
||||
if False:
|
||||
print("port {}".format(port))
|
||||
print(dir(port))
|
||||
print(port.getDestination())
|
||||
print(port.transport)
|
||||
print(dir(port.transport))
|
||||
print(port.transport.protocol)
|
||||
# can we like 'listen' for this connection/etc to die?
|
||||
yield Deferred()
|
||||
port = yield reactor.connectTCP("127.0.0.1", int(port), factory)
|
||||
|
||||
# okay, I give up: how do we detect that our connection was
|
||||
# refused?
|
||||
print("port: {}".format(port))
|
||||
yield factory.on_open
|
||||
print("opened")
|
||||
yield factory.on_close
|
||||
print("closed")
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user