예제 #1
0
    def __init__(self, prefix, nick=getpass.getuser()):
        self.handle = pyccn.CCN()
        self.flow = FlowController(prefix, self.handle)

        #XXX: temporary, until we allow fetching key from key storage
        self.key = self.handle.getDefaultKey()
        self.keylocator = pyccn.KeyLocator(self.key)

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

        member_name = self.members_uri.appendKeyID(
            fix_digest(self.key.publicKeyID))
        self.member_message = self.publish(member_name, nick)
        self.flow.put(self.member_message)
예제 #2
0
파일: ChatNet.py 프로젝트: chris-wood/PyCCN
	def __init__(self, prefix, nick=getpass.getuser()):
		self.handle = pyccn.CCN()
		self.flow = FlowController(prefix, self.handle)

		#XXX: temporary, until we allow fetching key from key storage
		self.key = self.handle.getDefaultKey()
		self.keylocator = pyccn.KeyLocator(self.key)

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

		member_name = self.members_uri.appendKeyID(fix_digest(self.key.publicKeyID))
		self.member_message = self.publish(member_name, nick)
		self.flow.put(self.member_message)
예제 #3
0
class ChatServer(pyccn.Closure):
    def __init__(self, prefix, nick=getpass.getuser()):
        self.handle = pyccn.CCN()
        self.flow = FlowController(prefix, self.handle)

        #XXX: temporary, until we allow fetching key from key storage
        self.key = self.handle.getDefaultKey()
        self.keylocator = pyccn.KeyLocator(self.key)

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

        member_name = self.members_uri.appendKeyID(
            fix_digest(self.key.publicKeyID))
        self.member_message = self.publish(member_name, nick)
        self.flow.put(self.member_message)

    def listen(self):
        #listen to requests in namespace
        #self.handle.setInterestFilter(self.prefix, self)
        self.handle.run(-1)

    def publish(self, name, content):
        # Name
        co_name = name.appendSegment(0)

        # SignedInfo
        si = pyccn.SignedInfo()
        si.type = pyccn.CONTENT_DATA
        si.finalBlockID = pyccn.Name.num2seg(0)
        si.publisherPublicKeyDigest = self.key.publicKeyID
        si.keyLocator = self.keylocator

        # ContentObject
        co = pyccn.ContentObject()
        co.content = content
        co.name = co_name
        co.signedInfo = si

        co.sign(self.key)
        return co

    def send_message(self, message):
        name = self.prefix.appendVersion()
        co = self.publish(name, message)
        self.flow.put(co)

    def upcall(self, kind, upcallInfo):
        interest = upcallInfo.Interest
        name = interest.name

        log.debug("Got request for: %s" % name)

        if self.message.matchesInterest(interest):
            log.debug("Publishing content")
            self.handle.put(self.message)
            return pyccn.RESULT_INTEREST_CONSUMED

        if self.member_message.matchesInterest(interest):
            log.debug("Publishing member's name")
            self.handle.put(self.member_message)
            return pyccn.RESULT_INTEREST_CONSUMED

        log.error("Got unknown request: %s" % name)

        return pyccn.RESULT_OK
예제 #4
0
파일: ChatNet.py 프로젝트: Emat12/PyCCN
class ChatServer(Closure.Closure):
	def __init__(self, prefix, nick=getpass.getuser()):
		self.handle = CCN.CCN()
		self.flow = FlowController(prefix, self.handle)

		#XXX: temporary, until we allow fetching key from key storage
		self.key = self.handle.getDefaultKey()
		self.keylocator = Key.KeyLocator(self.key)

		self.prefix = Name.Name(prefix)
		self.members_uri = Name.Name(prefix)
		self.members_uri += "members"

		member_name = Name.Name(self.members_uri)
		member_name.appendKeyID(fix_digest(self.key.publicKeyID))
		self.member_message = self.publish(member_name, nick)
		self.flow.put(self.member_message)

	def listen(self):
		#listen to requests in namespace
		#self.handle.setInterestFilter(self.prefix, self)
		self.handle.run(-1)

	def publish(self, name, content):
		# Name
		co_name = Name.Name(name)
		co_name += b'\x00'

		# SignedInfo
		si = ContentObject.SignedInfo()
		si.type = ContentObject.ContentType.CCN_CONTENT_DATA
		si.finalBlockID = b'\x00'
		si.publisherPublicKeyDigest = self.key.publicKeyID
		si.keyLocator = self.keylocator

		# ContentObject
		co = ContentObject.ContentObject()
		co.content = content
		co.name = co_name
		co.signedInfo = si

		co.sign(self.key)
		return co

	def send_message(self, message):
		name = Name.Name(self.prefix)
		name.appendVersion()
		co = self.publish(name, message)
		self.flow.put(co)

	def upcall(self, kind, upcallInfo):
		interest = upcallInfo.Interest
		name = interest.name

		log.debug("Got request for: %s" % name)

		if self.message.matchesInterest(interest):
			log.debug("Publishing content")
			self.handle.put(self.message)
			return Closure.UPCALL_RESULT_INTEREST_CONSUMED

		if self.member_message.matchesInterest(interest):
			log.debug("Publishing member's name")
			self.handle.put(self.member_message)
			return Closure.UPCALL_RESULT_INTEREST_CONSUMED

		log.error("Got unknown request: %s" % name)

		return Closure.RESULT_OK