def evaluateF2FCoreMessages(): while( f2fcore.f2fMessageAvailable()): # There can be several messages messagePtr = f2fcore.f2fReceiveMessage() if messagePtr: if f2fcore.f2fMessageIsForward( messagePtr ): # forward message sendOutSendIMBuffer( messagePtr ) f2fcore.f2fMessageRelease( messagePtr ) elif(f2fcore.f2fMessageIsRaw( messagePtr )): content = f2fcore.f2fMessageGetContent( messagePtr, MAXMessageSize) try: obj = pickle.loads(content) answer = (Group(f2fcore.f2fMessageGetGroup( messagePtr ), "unknown"), Peer(f2fcore.f2fMessageGetSourcePeer( messagePtr )), obj) f2f.pushReceiveData( answer ) except (pickle.PicklingError, IndexError, KeyError): print "Problem unpickling: %s"%repr(content) # TODO: find better solution f2fcore.f2fMessageRelease( messagePtr ) elif f2fcore.f2fMessageIsText(messagePtr): print "Buffer is text. Content:", \ f2fcore.f2fMessageGetContent(MAXMessageSize) f2fcore.f2fMessageRelease( messagePtr ) elif f2fcore.f2fMessageIsJob(messagePtr): myGroup = f2f.Group(f2fcore.f2fMessageGetGroup( messagePtr ),"unknown") # TODO: make sure it is not unknown myInitiator = f2f.Peer(f2fcore.f2fMessageGetSourcePeer( messagePtr ) ) job = f2fcore.f2fMessageGetJob(messagePtr, MAXMessageSize).strip() + "\n" # make sure it ends with a new line and no blanks f2fcore.f2fMessageRelease( messagePtr ) # release before starting to avoid double starts # TODO: make sure to execute only one print "Starting job***************" #print "Job:",job,":Jobend" jobcompiled = compile( job, '<f2f job>', 'exec') #jobcompiled = job jobslavethread = Thread(target=runjob,args=(myGroup,myInitiator,jobcompiled)) #exec(jobcompiled) jobslavethread.start()
def sendOutSendIMBuffer(messagePtr): while (True): nextpeer = f2fcore.f2fMessageGetNextLocalPeerID(messagePtr) if( nextpeer < 0 ): break sendMessage( nextpeer, f2fcore.f2fMessageGetContent(messagePtr,MAXMessageSize) )