Exemple #1
0
    def _collect_top_hots(self):
        now = time()
        self._top_squares = []
        self._top_text = []

        for index, key in enumerate(self._hots):
            hot = self._hots[key]
            assert isinstance(hot, HotCache), hot
            if not hot.square:
                try:
                    hot.square = self._dispersy.get_community(hot.cid, load=True)
                except KeyError:
                    master = DummyMember(hot.cid)
                    hot.square = PreviewCommunity.join_community(master, self._my_member, self)

            if index < 10:
                if not hot.message and hot.last_requested < now - 10.0 and hot.sources:
                    hot.message = hot.square.fetch_hot_text(hot)

                if hot.message:
                    self._top_text.append(hot.message)

            if not hot.square in self._top_squares:
                self._top_squares.append(hot.square)
                if len(self._top_squares) == 10:
                    break

        if __debug__:
            for index, square in enumerate(self._top_squares):
                dprint(index, "] SQUARE ", square.cid.encode("HEX"), " - ", square.title)
            for index, message in enumerate(self._top_text):
                dprint(index, "]   TEXT ", message.community.cid.encode("HEX"), " - ", message.payload.text)
Exemple #2
0
 def __init__(self, callback, dispersy, port, ip="0.0.0.0"):
     while True:
         try:
             self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
             self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 870400)
             self.socket.bind((ip, port))
             self.socket.setblocking(0)
             if __debug__: dprint("Dispersy listening at ", port, force=True)
         except socket.error, error:
             port += 1
             continue
         break
Exemple #3
0
    def _gui_thread(self):
        callback = self._dispersy.callback
        while True:
            #TODO: Get the message from the user
            text = "Hello World! Its party time! %s" % time()
            if not text:
                break
            callback.register(self.create_text, (self.nick + u" says " + text,))
            yield 5.0

        dprint("Shutting down", force=1)
        callback.stop(wait=False)
        self._ui_callback.stop(wait=False)
Exemple #4
0
    def _select_and_announce_hot(self):
        meta = self._meta_messages[u"hots"]
        while True:
            # TODO yield 60.0, lowered for debugging
            yield 10.0
            # what is hot?
            # explicit: a message the user marked as 'hot'
            # implicit: a newly received message
            messages = sample(self._explicitly_hot_text, min(15, len(self._explicitly_hot_text)))
            messages.extend(sample(self._implicitly_hot_text, min(20-len(messages), len(self._implicitly_hot_text))))
            # TODO all messages should be unique

            if messages:
                if __debug__: dprint(len(messages), "x text")
                hots = [Hot(message.community.cid, message.authentication.member.mid, message.distribution.global_time) for message in messages]
                message = meta.impl(distribution=(self.global_time,), payload=(hots,))
                self._dispersy.store_update_forward([message], False, False, True)
Exemple #5
0
 def on_text(self, messages):
     for message in messages:
         if __debug__: dprint(message.payload.text, force=1)
         print "Message:", message.payload.text
         self.textMessageReceived.emit(message.payload.text)
Exemple #6
0
 def create_text(self, text, store=True, update=True, forward=True):
     assert isinstance(text, unicode)
     meta = self._meta_messages[u"text"]
     message = meta.impl(authentication=(self._my_member,), distribution=(self.claim_global_time(),), payload=(text,))
     self._dispersy.store_update_forward([message], store, update, forward)
     if __debug__: dprint(message, force=1)
Exemple #7
0
 def test(self):
     dprint("testing...")
     assert True
Exemple #8
0
 def on_search(self, messages):
     for message in messages:
         if __debug__: dprint("searching for \\", message.payload.expression, "\\")