Exemplo n.º 1
0
Arquivo: dc.py Projeto: LiPeK/dtella
    def debug_nodes(self, out, sortkey):

        osm = self.main.osm
        if not (osm and osm.syncd):
            out("Not syncd")
            return

        me = osm.me

        now = seconds()

        out("Online Nodes: {ipp, nb, persist, expire, uptime, dttag, nick}")

        lines = []

        for n in ([me] + osm.nodes):
            info = []
            info.append(binascii.hexlify(n.ipp).upper())

            if n.ipp in osm.pgm.pnbs:
                info.append("Y")
            else:
                info.append("N")

            if n.persist:
                info.append("Y")
            else:
                info.append("N")

            if n is me:
                info.append("%4d" % dcall_timeleft(osm.sendStatus_dcall))
            else:
                info.append("%4d" % dcall_timeleft(n.expire_dcall))

            info.append("%8d" % (now - n.uptime))
            info.append("%8s" % n.dttag[3:])
            info.append("(%s)" % n.nick)

            lines.append(info)

        if 1 <= sortkey <= 7:
            lines.sort(key=lambda l: l[sortkey-1])

        for line in lines:
            out(' '.join(line))
Exemplo n.º 2
0
    def debug_nodes(self, out, sortkey):

        osm = self.main.osm
        if not (osm and osm.syncd):
            out("Not syncd")
            return

        me = osm.me

        now = seconds()

        out("Online Nodes: {ipp, nb, persist, expire, uptime, dttag, nick}")

        lines = []

        for n in ([me] + osm.nodes):
            info = []
            info.append(binascii.hexlify(n.ipp).upper())

            if n.ipp in osm.pgm.pnbs:
                info.append("Y")
            else:
                info.append("N")

            if n.persist:
                info.append("Y")
            else:
                info.append("N")

            if n is me:
                info.append("%4d" % dcall_timeleft(osm.sendStatus_dcall))
            else:
                info.append("%4d" % dcall_timeleft(n.expire_dcall))

            info.append("%8d" % (now - n.uptime))
            info.append("%8s" % n.dttag[3:])
            info.append("(%s)" % n.nick)

            lines.append(info)

        if 1 <= sortkey <= 7:
            lines.sort(key=lambda l: l[sortkey - 1])

        for line in lines:
            out(' '.join(line))
Exemplo n.º 3
0
    def getStateData(self, packet):
        # All the state info common between BS and Br packets

        osm = self.main.osm
        CHECK(osm and osm.syncd)

        # Get the IRC Server, if it's ready
        ism = self.main.ism

        # Sequence number
        packet.append(self.nextPktNum())

        # Expiration time
        when = int(dcall_timeleft(self.sendState_dcall))
        packet.append(struct.pack("!H", when))

        # Session ID, uptime flags
        packet.append(osm.me.sesid)
        packet.append(struct.pack("!I", int(seconds() - osm.me.uptime)))
        packet.append(struct.pack("!B", core.PERSIST_BIT))

        chunks = []

        # Add info strings
        self.addInfoChunk(chunks)

        if ism:
            # Add the list of online nicks
            for dnick, infoindex in ism.getNicksAndInfo():
                self.addNickChunk(chunks, dnick, infoindex)

            self.addTopicChunk(
                chunks, ism.topic_whoset, ism.topic, changed=False)

            # Get bans list
            for ip, mask in ism.bans:
                self.addBanChunk(chunks, ip, mask, True)

            if ism.moderated:
                self.addModeratedChunk(chunks, True)

        chunks = ''.join(chunks)

        # Split data string into 1k blocks
        blocks = []
        for i in range(0, len(chunks), 1024):
            blocks.append(chunks[i:i+1024])

        block_hashes = [md5(b).digest() for b in blocks]

        # Add the list of block hashes
        packet.append(struct.pack("!B", len(block_hashes)))
        packet.extend(block_hashes)

        # Add the public key
        pubkey = long_to_bytes(self.rsa_obj.n)
        packet.append(struct.pack("!H", len(pubkey)))
        packet.append(pubkey)

        # Return hashes and blocks
        return block_hashes, blocks
Exemplo n.º 4
0
    def getStateData(self, packet):
        # All the state info common between BS and Br packets

        osm = self.main.osm
        CHECK(osm and osm.syncd)

        # Get the IRC Server, if it's ready
        ism = self.main.ism

        # Sequence number
        packet.append(self.nextPktNum())

        # Expiration time
        when = int(dcall_timeleft(self.sendState_dcall))
        packet.append(struct.pack("!H", when))

        # Session ID, uptime flags
        packet.append(osm.me.sesid)
        packet.append(struct.pack("!I", int(seconds() - osm.me.uptime)))
        packet.append(struct.pack("!B", core.PERSIST_BIT))

        chunks = []

        # Add info strings
        self.addInfoChunk(chunks)

        if ism:
            # Add the list of online nicks
            for dnick, infoindex in ism.getNicksAndInfo():
                self.addNickChunk(chunks, dnick, infoindex)

            self.addTopicChunk(chunks,
                               ism.topic_whoset,
                               ism.topic,
                               changed=False)

            # Get bans list
            for ip, mask in ism.bans:
                self.addBanChunk(chunks, ip, mask, True)

            if ism.moderated:
                self.addModeratedChunk(chunks, True)

        chunks = ''.join(chunks)

        # Split data string into 1k blocks
        blocks = []
        for i in range(0, len(chunks), 1024):
            blocks.append(chunks[i:i + 1024])

        block_hashes = [md5(b).digest() for b in blocks]

        # Add the list of block hashes
        packet.append(struct.pack("!B", len(block_hashes)))
        packet.extend(block_hashes)

        # Add the public key
        pubkey = long_to_bytes(self.rsa_obj.n)
        packet.append(struct.pack("!H", len(pubkey)))
        packet.append(pubkey)

        # Return hashes and blocks
        return block_hashes, blocks