def dispatch(self, msg, owner): serviceID = msg["service_id"] if not serviceID in self.services: raise Exception("Bad Service %d" % serviceID) service = self.services[serviceID] service.handle(msg, owner) print("Server Dispatcher dispatching!")
def dispatch(self, msg, owner): try: serviceID = msg['service_id'] if not service_id in self.services: raise Exception('bad service %d' % serviceID) service = self.services[serviceID] service.handle(msg, owner) except (BaseException, e): print ("error in client dispatcher dispatching") print (e)
def handle(comingFrom, goingTo, data, forward, reply): try: if len(data)==0: forward(data) return bundle = Bundle(data) bundle.display() forward(data) return if bundle.destination != LOCAL_EID[4:]: forward(data) return if bundle.isstatusreport(): forward(data) print "Status Report!" #TODO: do it better, instead of instanciating bundle AND statusreport statusReport = statusreport(data) statusReport.display() storage.report(statusReport) elif bundle.getBlock(200) != None: #elif bundle.destination == LOCAL_EID[4:]:#"//village.bytewalla.com/": # forward(data) print "From: ", comingFrom print "To: ", goingTo serviceBlock = ServiceBlock(bundle.getBlock(200).payload) #if we are authorized to handle the request if serviceBlock.destination == "" or serviceBlock.destination == LOCAL_EID[4:]: try:#try to handle the request. If we can't, forward it. #TODO: store and confirm delivery? service.handle(serviceBlock.service, bundle.payloadBlock.payload) forward(data) return except: pass #the request could not be handled storage.store(bundle) if serviceBlock.destination == "": destination = service.getDestination() if destination == None: raise Exception("No destination for this service") serviceBlock.destination = destination else: destination = serviceBlock.destination bundle.primaryBlock.destination = destination priority = service.getPriority(serviceBlock.service) if priority != None: bundle.setPriority(priority) #bundle.getBlock(200).controlFlags = bundle.getBlock(200).controlFlags | (1<<2)#set processed bundle.invokeReports() #TODO: maybe its not necessary to do that bundle.getBlock(200).payload = serviceBlock.serialize() bundle.display() #if Caching.caching(bundle): #bundle2 = Bundle(bundle.serialize()) #bundle2.display() forward(bundle.serialize()) else: forward(data) except NotSegment: forward(data) except Exception, e: print "Bundle handle error: "+str(e) traceback.print_exc() forward(data)