From 23ff873c635af6300e755254243296e737e7357b Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Sat, 21 Apr 2018 23:15:48 +0200 Subject: [PATCH] Tied link teardown to resource cancellation --- RNS/Destination.py | 1 - RNS/Link.py | 7 +++++++ RNS/Resource.py | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/RNS/Destination.py b/RNS/Destination.py index 4e6e711..d9b5f60 100755 --- a/RNS/Destination.py +++ b/RNS/Destination.py @@ -123,7 +123,6 @@ class Destination: def incomingLinkRequest(self, data, packet): link = RNS.Link.validateRequest(self, data, packet) if link != None: - RNS.log(str(self)+" accepted link request", RNS.LOG_DEBUG) self.links.append(link) def createKeys(self): diff --git a/RNS/Link.py b/RNS/Link.py index ec3de32..03914a8 100644 --- a/RNS/Link.py +++ b/RNS/Link.py @@ -65,7 +65,9 @@ class Link: if link.owner.callbacks.link_established != None: link.owner.callbacks.link_established(link) + RNS.log("Incoming link request "+str(link)+" accepted", RNS.LOG_VERBOSE) + return link except Exception as e: RNS.log("Validating link request failed", RNS.LOG_VERBOSE) @@ -232,6 +234,11 @@ class Link: pass def link_closed(self): + for resource in self.incoming_resources: + resource.cancel() + for resource in self.outgoing_resources: + resource.cancel() + self.prv = None self.pub = None self.pub_bytes = None diff --git a/RNS/Resource.py b/RNS/Resource.py index 2901887..c42943c 100644 --- a/RNS/Resource.py +++ b/RNS/Resource.py @@ -364,8 +364,9 @@ class Resource: def cancel(self): self.status = Resource.FAILED if self.initiator: - cancel_packet = RNS.Packet(self.link, self.hash, context=RNS.Packet.RESOURCE_ICL) - cancel_packet.send() + if self.link.status == RNS.Link.ACTIVE: + cancel_packet = RNS.Packet(self.link, self.hash, context=RNS.Packet.RESOURCE_ICL) + cancel_packet.send() self.link.cancel_outgoing_resource(self) else: self.link.cancel_incoming_resource(self)