Пример #1
0
    def __init__(self, prefix, callback):
        self.gui_callback = callback
        self.friendly_names = {}

        self.handle = pyccn.CCN()
        self.chat_uri = pyccn.Name(prefix)
        self.members_uri = self.chat_uri + "members"

        self.net_pull = VersionedPull(self.chat_uri, None, handle=self.handle)

        self.default_key = self.handle.getDefaultKey()
        digest = fix_digest(self.default_key.publicKeyID)
        self.friendly_names[digest] = getpass.getuser()
Пример #2
0
	def __init__(self, prefix, callback):
		self.gui_callback = callback
		self.friendly_names = {}

		self.handle = pyccn.CCN()
		self.chat_uri = pyccn.Name(prefix)
		self.members_uri = self.chat_uri + "members"

		self.net_pull = VersionedPull(self.chat_uri, None, handle=self.handle)

		self.default_key = self.handle.getDefaultKey()
		digest = fix_digest(self.default_key.publicKeyID)
		self.friendly_names[digest] = getpass.getuser()
Пример #3
0
class ChatNet(object):
	def __init__(self, prefix, callback):
		self.gui_callback = callback
		self.friendly_names = {}

		self.handle = CCN.CCN()
		self.chat_uri = Name.Name(prefix)
		self.members_uri = Name.Name(prefix)
		self.members_uri += "members"

		self.net_pull = VersionedPull(self.chat_uri, None, handle=self.handle)

		self.default_key = self.handle.getDefaultKey();
		digest = fix_digest(self.default_key.publicKeyID)
		self.friendly_names[digest] = getpass.getuser()

	def pullData(self):
		co = self.net_pull.fetchNext()
		if not co:
			return

		text = unicode(co.content, "utf-8", "replace")
		digest = fix_digest(co.signedInfo.publisherPublicKeyDigest)
		nick = self.get_friendly_name(digest)

		self.gui_callback(nick, text)

	def get_friendly_name(self, digest):
		if digest in self.friendly_names:
			return self.friendly_names.get(digest)

		n = Name.Name(self.members_uri)
		n.appendKeyID(digest)
		co = self.handle.get(n)
		if not co:
			return "~unknown~"

		nick = unicode(co.content, "utf-8", "replace")
		self.friendly_names[digest] = nick

		return nick
Пример #4
0
class ChatNet(object):
    def __init__(self, prefix, callback):
        self.gui_callback = callback
        self.friendly_names = {}

        self.handle = pyccn.CCN()
        self.chat_uri = pyccn.Name(prefix)
        self.members_uri = self.chat_uri + "members"

        self.net_pull = VersionedPull(self.chat_uri, None, handle=self.handle)

        self.default_key = self.handle.getDefaultKey()
        digest = fix_digest(self.default_key.publicKeyID)
        self.friendly_names[digest] = getpass.getuser()

    def pullData(self):
        co = self.net_pull.fetchNext()
        if not co:
            return

        text = unicode(co.content, "utf-8", "replace")
        digest = fix_digest(co.signedInfo.publisherPublicKeyDigest)
        nick = self.get_friendly_name(digest)

        self.gui_callback(nick, text)

    def get_friendly_name(self, digest):
        if digest in self.friendly_names:
            return self.friendly_names.get(digest)

        n = self.members_uri.appendKeyID(digest)
        co = self.handle.get(n)
        if not co:
            return "~unknown~"

        nick = unicode(co.content, "utf-8", "replace")
        self.friendly_names[digest] = nick

        return nick