def _on_cancel_service_received(self, newpacket, info): from twisted.internet.defer import Deferred from logs import lg from lib import serialization from services import driver from p2p import p2p_service from transport import packet_out if len(newpacket.Payload) > 1024 * 10: p2p_service.SendFail(newpacket, 'too long payload') return False try: json_payload = serialization.BytesToDict(newpacket.Payload, keys_to_text=True, values_to_text=True) json_payload['name'] json_payload['payload'] except: p2p_service.SendFail(newpacket, 'json payload invalid') return False service_name = json_payload['name'] lg.out( self.debug_level, "service_p2p_hookups.CancelService {%s} from %s" % ( service_name, newpacket.OwnerID, )) if not driver.is_exist(service_name): lg.warn("got wrong payload in %s" % newpacket) p2p_service.SendFail(newpacket, 'service %s not exist' % service_name) return False if not driver.is_on(service_name): p2p_service.SendFail(newpacket, 'service %s is off' % service_name) return False try: result = driver.cancel(service_name, json_payload['payload'], newpacket, info) except: lg.exc() p2p_service.SendFail(newpacket, 'request processing failed with exception') return False if not result: lg.out( self.debug_level, "service_p2p_hookups._send_cancel_service SKIP request %s" % service_name) return False if isinstance(result, Deferred): lg.out( self.debug_level, "service_p2p_hookups._send_cancel_service fired delayed execution" ) elif isinstance(result, packet_out.PacketOut): lg.out( self.debug_level, "service_p2p_hookups._send_cancel_service outbox packet sent") return True
def CancelService(request, info): if _Debug: lg.out(_DebugLevel, "p2p_service.CancelService") words = request.Payload.split(" ") if len(words) < 1: lg.warn("got wrong payload in %s" % request) return SendFail(request, "wrong payload") service_name = words[0] # TODO: - temporary keep that for backward compatibility if service_name == "storage": if not driver.is_started("service_supplier"): return SendFail(request, "supplier service is off") return driver.cancel("service_supplier", request, info) if not driver.is_exist(service_name): lg.warn("got wrong payload in %s" % request) return SendFail(request, "service %s not exist" % service_name) if not driver.is_started(service_name): return SendFail(request, "service %s is off" % service_name) return driver.cancel(service_name, request, info)
def CancelService(request, info): if _Debug: lg.out(_DebugLevel, "p2p_service.CancelService") # TODO: move code into driver module, use callback module here instead of direct call words = request.Payload.split(' ') if len(words) < 1: lg.warn("got wrong payload in %s" % request) return SendFail(request, 'wrong payload') service_name = words[0] # TODO: add validation if not driver.is_exist(service_name): lg.warn("got wrong payload in %s" % request) return SendFail(request, 'service %s not exist' % service_name) if not driver.is_on(service_name): return SendFail(request, 'service %s is off' % service_name) return driver.cancel(service_name, request, info)