relay: log total bytes sent in each direction
This commit is contained in:
parent
8dfe4e7b8d
commit
8b3e5836ee
|
@ -133,10 +133,12 @@ class TransitConnection(protocol.Protocol):
|
||||||
self.token_buffer = b""
|
self.token_buffer = b""
|
||||||
self.sent_ok = False
|
self.sent_ok = False
|
||||||
self.buddy = None
|
self.buddy = None
|
||||||
|
self.total_sent = 0
|
||||||
|
|
||||||
def dataReceived(self, data):
|
def dataReceived(self, data):
|
||||||
if self.sent_ok:
|
if self.sent_ok:
|
||||||
# TODO: connect as producer/consumer
|
# TODO: connect as producer/consumer
|
||||||
|
self.total_sent += len(data)
|
||||||
self.buddy.transport.write(data)
|
self.buddy.transport.write(data)
|
||||||
return
|
return
|
||||||
if self.got_token: # but not yet sent_ok
|
if self.got_token: # but not yet sent_ok
|
||||||
|
@ -182,7 +184,7 @@ class TransitConnection(protocol.Protocol):
|
||||||
print("connectionLost %r %s" % (self, reason))
|
print("connectionLost %r %s" % (self, reason))
|
||||||
if self.buddy:
|
if self.buddy:
|
||||||
self.buddy.buddy_disconnected()
|
self.buddy.buddy_disconnected()
|
||||||
self.factory.transitFinished(self)
|
self.factory.transitFinished(self, self.total_sent)
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
self.transport.loseConnection()
|
self.transport.loseConnection()
|
||||||
|
@ -232,8 +234,8 @@ class Transit(protocol.ServerFactory, service.MultiService):
|
||||||
self.pending_requests[token] = p
|
self.pending_requests[token] = p
|
||||||
print("transit relay 1: %r" % token)
|
print("transit relay 1: %r" % token)
|
||||||
# TODO: timer
|
# TODO: timer
|
||||||
def transitFinished(self, p):
|
def transitFinished(self, p, total_sent):
|
||||||
print("transitFinished %r" % p)
|
print("transitFinished (%dB) %r" % (total_sent, p))
|
||||||
for token,tc in self.pending_requests.items():
|
for token,tc in self.pending_requests.items():
|
||||||
if tc is p:
|
if tc is p:
|
||||||
del self.pending_requests[token]
|
del self.pending_requests[token]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user